use of org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent in project ecf by eclipse.
the class PublishedServiceDirectory method disconnected.
protected void disconnected(IContainerDisconnectedEvent event) {
ID containerID = event.getTargetID();
if (!containerID.equals(event.getLocalContainerID())) {
synchronized (this) {
Collection values = (Collection) services.remove(event.getTargetID());
if (values != null) {
PublishedServiceDescriptor[] buf = new PublishedServiceDescriptor[values.size()];
values.toArray(buf);
fireServiceChangedEvent(new PublishedServiceDirectoryChangeEvent(this, PublishedServiceDirectoryChangeEvent.REMOVED, buf));
}
}
}
}
use of org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent in project ecf by eclipse.
the class PublishedServiceDirectory method handleDiscovery.
void handleDiscovery(ID containerID, DiscoveryMessage msg) {
PublishedServiceDescriptor[] descriptors = msg.getDescriptors();
synchronized (this) {
Collection values = (Collection) services.get(containerID);
if (values == null) {
values = new HashSet();
services.put(containerID, values);
}
if (msg.getKind() == DiscoveryMessage.ADDED) {
values.addAll(Arrays.asList(descriptors));
} else {
values.removeAll(Arrays.asList(descriptors));
if (values.isEmpty())
services.remove(containerID);
}
int kind = msg.getKind() == DiscoveryMessage.ADDED ? PublishedServiceDirectoryChangeEvent.ADDED : PublishedServiceDirectoryChangeEvent.REMOVED;
fireServiceChangedEvent(new PublishedServiceDirectoryChangeEvent(this, kind, descriptors));
}
}
use of org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent in project ecf by eclipse.
the class PublishedServiceDirectory method addReplicatedServiceListener.
public synchronized void addReplicatedServiceListener(final IPublishedServiceDirectoryListener listener) {
listeners.add(listener);
PublishedServiceDescriptor[] buf = new PublishedServiceDescriptor[services.values().size()];
services.values().toArray(buf);
final PublishedServiceDirectoryChangeEvent event = new PublishedServiceDirectoryChangeEvent(this, PublishedServiceDirectoryChangeEvent.ADDED, buf);
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
listener.publishedServiceDirectoryChanged(event);
}
public void handleException(Throwable exception) {
// TODO Auto-generated method stub
exception.printStackTrace();
}
});
}
Aggregations