From: Bill S. <wst...@co...> - 2005-04-19 20:19:35
|
I'm trying to create a Jython class that I can use to server as my interface to a daemon process on my local host. I've got a Jython script and Java class (can I just use my working java class in jython?) that does the connect and writes to the port fine. I'm trying convert this to a jython class and get nothing but 'invalid syntax' errors. The error happens at the following line... -> self.argusSocket = Socket(host, port) ^ This is the first class that I've tried. class... from java.lang import Object from java.io import * from java.net import * from java.util import Date class ArgusClient(Object): def __init__(self, host, port) : self.argusSocket = Socket(host, port) self.inputStream = BufferedReader( InputStreamReader(argusSocket.getInputStream())) self.outputStream = PrintWriter( OutputStreamWriter(argusSocket.getOutputStream()), 1) def sendMetric (self, prefix, epochtime, metrics): """sendMetric(prefix, epochtime, metricString) -> Create formatted metric string and send it to the ArgusDaemon. prefix = lower case prefic string epochtime = epoch time converted to minutes (/1000) metrics = string of the format name=value:name=value:...""" rtnValue = 0 argusSuccess = "PASS"; argusFailure = "FAIL"; argusFormat = "%s:%d:%s" metricString = argusFormat % (prefix, epochtime, metrics) self.outputStream.println(metricString) responseLine = self.inputStream.readLine() print responseline while responseLine != None: if (responseLine.indexOf(self.argusSuccess) != -1) rtnValue = 1; break; responseLine = self.inputStream.readLine() return rtnValue def close (self): """close() -> close the connection to the ArgusDaemon""" argusBye = "BYE"; self.outputStream.println(bye) self.inputStream.close() self.outputStream.close() self.argusSocket.close() #test if __name__=='__main__': client=ArgusClient("localhost", 1029) date=Date() epochTime=date.getTime()/1000 success=client.sendMetric('smi_wl', epochTime, 'jvmfree=100005') client.close |