Search in sources :

Example 11 with ISharedObjectManager

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

use of org.eclipse.ecf.core.sharedobject.ISharedObjectManager 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)

Example 13 with ISharedObjectManager

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

the class RssServerSOContainer method main.

public static void main(String[] args) throws Exception {
    RssServerSOContainerGroup[] serverGroups = null;
    final List servers = new ArrayList();
    int port = DEFAULT_PORT;
    if (args.length > 0) {
        if (args[0].equals("-p")) {
            port = Integer.parseInt(args[1]);
        }
    }
    // Get server identity
    final String serverName = "//" + InetAddress.getLocalHost().getHostName() + ":" + port;
    serverGroups = new RssServerSOContainerGroup[1];
    // Setup server group
    serverGroups[0] = new RssServerSOContainerGroup(port);
    // Create identity for server
    final ID id = IDFactory.getDefault().createStringID(serverName);
    // Create server config object with identity and default timeout
    final SOContainerConfig config = new SOContainerConfig(id);
    // Make server instance
    System.out.println("Creating ECF server container...");
    final RssServerSOContainer server = new RssServerSOContainer(config, serverGroups[0], DEFAULT_KEEPALIVE);
    // Setup join policy
    ((ISharedObjectContainerGroupManager) server).setConnectPolicy(new IConnectHandlerPolicy() {

        public PermissionCollection checkConnect(Object address, ID fromID, ID targetID, String targetGroup, Object connectData) throws Exception {
            System.out.println("JOIN Addr=" + address + ";From=" + fromID + ";Group=" + targetGroup + ";Data=" + connectData);
            return null;
        }

        public void refresh() {
            System.out.println("joinPolicy.refresh()");
        }
    });
    // Setup add shared object policy
    final ISharedObjectManager manager = server.getSharedObjectManager();
    manager.setRemoteAddPolicy(new ISharedObjectPolicy() {

        public PermissionCollection checkAddSharedObject(ID fromID, ID toID, ID localID, ReplicaSharedObjectDescription newObjectDescription) throws SecurityException {
            System.out.println("ADDSHAREDOBJECT From=" + fromID + ";To=" + toID + ";SharedObjectDesc=" + newObjectDescription);
            return null;
        }

        public void refresh() {
            System.out.println("sharedObjectPolicy.refresh()");
        }
    });
    serverGroups[0].putOnTheAir();
    servers.add(server);
    System.out.println("success!");
    System.out.println("Waiting for JOIN requests at '" + id.getName() + "'...");
    System.out.println("<Ctrl>+C to stop server");
}
Also used : PermissionCollection(java.security.PermissionCollection) IConnectHandlerPolicy(org.eclipse.ecf.core.security.IConnectHandlerPolicy) ArrayList(java.util.ArrayList) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) ReplicaSharedObjectDescription(org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription) SOContainerConfig(org.eclipse.ecf.provider.generic.SOContainerConfig) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ISharedObjectPolicy(org.eclipse.ecf.core.sharedobject.security.ISharedObjectPolicy) ISharedObjectContainerGroupManager(org.eclipse.ecf.core.sharedobject.ISharedObjectContainerGroupManager) ArrayList(java.util.ArrayList) List(java.util.List) ID(org.eclipse.ecf.core.identity.ID)

Aggregations

ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)13 ID (org.eclipse.ecf.core.identity.ID)11 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)9 IContainer (org.eclipse.ecf.core.IContainer)4 ISharedObjectContainer (org.eclipse.ecf.core.sharedobject.ISharedObjectContainer)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 ISharedObjectContext (org.eclipse.ecf.core.sharedobject.ISharedObjectContext)2 ReplicaSharedObjectDescription (org.eclipse.ecf.core.sharedobject.ReplicaSharedObjectDescription)2 SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)2 IPublishedService (org.eclipse.ecf.pubsub.IPublishedService)2 URISyntaxException (java.net.URISyntaxException)1 PermissionCollection (java.security.PermissionCollection)1 List (java.util.List)1 Map (java.util.Map)1 PlatformObject (org.eclipse.core.runtime.PlatformObject)1 IContainerListener (org.eclipse.ecf.core.IContainerListener)1 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 IConnectHandlerPolicy (org.eclipse.ecf.core.security.IConnectHandlerPolicy)1