Exemplo n.º 1
1
  /** {@inheritDoc} */
  protected void getNewMonitors(Map<String, Monitor> map) throws MonitorException {
    assert Thread.holdsLock(this);

    int used = prologue.getUsed();
    long modificationTime = prologue.getModificationTimeStamp();

    if ((used > lastUsed) || (lastModificationTime > modificationTime)) {

      lastUsed = used;
      lastModificationTime = modificationTime;

      Monitor monitor = getNextMonitorEntry();
      while (monitor != null) {
        String name = monitor.getName();

        // guard against duplicate entries
        if (!map.containsKey(name)) {
          map.put(name, monitor);

          /*
           * insertedMonitors is null when called from pollFor()
           * via buildMonitorMap(). Since we update insertedMonitors
           * at the end of buildMonitorMap(), it's ok to skip the
           * add here.
           */
          if (insertedMonitors != null) {
            insertedMonitors.add(monitor);
          }
        }
        monitor = getNextMonitorEntry();
      }
    }
  }
 /** {@inheritDoc} */
 public void removeHostListener(HostListener listener) {
   /*
    * XXX: if a disconnect method is added, make sure it calls
    * this method to unregister this object from the watcher. otherwise,
    * an unused MonitoredHostProvider instance may go uncollected.
    */
   synchronized (listeners) {
     listeners.remove(listener);
     if (listeners.isEmpty() && (task != null)) {
       task.cancel();
       task = null;
     }
   }
 }
  /** Fire hostDisconnectEvent events. */
  void fireDisconnectedEvents() {
    ArrayList registered = null;
    HostEvent ev = null;

    synchronized (listeners) {
      registered = (ArrayList) listeners.clone();
    }

    for (Iterator i = registered.iterator(); i.hasNext(); /* empty */ ) {
      HostListener l = (HostListener) i.next();
      if (ev == null) {
        ev = new HostEvent(this);
      }
      l.disconnected(ev);
    }
  }
  /**
   * Fire VmStatusChangeEvent events to HostListener objects
   *
   * @param active Set of Integer objects containing the local Vm Identifiers of the active JVMs
   * @param started Set of Integer objects containing the local Vm Identifiers of new JVMs started
   *     since last interval.
   * @param terminated Set of Integer objects containing the local Vm Identifiers of terminated JVMs
   *     since last interval.
   */
  private void fireVmStatusChangedEvents(Set active, Set started, Set terminated) {
    ArrayList registered = null;
    VmStatusChangeEvent ev = null;

    synchronized (listeners) {
      registered = (ArrayList) listeners.clone();
    }

    for (Iterator i = registered.iterator(); i.hasNext(); /* empty */ ) {
      HostListener l = (HostListener) i.next();
      if (ev == null) {
        ev = new VmStatusChangeEvent(this, active, started, terminated);
      }
      l.vmStatusChanged(ev);
    }
  }
 /** {@inheritDoc} */
 public void addHostListener(HostListener listener) {
   synchronized (listeners) {
     listeners.add(listener);
     if (task == null) {
       task = new NotifierTask();
       timer.schedule(task, 0, interval);
     }
   }
 }