Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-10-21 19:09:08 -0400
committerslewis2008-10-21 19:09:08 -0400
commit3b030e5eb08915ba736ac90200878a7a48f56104 (patch)
tree4d7670ca131074ec7b4ad899d8d04d631f00e923 /framework/bundles/org.eclipse.ecf.sync
parent9eff51e580fb504cba44936f6913899108067ea3 (diff)
downloadorg.eclipse.ecf-3b030e5eb08915ba736ac90200878a7a48f56104.tar.gz
org.eclipse.ecf-3b030e5eb08915ba736ac90200878a7a48f56104.tar.xz
org.eclipse.ecf-3b030e5eb08915ba736ac90200878a7a48f56104.zip
Added IAdaptable extension for ISynchronizationStrategy and other API. Provided implementations for identity and cola impls
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.sync')
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF4
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/Activator.java49
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/cola/ColaSynchronizationStrategy.java11
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/identity/IdentitySynchronizationStrategy.java12
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java4
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChangeMessage.java4
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelSynchronizationStrategy.java121
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java12
8 files changed, 163 insertions, 54 deletions
diff --git a/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
index b92239e96..eb666affa 100644
--- a/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
@@ -10,7 +10,9 @@ Import-Package: org.eclipse.core.runtime,
org.eclipse.ecf.core.identity,
org.eclipse.ecf.core.util,
org.eclipse.osgi.util,
- org.osgi.framework
+ org.osgi.framework,
+ org.osgi.service.log,
+ org.osgi.util.tracker
Eclipse-LazyStart: true
Bundle-ActivationPolicy: lazy
Bundle-Localization: plugin
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/Activator.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/Activator.java
index a6934b726..16cce7d48 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/Activator.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/Activator.java
@@ -3,6 +3,11 @@ package org.eclipse.ecf.internal.sync;
import java.util.Dictionary;
import java.util.Properties;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.core.util.LogHelper;
+import org.eclipse.ecf.core.util.PlatformHelper;
import org.eclipse.ecf.internal.sync.doc.cola.ColaSynchronizationStrategyFactory;
import org.eclipse.ecf.internal.sync.doc.identity.IdentitySynchronizationStrategyFactory;
import org.eclipse.ecf.sync.IServiceConstants;
@@ -10,6 +15,8 @@ import org.eclipse.ecf.sync.doc.IDocumentSynchronizationStrategyFactory;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.ServiceTracker;
public class Activator implements BundleActivator {
@@ -23,6 +30,40 @@ public class Activator implements BundleActivator {
IDocumentSynchronizationStrategyFactory identity;
IDocumentSynchronizationStrategyFactory cola;
+ private ServiceTracker adapterManagerTracker = null;
+ private ServiceTracker logServiceTracker = null;
+
+ public IAdapterManager getAdapterManager() {
+ // First, try to get the adapter manager via
+ if (adapterManagerTracker == null) {
+ adapterManagerTracker = new ServiceTracker(this.context, IAdapterManager.class.getName(), null);
+ adapterManagerTracker.open();
+ }
+ IAdapterManager adapterManager = (IAdapterManager) adapterManagerTracker.getService();
+ // Then, if the service isn't there, try to get from Platform class via
+ // PlatformHelper class
+ if (adapterManager == null)
+ adapterManager = PlatformHelper.getPlatformAdapterManager();
+ if (adapterManager == null)
+ getDefault().log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "Cannot get adapter manager", null)); //$NON-NLS-1$
+ return adapterManager;
+ }
+
+ protected LogService getLogService() {
+ if (logServiceTracker == null) {
+ logServiceTracker = new ServiceTracker(this.context, LogService.class.getName(), null);
+ logServiceTracker.open();
+ }
+ return (LogService) logServiceTracker.getService();
+ }
+
+ public void log(IStatus status) {
+ LogService logService = getLogService();
+ if (logService != null) {
+ logService.log(LogHelper.getLogCode(status), LogHelper.getLogMessage(status), status.getException());
+ }
+ }
+
public static Activator getDefault() {
return bundle;
}
@@ -69,6 +110,14 @@ public class Activator implements BundleActivator {
this.cola.dispose();
this.cola = null;
}
+ if (logServiceTracker != null) {
+ logServiceTracker.close();
+ logServiceTracker = null;
+ }
+ if (adapterManagerTracker != null) {
+ adapterManagerTracker.close();
+ adapterManagerTracker = null;
+ }
this.context = null;
bundle = null;
}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/cola/ColaSynchronizationStrategy.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/cola/ColaSynchronizationStrategy.java
index 05cd95a39..901d61c3c 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/cola/ColaSynchronizationStrategy.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/cola/ColaSynchronizationStrategy.java
@@ -19,6 +19,7 @@ import java.util.ListIterator;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.util.Trace;
import org.eclipse.ecf.internal.sync.Activator;
@@ -225,4 +226,14 @@ public class ColaSynchronizationStrategy implements IModelSynchronizationStrateg
final List l = this.transformIncomingMessage(m);
return (IDocumentChange[]) l.toArray(new IDocumentChange[] {});
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == null) return null;
+ IAdapterManager manager = Activator.getDefault().getAdapterManager();
+ if (manager == null) return null;
+ return manager.loadAdapter(this, adapter.getName());
+ }
} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/identity/IdentitySynchronizationStrategy.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/identity/IdentitySynchronizationStrategy.java
index b2dc92690..feef0d902 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/identity/IdentitySynchronizationStrategy.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/internal/sync/doc/identity/IdentitySynchronizationStrategy.java
@@ -11,6 +11,8 @@
package org.eclipse.ecf.internal.sync.doc.identity;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.ecf.internal.sync.Activator;
import org.eclipse.ecf.sync.IModelChange;
import org.eclipse.ecf.sync.IModelChangeMessage;
import org.eclipse.ecf.sync.IModelSynchronizationStrategy;
@@ -47,4 +49,14 @@ public class IdentitySynchronizationStrategy implements IModelSynchronizationStr
return new IModelChange[] {remoteChange};
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == null) return null;
+ IAdapterManager manager = Activator.getDefault().getAdapterManager();
+ if (manager == null) return null;
+ return manager.loadAdapter(this, adapter.getName());
+ }
+
}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
index 7a11c7f04..066a2bfbd 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
@@ -1,11 +1,13 @@
package org.eclipse.ecf.sync;
+import org.eclipse.core.runtime.IAdaptable;
+
/**
* Model change interface. This super interface is
* a 'tag' interface and does not define any methods.
* See sub-interfaces that extend this interface.
*
*/
-public interface IModelChange {
+public interface IModelChange extends IAdaptable {
}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChangeMessage.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChangeMessage.java
index 2f1d42d9c..98474a66c 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChangeMessage.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChangeMessage.java
@@ -11,13 +11,15 @@
package org.eclipse.ecf.sync;
+import org.eclipse.core.runtime.IAdaptable;
+
/**
* Change message. Instances of this interface
* may be serialized to a byte [] so that they can be
* communicated to remote processes.
*/
-public interface IModelChangeMessage {
+public interface IModelChangeMessage extends IAdaptable {
public byte[] serialize() throws SerializationException;
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelSynchronizationStrategy.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelSynchronizationStrategy.java
index 8f0db4a4c..14cbb0543 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelSynchronizationStrategy.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelSynchronizationStrategy.java
@@ -1,80 +1,99 @@
package org.eclipse.ecf.sync;
+import org.eclipse.core.runtime.IAdaptable;
/**
- * Model synchronization strategy contract. Model synchronization strategy instances
- * are used to synchronize replicated instances of an arbitrary model. This is done
- * by creating instances implementing this interface on participating processes, and
- * then using them in the following manner.
+ * Model synchronization strategy contract. Model synchronization strategy
+ * instances are used to synchronize replicated instances of an arbitrary model.
+ * This is done by creating instances implementing this interface on
+ * participating processes, and then using them in the following manner.
* <p>
- * First, assume for simplicity that there are two processes (A and B), each with a replica of
- * a given model (a and b). Also assume that prior to using a synchronization strategy
- * that the model is accurately and reliably replicated to A and B (i.e. a == b). Further, assume
- * that for both A and B an instance of IModelSynchronizationStrategy is created (call them
- * Sa and Sb) prior to any changes being made to either a or b.
+ * First, assume for simplicity that there are two processes (A and B), each
+ * with a replica of a given model (a and b). Also assume that prior to using a
+ * synchronization strategy that the model is accurately and reliably replicated
+ * to A and B (i.e. a == b). Further, assume that for both A and B an instance
+ * of IModelSynchronizationStrategy is created (call them Sa and Sb) prior to
+ * any changes being made to either a or b.
* </p>
* <p>
- * On process A assume that the user makes a change to a via a (local) editor. Then the expected
- * sequence of activities is as follows:
+ * On process A assume that the user makes a change to a via a (local) editor.
+ * Then the expected sequence of activities is as follows:
* </p>
* <ul>
- * <li>Process A should synchronously call {@link #registerLocalChange(IModelChange)}.
- * The IModelChange instance provided must be 1) not <code>null</code>; and 2) Of a type that is
+ * <li>Process A should synchronously call
+ * {@link #registerLocalChange(IModelChange)}. The IModelChange instance
+ * provided must be 1) not <code>null</code>; and 2) Of a type that is
* appropriate for this synchronization strategy.</li>
- * <li>Process A should take the resulting {@link IModelChangeMessage}, serialize it (by
- * calling {@link IModelChangeMessage#serialize()} and send the message to remote
- * processes (i.e. B).
- * </li>
+ * <li>Process A should take the resulting {@link IModelChangeMessage},
+ * serialize it (by calling {@link IModelChangeMessage#serialize()} and send the
+ * message to remote processes (i.e. B).</li>
* <li>
- * Process B should take the received byte array and call {@link #deserializeRemoteChange(byte[])}
- * to create an IModelChange instance.
- * </li>
+ * Process B should take the received byte array and call
+ * {@link #deserializeRemoteChange(byte[])} to create an IModelChange instance.</li>
* <li>
- * Process B should then pass the IModelChange instance to {@link #transformRemoteChange(IModelChange)}.
- * The synchronization implementation will then return an array of IModelChange instances (IModelChange []).
- * These IModelChange instance should then be cast to the appropriate type, and applied to
- * the local instance of the model (i.e. b). The {@link #transformRemoteChange(IModelChange)} metho
- * will take the local changes (previously registered with the synchronization strategy via
- * {@link #registerLocalChange(IModelChange)}), and the remote changes provided via
- * {@link #transformRemoteChange(IModelChange)},
- * and transform the changes into a set that will result in a synchronized local copy.
- * </li>
+ * Process B should then pass the IModelChange instance to
+ * {@link #transformRemoteChange(IModelChange)}. The synchronization
+ * implementation will then return an array of IModelChange instances
+ * (IModelChange []). These IModelChange instance should then be cast to the
+ * appropriate type, and applied to the local instance of the model (i.e. b).
+ * The {@link #transformRemoteChange(IModelChange)} metho will take the local
+ * changes (previously registered with the synchronization strategy via
+ * {@link #registerLocalChange(IModelChange)}), and the remote changes provided
+ * via {@link #transformRemoteChange(IModelChange)}, and transform the changes
+ * into a set that will result in a synchronized local copy.</li>
* </ul>
+ * <p>
+ * Note that clients should generally call the
+ * {@link #registerLocalChange(IModelChange)} and apply the IModelChanges
+ * returned from {@link #transformRemoteChange(IModelChange)} on the same thread
+ * that is responsible for modifying the underlying model. For example, if a
+ * document model is modified by an editor (via UI thread) then the UI thread
+ * should also synchronously call {@link #registerLocalChange(IModelChange)},
+ * and the changes from {@link #transformRemoteChange(IModelChange)} should also
+ * be applied to the local document from within this same thread.
+ * </p>
*/
-public interface IModelSynchronizationStrategy {
+public interface IModelSynchronizationStrategy extends IAdaptable {
/**
- * Register local model change with synchronization strategy. This method
- * should be synchronously called when a local model change has
- * been made to the underlying model.
- * @param localChange the IModelChange made to the local model. Must be non-<code>null</code>,
- * and must be of type appropriate for the synchronization strategy.
- * @return IModelChangeMessage[] an array of change message to be
- * delivered to remote participants. If no change message can be created
- * for this local change (e.g. because the localChange is not of the
- * expected type, or because the change is not to be propogated to remotes,
- * then an empty array will be returned).
+ * Register local model change with synchronization strategy. This method
+ * should be synchronously called when a local model change has been made to
+ * the underlying model.
+ *
+ * @param localChange
+ * the IModelChange made to the local model. Must be non-
+ * <code>null</code>, and must be of type appropriate for the
+ * synchronization strategy.
+ * @return IModelChangeMessage[] an array of change message to be delivered
+ * to remote participants. If no change message can be created for
+ * this local change (e.g. because the localChange is not of the
+ * expected type, or because the change is not to be propogated to
+ * remotes, then an empty array will be returned).
*/
public IModelChangeMessage[] registerLocalChange(IModelChange localChange);
/**
- * Transform remote change into a set of local changes to
- * be synchronously applied to the local model.
- * @param remoteChange the remote model change instance to
- * be transformed by this synchronization strategy.
+ * Transform remote change into a set of local changes to be synchronously
+ * applied to the local model.
+ *
+ * @param remoteChange
+ * the remote model change instance to be transformed by this
+ * synchronization strategy.
* @return IDocumentChange[] to apply to local model
*/
public IModelChange[] transformRemoteChange(IModelChange remoteChange);
-
/**
- * Deserialization of given byte array to concrete instance of
- * IModelChange object to represent local change to be applied
+ * Deserialization of given byte array to concrete instance of IModelChange
+ * object to represent local change to be applied
*
- * @param bytes the bytes to be deserialized
- * @return IModelChange instance from bytes. Will not be <code>null</code>.
- * @throws SerializationException thrown if some problem deserializing given bytes.
+ * @param bytes
+ * the bytes to be deserialized.
+ * @return IModelChange instance from bytes. Will not be <code>null</code>.
+ * @throws SerializationException
+ * thrown if some problem deserializing given bytes.
*/
- public IModelChange deserializeRemoteChange(byte[] bytes) throws SerializationException;
+ public IModelChange deserializeRemoteChange(byte[] bytes)
+ throws SerializationException;
}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
index 9a6581770..26eaaf7eb 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
@@ -19,6 +19,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import org.eclipse.core.runtime.IAdapterManager;
+import org.eclipse.ecf.internal.sync.Activator;
import org.eclipse.ecf.sync.IModelChangeMessage;
import org.eclipse.ecf.sync.SerializationException;
@@ -106,4 +108,14 @@ public class DocumentChangeMessage implements IDocumentChange, IModelChangeMessa
}
}
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class adapter) {
+ if (adapter == null) return null;
+ IAdapterManager manager = Activator.getDefault().getAdapterManager();
+ if (manager == null) return null;
+ return manager.loadAdapter(this, adapter.getName());
+ }
+
}

Back to the top