Search in sources :

Example 1 with SharedObjectCreateException

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

the class SharedModelFactory method createSharedDataSource.

public IMasterModel createSharedDataSource(ISharedObjectContainer container, final ID id, Object data, String updaterID) throws SharedObjectCreateException {
    final ISharedObjectManager mgr = container.getSharedObjectManager();
    final Object[] result = new Object[1];
    final Object monitor = new Object();
    IContainerListener listener = new IContainerListener() {

        public void handleEvent(IContainerEvent event) {
            if (event instanceof ISharedObjectActivatedEvent) {
                ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event;
                if (e.getActivatedID().equals(id)) {
                    result[0] = mgr.getSharedObject(id);
                    synchronized (monitor) {
                        monitor.notify();
                    }
                }
            }
        }
    };
    try {
        container.addListener(listener);
        /*			SharedObjectDescription desc = createLocalAgentDescription(id, container.getID(), data, updaterID);
			synchronized (monitor) {
				mgr.createSharedObject(desc);
				if (result[0] == null)
					monitor.wait(getCreationTimeout());
			}
*/
        synchronized (monitor) {
            addSharedObject(mgr, id, data, updaterID);
            if (result[0] == null)
                monitor.wait(getCreationTimeout());
        }
    } catch (InterruptedException e) {
        throw new SharedObjectCreateException(e);
    } finally {
        container.removeListener(listener);
    }
    return (IMasterModel) result[0];
}
Also used : ISharedObjectActivatedEvent(org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) IContainerListener(org.eclipse.ecf.core.IContainerListener)

Example 2 with SharedObjectCreateException

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

the class PubSubAdapterFactory method getDirectory.

protected IPublishedServiceDirectory getDirectory(ISharedObjectContainer container) {
    ID directoryID;
    try {
        directoryID = IDFactory.getDefault().createStringID(PublishedServiceDirectory.SHARED_OBJECT_ID);
    } catch (IDCreateException e) {
        throw new RuntimeException(e);
    }
    final ISharedObjectManager mgr = container.getSharedObjectManager();
    IPublishedServiceDirectory directory = (IPublishedServiceDirectory) mgr.getSharedObject(directoryID);
    if (directory != null)
        return directory;
    try {
        SharedObjectDescription desc = createDirectoryDescription(directoryID);
        mgr.createSharedObject(desc);
        return (IPublishedServiceDirectory) mgr.getSharedObject(directoryID);
    } catch (SharedObjectCreateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
Also used : IPublishedServiceDirectory(org.eclipse.ecf.pubsub.IPublishedServiceDirectory) SharedObjectDescription(org.eclipse.ecf.core.sharedobject.SharedObjectDescription) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) ISharedObjectManager(org.eclipse.ecf.core.sharedobject.ISharedObjectManager) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with SharedObjectCreateException

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

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

the class RssClientSOContainer method createSharedObject.

private ISharedObject createSharedObject(SharedObjectTypeDescription sotypedesc, IChannelListener listener) throws SharedObjectCreateException {
    Class clazz;
    try {
        clazz = Class.forName(sotypedesc.getClassName());
    } catch (final ClassNotFoundException e) {
        throw new SharedObjectCreateException("No constructor for shared object of class " + sotypedesc.getClassName(), e);
    }
    Constructor cons = null;
    try {
        cons = clazz.getDeclaredConstructor(new Class[] { IChannelListener.class });
    } catch (final NoSuchMethodException e) {
        throw new SharedObjectCreateException("No constructor for shared object of class " + sotypedesc.getClassName(), e);
    }
    ISharedObject so = null;
    try {
        so = (ISharedObject) cons.newInstance(new Object[] { listener });
    } catch (final Exception e) {
        throw new SharedObjectCreateException("Cannot create instance of class " + sotypedesc.getClassName(), e);
    }
    return so;
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) Constructor(java.lang.reflect.Constructor) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) ECFException(org.eclipse.ecf.core.util.ECFException) ConnectionCreateException(org.eclipse.ecf.provider.comm.ConnectionCreateException) ParseException(org.eclipse.higgins.rsse.parser.ParseException) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IOException(java.io.IOException) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)

Example 5 with SharedObjectCreateException

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

the class RssClientSOContainer method createChannel.

public IMergeableChannel createChannel(IChannelConfig newChannelConfig) throws ECFException {
    final IChannelListener listener = newChannelConfig.getListener();
    final SharedObjectDescription sodesc = new SharedObjectDescription(FeedSharedObject.class, IDFactory.getDefault().createGUID(), new HashMap());
    final SharedObjectTypeDescription sotypedesc = sodesc.getTypeDescription();
    ISharedObject sharedObject = null;
    if (sotypedesc.getName() != null) {
        sharedObject = SharedObjectFactory.getDefault().createSharedObject(sotypedesc, new Object[] { listener });
    } else {
        sharedObject = createSharedObject(sotypedesc, listener);
    }
    final IMergeableChannel channel = (IMergeableChannel) sharedObject.getAdapter(IMergeableChannel.class);
    if (channel == null) {
        throw new SharedObjectCreateException("Cannot coerce object " + channel + " to be of type IChannel");
    }
    ID newID = sodesc.getID();
    if (newID == null) {
        newID = IDFactory.getDefault().createGUID();
    }
    Map properties = sodesc.getProperties();
    if (properties == null) {
        properties = new HashMap();
    }
    // Now add channel to container...this will block
    getSharedObjectManager().addSharedObject(newID, sharedObject, properties);
    return channel;
}
Also used : SharedObjectDescription(org.eclipse.ecf.core.sharedobject.SharedObjectDescription) IChannelListener(org.eclipse.ecf.datashare.IChannelListener) HashMap(java.util.HashMap) SharedObjectCreateException(org.eclipse.ecf.core.sharedobject.SharedObjectCreateException) SharedObjectTypeDescription(org.eclipse.ecf.core.sharedobject.SharedObjectTypeDescription) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) IMergeableChannel(org.eclipse.ecf.datashare.mergeable.IMergeableChannel) ID(org.eclipse.ecf.core.identity.ID) StringID(org.eclipse.ecf.core.identity.StringID) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

SharedObjectCreateException (org.eclipse.ecf.core.sharedobject.SharedObjectCreateException)6 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ID (org.eclipse.ecf.core.identity.ID)2 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)2 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)2 SharedObjectDescription (org.eclipse.ecf.core.sharedobject.SharedObjectDescription)2 IChannelListener (org.eclipse.ecf.datashare.IChannelListener)2 IPublishedServiceDirectory (org.eclipse.ecf.pubsub.IPublishedServiceDirectory)2 LocalAgent (org.eclipse.ecf.pubsub.model.impl.LocalAgent)2 Constructor (java.lang.reflect.Constructor)1 Map (java.util.Map)1 IContainerListener (org.eclipse.ecf.core.IContainerListener)1 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)1 StringID (org.eclipse.ecf.core.identity.StringID)1 SharedObjectAddException (org.eclipse.ecf.core.sharedobject.SharedObjectAddException)1 SharedObjectTypeDescription (org.eclipse.ecf.core.sharedobject.SharedObjectTypeDescription)1 ISharedObjectActivatedEvent (org.eclipse.ecf.core.sharedobject.events.ISharedObjectActivatedEvent)1 ECFException (org.eclipse.ecf.core.util.ECFException)1