Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpnehrer2005-04-24 04:07:19 +0000
committerpnehrer2005-04-24 04:07:19 +0000
commit9504159480fc6266874b084cf84608edd72ca960 (patch)
treee10391751d3b5baa5ccea0772ef2887f164740c6
parentf93fd71be72c93b4fbc8c1745c81010374b9ee0a (diff)
downloadorg.eclipse.ecf-9504159480fc6266874b084cf84608edd72ca960.tar.gz
org.eclipse.ecf-9504159480fc6266874b084cf84608edd72ca960.tar.xz
org.eclipse.ecf-9504159480fc6266874b084cf84608edd72ca960.zip
Migrated from ECF+SDO.
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/build.properties4
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/plugin.xml6
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/schema/manager.exsd127
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareServiceFactory.java62
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareService.java70
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareServiceManager.java23
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java29
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISharedData.java50
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISubscriptionCallback.java43
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateListener.java50
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProvider.java81
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitablePublicationCallback.java51
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitableSubscriptionCallback.java75
-rw-r--r--framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java232
14 files changed, 838 insertions, 65 deletions
diff --git a/framework/bundles/org.eclipse.ecf.datashare/build.properties b/framework/bundles/org.eclipse.ecf.datashare/build.properties
index 0029613a7..0b4cfbcea 100644
--- a/framework/bundles/org.eclipse.ecf.datashare/build.properties
+++ b/framework/bundles/org.eclipse.ecf.datashare/build.properties
@@ -1,4 +1,6 @@
source.datashare.jar = src/
output.datashare.jar = bin/
bin.includes = META-INF/,\
- datashare.jar
+ datashare.jar,\
+ schema/,\
+ build.properties
diff --git a/framework/bundles/org.eclipse.ecf.datashare/plugin.xml b/framework/bundles/org.eclipse.ecf.datashare/plugin.xml
new file mode 100644
index 000000000..19c6ead29
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/plugin.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <extension-point id="manager" name="DataShare Manager" schema="schema/manager.exsd"/>
+
+</plugin>
diff --git a/framework/bundles/org.eclipse.ecf.datashare/schema/manager.exsd b/framework/bundles/org.eclipse.ecf.datashare/schema/manager.exsd
new file mode 100644
index 000000000..4804bea20
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/schema/manager.exsd
@@ -0,0 +1,127 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ecf.datashare">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.ecf.datashare" id="manager" name="Data Graph Sharing Manager"/>
+ </appInfo>
+ <documentation>
+ Allows plugins to provide custom implementations of the Data Graph Sharing facility by registering uniquely named Data Graph Sharing Managers (classes that implement &lt;code&gt;org.eclipse.ecf.sdo.IDataGraphSharingManager&lt;/code&gt;), which are responsible for producing per-container instances of the Data Graph Sharing service implementation (&lt;code&gt;org.eclipse.ecf.sdo.IDataGraphSharing&lt;/code&gt;).
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="manager" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="manager">
+ <annotation>
+ <appInfo>
+ <meta.element labelAttribute="name"/>
+ </appInfo>
+ </annotation>
+ <complexType>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ Unique name that identifies this manager within the system.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ The fully qualified name of the class that implements this manager. The class must implement &lt;code&gt;org.eclipse.ecf.sdo.IDataGraphSharingManager&lt;/code&gt;.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.eclipse.ecf.sdo.IDataGraphSharingManager"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ This plugin defines a default Data Graph Sharing Manager:
+&lt;pre&gt;
+ &lt;extension
+ point=&quot;org.eclipse.ecf.sdo.manager&quot;&gt;
+ &lt;manager
+ class=&quot;org.eclipse.ecf.internal.sdo.DataGraphSharingManager&quot;
+ name=&quot;default&quot;&gt;
+ &lt;/manager&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ To use a registered manager, use the static methods provided by &lt;code&gt;org.eclipse.ecf.sdo.DataGraphSharingFactory&lt;/code&gt;.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ A default implementation (named &lt;code&gt;default&lt;/code&gt;) is provided by this plugin.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2005 Peter Nehrer and Composent, Inc.
+All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html. Contributors: Peter Nehrer - initial API and implementation
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareServiceFactory.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareServiceFactory.java
new file mode 100644
index 000000000..e7633382d
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareServiceFactory.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import java.util.Hashtable;
+
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.internal.datashare.DataSharePlugin;
+
+/**
+ * @author pnehrer
+ */
+public class DataShareServiceFactory {
+
+ public static final String TRACE_TAG = "DataShareServiceFactory";
+
+ private static final Hashtable managers = new Hashtable();
+
+ private DataShareServiceFactory() {
+ }
+
+ public static final IDataShareService getDataShareService(
+ ISharedObjectContainer container, String name) throws ECFException {
+ IDataShareServiceManager instantiator = (IDataShareServiceManager) managers
+ .get(name);
+ if (instantiator == null)
+ return null;
+ else
+ return instantiator.getInstance(container);
+ }
+
+ public static void registerManager(String name,
+ IDataShareServiceManager manager) {
+ if (DataSharePlugin.isTracing(TRACE_TAG))
+ DataSharePlugin.getTraceLog().println("registerManager: " + name);
+
+ managers.put(name, manager);
+ }
+
+ public static void unregisterManager(String name) {
+ if (DataSharePlugin.isTracing(TRACE_TAG))
+ DataSharePlugin.getTraceLog().println("unregisterManager: " + name);
+
+ managers.remove(name);
+ }
+
+ public static void unregisterAllManagers() {
+ if (DataSharePlugin.isTracing(TRACE_TAG))
+ DataSharePlugin.getTraceLog().println("unregisterAllManagers");
+
+ managers.clear();
+ }
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareService.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareService.java
new file mode 100644
index 000000000..afa10f171
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareService.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * Allows clients to participate in data graph sharing.
+ *
+ * @author pnehrer
+ */
+public interface IDataShareService {
+
+ /**
+ * Publishes the given data graph under the given id.
+ *
+ * @param dataGraph
+ * local data graph instance to share
+ * @param id
+ * identifier under which to share this data graph
+ * @param provider
+ * update provider compatible with the given data graph's
+ * implementation
+ * @param consumer
+ * application-specific update consumer
+ * @param callback
+ * optional callback used to notify the caller about publication
+ * status
+ * @return shared data graph
+ * @throws ECFException
+ */
+ ISharedData publish(Object dataGraph, ID id, IUpdateProvider provider,
+ IUpdateListener consumer, IPublicationCallback callback)
+ throws ECFException;
+
+ /**
+ * Subscribes to a data graph with the given id.
+ *
+ * @param id
+ * identifier of a previously-published data graph
+ * @param provider
+ * update provider compatible with the given data graph's
+ * implementation
+ * @param consumer
+ * application-specific update consumer
+ * @param callback
+ * optional callback used to notify the caller about subscription
+ * status
+ * @return shared data graph
+ * @throws ECFException
+ */
+ ISharedData subscribe(ID id, IUpdateProvider provider,
+ IUpdateListener consumer, ISubscriptionCallback callback)
+ throws ECFException;
+
+ /**
+ * Disposes this instance, after which it will be no longer possible to
+ * publish or subscribe.
+ */
+ void dispose();
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareServiceManager.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareServiceManager.java
new file mode 100644
index 000000000..9abdd3eb4
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareServiceManager.java
@@ -0,0 +1,23 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * @author pnehrer
+ */
+public interface IDataShareServiceManager {
+
+ IDataShareService getInstance(ISharedObjectContainer container)
+ throws ECFException;
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java
new file mode 100644
index 000000000..a576daef6
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+/**
+ * Interface used by service implementations to notify publishing applications
+ * of the publication status.
+ *
+ * @author pnehrer
+ */
+public interface IPublicationCallback {
+
+ /**
+ * Notifies implementor that the give data graph has been successfully
+ * published.
+ *
+ * @param graph
+ * data graph that has been published
+ */
+ void dataPublished(ISharedData graph);
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISharedData.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISharedData.java
new file mode 100644
index 000000000..969ac5db6
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISharedData.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * Represents a shared data graph. Provides access to local data graph instance
+ * and allows clients to share (commit) local changes with the network.
+ *
+ * @author pnehrer
+ */
+public interface ISharedData {
+
+ /**
+ * Returns the shared data graph identifier.
+ *
+ * @return id of the shared data graph
+ */
+ ID getID();
+
+ /**
+ * Returns local instance of the data graph.
+ *
+ * @return local instance of the data graph
+ */
+ Object getData();
+
+ /**
+ * Commits any outstanding local changes to the network.
+ *
+ * @throws ECFException
+ */
+ void commit() throws ECFException;
+
+ /**
+ * Disposes this shared data graph. This will make it impossible to commit
+ * any further changes. Also, no more remote updates will be received.
+ */
+ void dispose();
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISubscriptionCallback.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISubscriptionCallback.java
new file mode 100644
index 000000000..1fae39019
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISubscriptionCallback.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import org.eclipse.ecf.core.identity.ID;
+
+/**
+ * Interface used by service implementations to notify subscribing applications
+ * of the subscription status.
+ *
+ * @author pnehrer
+ */
+public interface ISubscriptionCallback {
+
+ /**
+ * Notifies the implementor that the given graph has been successfully
+ * subscribed to.
+ *
+ * @param graph
+ * shared data graph that has been subscribed
+ * @param containerID
+ * id of the container that originated the initial copy
+ */
+ void dataSubscribed(ISharedData graph, ID containerID);
+
+ /**
+ * Notifies the implementor that the subscription failed.
+ *
+ * @param graph
+ * shared data graph whose subscription failed
+ * @param cause
+ * exception that is the cause of the failure
+ */
+ void subscriptionFailed(ISharedData graph, Throwable cause);
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateListener.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateListener.java
new file mode 100644
index 000000000..293f2036b
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateListener.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import org.eclipse.ecf.core.identity.ID;
+
+/**
+ * Interface used by service implementations to notify the application that a
+ * change has been made to the data graph by a remote group member.
+ *
+ * @author pnehrer
+ */
+public interface IUpdateListener {
+
+ /**
+ * Gives implementor the opportunity to consume the remote update. The
+ * implementor is expected to leave behind an empty Change Summary (with
+ * logging turned on).
+ *
+ * @param graph
+ * shared data graph whose remote changes to consume
+ * @param containerID
+ * id of the remote container that made the change
+ * @return <code>true</code> if the update has been consumed,
+ * <code>false</code> otherwise (the update will be rejected as a
+ * result)
+ */
+ boolean consumeUpdate(ISharedData graph, ID containerID);
+
+ /**
+ * Notifies the implementor that a remote update has been received, but was
+ * not successfully applied (i.e., cannot be consumed).
+ *
+ * @param graph
+ * shared data graph whose update failed
+ * @param containerID
+ * id of the container that sent the update
+ * @param cause
+ * optional exception that caused the failure
+ */
+ void updateFailed(ISharedData graph, ID containerID, Throwable cause);
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProvider.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProvider.java
new file mode 100644
index 000000000..880c95026
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProvider.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare;
+
+import java.io.IOException;
+
+import org.eclipse.ecf.core.util.ECFException;
+
+/**
+ * <p>
+ * Interface used by service implementations to manage SDO
+ * implementation-specific data graph updates. Upon commit, the service needs to
+ * create an update (an arbitrary serializable object), which it then propagates
+ * across the network. On the other end, the service needs to apply the received
+ * update to the local data graph.
+ * </p>
+ * <p>
+ * Until serialization-related issues within ECF are resolved, the service also
+ * needs to delegate data graph (de)serialization during subscription.
+ * </p>
+ *
+ * @author pnehrer
+ */
+public interface IUpdateProvider {
+
+ /**
+ * Creates an update from the given data graph, which will be forwarded to
+ * other group members. The implementor may use the graph's Change Summary
+ * to find out what changed.
+ *
+ * @param graph
+ * shared data graph from whose changes to create the update
+ * @return serialized update data
+ * @throws ECFException
+ * when an update cannot be created
+ */
+ byte[] createUpdate(ISharedData graph) throws ECFException;
+
+ /**
+ * Applies the remote update to the given data graph. The implementor is
+ * expected to create a Change Summary that reflects the received changes.
+ *
+ * @param graph
+ * local data graph to which to apply the update
+ * @param data
+ * update data received from a remote group member
+ * @throws ECFException
+ * when this update cannot be applied
+ */
+ void applyUpdate(ISharedData graph, Object data) throws ECFException;
+
+ /**
+ * Serializes the given data graph.
+ *
+ * @param graph
+ * data graph instance to serialize
+ * @return serialized data graph
+ * @throws IOException
+ */
+ Object serializeData(Object graph) throws IOException;
+
+ /**
+ * Deserializes the given data graph.
+ *
+ * @param data
+ * serialized data graph
+ * @return deserialized instance of data graph
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ Object deserializeData(Object data) throws IOException,
+ ClassNotFoundException;
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitablePublicationCallback.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitablePublicationCallback.java
new file mode 100644
index 000000000..038956994
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitablePublicationCallback.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare.util;
+
+import org.eclipse.ecf.datashare.IPublicationCallback;
+import org.eclipse.ecf.datashare.ISharedData;
+
+/**
+ * Convenience callback implementation that can be used to block the calling
+ * thread until the data graph is published.
+ *
+ * @author pnehrer
+ */
+public class WaitablePublicationCallback implements IPublicationCallback {
+
+ private boolean published;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IPublicationCallback#dataGraphPublished(org.eclipse.ecf.sdo.ISharedDataGraph)
+ */
+ public synchronized void dataPublished(ISharedData graph) {
+ published = true;
+ notifyAll();
+ }
+
+ /**
+ * Blocks the calling thread until the data graph is published.
+ *
+ * @param timeout
+ * period, in milliseconds, to wait for publication
+ * @throws InterruptedException
+ * if interrupted while waiting for notification
+ */
+ public synchronized boolean waitForPublication(long timeout)
+ throws InterruptedException {
+ if (!published)
+ wait(timeout);
+
+ return published;
+ }
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitableSubscriptionCallback.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitableSubscriptionCallback.java
new file mode 100644
index 000000000..24742e389
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitableSubscriptionCallback.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.datashare.util;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.datashare.ISharedData;
+import org.eclipse.ecf.datashare.ISubscriptionCallback;
+
+/**
+ * Convenience callback implementation that can be used to block the calling
+ * thread until the data graph is obtained.
+ *
+ * @author pnehrer
+ */
+public class WaitableSubscriptionCallback implements ISubscriptionCallback {
+
+ private ID containerID;
+
+ private Throwable cause;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISubscriptionCallback#dataGraphObtained(org.eclipse.ecf.sdo.ISharedDataGraph,
+ * org.eclipse.ecf.core.identity.ID)
+ */
+ public synchronized void dataSubscribed(ISharedData graph,
+ ID containerID) {
+ this.containerID = containerID;
+ notifyAll();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISubscriptionCallback#subscriptionFailed(org.eclipse.ecf.sdo.ISharedDataGraph,
+ * java.lang.Throwable)
+ */
+ public synchronized void subscriptionFailed(ISharedData graph,
+ Throwable cause) {
+ this.cause = cause;
+ notifyAll();
+ }
+
+ /**
+ * Blocks the calling thread until the data graph is obtained.
+ *
+ * @param timeout
+ * period, in milliseconds, to wait for subscription
+ * @return id of the container from which the data graph originated
+ * @throws InterruptedException
+ * if interrupted while waiting for notification
+ * @throws ECFException
+ * if subscription failed
+ */
+ public synchronized ID waitForSubscription(long timeout)
+ throws InterruptedException, ECFException {
+ if (containerID == null && cause == null)
+ wait(timeout);
+
+ if (cause != null)
+ throw new ECFException(cause);
+
+ return containerID;
+ }
+}
diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java
index deb5ad4bf..9cb1f57ca 100644
--- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java
+++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java
@@ -10,76 +10,180 @@
*******************************************************************************/
package org.eclipse.ecf.internal.datashare;
+import java.io.PrintStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionDelta;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.IRegistryChangeEvent;
+import org.eclipse.core.runtime.IRegistryChangeListener;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.datashare.DataShareServiceFactory;
+import org.eclipse.ecf.datashare.IDataShareServiceManager;
import org.osgi.framework.BundleContext;
-import java.util.*;
/**
- * The main plugin class to be used in the desktop.
* @author pnehrer
*
*/
-public class DataSharePlugin extends Plugin {
- //The shared instance.
- private static DataSharePlugin plugin;
- //Resource bundle.
- private ResourceBundle resourceBundle;
-
- /**
- * The constructor.
- */
- public DataSharePlugin() {
- super();
- plugin = this;
- }
-
- /**
- * This method is called upon plug-in activation
- */
- public void start(BundleContext context) throws Exception {
- super.start(context);
- }
-
- /**
- * This method is called when the plug-in is stopped
- */
- public void stop(BundleContext context) throws Exception {
- super.stop(context);
- plugin = null;
- resourceBundle = null;
- }
-
- /**
- * Returns the shared instance.
- */
- public static DataSharePlugin getDefault() {
- return plugin;
- }
-
- /**
- * Returns the string from the plugin's resource bundle,
- * or 'key' if not found.
- */
- public static String getResourceString(String key) {
- ResourceBundle bundle = DataSharePlugin.getDefault().getResourceBundle();
- try {
- return (bundle != null) ? bundle.getString(key) : key;
- } catch (MissingResourceException e) {
- return key;
- }
- }
-
- /**
- * Returns the plugin's resource bundle,
- */
- public ResourceBundle getResourceBundle() {
- try {
- if (resourceBundle == null)
- resourceBundle = ResourceBundle.getBundle("org.eclipse.ecf.internal.datashare.DataSharePluginResources");
- } catch (MissingResourceException x) {
- resourceBundle = null;
- }
- return resourceBundle;
- }
+public class DataSharePlugin {
+
+ public static final String PLUGIN_ID = "org.eclipse.ecf.datashare";
+
+ private static final String TRACE_PREFIX = PLUGIN_ID + "/";
+
+ private static EclipsePlugin plugin;
+
+ private static boolean tracingEnabled = Boolean.getBoolean(TRACE_PREFIX
+ + "debug");
+
+ private DataSharePlugin() {
+ }
+
+ public static void log(Object entry) {
+ if (plugin == null) {
+ if (entry instanceof Throwable)
+ ((Throwable) entry).printStackTrace();
+ else
+ System.err.println(entry);
+ } else {
+ plugin.log(entry);
+ }
+ }
+
+ public static boolean isTracing(String tag) {
+ if (tracingEnabled) {
+ return plugin == null ? Boolean.getBoolean(TRACE_PREFIX + tag)
+ : plugin.isTracing(tag);
+ } else
+ return false;
+ }
+
+ public static PrintStream getTraceLog() {
+ return System.out;
+ }
+
+ public static class EclipsePlugin extends Plugin {
+
+ private static final String MANAGER_EXTENSION_POINT = "manager";
+
+ private static final String MANAGER_EXTENSION = "manager";
+
+ private static final String ATTR_NAME = "name";
+
+ private static final String ATTR_CLASS = "class";
+
+ private IRegistryChangeListener registryChangeListener;
+
+ public EclipsePlugin() {
+ plugin = this;
+ tracingEnabled = Platform.inDebugMode();
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ registryChangeListener = new IRegistryChangeListener() {
+ public void registryChanged(IRegistryChangeEvent event) {
+ IExtensionDelta[] deltas = event.getExtensionDeltas(
+ getBundle().getSymbolicName(),
+ MANAGER_EXTENSION_POINT);
+ for (int i = 0; i < deltas.length; ++i) {
+ switch (deltas[i].getKind()) {
+ case IExtensionDelta.ADDED:
+ registerManagers(deltas[i].getExtension()
+ .getConfigurationElements());
+ break;
+
+ case IExtensionDelta.REMOVED:
+ IConfigurationElement[] elems = deltas[i]
+ .getExtension().getConfigurationElements();
+ for (int j = 0; j < elems.length; ++j) {
+ if (!MANAGER_EXTENSION.equals(elems[j]
+ .getName()))
+ continue;
+
+ String name = elems[j].getAttribute(ATTR_NAME);
+ if (name != null && name.length() > 0)
+ DataShareServiceFactory
+ .unregisterManager(name);
+ }
+
+ break;
+ }
+ }
+ }
+ };
+
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ IConfigurationElement[] elems = reg.getConfigurationElementsFor(
+ getBundle().getSymbolicName(), MANAGER_EXTENSION_POINT);
+ registerManagers(elems);
+ }
+
+ private void registerManagers(IConfigurationElement[] elems) {
+ for (int i = 0; i < elems.length; ++i) {
+ if (!MANAGER_EXTENSION.equals(elems[i].getName()))
+ continue;
+
+ String name = elems[i].getAttribute(ATTR_NAME);
+ if (name == null || name.length() == 0)
+ continue;
+
+ IDataShareServiceManager mgr;
+ try {
+ mgr = (IDataShareServiceManager) elems[i]
+ .createExecutableExtension(ATTR_CLASS);
+ } catch (Exception ex) {
+ continue;
+ }
+
+ DataShareServiceFactory.registerManager(name, mgr);
+ }
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ if (registryChangeListener != null)
+ Platform.getExtensionRegistry().removeRegistryChangeListener(
+ registryChangeListener);
+
+ DataShareServiceFactory.unregisterAllManagers();
+ plugin = null;
+ super.stop(context);
+ }
+
+ public void log(Object entry) {
+ IStatus status;
+ if (entry instanceof IStatus)
+ status = (IStatus) entry;
+ else if (entry instanceof CoreException)
+ status = ((CoreException) entry).getStatus();
+ else if (entry instanceof Throwable) {
+ Throwable t = (Throwable) entry;
+ status = new Status(Status.ERROR,
+ getBundle().getSymbolicName(), 0,
+ t.getLocalizedMessage() == null ? "Unknown error." : t
+ .getLocalizedMessage(), t);
+ } else
+ status = new Status(Status.WARNING, getBundle()
+ .getSymbolicName(), 0, String.valueOf(entry),
+ new RuntimeException().fillInStackTrace());
+
+ getLog().log(status);
+ }
+ public boolean isTracing(String tag) {
+ return Boolean.TRUE.equals(Boolean.valueOf(Platform
+ .getDebugOption(TRACE_PREFIX + tag)));
+ }
+ }
}

Back to the top