Search in sources :

Example 6 with PublishedServiceDescriptor

use of org.eclipse.ecf.pubsub.PublishedServiceDescriptor in project ecf by eclipse.

the class DiscoveryAgent method connected.

protected void connected() {
    if (isPrimary()) {
        try {
            config.getContext().sendCreate(null, new ReplicaSharedObjectDescription(getClass(), config.getSharedObjectID()));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else {
        ArrayList published = new ArrayList();
        ISharedObjectContext ctx = config.getContext();
        ISharedObjectManager mgr = ctx.getSharedObjectManager();
        ID[] ids = mgr.getSharedObjectIDs();
        ID containerID = ctx.getLocalContainerID();
        for (int i = 0; i < ids.length; ++i) {
            Object object = mgr.getSharedObject(ids[i]);
            if (object instanceof IPublishedService) {
                IPublishedService svc = (IPublishedService) object;
                Map props = svc.getProperties();
                published.add(new PublishedServiceDescriptor(containerID, ids[i], props));
            }
        }
        if (published.isEmpty())
            return;
        PublishedServiceDescriptor[] descriptors = new PublishedServiceDescriptor[published.size()];
        published.toArray(descriptors);
        try {
            ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.ADDED, descriptors)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) ArrayList(java.util.ArrayList) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) IOException(java.io.IOException) IPublishedService(org.eclipse.ecf.pubsub.IPublishedService) ReplicaSharedObjectDescription(org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription) ISharedObjectContext(org.eclipse.ecf.core.sharedobject.ISharedObjectContext) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) ID(org.eclipse.ecf.core.identity.ID) Map(java.util.Map)

Example 7 with PublishedServiceDescriptor

use of org.eclipse.ecf.pubsub.PublishedServiceDescriptor 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)7 IOException (java.io.IOException)4 Map (java.util.Map)3 PlatformObject (org.eclipse.core.runtime.PlatformObject)3 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)3 ISharedObjectContext (org.eclipse.ecf.core.sharedobject.ISharedObjectContext)3 IPublishedService (org.eclipse.ecf.pubsub.IPublishedService)3 PublishedServiceDirectoryChangeEvent (org.eclipse.ecf.pubsub.PublishedServiceDirectoryChangeEvent)3 Collection (java.util.Collection)2 ID (org.eclipse.ecf.core.identity.ID)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)1 ReplicaSharedObjectDescription (org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription)1 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)1 SharedObjectInitException (org.eclipse.ecf.core.sharedobject.SharedObjectInitException)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IPublishedServiceDirectory (org.eclipse.ecf.pubsub.IPublishedServiceDirectory)1