Index: trunk/jobarchived/jobarchived.py
===================================================================
--- trunk/jobarchived/jobarchived.py	(revision 286)
+++ trunk/jobarchived/jobarchived.py	(revision 287)
@@ -450,12 +450,15 @@
 	"""Main class for processing XML and acting with it"""
 
-	def __init__( self ):
+	def __init__( self, XMLSource ):
 		"""Setup initial XML connection and handlers"""
 
-		self.myXMLGatherer = XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] ) 
-		self.myXMLSource = self.myXMLGatherer.getFileObject()
-		self.myXMLHandler = TorqueXMLHandler()
-		self.myXMLError = XMLErrorHandler()
-		self.config = GangliaConfigParser( GMETAD_CONF )
+		self.myXMLGatherer	= XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] ) 
+		#self.myXMLSource	= self.myXMLGatherer.getFileObject()
+		self.myXMLSource	= XMLSource
+		print self.myXMLSource
+		self.myXMLHandler	= TorqueXMLHandler()
+		self.myXMLError		= XMLErrorHandler()
+
+		self.config		= GangliaConfigParser( GMETAD_CONF )
 
 	def run( self ):
@@ -466,9 +469,11 @@
 		while( 1 ):
 
-			self.myXMLSource = self.myXMLGatherer.getFileObject()
+			#self.myXMLSource = self.mXMLGatherer.getFileObject()
 			debug_msg( 1, 'torque_xml_thread(): Parsing..' )
 
+			my_data	= self.myXMLSource.getData()
+
 			try:
-				xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
+				xml.sax.parseString( my_data, self.myXMLHandler, self.myXMLError )
 			except socket.error, msg:
 				debug_msg( 0, 'ERROR: Socket error in connect to datasource!: %s' %msg )
@@ -769,6 +774,19 @@
 	"""Setup a connection and file object to Ganglia's XML"""
 
-	s = None
-	fd = None
+	s		= None
+	fd		= None
+	data		= None
+
+	# Time since the last update
+	#
+	LAST_UPDATE	= 0
+
+	# Minimum interval between updates
+	#
+	MIN_UPDATE_INT	= 10
+
+	# Is a update occuring now
+	#
+	update_now	= False
 
 	def __init__( self, host, port ):
@@ -777,9 +795,11 @@
 		self.host = host
 		self.port = port
-		self.connect()
-		self.makeFileDescriptor()
-
-	def connect( self ):
+
+		self.retrieveData()
+
+	def retrieveData( self ):
 		"""Setup connection to XML source"""
+
+		self.update_now	= True
 
 		for res in socket.getaddrinfo( self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM ):
@@ -796,4 +816,6 @@
 				continue
 
+			print self.s
+
 		    	try:
 
@@ -807,8 +829,24 @@
 		    	break
 
+		print self.s
+
 		if self.s is None:
 
 			debug_msg( 0, 'FATAL ERROR: Could not open socket or unable to connect to datasource!' )
+			self.update_now	= False
 			sys.exit( 1 )
+
+		else:
+			self.s.send( '\n' )
+
+			my_fp			= self.s.makefile( 'r' )
+			my_data			= my_fp.readlines()
+			my_data			= string.join( my_data, '' )
+
+			self.data		= my_data
+
+			self.LAST_UPDATE	= time.time()
+
+		self.update_now	= False
 
 	def disconnect( self ):
@@ -816,5 +854,5 @@
 
 		if self.s:
-			self.s.shutdown( 2 )
+			#self.s.shutdown( 2 )
 			self.s.close()
 			self.s = None
@@ -825,11 +863,41 @@
 		self.disconnect()
 
-	def reconnect( self ):
+	def reGetData( self ):
 		"""Reconnect"""
+
+		while self.update_now:
+
+			# Must be another update in progress:
+			# Wait until the update is complete
+			#
+			time.sleep( 1 )
 
 		if self.s:
 			self.disconnect()
 
-		self.connect()
+		self.retrieveData()
+
+	def getData( self ):
+
+		"""Return the XML data"""
+
+		# If more than MIN_UPDATE_INT seconds passed since last data update
+		# update the XML first before returning it
+		#
+
+		cur_time	= time.time()
+
+		if ( cur_time - self.LAST_UPDATE ) > self.MIN_UPDATE_INT:
+
+			self.reGetData()
+
+		while self.update_now:
+
+			# Must be another update in progress:
+			# Wait until the update is complete
+			#
+			time.sleep( 1 )
+			
+		return self.data
 
 	def makeFileDescriptor( self ):
@@ -852,13 +920,15 @@
 	"""Main class for processing XML and acting with it"""
 
-	def __init__( self ):
+	def __init__( self, XMLSource ):
 		"""Setup initial XML connection and handlers"""
 
-		self.config = GangliaConfigParser( GMETAD_CONF )
-
-		self.myXMLGatherer = XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] ) 
-		self.myXMLSource = self.myXMLGatherer.getFileObject()
-		self.myXMLHandler = GangliaXMLHandler( self.config )
-		self.myXMLError = XMLErrorHandler()
+		self.config		= GangliaConfigParser( GMETAD_CONF )
+
+		self.myXMLGatherer	= XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] ) 
+		#self.myXMLSource	= self.myXMLGatherer.getFileObject()
+		self.myXMLSource	= XMLSource
+		print self.myXMLSource
+		self.myXMLHandler	= GangliaXMLHandler( self.config )
+		self.myXMLError		= XMLErrorHandler()
 
 	def run( self ):
@@ -971,8 +1041,10 @@
 		debug_msg( 1, 'ganglia_parse_thread(): started.' )
 		debug_msg( 1, 'ganglia_parse_thread(): Parsing XML..' )
-		self.myXMLSource = self.myXMLGatherer.getFileObject()
+		#self.myXMLSource = self.myXMLGatherer.getFileObject()
+		
+		my_data	= self.myXMLSource.getData()
 
 		try:
-			xml.sax.parse( self.myXMLSource, self.myXMLHandler, self.myXMLError )
+			xml.sax.parseString( my_data, self.myXMLHandler, self.myXMLError )
 		except socket.error, msg:
 			debug_msg( 0, 'ERROR: Socket error in connect to datasource!: %s' %msg )
@@ -1479,6 +1551,8 @@
 	"""Threading start"""
 
-	myTorqueProcessor = TorqueXMLProcessor()
-	myGangliaProcessor = GangliaXMLProcessor()
+	myXMLSource		= XMLGatherer( ARCHIVE_XMLSOURCE.split( ':' )[0], ARCHIVE_XMLSOURCE.split( ':' )[1] )
+
+	myTorqueProcessor	= TorqueXMLProcessor( myXMLSource )
+	myGangliaProcessor	= GangliaXMLProcessor( myXMLSource )
 
 	try:
