Search in sources :

Example 1 with PublishedServiceDescriptor

use of org.eclipse.ecf.pubsub.PublishedServiceDescriptor 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 PublishedServiceDescriptor

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

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

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

the class PubSubView method init.

public void init(IViewSite site) throws PartInitException {
    super.init(site);
    final Action shareSomethingAction = new Action("Share something") {

        public void run() {
            try {
                IMasterModel sds = SharedModelFactory.getInstance().createSharedDataSource(container, IDFactory.getDefault().createGUID(), new AppendableList(), ListAppender.ID);
                if (sds == null)
                    MessageDialog.openError(getSite().getShell(), "Error", "Could not share anything.");
                else {
                    sharedLists.add(sds);
                    sharedListViewer.add(sds);
                }
            } catch (SharedObjectCreateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IDCreateException e) {
                throw new RuntimeException(e);
            }
        }
    };
    shareSomethingAction.setEnabled(false);
    IMenuManager mgr = site.getActionBars().getMenuManager();
    mgr.add(new Action("Start") {

        public void run() {
            container = CollabClient.getContainer(ResourcesPlugin.getWorkspace().getRoot());
            if (container == null) {
                MessageDialog.openError(getSite().getShell(), "Error", "Collaboration environment not found.");
                return;
            }
            IPublishedServiceDirectory directory = (IPublishedServiceDirectory) container.getAdapter(IPublishedServiceDirectory.class);
            viewer.setInput(directory);
            setEnabled(false);
            shareSomethingAction.setEnabled(true);
        }
    });
    mgr.add(shareSomethingAction);
    menuManager = new MenuManager();
    subscribeAction = new BaseSelectionListenerAction("Subscribe") {

        public void run() {
            PublishedServiceDescriptor desc = (PublishedServiceDescriptor) getStructuredSelection().getFirstElement();
            IPublishedServiceRequestor requestor = (IPublishedServiceRequestor) container.getAdapter(IPublishedServiceRequestor.class);
            requestor.subscribe(desc.getContainerID(), desc.getSharedObjectID(), new SubscriptionViewOpener());
        }

        protected boolean updateSelection(IStructuredSelection selection) {
            return !selection.isEmpty();
        }
    };
    subscribeAction.setEnabled(false);
    menuManager.add(subscribeAction);
    sharedListMenuManager = new MenuManager();
    appendAction = new BaseSelectionListenerAction("Append...") {

        public void run() {
            InputDialog dlg = new InputDialog(getSite().getShell(), "Append to Shared List", "Enter element to append:", null, null);
            dlg.open();
            String value = dlg.getValue();
            if (value != null) {
                LocalAgent model = (LocalAgent) getStructuredSelection().getFirstElement();
                AppendableList list = (AppendableList) model.getData();
                if (list.add(value)) {
                    try {
                        model.update(value);
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }

        protected boolean updateSelection(IStructuredSelection selection) {
            return !selection.isEmpty();
        }
    };
    appendAction.setEnabled(false);
    sharedListMenuManager.add(appendAction);
}
Also used : IPublishedServiceDirectory(org.eclipse.ecf.pubsub.IPublishedServiceDirectory) LocalAgent(org.eclipse.ecf.pubsub.model.impl.LocalAgent) PublishedServiceDescriptor(org.eclipse.ecf.pubsub.PublishedServiceDescriptor) Action(org.eclipse.jface.action.Action) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) InputDialog(org.eclipse.jface.dialogs.InputDialog) IMasterModel(org.eclipse.ecf.pubsub.model.IMasterModel) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) BaseSelectionListenerAction(org.eclipse.ui.actions.BaseSelectionListenerAction) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IPublishedServiceRequestor(org.eclipse.ecf.pubsub.IPublishedServiceRequestor) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 5 with PublishedServiceDescriptor

use of org.eclipse.ecf.pubsub.PublishedServiceDescriptor 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)

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