/** publishes only requested sensor data */ public void publishdata() { RootFactory theRF = getFactory(); if (!currentlypublishing.isEmpty()) { Task sensortask = null; SensorDataObj sensordata = null; for (int i = 0; i < currentlypublishing.size(); i++) { String type = (String) currentlypublishing.elementAt(i); System.out.println("In Sensor Plugin publishdata Type is :::::::::::::" + type); if (type.equalsIgnoreCase("SecurityException")) { if (fi.length > 0) { for (int z = 0; z < fi.length; z++) { Vector data = getsecurityevent(fi[z]); if (!data.isEmpty()) { for (int j = 0; j < data.size(); j++) { sensordata = new SensorDataObj( (String) currentlypublishing.elementAt(i), new Date(System.currentTimeMillis()), (String) data.elementAt(j), nodename[z]); sensortask = MonitoringUtils.createTask( theRF, sensordata, MonitoringUtils.Send_SensorData_Preposition, MonitoringUtils.Send_Sensor_Data); publishAdd(sensortask); if (MonitoringUtils.debug > 0) System.out.println( "*****In sensor Plugin publishing security excep::****************************"); } } else { if (MonitoringUtils.debug > 0) System.out.println( "In Sensor Plugin got data vector for publishing security empty ********************************"); } } } } else { if (MonitoringUtils.debug > 0) System.out.println( "Currently publishing::::" + (String) currentlypublishing.elementAt(i)); sensordata = new SensorDataObj( (String) currentlypublishing.elementAt(i), new Date(System.currentTimeMillis()), (String) currentlypublishing.elementAt(i)); sensortask = MonitoringUtils.createTask( theRF, sensordata, MonitoringUtils.Send_SensorData_Preposition, MonitoringUtils.Send_Sensor_Data); publishAdd(sensortask); } } } }
/** * Publishes capabilities to it superior in form of a Task with verb<b> * SEND_CAPABILITIES_Verb</B>. It first find the Organization it is associated with and then reads * capabilities from roles specified in clustername-prototype-ini.dat. * * <p><B>Note Roles are specified for sensor/analyzer plugins in different format compared to * roles specified in Ultra*Log cluster.</B> <br> * for e.g <br> * Roles specified in a typical prototype-ini.dat is<br> * [OrganizationPG] <br> * Roles Collection<Role> "StrategicTransportationProvider,TransportationProvider"<br> * <br> * Roles specified for sensor/analyzer prototype-ini.dat is <br> * [OrganizationPG] <br> * Roles Collection<Role> "Sensor-POD:TCPSCAN,Analyzer-TCPSCAN"<br> */ public boolean publishcapabilities() { boolean published = false; if (self == null) { if (MonitoringUtils.debug > 0) System.out.println("Self was null in Sensor Plugin "); self = findself(); if (self != null) { if (Services.isEmpty()) { for (Iterator e = self.getOrganizationPG().getRoles().iterator(); e.hasNext(); ) { String role = ((Role) e.next()).getName(); if (MonitoringUtils.debug > 0) System.out.println("In Sensor Plugin publishcapabilities Role :" + role); if (role.startsWith(Type, 0)) { int index = role.indexOf('-'); if (index == -1) { System.out.println("Got a wrong format from ini file"); } else { Services = MonitoringUtils.parseString(role.substring(index + 1), ':'); } } } if (MonitoringUtils.debug > 0) { // System.out.println("Got roles first time is:::::::::::::::::: // :"+Services.toString()); DumpVector(Services); } } } } if (self != null) { if (MonitoringUtils.debug > 0) { System.out.println( "In sensor Plugin Creating send cap obj:%%%%%%%%%%%%%%%%%%%%%%%%%" + publishedcapabilities); DumpVector(Services); System.out.println("first time going to publish capabilities::::::::"); } SendCapabilitiesObj obj = new SendCapabilitiesObj(self, Type, Services); if (MonitoringUtils.debug > 0) System.out.println("In Sensor Plugin services to be send =" + obj.toString()); Task task = MonitoringUtils.createTask( getFactory(), obj, MonitoringUtils.OtherPreposition, MonitoringUtils.SEND_CAPABILITIES_Verb); publishAdd(task); published = true; } return published; }
private String[] findfiles(String startswith, String[] filelist) { Vector foundfiles = new Vector(); String temp; if (filelist == null) { return MonitoringUtils.toStringArray(foundfiles); } if (filelist.length > 0) { for (int i = 0; i < filelist.length; i++) { temp = filelist[i]; if (temp.startsWith(startswith)) { foundfiles.add(new String(temp)); } } } return MonitoringUtils.toStringArray(foundfiles); }
private String[] findlatest(String[] onlysecuritym, File dir) { Hashtable list = new Hashtable(); String filename; Vector parsed; Vector similarlist; String Key; if (onlysecuritym != null) { for (int i = 0; i < onlysecuritym.length; i++) { filename = onlysecuritym[i]; parsed = MonitoringUtils.parseString(filename, '_'); if (MonitoringUtils.debug > 0) { for (int z = 0; z < parsed.size(); z++) { System.out.println("parsed data is : " + z + " :: " + (String) parsed.elementAt(z)); } } if (parsed.size() > 2) { Key = (String) parsed.elementAt(1); if (list.containsKey(Key)) { similarlist = (Vector) list.get(Key); similarlist.add(filename); list.put(Key, similarlist); } else { similarlist = new Vector(); similarlist.add(filename); list.put(Key, similarlist); } } else { System.err.println("Error in parsing the log file name::" + filename); } } } Enumeration keylist = list.keys(); String nodename; String latestfile = null; Date latestdate = null; Date tempdate; File completepath; parsed = new Vector(); long ldate; for (; keylist.hasMoreElements(); ) { nodename = (String) keylist.nextElement(); similarlist = (Vector) list.get(nodename); for (int i = 0; i < similarlist.size(); i++) { filename = (String) similarlist.elementAt(i); if (latestdate == null) { completepath = new File(dir, filename); ldate = completepath.lastModified(); latestdate = new Date(ldate); latestfile = filename; } else { completepath = new File(dir, filename); ldate = completepath.lastModified(); tempdate = new Date(ldate); if (tempdate.after(latestdate)) { latestdate = tempdate; latestfile = filename; } latestfile = filename; } } if (latestfile != null) parsed.add(latestfile); else System.err.println("Could not get latest file for ::" + nodename); latestdate = null; latestfile = null; } return MonitoringUtils.toStringArray(parsed); }