Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
  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);
  }