Search in sources :

Example 1 with IPublishedService

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

the class DiscoveryAgent method deactivated.

protected void deactivated(ID sharedObjectID) {
    if (isPrimary())
        return;
    ISharedObjectContext ctx = config.getContext();
    Object object = ctx.getSharedObjectManager().getSharedObject(sharedObjectID);
    if (object instanceof IPublishedService) {
        IPublishedService svc = (IPublishedService) object;
        Map props = svc.getProperties();
        PublishedServiceDescriptor desc = new PublishedServiceDescriptor(ctx.getLocalContainerID(), sharedObjectID, props);
        try {
            ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.REMOVED, desc)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) ISharedObjectContext(org.eclipse.ecf.core.sharedobject.ISharedObjectContext) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IPublishedService(org.eclipse.ecf.pubsub.IPublishedService) IOException(java.io.IOException) Map(java.util.Map)

Example 2 with IPublishedService

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

the class DiscoveryAgent method activated.

protected void activated(ID sharedObjectID) {
    if (isPrimary())
        return;
    ISharedObjectContext ctx = config.getContext();
    Object object = ctx.getSharedObjectManager().getSharedObject(sharedObjectID);
    if (object instanceof IPublishedService) {
        IPublishedService svc = (IPublishedService) object;
        Map props = svc.getProperties();
        PublishedServiceDescriptor desc = new PublishedServiceDescriptor(ctx.getLocalContainerID(), sharedObjectID, props);
        try {
            ctx.sendMessage(config.getHomeContainerID(), SerializationUtil.serialize(new DiscoveryMessage(DiscoveryMessage.ADDED, desc)));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) ISharedObjectContext(org.eclipse.ecf.core.sharedobject.ISharedObjectContext) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) PlatformObject(org.eclipse.core.runtime.PlatformObject) IPublishedService(org.eclipse.ecf.pubsub.IPublishedService) IOException(java.io.IOException) Map(java.util.Map)

Example 3 with IPublishedService

use of org.eclipse.ecf.pubsub.IPublishedService 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 4 with IPublishedService

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

the class SubscriptionAgent method activated.

protected void activated() {
    ISharedObjectContext ctx = config.getContext();
    if (isPrimary()) {
        try {
            ctx.sendCreate(containerID, createReplicaDescription());
        } catch (IOException e) {
            callback.requestFailed(e);
            ctx.getSharedObjectManager().removeSharedObject(config.getSharedObjectID());
        }
        return;
    }
    ISharedObjectManager mgr = ctx.getSharedObjectManager();
    ISharedObject so = mgr.getSharedObject(sharedObjectID);
    try {
        ID homeContainerID = config.getHomeContainerID();
        if (so instanceof IPublishedService) {
            IPublishedService svc = (IPublishedService) so;
            svc.subscribe(homeContainerID, config.getSharedObjectID());
        } else {
            ctx.sendCreateResponse(homeContainerID, new IllegalArgumentException("Not an IPublishedService."), -1);
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        ctx.getSharedObjectManager().removeSharedObject(config.getSharedObjectID());
    }
}
Also used : ISharedObjectContext(org.eclipse.ecf.core.sharedobject.ISharedObjectContext) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) IOException(java.io.IOException) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) ID(org.eclipse.ecf.core.identity.ID) IPublishedService(org.eclipse.ecf.pubsub.IPublishedService)

Aggregations

IOException (java.io.IOException)4 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)4 ISharedObjectContext (org.eclipse.ecf.core.sharedobject.ISharedObjectContext)4 IPublishedService (org.eclipse.ecf.pubsub.IPublishedService)4 Map (java.util.Map)3 PlatformObject (org.eclipse.core.runtime.PlatformObject)3 PublishedServiceDescriptor (org.eclipse.ecf.pubsub.PublishedServiceDescriptor)3 ID (org.eclipse.ecf.core.identity.ID)2 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)2 ArrayList (java.util.ArrayList)1 ReplicaSharedObjectDescription (org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription)1