diff options
| author | pnehrer | 2005-12-07 22:06:22 +0000 |
|---|---|---|
| committer | pnehrer | 2005-12-07 22:06:22 +0000 |
| commit | 7dcc0fa603f39a463aafa805fd1643b002a2bede (patch) | |
| tree | 76aba2421b68e7e425c083d849cd36b3e2e535f2 | |
| parent | 69e117b061970b12cfbecad6621d640856581e70 (diff) | |
| download | org.eclipse.ecf-7dcc0fa603f39a463aafa805fd1643b002a2bede.tar.gz org.eclipse.ecf-7dcc0fa603f39a463aafa805fd1643b002a2bede.tar.xz org.eclipse.ecf-7dcc0fa603f39a463aafa805fd1643b002a2bede.zip | |
Replaced old DataShare with DataShare2.
53 files changed, 244 insertions, 4127 deletions
diff --git a/framework/bundles/org.eclipse.ecf.datashare/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.datashare/META-INF/MANIFEST.MF index d10047bc1..874b4c0f7 100644 --- a/framework/bundles/org.eclipse.ecf.datashare/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.datashare/META-INF/MANIFEST.MF @@ -4,13 +4,8 @@ Bundle-Name: ECF DataShare Bundle-SymbolicName: org.eclipse.ecf.datashare;singleton:=true Bundle-Version: 0.5.3 Bundle-ClassPath: datashare.jar -Bundle-Activator: org.eclipse.ecf.internal.datashare.DataSharePlugin$EclipsePlugin Bundle-Vendor: Eclipse.org Bundle-Localization: plugin -Require-Bundle: org.eclipse.core.runtime, - org.eclipse.ecf +Require-Bundle: org.eclipse.ecf;visibility:=reexport Eclipse-AutoStart: true -Export-Package: org.eclipse.ecf.datashare, - org.eclipse.ecf.datashare.multicast, - org.eclipse.ecf.datashare.util, - org.eclipse.ecf.internal.datashare +Export-Package: org.eclipse.ecf.datashare diff --git a/framework/bundles/org.eclipse.ecf.datashare/notes.txt b/framework/bundles/org.eclipse.ecf.datashare/notes.txt deleted file mode 100644 index 62d05300a..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/notes.txt +++ /dev/null @@ -1,20 +0,0 @@ -Service -- create/obtain Agents -- manage subscriptions - -Agent -- create remote replicas when/where needed -- stay alive only when connected -- client facade -- coordinate sub-components to implement the service - -Coordinator -- ensures there's exactly one coordinator replica (when needed) - -Multicaster -- implements 1/2/3-phase "commit" protocol -- pause/resume messages (commits) - -Disposer (Garbage Collector) -- dispose Agents with no subscriptions - diff --git a/framework/bundles/org.eclipse.ecf.datashare/plugin.xml b/framework/bundles/org.eclipse.ecf.datashare/plugin.xml deleted file mode 100644 index a62303377..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/plugin.xml +++ /dev/null @@ -1,19 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.0"?> -<plugin> - <extension-point id="servicemanager" name="DataShare Service Manager" schema="schema/servicemanager.exsd"/> - <extension-point id="updateprovider" name="DataShare Update Provider" schema="schema/updateprovider.exsd"/> - <extension - point="org.eclipse.ecf.datashare.servicemanager"> - <manager - class="org.eclipse.ecf.internal.datashare.ServiceManager" - name="org.eclipse.ecf.datashare.default"/> - </extension> - <extension - point="org.eclipse.ecf.datashare.updateprovider"> - <updateProvider - factory="org.eclipse.ecf.datashare.util.TrackedSetUpdateProvider$Factory" - id="org.eclipse.ecf.datashare.util.TrackedSet"/> - </extension> - -</plugin> diff --git a/framework/bundles/org.eclipse.ecf.datashare/schema/servicemanager.exsd b/framework/bundles/org.eclipse.ecf.datashare/schema/servicemanager.exsd deleted file mode 100644 index 5444bd54a..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/schema/servicemanager.exsd +++ /dev/null @@ -1,127 +0,0 @@ -<?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="DataShare Service 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 <code>org.eclipse.ecf.sdo.IDataGraphSharingManager</code>), which are responsible for producing per-container instances of the Data Graph Sharing service implementation (<code>org.eclipse.ecf.sdo.IDataGraphSharing</code>). - </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 <code>org.eclipse.ecf.sdo.IDataGraphSharingManager</code>. - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn="org.eclipse.ecf.datashare.IDataShareServiceManager"/> - </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: -<pre> - <extension - point="org.eclipse.ecf.sdo.manager"> - <manager - class="org.eclipse.ecf.internal.sdo.DataGraphSharingManager" - name="default"> - </manager> - </extension> -</pre> - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="apiInfo"/> - </appInfo> - <documentation> - To use a registered manager, use the static methods provided by <code>org.eclipse.ecf.sdo.DataGraphSharingFactory</code>. - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="implementation"/> - </appInfo> - <documentation> - A default implementation (named <code>default</code>) 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/schema/updateprovider.exsd b/framework/bundles/org.eclipse.ecf.datashare/schema/updateprovider.exsd deleted file mode 100644 index 2c189fbfa..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/schema/updateprovider.exsd +++ /dev/null @@ -1,117 +0,0 @@ -<?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="updateprovider" name="DataShare Update Provider"/> - </appInfo> - <documentation> - [Enter description of this extension point.] - </documentation> - </annotation> - - <element name="extension"> - <complexType> - <sequence> - <element ref="updateProvider" 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="updateProvider"> - <annotation> - <appInfo> - <meta.element labelAttribute="id"/> - </appInfo> - </annotation> - <complexType> - <attribute name="id" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - </annotation> - </attribute> - <attribute name="factory" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn="org.eclipse.ecf.datashare.IUpdateProvider"/> - </appInfo> - </annotation> - </attribute> - </complexType> - </element> - - <annotation> - <appInfo> - <meta.section type="since"/> - </appInfo> - <documentation> - [Enter the first release in which this extension point appears.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="examples"/> - </appInfo> - <documentation> - [Enter extension point usage example here.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="apiInfo"/> - </appInfo> - <documentation> - [Enter API information here.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="implementation"/> - </appInfo> - <documentation> - [Enter information about supplied implementation of this extension point.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="copyright"/> - </appInfo> - <documentation> - - </documentation> - </annotation> - -</schema> diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareService.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareService.java new file mode 100644 index 000000000..a63dcc495 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareService.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * 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; + +/** + * Allows the client to join a data sharing session. This interface is + * implemented by service providers; clients typically acquire an instance in a + * provider-specific way. + * + * @see org.eclipse.ecf.datashare.Participant + * @see org.eclipse.ecf.datashare.Session + */ +public interface DataShareService { + + /** + * Connects the given participant instance to the identified data sharing + * session. + * + * @param sessionID + * unique identifier of a data sharing session to join + * @param participant + * client's "agent" that allows the client to participate in data + * sharing + * @param data + * arbitrary data to pass to existing participants via + * {@link Participant#joined(Object)} + * @throws JoinException + * if unable to join the specified session + */ + void joinSession(ID sessionID, Participant participant, Object data) + throws JoinException; +} 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 deleted file mode 100644 index e7633382d..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/DataShareServiceFactory.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * 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 deleted file mode 100644 index 8da643270..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IDataShareService.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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 callback - * optional callback used to notify the caller about publication - * status - * - * @throws ECFException - */ - void publish(Object dataGraph, ID id, IUpdateProvider provider, - IPublicationCallback callback) - throws ECFException; - - /** - * Subscribes to a data graph with the given id. - * @param id - * identifier of a previously-published data graph - * @param callback - * optional callback used to notify the caller about subscription - * status - * - * @return shared data graph - * @throws ECFException - */ - ISharedData subscribe(ID id, 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/IPublicationCallback.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java deleted file mode 100644 index c8d6f5d33..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IPublicationCallback.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * 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); - - /** - * Notifies the implementor that the publication failed. - * - * @param graph - * shared data graph whose publication failed - * @param cause - * exception that is the cause of the failure - */ - void publicationFailed(ISharedData graph, Throwable cause); -} 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 deleted file mode 100644 index 6e73016da..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISharedData.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * 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 deleted file mode 100644 index 2dd37f99f..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/ISubscriptionCallback.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * 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 deleted file mode 100644 index 5e2e3fae9..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateListener.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * 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; - -/** - * 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 deleted file mode 100644 index ea258a562..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.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 { - - IUpdateProviderFactory getFactory(); - - /** - * 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 - */ - Object 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; -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProviderFactory.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/JoinException.java index bbb23679e..0951a52dd 100644 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/IUpdateProviderFactory.java +++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/JoinException.java @@ -10,14 +10,28 @@ *******************************************************************************/ package org.eclipse.ecf.datashare; -import java.util.Map; +public class JoinException extends Exception { -/** - * @author pnehrer - */ -public interface IUpdateProviderFactory { + private static final long serialVersionUID = 2848924367904661732L; - String getID(); + public JoinException() { + super(); + // TODO Auto-generated constructor stub + } + + public JoinException(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public JoinException(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public JoinException(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } - IUpdateProvider createProvider(Map params); } diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Participant.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Participant.java new file mode 100644 index 000000000..de0770b7b --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Participant.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * 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; + +/** + * <p> + * Interface for clients that wish to participate in data sharing sessions. The + * client must provide an implementation when requesting to + * {@link DataShareService#joinSession(ID, Participant, Object) join} a session. When + * successful, the service will + * {@link #initialize(Session, Object[]) initialize} the participant with a + * valid {@link Session session} and any initial data. The participant will then + * {@link #receive(Object) receive} zero or more messages (typically, shared + * data updates}, and will be {@link #dispose() disposed} when it can no longer + * participate in the session (e.g., as a result of + * {@link Session#leave() leaving} the session, or because the session + * terminated for some other reason). + * </p> + * <p> + * The participant is {@link #joined(Object) notified} when a new particpant + * joins the session, at which point it may return some data that would be used + * to {@link #initialize(Session, Object[]) initialize} the new participant. + * </p> + * + * @see org.eclipse.ecf.datashare.DataShareService + * @see org.eclipse.ecf.datashare.Session + */ +public interface Participant { + + /** + * Initializes this participant with a valid session. The session instance + * becomes invalid when the participant is {@link #dispose() disposed}. + * + * @param session + * session instance that can be used to broadcast messages to + * other connected participants + * @param data + * data obtained from other participants + * @see #initialize(Session, Object[]) + */ + void initialize(Session session, Object[] data); + + /** + * Delivers a message broadcast by another session participant. + * + * @param data + * message (e.g., a shared data update) from another participant + */ + void receive(Object data); + + /** + * Notifies this participant that another participant is joining the + * session. + * + * @param data + * data provided by the joining participant + * @return any data to pass to the joining participant in + * {@link #initialize(Session, Object[])} + * @throws JoinException + * if the participant should not be allowed to join + */ + Object joined(Object data) throws JoinException; + + /** + * Disposes this participant when it can no longer participate in the + * session (e.g., as a result of leaving, or involuntary disconnect). + */ + 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/SendException.java index 1efdd7a58..87354d566 100644 --- 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/SendException.java @@ -10,14 +10,28 @@ *******************************************************************************/ package org.eclipse.ecf.datashare; -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.util.ECFException; +public class SendException extends Exception { -/** - * @author pnehrer - */ -public interface IDataShareServiceManager { + private static final long serialVersionUID = -4255877134637196156L; + + public SendException() { + super(); + // TODO Auto-generated constructor stub + } + + public SendException(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public SendException(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public SendException(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } - IDataShareService getInstance(ISharedObjectContainer container) - throws ECFException; } diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Session.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Session.java new file mode 100644 index 000000000..8f82d57cb --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/Session.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * 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; + +/** + * <p> + * Represents a data sharing session. Allows a + * {@link org.eclipse.ecf.datashare.Participant Participant} to broadcast + * messages (typically, shared data updates) to other connected participants. + * </p> + * <p> + * A Participant is + * {@link Participant#initialize(Session, Object[]) initialized} with a valid + * Session instance; this in turn becomes invalid when the Participant is + * {@link Participant#dispose() disposed}. + * </p> + * <p> + * This interface is intended for service providers and should not be + * implemented by clients. + * </p> + * + * @see org.eclipse.ecf.datashare.Participant + */ +public interface Session { + + /** + * Broadcasts a message (typically, an update to the shared data) to other + * connected {@link Participant participants}. + * + * @param data + * the message to broadcast + * @throws SendException + * if the message could not be successfully broadcast + */ + void send(Object data) throws SendException; + + /** + * Requests to leave the data sharing session. As a result, the + * {@link Participant participant} is {@link Participant#dispose() disposed}. + */ + void leave(); +} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/UpdateProviderRegistry.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/UpdateProviderRegistry.java deleted file mode 100644 index 2015adc2b..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/UpdateProviderRegistry.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * 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 java.util.Map; - -/** - * @author pnehrer - */ -public class UpdateProviderRegistry { - - private static final Hashtable providers = new Hashtable(); - - private UpdateProviderRegistry() { - } - - public static IUpdateProvider createProvider(String id, Map params) { - IUpdateProviderFactory f = (IUpdateProviderFactory) providers.get(id); - if (f == null) - return null; - else - return f.createProvider(params); - } - - public static void registerFactory(String id, IUpdateProviderFactory f) { - providers.put(id, f); - } - - public static void unregisterFactory(String id) { - providers.remove(id); - } - - public static void unregisterAllFactories() { - providers.clear(); - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Abort.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Abort.java deleted file mode 100644 index 1fb62f8fc..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Abort.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Abort implements Serializable { - - private static final long serialVersionUID = 3258410616858294325L; - - final Version version; - - public Abort(Version version) { - this.version = version; - } - - public Version getVersion() { - return version; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Abort[version="); - buf.append(version).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/AbstractMulticaster.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/AbstractMulticaster.java deleted file mode 100644 index 669acb75d..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/AbstractMulticaster.java +++ /dev/null @@ -1,382 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.ecf.core.ISharedObject; -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.ISharedObjectContext; -import org.eclipse.ecf.core.ISharedObjectManager; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectActivatedEvent; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisconnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectDeactivatedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.internal.datashare.DataSharePlugin; - -/** - * @author pnehrer - */ -public abstract class AbstractMulticaster implements ISharedObject { - - public static final short NEW = 0; - - public static final short READY = 1; - - public static final short DISPOSED = 2; - - public class Testable { - - public Version getVersion() { - return version; - } - - public short getState() { - return state; - } - - public String getStateCode() { - return getStateStr(); - } - } - - protected final HashSet listeners = new HashSet(); - - protected ISharedObjectConfig config; - - protected ID sharedObjectID; - - protected ISharedObjectContext context; - - protected ID localContainerID; - - protected ID groupID; - - protected Version version; - - protected short state = NEW; - - protected final HashSet pauses = new HashSet(); - - protected HashSet pauseRequests; - - protected final HashSet groupMembers = new HashSet(); - - protected Testable testable; - - public void addMessageListener(IMessageListener l) { - synchronized (listeners) { - listeners.add(l); - } - } - - public void removeMessageListener(IMessageListener l) { - synchronized (listeners) { - listeners.remove(l); - } - } - - public abstract boolean sendMessage(Object message) throws ECFException; - - public synchronized void pause() throws ECFException, IllegalStateException { - if (pauses.contains(localContainerID)) - throw new IllegalStateException(); - - while (state == NEW) { - try { - wait(); - } catch (InterruptedException e) { - throw new ECFException(e); - } - } - - if (state == DISPOSED) - throw new IllegalStateException(); - - boolean wasEmpty = pauses.isEmpty(); - pauses.add(localContainerID); - pauseRequests = new HashSet(groupMembers); - try { - if (!pauseRequests.isEmpty()) { - context.sendMessage(null, new Pause()); - synchronized (pauses) { - pauses.wait(1000); - } - } - - if (!pauseRequests.isEmpty()) - throw new ECFException("Failed to pause."); - } catch (IOException e) { - pauses.remove(localContainerID); - throw new ECFException(e); - } catch (InterruptedException e) { - pauses.remove(localContainerID); - throw new ECFException(e); - } finally { - if (wasEmpty && !pauses.isEmpty()) - notify(); - } - } - - public synchronized void resume() throws ECFException { - if (state == DISPOSED) - throw new IllegalStateException(); - - if (!pauses.contains(localContainerID)) - throw new IllegalStateException(); - - try { - context.sendMessage(null, new Resume()); - pauses.remove(localContainerID); - } catch (IOException e) { - throw new ECFException(e); - } finally { - if (pauses.isEmpty()) - notify(); - } - } - - public synchronized SharedObjectDescription createDescription() { - HashMap params = new HashMap(1); - params.put("version", version); - return new SharedObjectDescription(sharedObjectID, getClass(), params); - } - - protected void receiveMessage(Version version, Object message) { - synchronized (listeners) { - for (Iterator i = listeners.iterator(); i.hasNext();) - ((IMessageListener) i.next()).messageReceived(version, message); - } - } - - protected synchronized boolean waitToSend() { - while (state != READY || !pauses.isEmpty()) { - if (state == DISPOSED) - return false; - - try { - wait(); - } catch (InterruptedException e) { - DataSharePlugin.log(e); - return false; - } - } - - return true; - } - - protected void traceEntry(String method) { - StringBuffer buf = new StringBuffer("> "); - buf.append(getStateStr()); - buf.append(' '); - buf.append(localContainerID); - buf.append(": "); - buf.append(method); - DataSharePlugin.getTraceLog().println(buf); - } - - protected void traceExit(String method) { - StringBuffer buf = new StringBuffer("< "); - buf.append(getStateStr()); - buf.append(' '); - buf.append(localContainerID); - buf.append(": "); - buf.append(method); - DataSharePlugin.getTraceLog().println(buf); - } - - protected String getStateStr() { - switch (state) { - case NEW: - return "NEW"; - case READY: - return "RDY"; - case DISPOSED: - return "DIS"; - default: - return "UNK"; - } - } - - public synchronized Testable getTestable() { - if (testable == null) - testable = new Testable(); - - return testable; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public synchronized void init(ISharedObjectConfig config) - throws SharedObjectInitException { - this.config = config; - sharedObjectID = config.getSharedObjectID(); - Map params = config.getProperties(); - if (params != null) { - Object param = params.get("version"); - if (param != null) - version = (Version) param; - } - - if (version == null) - version = new Version(sharedObjectID, 0); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - if (event instanceof ISharedObjectActivatedEvent) - handleActivated((ISharedObjectActivatedEvent) event); - else if (event instanceof ISharedObjectDeactivatedEvent) - handleDeactivated((ISharedObjectDeactivatedEvent) event); - else if (event instanceof ISharedObjectContainerDisconnectedEvent) - handleDeparted((ISharedObjectContainerDisconnectedEvent) event); - else if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Message) - handleMessage(e.getRemoteContainerID(), (Message) e.getData()); - else if (e.getData() instanceof Pause) - handlePause(e.getRemoteContainerID(), (Pause) e.getData()); - else if (e.getData() instanceof Paused) - handlePaused(e.getRemoteContainerID(), (Paused) e.getData()); - else if (e.getData() instanceof Resume) - handleResume(e.getRemoteContainerID(), (Resume) e.getData()); - } - } - - protected void handleActivated(ISharedObjectActivatedEvent event) { - if (event.getActivatedID().equals(sharedObjectID)) { - context = config.getContext(); - localContainerID = context.getLocalContainerID(); - groupID = context.getConnectedID(); - if (groupID == null) - try { - context.sendDispose(localContainerID); - } catch (IOException e) { - DataSharePlugin.log(e); - } - else { - synchronized (this) { - groupMembers.addAll(Arrays.asList(context - .getGroupMemberIDs())); - groupMembers.remove(localContainerID); - try { - context.sendMessage(null, new Activated()); - } catch (IOException e) { - DataSharePlugin.log(e); - } - - state = READY; - notifyAll(); - } - } - } - } - - protected void handleDeactivated(ISharedObjectDeactivatedEvent event) { - if (event.getDeactivatedID().equals(sharedObjectID)) { - synchronized (this) { - state = DISPOSED; - notifyAll(); - } - } - } - - protected void handleDeparted(ISharedObjectContainerDisconnectedEvent event) { - if (event.getTargetID().equals(localContainerID)) { - ISharedObjectManager manager = context.getSharedObjectManager(); - if (manager != null) { - manager.removeSharedObject(sharedObjectID); - } - } else { - synchronized (this) { - groupMembers.remove(event.getTargetID()); - } - } - } - - protected synchronized void handleActivated(ID remoteContainerID, - Activated activated) { - groupMembers.add(remoteContainerID); - } - - protected synchronized void handlePause(ID remoteContainerID, Pause pause) { - if (pauses.isEmpty()) - notify(); - - pauses.add(remoteContainerID); - } - - protected synchronized void handlePaused(ID remoteContainerID, Paused paused) { - if (pauses.contains(localContainerID) && pauseRequests != null - && pauseRequests.remove(remoteContainerID) - && pauseRequests.isEmpty()) - synchronized (pauses) { - pauses.notify(); - } - } - - protected synchronized void handleResume(ID remoteContainerID, Resume resume) { - if (pauses.remove(remoteContainerID) && pauses.isEmpty()) - notify(); - } - - protected void handleMessage(ID remoteContainerID, Message message) { - synchronized (this) { - version = message.getVersion(); - } - - receiveMessage(message.getVersion(), message.getData()); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[]) - */ - public void handleEvents(Event[] events) { - for (int i = 0; i < events.length; ++i) - handleEvent(events[i]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Ack.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Ack.java deleted file mode 100644 index c61ebcec3..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Ack.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Ack implements Serializable { - - private static final long serialVersionUID = 3832621776860952377L; - - final Version version; - - public Ack(Version version) { - this.version = version; - } - - public Version getVersion() { - return version; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Ack[version="); - buf.append(version).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Activated.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Activated.java deleted file mode 100644 index 5d7fe0d6e..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Activated.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -/** - * @author pnehrer - * - */ -public class Activated implements Serializable { - - private static final long serialVersionUID = 3256726186536351801L; - -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Commit.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Commit.java deleted file mode 100644 index d66c30b6b..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Commit.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Commit implements Serializable { - - private static final long serialVersionUID = 3258126938529740848L; - - final Version version; - - public Commit(Version version) { - this.version = version; - } - - public Version getVersion() { - return version; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Commit[version="); - buf.append(version).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/ConsistentMulticaster.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/ConsistentMulticaster.java deleted file mode 100644 index dc740008b..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/ConsistentMulticaster.java +++ /dev/null @@ -1,394 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Timer; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisconnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.internal.datashare.DataSharePlugin; - -/** - * @author pnehrer - */ -public class ConsistentMulticaster extends AbstractMulticaster implements - Timeout.Listener { - - public static final short SEND = 3; - - public static final short RECEIVE = 4; - - public static final long DEFAULT_TIMEOUT = 1000; - - public static final String TRACE_TAG = "ConsistentMulticaster"; - - private long sendTimeout; - - private long receiveTimeout; - - private Version nextVersion; - - private HashSet requests; - - private final Timer timer = new Timer(); - - private final HashMap timeouts = new HashMap(); - - private final HashMap commits = new HashMap(); - - private boolean granted; - - public synchronized boolean sendMessage(Object message) throws ECFException { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "sendMessage[message=" + message + "]"); - - try { - if (!waitToSend()) - return false; - - state = SEND; - nextVersion = new Version(localContainerID, - version.getSequence() + 1); - HashSet others = new HashSet(groupMembers); - requests = new HashSet(others); - granted = true; - try { - if (!requests.isEmpty()) { - context.sendMessage(null, new Request(nextVersion)); - wait(sendTimeout); - if (state != SEND) - return false; - } - - if (!granted || !requests.isEmpty()) { - context.sendMessage(null, new Abort(nextVersion)); - return false; - } - - requests.addAll(others); - if (!requests.isEmpty()) { - context - .sendMessage(null, - new Message(nextVersion, message)); - wait(sendTimeout); - if (state != SEND) - return false; - } - - if (!requests.isEmpty()) { - context.sendMessage(null, new Abort(nextVersion)); - return false; - } - - context.sendMessage(null, new Commit(nextVersion)); - version = nextVersion; - return true; - } catch (IOException e) { - throw new ECFException(e); - } catch (InterruptedException e) { - throw new ECFException(e); - } finally { - state = READY; - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - public String getStateStr() { - switch (state) { - case SEND: - return "SND"; - case RECEIVE: - return "RCV"; - default: - return super.getStateStr(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public synchronized void init(ISharedObjectConfig config) - throws SharedObjectInitException { - super.init(config); - - sendTimeout = DEFAULT_TIMEOUT; - receiveTimeout = DEFAULT_TIMEOUT; - - Map params = config.getProperties(); - if (params != null) { - Object param = params.get("sendTimeout"); - if (param instanceof Long) - sendTimeout = ((Long) param).longValue(); - - param = params.get("receiveTimeout"); - if (param instanceof Long) - receiveTimeout = ((Long) param).longValue(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - super.handleEvent(event); - if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Request) - handleRequest(e.getRemoteContainerID(), (Request) e.getData()); - else if (e.getData() instanceof Reply) - handleReply(e.getRemoteContainerID(), (Reply) e.getData()); - else if (e.getData() instanceof Abort) - handleAbort(e.getRemoteContainerID(), (Abort) e.getData()); - else if (e.getData() instanceof Ack) - handleAck(e.getRemoteContainerID(), (Ack) e.getData()); - else if (e.getData() instanceof Commit) - handleCommit(e.getRemoteContainerID(), (Commit) e.getData()); - } - } - - protected void handleDeparted(ISharedObjectContainerDisconnectedEvent event) { - super.handleDeparted(event); - if (!event.getTargetID().equals(localContainerID)) { - synchronized (this) { - if (state == SEND) { - requests.remove(event.getTargetID()); - if (requests.isEmpty()) - notify(); - } else if (state == RECEIVE) { - Timeout[] t = (Timeout[]) timeouts.values().toArray( - new Timeout[timeouts.size()]); - for (int i = 0; i < t.length; ++i) { - if (t[i].getVersion().getSenderID().equals( - event.getTargetID()) - && t[i].cancel()) - timeouts.remove(t[i].getVersion()); - } - - for (Iterator i = commits.keySet().iterator(); i.hasNext();) { - Version version = (Version) i.next(); - if (version.getSenderID().equals( - event.getTargetID())) - i.remove(); - } - - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - } - } - } - } - - private synchronized void handleRequest(ID remoteContainerID, - Request request) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleRequest[remoteContainerID=" - + remoteContainerID + ";request=" + request + "]"); - - try { - if ((state == READY || state == RECEIVE) - && version.getSequence() + 1 == request.getVersion() - .getSequence()) { - state = RECEIVE; - Timeout timeout = new Timeout(this, request.getVersion()); - timeouts.put(request.getVersion(), timeout); - timer.schedule(timeout, receiveTimeout); - context.sendMessage(remoteContainerID, new Reply(request - .getVersion(), true)); - } else if (state != DISPOSED) - context.sendMessage(remoteContainerID, new Reply(request - .getVersion(), false)); - } catch (IOException e) { - DataSharePlugin.log(e); - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleReply(ID remoteContainerID, Reply reply) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleReply[remoteContainerID=" - + remoteContainerID + ";reply=" + reply + "]"); - - try { - if (state == SEND && reply.getVersion().equals(nextVersion)) { - if (!reply.isGranted()) { - granted = false; - notify(); - } - - requests.remove(remoteContainerID); - if (requests.isEmpty()) - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - protected synchronized void handleMessage(ID remoteContainerID, - Message message) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleMessage[remoteContainerID=" - + remoteContainerID + ";message=" + message + "]"); - - try { - Timeout timeout; - if (((timeout = (Timeout) timeouts.get(message.getVersion())) != null) - && timeout.cancel()) { - commits.put(message.getVersion(), message.getData()); - timeout = new Timeout(this, message.getVersion()); - timeouts.put(message.getVersion(), timeout); - timer.schedule(timeout, 1000); - context.sendMessage(remoteContainerID, new Ack(message - .getVersion())); - } - } catch (IOException e) { - DataSharePlugin.log(e); - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleAbort(ID remoteContainerID, Abort abort) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleAbort[remoteContainerID=" - + remoteContainerID + ";abort=" + abort + "]"); - - try { - Timeout timeout = (Timeout) timeouts.remove(abort.getVersion()); - if (timeout != null && timeout.cancel()) { - commits.remove(abort.getVersion()); - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleAck(ID remoteContainerID, Ack ack) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleAck[remoteContainerID=" - + remoteContainerID + ";ack=" + ack + "]"); - try { - if (state == SEND && ack.getVersion().equals(nextVersion)) { - requests.remove(remoteContainerID); - if (requests.isEmpty()) - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleCommit(ID remoteContainerID, Commit commit) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleCommit[remoteContainerID=" - + remoteContainerID + ";commit=" + commit + "]"); - - try { - Timeout timeout; - if (((timeout = (Timeout) timeouts.get(commit.getVersion())) != null) - && timeout.cancel()) { - version = commit.getVersion(); - timeouts.remove(version); - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - - receiveMessage(version, commits.remove(version)); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - public synchronized void timeout(Version version) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "timeout[version=" + version + "]"); - - try { - timeouts.remove(version); - if (timeouts.isEmpty()) { - commits.remove(version); - state = READY; - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[]) - */ - public void handleEvents(Event[] events) { - for (int i = 0; i < events.length; ++i) - handleEvent(events[i]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/IMessageListener.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/IMessageListener.java deleted file mode 100644 index d8c9aaaf8..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/IMessageListener.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -/** - * @author pnehrer - */ -public interface IMessageListener { - - void messageReceived(Version version, Object message); -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Message.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Message.java deleted file mode 100644 index 74b293d15..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Message.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Message implements Serializable { - - private static final long serialVersionUID = 3257281414121993014L; - - final Version version; - - final Object data; - - public Message(Version version, Object data) { - this.version = version; - this.data = data; - } - - public Version getVersion() { - return version; - } - - public Object getData() { - return data; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Message[version="); - buf.append(version).append(";data="); - buf.append(data).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/OrderedMulticaster.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/OrderedMulticaster.java deleted file mode 100644 index 943dfa413..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/OrderedMulticaster.java +++ /dev/null @@ -1,297 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.IOException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Timer; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisconnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.internal.datashare.DataSharePlugin; - -/** - * @author pnehrer - */ -public class OrderedMulticaster extends AbstractMulticaster implements - Timeout.Listener { - - public static final short SEND = 3; - - public static final short RECEIVE = 4; - - public static final long DEFAULT_TIMEOUT = 1000; - - public static final String TRACE_TAG = "OrderedMulticaster"; - - private long sendTimeout; - - private long receiveTimeout; - - private Version nextVersion; - - private HashSet requests; - - private final Timer timer = new Timer(); - - private final HashMap timeouts = new HashMap(); - - private boolean granted; - - public synchronized boolean sendMessage(Object message) throws ECFException { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "sendMessage[message=" + message + "]"); - - try { - if (!waitToSend()) - return false; - - state = SEND; - nextVersion = new Version(localContainerID, - version.getSequence() + 1); - HashSet others = new HashSet(groupMembers); - requests = new HashSet(others); - granted = true; - try { - if (!requests.isEmpty()) { - context.sendMessage(null, new Request(nextVersion)); - wait(sendTimeout); - if (state != SEND) - return false; - } - - if (!granted || !requests.isEmpty()) { - context.sendMessage(null, new Abort(nextVersion)); - return false; - } - - context.sendMessage(null, new Message(nextVersion, message)); - version = nextVersion; - return true; - } catch (IOException e) { - throw new ECFException(e); - } catch (InterruptedException e) { - throw new ECFException(e); - } finally { - state = READY; - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - public String getStateStr() { - switch (state) { - case SEND: - return "SND"; - case RECEIVE: - return "RCV"; - default: - return super.getStateStr(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public synchronized void init(ISharedObjectConfig config) - throws SharedObjectInitException { - super.init(config); - - sendTimeout = DEFAULT_TIMEOUT; - receiveTimeout = DEFAULT_TIMEOUT; - - Map params = config.getProperties(); - if (params != null) { - Object param = params.get("sendTimeout"); - if (param instanceof Long) - sendTimeout = ((Long) param).longValue(); - - param = params.get("receiveTimeout"); - if (param instanceof Long) - receiveTimeout = ((Long) param).longValue(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - super.handleEvent(event); - if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Request) - handleRequest(e.getRemoteContainerID(), (Request) e.getData()); - else if (e.getData() instanceof Reply) - handleReply(e.getRemoteContainerID(), (Reply) e.getData()); - else if (e.getData() instanceof Abort) - handleAbort(e.getRemoteContainerID(), (Abort) e.getData()); - } - } - - protected void handleDeparted(ISharedObjectContainerDisconnectedEvent event) { - super.handleDeparted(event); - if (!event.getTargetID().equals(localContainerID)) { - synchronized (this) { - if (state == SEND) { - requests.remove(event.getTargetID()); - if (requests.isEmpty()) - notify(); - } else if (state == RECEIVE) { - Timeout[] t = (Timeout[]) timeouts.values().toArray( - new Timeout[timeouts.size()]); - for (int i = 0; i < t.length; ++i) { - if (t[i].getVersion().getSenderID().equals( - event.getTargetID()) - && t[i].cancel()) - timeouts.remove(t[i].getVersion()); - } - - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - } - } - } - } - - private synchronized void handleRequest(ID remoteContainerID, - Request request) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleRequest[remoteContainerID=" - + remoteContainerID + ";request=" + request + "]"); - - try { - if ((state == READY || state == RECEIVE) - && version.getSequence() + 1 == request.getVersion() - .getSequence()) { - Timeout timeout = new Timeout(this, request.getVersion()); - timeouts.put(request.getVersion(), timeout); - timer.schedule(timeout, receiveTimeout); - context.sendMessage(remoteContainerID, new Reply(request - .getVersion(), true)); - if (state == READY) - notify(); - - state = RECEIVE; - } else if (state != DISPOSED) - context.sendMessage(remoteContainerID, new Reply(request - .getVersion(), false)); - } catch (IOException e) { - DataSharePlugin.log(e); - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleReply(ID remoteContainerID, Reply reply) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleReply[remoteContainerID=" - + remoteContainerID + ";reply=" + reply + "]"); - - try { - if (state == SEND && reply.getVersion().equals(nextVersion)) { - if (!reply.isGranted()) { - granted = false; - notify(); - } - - requests.remove(remoteContainerID); - if (requests.isEmpty()) - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - protected synchronized void handleMessage(ID remoteContainerID, - Message message) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleMessage[remoteContainerID=" - + remoteContainerID + ";message=" + message + "]"); - - try { - Timeout timeout; - if (((timeout = (Timeout) timeouts.get(message.getVersion())) != null) - && timeout.cancel()) { - version = message.getVersion(); - timeouts.remove(version); - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - - receiveMessage(message.getVersion(), message.getData()); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - private synchronized void handleAbort(ID remoteContainerID, Abort abort) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "handleAbort[remoteContainerID=" - + remoteContainerID + ";abort=" + abort + "]"); - - try { - Timeout timeout = (Timeout) timeouts.remove(abort.getVersion()); - if (timeout != null && timeout.cancel()) { - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } - - public synchronized void timeout(Version version) { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "timeout[version=" + version + "]"); - - try { - timeouts.remove(version); - if (timeouts.isEmpty()) { - state = READY; - notify(); - } - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Pause.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Pause.java deleted file mode 100644 index 4bf3ae694..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Pause.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -/** - * @author pnehrer - * - */ -public class Pause implements Serializable { - - private static final long serialVersionUID = 3258417222501347637L; - -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Paused.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Paused.java deleted file mode 100644 index 7c7f6d070..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Paused.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -/** - * @author pnehrer - */ -public class Paused implements Serializable { - - private static final long serialVersionUID = 3978705103752868913L; - -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Reply.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Reply.java deleted file mode 100644 index 19839bed2..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Reply.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Reply implements Serializable { - - private static final long serialVersionUID = 3689632497314837046L; - - final Version version; - - final boolean granted; - - public Reply(Version version, boolean granted) { - this.version = version; - this.granted = granted; - } - - public Version getVersion() { - return version; - } - - public boolean isGranted() { - return granted; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Reply[version="); - buf.append(version).append(";granted="); - buf.append(granted).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Request.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Request.java deleted file mode 100644 index e02d87511..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Request.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -public class Request implements Serializable { - - private static final long serialVersionUID = 3257003237730365493L; - - final Version version; - - public Request(Version version) { - this.version = version; - } - - public Version getVersion() { - return version; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Request[version="); - buf.append(version).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Resume.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Resume.java deleted file mode 100644 index 5046854df..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Resume.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -/** - * @author pnehrer - * - */ -public class Resume implements Serializable { - - private static final long serialVersionUID = 3258133557074540854L; - -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/SimpleMulticaster.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/SimpleMulticaster.java deleted file mode 100644 index 3421d221a..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/SimpleMulticaster.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.IOException; - -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.internal.datashare.DataSharePlugin; - -/** - * @author pnehrer - */ -public class SimpleMulticaster extends AbstractMulticaster { - - public static final String TRACE_TAG = "SimpleMulticaster"; - - public synchronized boolean sendMessage(Object message) throws ECFException { - String method = null; - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceEntry(method = "sendMessage[message=" + message + "]"); - - try { - if (!waitToSend()) - return false; - - version = new Version(localContainerID, version.getSequence() + 1); - context.sendMessage(null, new Message(version, message)); - return true; - } catch (IOException e) { - throw new ECFException(e); - } finally { - if (DataSharePlugin.isTracing(TRACE_TAG)) - traceExit(method); - } - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Timeout.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Timeout.java deleted file mode 100644 index 3ae5fd113..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Timeout.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.util.TimerTask; - -class Timeout extends TimerTask { - - interface Listener { - void timeout(Version version); - } - - private final Listener listener; - - final Version version; - - public Timeout(Listener listener, Version version) { - this.listener = listener; - this.version = version; - } - - public Version getVersion() { - return version; - } - - public void run() { - listener.timeout(version); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Version.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Version.java deleted file mode 100644 index 53753aa56..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/multicast/Version.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * 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.multicast; - -import java.io.Serializable; - -import org.eclipse.ecf.core.identity.ID; - -public class Version implements Serializable { - - private static final long serialVersionUID = 3762538901495101236L; - - private final ID senderID; - - private final long sequence; - - public Version(ID senderID, long sequence) { - this.senderID = senderID; - this.sequence = sequence; - } - - public ID getSenderID() { - return senderID; - } - - public long getSequence() { - return sequence; - } - - public boolean equals(Object other) { - if (other instanceof Version) { - Version o = (Version) other; - return senderID.equals(o.senderID) && sequence == o.sequence; - } else - return false; - } - - public int hashCode() { - int c = 17; - c = 37 * c + senderID.hashCode(); - c = 37 * c + (int) sequence; - return c; - } - - public String toString() { - StringBuffer buf = new StringBuffer("Version[senderID="); - buf.append(senderID).append(";sequence="); - buf.append(sequence).append(']'); - return buf.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/package.html b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/package.html new file mode 100644 index 000000000..e1721eee6 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/package.html @@ -0,0 +1,28 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<html> +<head> + <title>org.eclipse.ecf.datashare</title> +</head> +<body bgcolor="white"> +Provides DataShare Service API. DataShare allows clients to engage in real-time +collaborative sharing of arbitrary data. + +<h2>Package Specification</h2> + +<p>This package contains a set of interfaces that support a simple +protocol for real-time collaborative sharing of arbitrary data. +The client first obtains an implementation-specific {@link org.eclipse.ecf.datashare.DataShareService DataShareService}, +which allows it to {@link DataShareService#joinSession join} a data sharing {@link org.eclipse.ecf.datashare.Session session}. +The client may participate in the session by means of a {@link org.eclipse.ecf.datashare.Participant Participant}, +an instance of which it must supply to the service when joining the session. The participant instance is then +fully managed by the service -- it is {@link Participant#initialize initialized} with a {@link Session session} instance +and any initial data, it {@link Participant#receive receives} updates from others, and +{@link Session#send sends} its own updates using the session. It may choose +to {@link Session#leave leave} the session, or may otherwise be disconnected from it, +at which point it will be {@link Participant#dispose disposed}.</p> + +<p>The service makes no assumptions about the particular data representation or +the protocol that may be employed to keep the distributed copies synchronized. +The client is free to use any synchronization semantics it finds appropriate for the application.</p> +</body> +</html> diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/NotifyingSet.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/NotifyingSet.java deleted file mode 100644 index 28a8b6401..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/NotifyingSet.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * 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.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.Serializable; -import java.util.Collections; -import java.util.EventListener; -import java.util.EventObject; -import java.util.HashSet; -import java.util.Set; - -/** - * @author pnehrer - */ -public class NotifyingSet implements Serializable { - - private static final long serialVersionUID = 3258134639355967536L; - - public static interface IChangeListener extends EventListener { - - void changed(ChangeEvent e); - } - - public static class ChangeDelta implements Serializable { - - private static final long serialVersionUID = 3618133446644806960L; - - public static final short ADD = 0; - - public static final short REMOVE = 1; - - protected transient final NotifyingSet source; - - protected final Object member; - - private final short kind; - - protected ChangeDelta(NotifyingSet source, Object member, short kind) { - this.source = source; - this.member = member; - this.kind = kind; - } - - public final Object getMember() { - return member; - } - - public final short getKind() { - return kind; - } - } - - public static class ChangeEvent extends EventObject { - - private static final long serialVersionUID = 3834307341121041721L; - - private final ChangeDelta[] deltas; - - protected ChangeEvent(NotifyingSet source, ChangeDelta[] deltas) { - super(source); - this.deltas = deltas; - } - - protected ChangeEvent(NotifyingSet source, ChangeDelta delta) { - this(source, new ChangeDelta[] { delta }); - } - - public NotifyingSet getTrackedSet() { - return (NotifyingSet) source; - } - - public ChangeDelta[] getChangeDeltas() { - return deltas; - } - } - - private final HashSet set; - - private transient Set listeners = Collections - .synchronizedSet(new HashSet()); - - public NotifyingSet() { - set = new HashSet(); - } - - public NotifyingSet(Set set) { - this.set = new HashSet(set); - } - - public void addChangeListener(IChangeListener l) { - listeners.add(l); - } - - public void removeChangeListener(IChangeListener l) { - listeners.remove(l); - } - - public synchronized boolean add(Object object) { - boolean result = set.add(object); - if (result) - fireChangeEvent(new ChangeEvent(this, new ChangeDelta(this, object, - ChangeDelta.ADD))); - - return result; - } - - public synchronized boolean remove(Object object) { - boolean result = set.remove(object); - if (result) - fireChangeEvent(new ChangeEvent(this, new ChangeDelta(this, object, - ChangeDelta.REMOVE))); - - return result; - } - - public synchronized boolean contains(Object object) { - return set.contains(object); - } - - public synchronized int size() { - return set.size(); - } - - public synchronized Object[] toArray() { - return set.toArray(); - } - - private void fireChangeEvent(ChangeEvent e) { - IChangeListener[] l = (IChangeListener[]) listeners - .toArray(new IChangeListener[listeners.size()]); - for (int i = 0; i < l.length; ++i) - l[i].changed(e); - } - - private void readObject(ObjectInputStream in) throws IOException, - ClassNotFoundException { - in.defaultReadObject(); - listeners = Collections.synchronizedSet(new HashSet()); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSet.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSet.java deleted file mode 100644 index f4f8831e1..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSet.java +++ /dev/null @@ -1,104 +0,0 @@ -/******************************************************************************* - * 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.util; - -import java.io.IOException; -import java.io.ObjectInputStream; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Set; - -/** - * @author pnehrer - */ -public class TrackedSet extends NotifyingSet implements - NotifyingSet.IChangeListener { - - private static final long serialVersionUID = 3258134660897847607L; - - private transient LinkedList changes = new LinkedList(); - - /** - * - */ - public TrackedSet() { - addChangeListener(this); - } - - /** - * @param set - */ - public TrackedSet(Set set) { - super(set); - addChangeListener(this); - } - - public synchronized ChangeDelta[] getChanges() { - return (ChangeDelta[]) changes.toArray(new ChangeDelta[changes.size()]); - } - - /** - * @param deltas - */ - public synchronized void apply(ChangeDelta[] deltas) { - removeChangeListener(this); - LinkedList oldChanges = new LinkedList(changes); - while (!changes.isEmpty()) - undo((ChangeDelta) changes.removeLast()); - - for (int i = 0; i < deltas.length; ++i) - apply(deltas[i]); - - addChangeListener(this); - for (Iterator i = oldChanges.iterator(); i.hasNext();) - apply((ChangeDelta) i.next()); - } - - private void undo(ChangeDelta delta) { - switch (delta.getKind()) { - case ChangeDelta.ADD: - remove(delta.getMember()); - break; - case ChangeDelta.REMOVE: - add(delta.getMember()); - break; - } - } - - private void apply(ChangeDelta delta) { - switch (delta.getKind()) { - case ChangeDelta.ADD: - add(delta.getMember()); - break; - case ChangeDelta.REMOVE: - remove(delta.getMember()); - break; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.util.NotifyingSet.IChangeListener#changed(org.eclipse.ecf.datashare.util.NotifyingSet.ChangeEvent) - */ - public synchronized void changed(ChangeEvent e) { - ChangeDelta[] deltas = e.getChangeDeltas(); - for (int i = 0; i < deltas.length; ++i) - changes.add(deltas[i]); - } - - private void readObject(ObjectInputStream in) throws IOException, - ClassNotFoundException { - in.defaultReadObject(); - changes = new LinkedList(); - addChangeListener(this); - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSetUpdateProvider.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSetUpdateProvider.java deleted file mode 100644 index 83403da32..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/TrackedSetUpdateProvider.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * 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.util; - -import java.util.Map; - -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.datashare.ISharedData; -import org.eclipse.ecf.datashare.IUpdateProvider; -import org.eclipse.ecf.datashare.IUpdateProviderFactory; - -/** - * @author pnehrer - */ -public class TrackedSetUpdateProvider implements IUpdateProvider { - - private final Factory factory; - - private TrackedSetUpdateProvider(Factory factory) { - this.factory = factory; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IUpdateProvider#getFactory() - */ - public IUpdateProviderFactory getFactory() { - return factory; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IUpdateProvider#createUpdate(org.eclipse.ecf.datashare.ISharedData) - */ - public Object createUpdate(ISharedData graph) throws ECFException { - return ((TrackedSet) graph.getData()).getChanges(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IUpdateProvider#applyUpdate(org.eclipse.ecf.datashare.ISharedData, - * java.lang.Object) - */ - public void applyUpdate(ISharedData graph, Object data) throws ECFException { - ((TrackedSet) graph.getData()).apply((NotifyingSet.ChangeDelta[]) data); - } - - public static class Factory implements IUpdateProviderFactory { - - public static final String ID = "org.eclipse.ecf.datashare.util.TrackedSet"; - - public String getID() { - return ID; - } - - public IUpdateProvider createProvider(Map params) { - return new TrackedSetUpdateProvider(this); - } - } -} 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 deleted file mode 100644 index 03bb15d6e..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitablePublicationCallback.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * 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.util; - -import org.eclipse.ecf.core.util.ECFException; -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; - - private Throwable cause; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.sdo.IPublicationCallback#dataGraphPublished(org.eclipse.ecf.sdo.ISharedDataGraph) - */ - public synchronized void dataPublished(ISharedData graph) { - published = true; - notifyAll(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IPublicationCallback#publicationFailed(org.eclipse.ecf.datashare.ISharedData, - * java.lang.Throwable) - */ - public synchronized void publicationFailed(ISharedData graph, - Throwable cause) { - this.cause = cause; - 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, ECFException { - if (!published && cause == null) - wait(timeout); - - if (cause != null) - throw new ECFException(cause); - - 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 deleted file mode 100644 index 17da8bd3e..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/datashare/util/WaitableSubscriptionCallback.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * 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.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/Agent.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Agent.java deleted file mode 100644 index 0d51fa0bb..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Agent.java +++ /dev/null @@ -1,330 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.ecf.core.ISharedObject; -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.ISharedObjectContext; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectActivatedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.datashare.IPublicationCallback; -import org.eclipse.ecf.datashare.ISharedData; -import org.eclipse.ecf.datashare.IUpdateProvider; -import org.eclipse.ecf.datashare.UpdateProviderRegistry; -import org.eclipse.ecf.datashare.multicast.AbstractMulticaster; -import org.eclipse.ecf.datashare.multicast.Activated; -import org.eclipse.ecf.datashare.multicast.IMessageListener; -import org.eclipse.ecf.datashare.multicast.Version; - -/** - * <p> - * State chart: - * </p> - * <p> - * 1. DataShareService.publish(Object, ID, IUpdateProvider, - * IPublicationCallback) -> PUBLISHED - * </p> - * - * @author pnehrer - */ -public class Agent implements ISharedData, ISharedObject, IMessageListener { - - private Object sharedData; - - private ISharedObjectConfig config; - - private IBootstrap bootstrap; - - private ID newContainerID; - - private AbstractMulticaster sender; - - private IUpdateProvider updateProvider; - - private IPublicationCallback pubCallback; - - /** - * Default constructor; necessary for replication. - */ - public Agent() { - } - - /** - * Publisher's constructor; fully initializes the instance. - * - * @param sharedData - * @param bootstrap - * @param updateProvider - * @param pubCallback - */ - public Agent(Object sharedData, IBootstrap bootstrap, - AbstractMulticaster sender, IUpdateProvider updateProvider, - IPublicationCallback pubCallback) { - this.sharedData = sharedData; - this.bootstrap = bootstrap; - this.sender = sender; - this.updateProvider = updateProvider; - this.pubCallback = pubCallback; - } - - public synchronized ID getID() { - return config == null ? null : config.getSharedObjectID(); - } - - public Object getData() { - return sharedData; - } - - public synchronized void commit() throws ECFException { - Object update = updateProvider.createUpdate(this); - boolean sent = sender.sendMessage(update); - if (!sent) - throw new ECFException("Commit failed."); - } - - public synchronized void dispose() { - // TODO Finish implementing. - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public synchronized void init(ISharedObjectConfig config) - throws SharedObjectInitException { - this.config = config; - Map params = config.getProperties(); - ISharedObjectConfig bootstrapConfig = null; - ISharedObjectConfig senderConfig = null; - if (params != null) { - Object param = params.get("sharedData"); - if (param != null) - sharedData = param; - - param = params.get("bootstrap"); - if (param != null) { - SharedObjectDescription sd = (SharedObjectDescription) param; - try { - Class bootstrapClass = Class.forName(sd.getClassname()); - bootstrap = (IBootstrap) bootstrapClass.newInstance(); - bootstrapConfig = new ComponentConfig(sd); - } catch (ClassNotFoundException e) { - throw new SharedObjectInitException(e); - } catch (InstantiationException e) { - throw new SharedObjectInitException(e); - } catch (IllegalAccessException e) { - throw new SharedObjectInitException(e); - } - } - - param = params.get("sender"); - if (param != null) { - SharedObjectDescription sd = (SharedObjectDescription) param; - try { - Class senderClass = Class.forName(sd.getClassname()); - sender = (AbstractMulticaster) senderClass.newInstance(); - senderConfig = new ComponentConfig(sd); - } catch (ClassNotFoundException e) { - throw new SharedObjectInitException(e); - } catch (InstantiationException e) { - throw new SharedObjectInitException(e); - } catch (IllegalAccessException e) { - throw new SharedObjectInitException(e); - } - } - - param = params.get("updateProvider"); - if (param != null) - updateProvider = UpdateProviderRegistry.createProvider( - (String) param, null); // TODO what about params? - } - - bootstrap.setAgent(this); - bootstrap.init(bootstrapConfig == null ? new ComponentConfig(null) - : bootstrapConfig); - - sender.addMessageListener(this); - sender.init(senderConfig == null ? new ComponentConfig(null) - : senderConfig); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - bootstrap.handleEvent(event); - sender.handleEvent(event); - if (event instanceof ISharedObjectActivatedEvent) { - ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event; - if (e.getActivatedID().equals(config.getSharedObjectID())) - handleActivated(); - } else if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Activated) - handleActivated(e.getRemoteContainerID(), (Activated) e - .getData()); - } - } - - private void handleActivated() { - if (config.getHomeContainerID().equals( - config.getContext().getLocalContainerID())) - try { - Map params = new HashMap(4); - params.put("sharedData", sharedData); - params.put("bootstrap", bootstrap.createDescription()); - params.put("sender", sender.createDescription()); - params.put("updateProvider", updateProvider.getFactory() - .getID()); - config.getContext().sendCreate( - null, - new SharedObjectDescription(config.getSharedObjectID(), - getClass(), params)); - if (pubCallback != null) - pubCallback.dataPublished(this); - } catch (IOException e) { - handleError(e); - if (pubCallback != null) - pubCallback.publicationFailed(this, e); - } finally { - pubCallback = null; - } - } - - public synchronized void doBootstrap(ID containerID) { - while (newContainerID != null) - try { - wait(); - } catch (InterruptedException e) { - handleError(e); - } - - try { - sender.pause(); - } catch (IllegalStateException e) { - handleError(e); - return; - } catch (ECFException e) { - handleError(e); - return; - } - - Map params = new HashMap(4); - params.put("sharedData", sharedData); - params.put("bootstrap", bootstrap.createDescription()); - params.put("sender", sender.createDescription()); - params.put("updateProvider", updateProvider.getFactory().getID()); - try { - config.getContext().sendCreate( - containerID, - new SharedObjectDescription(config.getSharedObjectID(), - getClass(), params)); - wait(1000); - newContainerID = null; - } catch (IOException e) { - handleError(e); - } catch (InterruptedException e) { - handleError(e); - } finally { - try { - sender.resume(); - } catch (IllegalStateException e) { - handleError(e); - } catch (ECFException e) { - handleError(e); - } - } - } - - private synchronized void handleActivated(ID remoteContainerID, - Activated activated) { - if (remoteContainerID.equals(newContainerID)) - notify(); - } - - private void handleError(Throwable t) { - t.printStackTrace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[]) - */ - public void handleEvents(Event[] events) { - for (int i = 0; i < events.length; ++i) - handleEvent(events[i]); - } - - public synchronized void messageReceived(Version version, Object message) { - try { - updateProvider.applyUpdate(this, message); - } catch (ECFException e) { - handleError(e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - sender.dispose(containerID); - bootstrap.dispose(containerID); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } - - private class ComponentConfig implements ISharedObjectConfig { - - private final SharedObjectDescription sd; - - public ComponentConfig(SharedObjectDescription sd) { - this.sd = sd; - } - - public ID getSharedObjectID() { - return config.getSharedObjectID(); - } - - public ID getHomeContainerID() { - return config.getHomeContainerID(); - } - - public ISharedObjectContext getContext() { - return config.getContext(); - } - - public Map getProperties() { - return sd == null ? null : sd.getProperties(); - } - } -} 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 deleted file mode 100644 index 93eed4509..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataSharePlugin.java +++ /dev/null @@ -1,250 +0,0 @@ -/******************************************************************************* - * 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.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.eclipse.ecf.datashare.IUpdateProviderFactory; -import org.eclipse.ecf.datashare.UpdateProviderRegistry; -import org.osgi.framework.BundleContext; - -/** - * @author pnehrer - */ -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 = "servicemanager"; - - private static final String MANAGER_EXTENSION = "manager"; - - private static final String ATTR_NAME = "name"; - - private static final String ATTR_CLASS = "class"; - - private static final String PROVIDER_EXTENSION_POINT = "updateprovider"; - - private static final String PROVIDER_EXTENSION = "updateProvider"; - - private static final String ATTR_ID = "id"; - - private static final String ATTR_FACTORY = "factory"; - - 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); - final String namespace = getBundle().getSymbolicName(); - registryChangeListener = new IRegistryChangeListener() { - public void registryChanged(IRegistryChangeEvent event) { - IExtensionDelta[] deltas = event - .getExtensionDeltas(namespace); - for (int i = 0; i < deltas.length; ++i) { - IConfigurationElement[] elems = deltas[i] - .getExtension().getConfigurationElements(); - switch (deltas[i].getKind()) { - case IExtensionDelta.ADDED: - if (deltas[i].getExtensionPoint() - .getSimpleIdentifier().equals( - MANAGER_EXTENSION_POINT)) - registerManagers(elems); - else if (deltas[i].getExtensionPoint() - .getSimpleIdentifier().equals( - PROVIDER_EXTENSION_POINT)) - registerProviders(elems); - - break; - - case IExtensionDelta.REMOVED: - if (deltas[i].getExtensionPoint() - .getSimpleIdentifier().equals( - MANAGER_EXTENSION_POINT)) - unregisterManagers(elems); - else if (deltas[i].getExtensionPoint() - .getSimpleIdentifier().equals( - PROVIDER_EXTENSION_POINT)) - unregisterProviders(elems); - break; - } - } - } - }; - - IExtensionRegistry reg = Platform.getExtensionRegistry(); - reg.addRegistryChangeListener(registryChangeListener, namespace); - IConfigurationElement[] elems = reg.getConfigurationElementsFor( - namespace, MANAGER_EXTENSION_POINT); - registerManagers(elems); - elems = reg.getConfigurationElementsFor(namespace, - PROVIDER_EXTENSION_POINT); - registerProviders(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); - } - } - - private void registerProviders(IConfigurationElement[] elems) { - for (int i = 0; i < elems.length; ++i) { - if (!PROVIDER_EXTENSION.equals(elems[i].getName())) - continue; - - String id = elems[i].getAttribute(ATTR_ID); - if (id == null || id.length() == 0) - continue; - - IUpdateProviderFactory factory; - try { - factory = (IUpdateProviderFactory) elems[i] - .createExecutableExtension(ATTR_FACTORY); - } catch (Exception ex) { - continue; - } - - UpdateProviderRegistry.registerFactory(id, factory); - } - } - - private void unregisterManagers(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) - DataShareServiceFactory.unregisterManager(name); - } - } - - private void unregisterProviders(IConfigurationElement[] elems) { - for (int i = 0; i < elems.length; ++i) { - if (!PROVIDER_EXTENSION.equals(elems[i].getName())) - continue; - - String id = elems[i].getAttribute(ATTR_ID); - if (id != null && id.length() > 0) - UpdateProviderRegistry.unregisterFactory(id); - } - } - - /** - * 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(); - UpdateProviderRegistry.unregisterAllFactories(); - 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))); - } - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataShareService.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataShareService.java deleted file mode 100644 index ae8196eab..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/DataShareService.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.datashare.IDataShareService; -import org.eclipse.ecf.datashare.IPublicationCallback; -import org.eclipse.ecf.datashare.ISharedData; -import org.eclipse.ecf.datashare.ISubscriptionCallback; -import org.eclipse.ecf.datashare.IUpdateProvider; -import org.eclipse.ecf.datashare.multicast.AbstractMulticaster; -import org.eclipse.ecf.datashare.multicast.ConsistentMulticaster; - -/** - * @author pnehrer - */ -public class DataShareService implements IDataShareService { - - private ServiceManager mgr; - - private ISharedObjectContainer container; - - public DataShareService(ServiceManager mgr, ISharedObjectContainer container) { - this.mgr = mgr; - this.container = container; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IDataShareService#publish(java.lang.Object, - * org.eclipse.ecf.core.identity.ID, - * org.eclipse.ecf.datashare.IUpdateProvider, - * org.eclipse.ecf.datashare.IPublicationCallback) - */ - public synchronized void publish(Object dataGraph, ID id, - IUpdateProvider provider, IPublicationCallback callback) - throws ECFException { - Agent agent = (Agent) container.getSharedObjectManager() - .getSharedObject(id); - if (agent != null) - throw new ECFException("Already published!"); - - IBootstrap bootstrap = getBootstrap(); - AbstractMulticaster sender = getSender(); - agent = new Agent(dataGraph, bootstrap, sender, provider, callback); - container.getSharedObjectManager().addSharedObject(id, agent, null); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IDataShareService#subscribe(org.eclipse.ecf.core.identity.ID, - * org.eclipse.ecf.datashare.ISubscriptionCallback) - */ - public synchronized ISharedData subscribe(ID id, - ISubscriptionCallback callback) throws ECFException { - Agent agent = (Agent) container.getSharedObjectManager() - .getSharedObject(id); - if (agent == null) - return null; // TODO should we throw? - - if (callback != null) - callback.dataSubscribed(agent, container.getID()); - - return agent; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IDataShareService#dispose() - */ - public synchronized void dispose() { - mgr.dispose(container); - mgr = null; - container = null; - } - - private IBootstrap getBootstrap() { - return new ServerBootstrap(); // TODO strategize - } - - private AbstractMulticaster getSender() { - return new ConsistentMulticaster(); // TODO strategize - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/EagerElectionBootstrap.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/EagerElectionBootstrap.java deleted file mode 100644 index cc272fb25..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/EagerElectionBootstrap.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.Timer; -import java.util.TimerTask; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectActivatedEvent; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisconnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectContainerConnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.Event; - -/** - * @author pnehrer - */ -public class EagerElectionBootstrap implements IBootstrap { - - private final Random random = new Random(); - - private Agent agent; - - private ISharedObjectConfig config; - - private ID coordinatorID; - - private Election election; - - private final Timer timer = new Timer(); - - private TimerTask task; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#setAgent(org.eclipse.ecf.internal.datashare.Agent) - */ - public void setAgent(Agent agent) { - this.agent = agent; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public void init(ISharedObjectConfig config) - throws SharedObjectInitException { - this.config = config; - Map params = config.getProperties(); - if (params != null) { - Object param = params.get("coordinatorID"); - if (param != null) - coordinatorID = (ID) param; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - if (event instanceof ISharedObjectActivatedEvent) { - ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event; - if (e.getActivatedID().equals(config.getSharedObjectID())) - handleActivated(); - } else if (event instanceof ISharedObjectContainerConnectedEvent) { - ISharedObjectContainerConnectedEvent e = (ISharedObjectContainerConnectedEvent) event; - if (!e.getTargetID().equals(e.getLocalContainerID())) - handleJoined(e.getTargetID()); - } else if (event instanceof ISharedObjectContainerDisconnectedEvent) { - ISharedObjectContainerDisconnectedEvent e = (ISharedObjectContainerDisconnectedEvent) event; - if (!e.getTargetID().equals(e.getLocalContainerID())) - handleDeparted(e.getTargetID()); - } else if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Vote) - handleVote((Vote) e.getData(), e.getRemoteContainerID()); - else if (e.getData() instanceof Elected) - handleElected(e.getRemoteContainerID()); - else if (e.getData() instanceof Ping) - handlePing(); - } - } - - private synchronized void handleActivated() { - if (config.getHomeContainerID().equals( - config.getContext().getLocalContainerID())) { - coordinatorID = config.getContext().getLocalContainerID(); - timer.schedule(task = new Pinger(), 1000, 1000); // TODO make configurable - } else { - timer.schedule(task = new PingWatch(), 2000); // TODO make configurable - } - } - - private synchronized void handleJoined(ID containerID) { - // TODO what if election is pending? - if (config.getContext().getLocalContainerID().equals(coordinatorID)) - agent.doBootstrap(containerID); - } - - private synchronized void handleVote(Vote msg, ID containerID) { - if (election != null) { - switch (election.processVote(msg.getTicket(), containerID)) { - case Election.WON: - processVictory(); - case Election.LOST: - election = null; - } - } - } - - private synchronized void handleElected(ID containerID) { - election = null; - coordinatorID = containerID; - timer.schedule(task = new PingWatch(), 2000); - } - - private synchronized void handleDeparted(ID containerID) { - if (containerID.equals(coordinatorID)) - startElection(); - } - - private void handlePing() { - if (task != null) - task.cancel(); - - timer.schedule(task = new PingWatch(), 2000); - } - - private synchronized void startElection() { - if (task != null) - task.cancel(); - - List members = Arrays.asList(config.getContext().getGroupMemberIDs()); - members.remove(config.getContext().getLocalContainerID()); - if (members.isEmpty()) - processVictory(); - else { - long ticket = random.nextLong(); // TODO strategize this - election = new Election(ticket, members); - try { - config.getContext().sendMessage(null, new Vote(ticket, null)); - } catch (IOException e) { - handleError(e); - } - } - } - - private void processVictory() { - try { - config.getContext().sendMessage(null, new Elected(null)); - coordinatorID = config.getContext().getLocalContainerID(); - timer.schedule(task = new Pinger(), 1000, 1000); - } catch (IOException e) { - handleError(e); - } - } - - private void handleError(Throwable t) { - t.printStackTrace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - timer.cancel(); - config = null; - } - - public SharedObjectDescription createDescription() { - HashMap params = new HashMap(1); - params.put("coordinatorID", coordinatorID); - return new SharedObjectDescription(config.getSharedObjectID(), - getClass(), params); - } - - private class Pinger extends TimerTask { - - public void run() { - try { - config.getContext().sendMessage(null, new Ping()); - } catch (IOException e) { - handleError(e); - } - } - } - - private class PingWatch extends TimerTask { - - public void run() { - startElection(); - } - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Elected.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Elected.java deleted file mode 100644 index 6f0483f58..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Elected.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.Serializable; - -import org.eclipse.ecf.core.identity.ID; - -/** - * @author pnehrer - */ -public class Elected implements Serializable { - - private static final long serialVersionUID = 3258130271390937656L; - - private final ID electionID; - - public Elected(ID electionID) { - this.electionID = electionID; - } - - public ID getElectionID() { - return electionID; - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Election.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Election.java deleted file mode 100644 index cd8c74466..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Election.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.util.Collection; -import java.util.HashSet; - -import org.eclipse.ecf.core.identity.ID; - -/** - * @author pnehrer - */ -public class Election { - - public static final short LOST = 0; - - public static final short WON = 1; - - public static final short UNKNOWN = 2; - - private final long ticket; - - private final HashSet members; - - public Election(long ticket, Collection members) { - this.ticket = ticket; - this.members = new HashSet(members); - } - - public synchronized short processVote(long ticket, ID containerID) { - if (this.ticket < ticket) - return LOST; - else { - members.remove(containerID); - return members.isEmpty() ? WON : UNKNOWN; - } - } - - public synchronized short disqualify(ID containerID) { - members.remove(containerID); - return members.isEmpty() ? WON : UNKNOWN; - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/IBootstrap.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/IBootstrap.java deleted file mode 100644 index fdaeeb531..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/IBootstrap.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.Event; - -/** - * @author pnehrer - */ -public interface IBootstrap { - - void setAgent(Agent agent); - - void init(ISharedObjectConfig config) throws SharedObjectInitException; - - void handleEvent(Event event); - - void dispose(ID containerID); - - SharedObjectDescription createDescription(); -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/LazyElectionBootstrap.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/LazyElectionBootstrap.java deleted file mode 100644 index 89b12a220..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/LazyElectionBootstrap.java +++ /dev/null @@ -1,175 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Random; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisconnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectContainerConnectedEvent; -import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.Event; - -/** - * @author pnehrer - */ -public class LazyElectionBootstrap implements IBootstrap { - - private final Random random = new Random(); - - private Agent agent; - - private ISharedObjectConfig config; - - private final HashMap elections = new HashMap(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#setAgent(org.eclipse.ecf.internal.datashare.Agent) - */ - public void setAgent(Agent agent) { - this.agent = agent; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public void init(ISharedObjectConfig config) - throws SharedObjectInitException { - this.config = config; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - if (event instanceof ISharedObjectContainerConnectedEvent) { - ISharedObjectContainerConnectedEvent e = (ISharedObjectContainerConnectedEvent) event; - if (!e.getTargetID().equals(e.getLocalContainerID())) - handleJoined(e.getTargetID()); - } else if (event instanceof ISharedObjectContainerDisconnectedEvent) { - ISharedObjectContainerDisconnectedEvent e = (ISharedObjectContainerDisconnectedEvent) event; - if (!e.getTargetID().equals(e.getLocalContainerID())) - handleDeparted(e.getTargetID()); - } else if (event instanceof ISharedObjectMessageEvent) { - ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; - if (e.getData() instanceof Vote) - handleVote((Vote) e.getData(), e.getRemoteContainerID()); - else if (e.getData() instanceof Elected) - handleElected((Elected) e.getData()); - } - } - - private void handleJoined(ID containerID) { - ArrayList members = new ArrayList(Arrays.asList(config.getContext() - .getGroupMemberIDs())); - members.remove(containerID); - members.remove(config.getContext().getLocalContainerID()); - if (members.isEmpty()) - processVictory(containerID); - else { - long ticket = random.nextLong(); // TODO strategize this - Election election = new Election(ticket, members); - synchronized (elections) { - elections.put(containerID, election); - } - - try { - config.getContext().sendMessage(null, - new Vote(ticket, containerID)); - } catch (IOException e) { - handleError(e); - } - } - } - - private void handleVote(Vote msg, ID containerID) { - synchronized (elections) { - Election election = (Election) elections.get(msg.getElectionID()); - if (election != null) { - switch (election.processVote(msg.getTicket(), containerID)) { - case Election.WON: - processVictory(msg.getElectionID()); - case Election.LOST: - elections.remove(msg.getElectionID()); - } - } - } - } - - private void handleElected(Elected msg) { - synchronized (elections) { - elections.remove(msg.getElectionID()); - } - } - - private void handleDeparted(ID containerID) { - synchronized (elections) { - for (Iterator i = elections.entrySet().iterator(); i.hasNext();) { - Map.Entry entry = (Map.Entry) i.next(); - ID electionID = (ID) entry.getKey(); - if (containerID.equals(electionID)) - i.remove(); - else { - Election election = (Election) entry.getValue(); - switch (election.disqualify(containerID)) { - case Election.WON: - processVictory(electionID); - case Election.LOST: - i.remove(); - break; - } - } - } - } - } - - private void processVictory(ID electionID) { - try { - config.getContext().sendMessage(null, new Elected(electionID)); - agent.doBootstrap(electionID); - } catch (IOException e) { - handleError(e); - } - } - - private void handleError(Throwable t) { - t.printStackTrace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - config = null; - } - - public SharedObjectDescription createDescription() { - return new SharedObjectDescription(config.getSharedObjectID(), - getClass()); - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Ping.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Ping.java deleted file mode 100644 index 7759a0ac3..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Ping.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.Serializable; - -/** - * @author pnehrer - * - */ -public class Ping implements Serializable { - - private static final long serialVersionUID = 3258131340921812018L; - -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServerBootstrap.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServerBootstrap.java deleted file mode 100644 index d0d56c243..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServerBootstrap.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.ISharedObjectContainerConnectedEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.Event; - -/** - * @author pnehrer - */ -public class ServerBootstrap implements IBootstrap { - - private Agent agent; - - private ISharedObjectConfig config; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#setAgent(org.eclipse.ecf.internal.datashare.Agent) - */ - public void setAgent(Agent agent) { - this.agent = agent; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public void init(ISharedObjectConfig config) - throws SharedObjectInitException { - this.config = config; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - if (event instanceof ISharedObjectContainerConnectedEvent) { - ISharedObjectContainerConnectedEvent e = (ISharedObjectContainerConnectedEvent) event; - if (!e.getTargetID().equals(e.getLocalContainerID())) - handleJoined(e.getTargetID()); - } - } - - private void handleJoined(ID containerID) { - if (config.getContext().isGroupManager()) - agent.doBootstrap(containerID); - } - /* - private void handleError(Throwable t) { - t.printStackTrace(); - } - */ - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.datashare.IBootstrap#dispose(org.eclipse.ecf.core.identity.ID) - */ - public void dispose(ID containerID) { - config = null; - } - - public SharedObjectDescription createDescription() { - return new SharedObjectDescription(config.getSharedObjectID(), - getClass()); - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServiceManager.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServiceManager.java deleted file mode 100644 index 4e0dd9df2..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/ServiceManager.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.util.Hashtable; - -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.ISharedObjectContainerListener; -import org.eclipse.ecf.core.events.IContainerEvent; -import org.eclipse.ecf.core.events.ISharedObjectContainerDisposeEvent; -import org.eclipse.ecf.core.util.ECFException; -import org.eclipse.ecf.datashare.IDataShareService; -import org.eclipse.ecf.datashare.IDataShareServiceManager; - -/** - * @author pnehrer - */ -public class ServiceManager implements IDataShareServiceManager { - - private final Hashtable instances = new Hashtable(); - - private final Hashtable listeners = new Hashtable(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.datashare.IDataShareServiceManager#getInstance(org.eclipse.ecf.core.ISharedObjectContainer) - */ - public synchronized IDataShareService getInstance( - ISharedObjectContainer container) throws ECFException { - IDataShareService svc = (IDataShareService) instances.get(container); - if (svc == null) { - svc = new DataShareService(this, container); - instances.put(container, svc); - DisposeListener listener = new DisposeListener(container); - listeners.put(container, listener); - container.addListener(listener, null); - } - - return svc; - } - - public synchronized void dispose(ISharedObjectContainer container) { - instances.remove(container); - listeners.remove(container); - } - - private class DisposeListener implements ISharedObjectContainerListener { - - private final ISharedObjectContainer container; - - public DisposeListener(ISharedObjectContainer container) { - this.container = container; - } - - public void handleEvent(IContainerEvent evt) { - if (evt instanceof ISharedObjectContainerDisposeEvent) - dispose(container); - } - } -} diff --git a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Vote.java b/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Vote.java deleted file mode 100644 index f60f34427..000000000 --- a/framework/bundles/org.eclipse.ecf.datashare/src/org/eclipse/ecf/internal/datashare/Vote.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * 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.internal.datashare; - -import java.io.Serializable; - -import org.eclipse.ecf.core.identity.ID; - -/** - * @author pnehrer - */ -public class Vote implements Serializable { - - private static final long serialVersionUID = 3977585813699507248L; - - private final long ticket; - - private final ID electionID; - - public Vote(long ticket, ID electionID) { - this.ticket = ticket; - this.electionID = electionID; - } - - public long getTicket() { - return ticket; - } - - public ID getElectionID() { - return electionID; - } -} |
