Search in sources :

Example 1 with PublishedServiceDirectoryChangeEvent

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));
            }
        }
    }
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) PublishedServiceDirectoryChangeEvent(org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent) Collection(java.util.Collection) ID(org.eclipse.ecf.core.identity.ID)

Example 2 with PublishedServiceDirectoryChangeEvent

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));
    }
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) PublishedServiceDirectoryChangeEvent(org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 3 with PublishedServiceDirectoryChangeEvent

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();
        }
    });
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) PublishedServiceDirectoryChangeEvent(org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ECFException(org.eclipse.ecf.core.util.ECFException) SharedObjectInitException(org.eclipse.ecf.core.sharedobject.SharedObjectInitException)

Aggregations

PublishedServiceDescriptor (org.eclipse.ecf.pubsub.PublishedServiceDescriptor)3 PublishedServiceDirectoryChangeEvent (org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 ID (org.eclipse.ecf.core.identity.ID)1 SharedObjectInitException (org.eclipse.ecf.core.sharedobject.SharedObjectInitException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1