Index: trunk/web/addons/job_monarch/jobstore.php
===================================================================
--- trunk/web/addons/job_monarch/jobstore.php	(revision 646)
+++ trunk/web/addons/job_monarch/jobstore.php	(revision 648)
@@ -1,6 +1,10 @@
 <?php
 
-ini_set("memory_limit","200M");
+ini_set("memory_limit","1G");
 set_time_limit(0);
+
+//ini_set("xdebug.profiler_output_dir","/tmp");
+//ini_set("xdebug.profiler_output_name","timestamp");
+//ini_set("xdebug.profiler_enable","1");
 
 $c			= $_POST['c'];
@@ -53,94 +57,39 @@
 $_GET['c']		= $c;
 
-global $c, $clustername, $cluster;
+global $c, $clustername, $cluster, $mySession;
 
 include_once "./libtoga.php";
 
-function makeSession()
-{
-	$ds             = new DataSource();
-	$myxml_data     = &$ds->getData();
-
-	unset( $_SESSION['data'] );
-
-	$_SESSION['data']		= &$myxml_data;
-	$_SESSION['gather_time']	= time();
-}
-
-global $session_active, $_SESSION;
-
-function checkSessionPollInterval( $poll_interval )
-{
-	global $session_active, $_SESSION;
-
-	if( ! session_active )
-	{
-		return 0;
-	}
-
-	if( isset( $_SESSION['poll_interval'] ) )
-	{
-		if( $poll_interval <> $_SESSION['poll_interval'] )
-		{
-			$_SESSION['poll_interval']	= $poll_interval;
-		}
-	}
-	else
-	{
-		$_SESSION['poll_interval']	= $poll_interval;
-	}	
-
-	session_write_close();
-
-	$session_active	= false;
-}
-
-function checkSession()
-{
-	global $session_active, $_SESSION;
-
-	session_start();
-
-	$session_active 	= true;
-
-	// I got nothing; create session
-	//
-	if( ! isset( $_SESSION['gather_time'] ) || ! isset( $_SESSION['data'] ) )
-	{
-		makeSession();
-
-		return 0;	
-	}
-
-	if( isset( $_SESSION['poll_interval'] ) )
-	{
-		$gather_time	= $_SESSION['gather_time'];
-		$poll_interval	= $_SESSION['poll_interval'];
-
-		$cur_time	= time();
-
-		// If poll_interval time elapsed since last update; recreate session
-		//
-		if( ($cur_time - $gather_time) >= $poll_interval )
-		{
-			makeSession();
-
-			return 0;	
-		}
-	}
-}
-
-checkSession();
-
-global $jobs, $metrics;
-
-$data_gatherer  = new DataGatherer( $clustername );
-$data_gatherer->parseXML( &$_SESSION['data'] );
-
-$heartbeat      = &$data_gatherer->getHeartbeat();
-$jobs           = &$data_gatherer->getJobs();
-//$gnodes         = $data_gatherer->getNodes();
-$cpus           = &$data_gatherer->getCpus();
-$use_fqdn       = &$data_gatherer->getUsingFQDN();
+
+global $jobs, $metrics, $session;
+
+//printf( "c %s\n", $clustername );
+
+$mySession	= new SessionHandler( $clustername );
+$mySession->checkSession();
+
+$session	= &$mySession->getSession();
+$myXML		= $session['data'];
+
+//printf( "gt %s\n", $session['gather_time'] );
+//printf( "pi %s\n", $session['poll_interval'] );
+
+$myData		= new DataGatherer( $clustername );
+$myData->parseXML( $myXML );
+
+$mySession->updatePollInterval( $myData->getPollInterval() );
+//printf( "pi %s\n", $myData->getPollInterval() );
+//printf( "pi %s\n", $session['poll_interval'] );
+$mySession->endSession();
+
+
+$heartbeat      = &$myData->getHeartbeat();
+$jobs           = &$myData->getJobs();
+$cpus           = &$myData->getCpus();
+$use_fqdn       = &$myData->getUsingFQDN();
+
+//print_r( $jobs );
+
+//print_r( $session );
 
 // The ext grid script will send  a task field which will specify what it wants to do
@@ -518,5 +467,5 @@
 {
 	global $jobs, $jobids, $clustername, $metrics, $jid, $p_metricname;
-	global $always_timestamp, $always_constant;
+	global $always_timestamp, $always_constant, $mySession;
 
 	$display_nodes	= array();
@@ -566,5 +515,5 @@
 		$poll_interval	= (int) $jobs[$jid]['poll_interval'];
 
-		checkSessionPollInterval( $poll_interval );
+		//$mySession->updatePollInterval( $poll_interval );
 
 		$time		= time();
@@ -636,5 +585,5 @@
 	global $jobs, $hearbeat, $pstart, $pend;
 	global $sortfield, $sortorder, $query, $host;
-	global $jid, $owner, $queue,  $status;
+	global $jid, $owner, $queue,  $status, $mySession;
 
 	$job_count		= count( $jobs );
@@ -686,5 +635,5 @@
 		$poll_interval		= (int) $jobs[$jobid]['poll_interval'];
 
-		checkSessionPollInterval( $poll_interval );
+		//$mySession->updatePollInterval( $poll_interval );
 
 		if( $jr['status'] == 'R' )
