Search in sources :

Example 1 with ISharedObjectContext

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext in project ecf by eclipse.

the class LocalAgent method subscribe.

public void subscribe(ID containerID, ID requestorID) {
    synchronized (subscriptionMutex) {
        if (subscriptions == null)
            subscriptions = new HashSet();
        ISharedObjectContext ctx = config.getContext();
        try {
            if (subscriptions.add(containerID)) {
                ctx.sendCreate(containerID, createRemoteAgentDescription(requestorID));
            } else {
                SubscribeMessage msg = new SubscribeMessage(requestorID);
                ctx.sendMessage(containerID, SerializationUtil.serialize(msg));
            }
        } catch (IOException e) {
            // TODO Log me!
            e.printStackTrace();
        }
    }
}
Also used : SubscribeMessage(org.eclipse.ecf.pubsub.impl.SubscribeMessage) ISharedObjectContext(org.eclipse.ecf.core.sharedobject.ISharedObjectContext) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with ISharedObjectContext

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext 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 3 with ISharedObjectContext

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext 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 4 with ISharedObjectContext

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext 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 5 with ISharedObjectContext

use of org.eclipse.ecf.core.sharedobject.ISharedObjectContext 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)6 ISharedObjectContext (org.eclipse.ecf.core.sharedobject.ISharedObjectContext)6 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)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 HashSet (java.util.HashSet)1 ReplicaSharedObjectDescription (org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription)1 SubscribeMessage (org.eclipse.ecf.pubsub.impl.SubscribeMessage)1 UnsubscribeMessage (org.eclipse.ecf.pubsub.impl.UnsubscribeMessage)1