Prof. Guido Russo - Scope - Università degli Studi di Napoli Federico II
Prof. Guido Russo - Scope - Università degli Studi di Napoli Federico II
Prof. Guido Russo - Scope - Università degli Studi di Napoli Federico II
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
public List commandQueue;<br />
public void updateCommandQueue(CommandInstance comm){<br />
if(comm!=null) this.commandQueue.add(comm);<br />
for(int i = 0; i < this.commandQueue.size(); ){<br />
try{<br />
commandQueue.get(i).getProcess().exitValue();<br />
commandQueue.remove(i);<br />
}catch(IllegalThreadStateException e){<br />
i++;<br />
continue;<br />
}<br />
}<br />
}<br />
public Webpowerfarm(String XMLpathDir, String COMpathDir) throws Exception{<br />
try{<br />
this.database = new XMLDatabase(XMLpathDir);<br />
this.ping = new Ping(10, 10, 60);<br />
this.command = new PerlCommand(COMpathDir, "powerfarm.pl");<br />
this.commandQueue = new ArrayList();<br />
this.synch();<br />
}<br />
catch(Exception e){<br />
throw e;}<br />
finally<br />
{}<br />
}<br />
public IDatabase getDatabase(){ return this.database; }<br />
public Ping getPing(){ return this.ping; }<br />
public ICommand getCommand(){ return this.command; }<br />
public boolean synch(){<br />
try{<br />
List oldSet = new ArrayList();<br />
List newSet = Arrays.asList(this.database.getDevices());<br />
for(Enumeration en = this.ping.getStatus().keys(); en.hasMoreElements();)<br />
oldSet.add(en.nextElement());<br />
//delete old<br />
for(String d : oldSet){<br />
if(!newSet.contains(d))<br />
this.ping.delete(d);<br />
}<br />
//add new<br />
for(String d : newSet){<br />
if(!this.ping.contains(d)){<br />
String address, command;<br />
String[] commandArgs;<br />
try{<br />
Hashtable attr = database.getAttributesOfDevice(d);<br />
Hashtable pingAttr =<br />
database.getActionAttributesOfDevice(d, "check-on");<br />
address = attr.get("address");<br />
command = pingAttr.get("plugin");<br />
commandArgs = pingAttr.get("args").split(" ");<br />
}<br />
catch(Exception e){<br />
address = command = "";<br />
commandArgs = new String[]{};<br />
}<br />
if(command!=null && !command.equals("")){<br />
int lastIndexOfDot = command.lastIndexOf(".");<br />
Pietro Neroni 566/2833 Pagina 100 <strong>di</strong> 117