/** {@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); } } }