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];
}
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;
}
}
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);
}
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;
}
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;
}
Aggregations