Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpnehrer2005-01-31 00:55:08 -0500
committerpnehrer2005-01-31 00:55:08 -0500
commitb29a3350ff6fccf582240381a72e4dacf6dffb4f (patch)
tree3748612822f62800c1825ed45ef131624e2e50fc /examples/bundles/org.eclipse.ecf.sdo/src/org
parent8747bd9166f70acabdb3fe8c2393586b570e5030 (diff)
downloadorg.eclipse.ecf-b29a3350ff6fccf582240381a72e4dacf6dffb4f.tar.gz
org.eclipse.ecf-b29a3350ff6fccf582240381a72e4dacf6dffb4f.tar.xz
org.eclipse.ecf-b29a3350ff6fccf582240381a72e4dacf6dffb4f.zip
Initial check-in.
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.sdo/src/org')
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/DataGraphSharing.java176
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/ReceiveDataGraphMessage.java58
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/RequestDataGraphMessage.java20
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/SharedDataGraph.java275
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/UpdateDataGraphMessage.java58
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/Version.java68
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharing.java71
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISharedDataGraph.java52
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISubscriptionCallback.java33
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateConsumer.java47
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateProvider.java78
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java109
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SubscriptionBlocker.java52
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/emf/EMFUpdateProvider.java147
-rw-r--r--examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/package.html65
15 files changed, 1309 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/DataGraphSharing.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/DataGraphSharing.java
new file mode 100644
index 000000000..f54698110
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/DataGraphSharing.java
@@ -0,0 +1,176 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.core.ISharedObject;
+import org.eclipse.ecf.core.ISharedObjectConfig;
+import org.eclipse.ecf.core.ISharedObjectManager;
+import org.eclipse.ecf.core.SharedObjectAddException;
+import org.eclipse.ecf.core.SharedObjectInitException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.Event;
+import org.eclipse.ecf.sdo.IDataGraphSharing;
+import org.eclipse.ecf.sdo.ISharedDataGraph;
+import org.eclipse.ecf.sdo.ISubscriptionCallback;
+import org.eclipse.ecf.sdo.IUpdateConsumer;
+import org.eclipse.ecf.sdo.IUpdateProvider;
+import org.eclipse.ecf.sdo.SDOPlugin;
+
+import commonj.sdo.DataGraph;
+
+/**
+ * @author pnehrer
+ */
+public class DataGraphSharing extends PlatformObject implements
+ IDataGraphSharing, ISharedObject {
+
+ public static final String DATA_GRAPH_SHARING_ID = DataGraphSharing.class
+ .getName();
+
+ private ISharedObjectConfig config;
+
+ private boolean debug;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IDataGraphSharing#publish(commonj.sdo.DataGraph,
+ * org.eclipse.ecf.core.identity.ID,
+ * org.eclipse.ecf.sdo.IUpdateProvider,
+ * org.eclipse.ecf.sdo.IUpdateConsumer)
+ */
+ public synchronized ISharedDataGraph publish(DataGraph dataGraph, ID id,
+ IUpdateProvider provider, IUpdateConsumer consumer)
+ throws CoreException {
+
+ if (config == null)
+ throw new CoreException(new Status(Status.ERROR, SDOPlugin
+ .getDefault().getBundle().getSymbolicName(), 0,
+ "Not initialized.", null));
+
+ // create local object
+ ISharedObjectManager mgr = config.getContext().getSharedObjectManager();
+ SharedDataGraph sdg = new SharedDataGraph(dataGraph, provider, consumer);
+ sdg.setDebug(debug);
+
+ try {
+ mgr.addSharedObject(id, sdg, null, null);
+ } catch (SharedObjectAddException e) {
+ throw new CoreException(new Status(Status.ERROR, SDOPlugin
+ .getDefault().getBundle().getSymbolicName(), 0,
+ "Could not publish data graph.", e));
+ }
+
+ return sdg;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IDataGraphSharing#subscribe(org.eclipse.ecf.core.identity.ID,
+ * org.eclipse.ecf.sdo.ISubscriptionCallback,
+ * org.eclipse.ecf.sdo.IUpdateProvider,
+ * org.eclipse.ecf.sdo.IUpdateConsumer)
+ */
+ public synchronized ISharedDataGraph subscribe(ID id,
+ ISubscriptionCallback callback, IUpdateProvider provider,
+ IUpdateConsumer consumer) throws CoreException {
+
+ if (config == null)
+ throw new CoreException(new Status(Status.ERROR, SDOPlugin
+ .getDefault().getBundle().getSymbolicName(), 0,
+ "Not initialized.", null));
+
+ // create local object
+ ISharedObjectManager mgr = config.getContext().getSharedObjectManager();
+ SharedDataGraph sdg = new SharedDataGraph(null, provider, consumer,
+ callback);
+ sdg.setDebug(debug);
+
+ try {
+ mgr.addSharedObject(id, sdg, null, null);
+ } catch (SharedObjectAddException e) {
+ throw new CoreException(new Status(Status.ERROR, SDOPlugin
+ .getDefault().getBundle().getSymbolicName(), 0,
+ "Could not subscribe to data graph with id" + id + ".", e));
+ }
+
+ return sdg;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IDataGraphSharing#dispose()
+ */
+ public synchronized void dispose() {
+ if (config != null)
+ config.getContext().getSharedObjectManager().removeSharedObject(
+ config.getSharedObjectID());
+ }
+
+ /**
+ * Sets the debug flag.
+ *
+ * @param debug
+ * @deprecated Use Eclipse's plugin tracing support instead.
+ */
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
+ */
+ public synchronized void init(ISharedObjectConfig initData)
+ throws SharedObjectInitException {
+
+ if (config == null)
+ config = initData;
+ else
+ throw new SharedObjectInitException("Already initialized.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event)
+ */
+ public void handleEvent(Event event) {
+ }
+
+ /*
+ * (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 synchronized void dispose(ID containerID) {
+ if (config != null
+ && config.getContext().getLocalContainerID()
+ .equals(containerID))
+ config = null;
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/ReceiveDataGraphMessage.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/ReceiveDataGraphMessage.java
new file mode 100644
index 000000000..b586a06e9
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/ReceiveDataGraphMessage.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import java.io.Serializable;
+
+/**
+ * @author pnehrer
+ */
+public class ReceiveDataGraphMessage implements Serializable {
+
+ private final Version version;
+
+ private final byte[] data;
+
+ public ReceiveDataGraphMessage(Version version, byte[] data) {
+ this.version = version;
+ this.data = data;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof ReceiveDataGraphMessage) {
+ ReceiveDataGraphMessage o = (ReceiveDataGraphMessage) other;
+ return version.equals(o.version) && data.equals(o.data);
+ } else
+ return false;
+ }
+
+ public int hashCode() {
+ int c = 17;
+ c = 37 * c + version.hashCode();
+ c = 37 * c + data.hashCode();
+ return c;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("ReceiveDataGraphMessage[");
+ buf.append("version=").append(version).append(";");
+ buf.append("data=").append(data).append("]");
+ return buf.toString();
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/RequestDataGraphMessage.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/RequestDataGraphMessage.java
new file mode 100644
index 000000000..6b2ce7e0c
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/RequestDataGraphMessage.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import java.io.Serializable;
+
+/**
+ * @author pnehrer
+ */
+public class RequestDataGraphMessage implements Serializable {
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/SharedDataGraph.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/SharedDataGraph.java
new file mode 100644
index 000000000..22f42ae08
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/SharedDataGraph.java
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.PlatformObject;
+import org.eclipse.ecf.core.ISharedObject;
+import org.eclipse.ecf.core.ISharedObjectConfig;
+import org.eclipse.ecf.core.SharedObjectInitException;
+import org.eclipse.ecf.core.events.ISharedObjectActivatedEvent;
+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.sdo.ISharedDataGraph;
+import org.eclipse.ecf.sdo.ISubscriptionCallback;
+import org.eclipse.ecf.sdo.IUpdateConsumer;
+import org.eclipse.ecf.sdo.IUpdateProvider;
+
+import commonj.sdo.ChangeSummary;
+import commonj.sdo.DataGraph;
+
+/**
+ * @author pnehrer
+ */
+public class SharedDataGraph extends PlatformObject implements ISharedObject,
+ ISharedDataGraph {
+
+ private final IUpdateConsumer updateConsumer;
+
+ private final ISubscriptionCallback subscriptionCallback;
+
+ private final IUpdateProvider updateProvider;
+
+ private ISharedObjectConfig config;
+
+ private DataGraph dataGraph;
+
+ private Version version;
+
+ private boolean debug;
+
+ SharedDataGraph(DataGraph dataGraph, IUpdateProvider updateProvider,
+ IUpdateConsumer updateConsumer,
+ ISubscriptionCallback subscriptionCallback) {
+ this.dataGraph = dataGraph;
+ this.updateProvider = updateProvider;
+ this.updateConsumer = updateConsumer;
+ this.subscriptionCallback = subscriptionCallback;
+ }
+
+ SharedDataGraph(DataGraph dataGraph, IUpdateProvider updateProvider,
+ IUpdateConsumer updateConsumer) {
+ this(dataGraph, updateProvider, updateConsumer, null);
+ }
+
+ void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISharedDataGraph#getID()
+ */
+ public synchronized ID getID() {
+ return config == null ? null : config.getSharedObjectID();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISharedDataGraph#getDataGraph()
+ */
+ public synchronized DataGraph getDataGraph() {
+ return dataGraph;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISharedDataGraph#dispose()
+ */
+ public synchronized void dispose() {
+ if (config != null)
+ config.getContext().getSharedObjectManager().removeSharedObject(
+ config.getSharedObjectID());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISharedDataGraph#commit()
+ */
+ public synchronized void commit() throws ECFException {
+ if (config == null)
+ throw new ECFException("Object is disconnected.");
+
+ if (dataGraph == null)
+ throw new ECFException("Not subscribed.");
+
+ ChangeSummary changeSummary = dataGraph.getChangeSummary();
+ if (changeSummary.getChangedDataObjects().isEmpty())
+ return;
+
+ changeSummary.endLogging();
+ byte[] data = updateProvider.createUpdate(this);
+ try {
+ config.getContext().sendMessage(null,
+ new UpdateDataGraphMessage(version, data));
+ } catch (IOException e) {
+ throw new ECFException(e);
+ }
+
+ changeSummary.beginLogging();
+ version = version.getNext(config.getContext().getLocalContainerID());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
+ */
+ public synchronized void init(ISharedObjectConfig initData)
+ throws SharedObjectInitException {
+
+ if (config == null)
+ config = initData;
+ else
+ throw new SharedObjectInitException("Already initialized.");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.util.Event)
+ */
+ public void handleEvent(Event event) {
+ if (event instanceof ISharedObjectActivatedEvent
+ && ((ISharedObjectActivatedEvent) event).getActivatedID()
+ .equals(config.getSharedObjectID())) {
+ synchronized (this) {
+ if (dataGraph == null) {
+ try {
+ config.getContext().sendMessage(null,
+ new RequestDataGraphMessage());
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ } else {
+ if (version == null)
+ version = new Version(config.getSharedObjectID());
+
+ dataGraph.getChangeSummary().beginLogging();
+ }
+ }
+ } else if (event instanceof ISharedObjectDeactivatedEvent
+ && ((ISharedObjectDeactivatedEvent) event).getDeactivatedID()
+ .equals(config.getSharedObjectID())) {
+ synchronized (this) {
+ if (dataGraph != null
+ && dataGraph.getChangeSummary().isLogging())
+ dataGraph.getChangeSummary().endLogging();
+ }
+ } else if (event instanceof ISharedObjectMessageEvent) {
+ ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event;
+ Object msg = e.getData();
+ if (msg instanceof RequestDataGraphMessage)
+ handleRequestDataGraphMessage(e.getRemoteContainerID());
+ else if (msg instanceof ReceiveDataGraphMessage) {
+ ReceiveDataGraphMessage m = (ReceiveDataGraphMessage) msg;
+ handleReceiveDataGraphMessage(e.getRemoteContainerID(), m
+ .getVersion(), m.getData());
+ } else if (msg instanceof UpdateDataGraphMessage) {
+ UpdateDataGraphMessage m = (UpdateDataGraphMessage) msg;
+ handleUpdateDataGraphMessage(e.getRemoteContainerID(), m
+ .getVersion(), m.getData());
+ }
+ }
+ }
+
+ private synchronized void handleRequestDataGraphMessage(ID containerID) {
+ if (dataGraph == null)
+ return;
+
+ try {
+ byte[] data = updateProvider.serializeDataGraph(dataGraph);
+ config.getContext().sendMessage(containerID,
+ new ReceiveDataGraphMessage(version, data));
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private synchronized void handleReceiveDataGraphMessage(ID containerID,
+ Version version, byte[] data) {
+ if (dataGraph == null) {
+ try {
+ dataGraph = updateProvider.deserializeDataGraph(data);
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ return;
+ }
+
+ this.version = version;
+ dataGraph.getChangeSummary().beginLogging();
+ if (subscriptionCallback != null)
+ subscriptionCallback.dataGraphSubscribed(this, containerID);
+ }
+ }
+
+ private synchronized void handleUpdateDataGraphMessage(ID containerID,
+ Version version, byte[] data) {
+
+ if (dataGraph == null)
+ return;
+
+ if (!version.equals(this.version)) {
+ if (debug)
+ System.err.println("Version mismatch: current=" + this.version
+ + "; new=" + version);
+
+ updateConsumer.updateFailed(this, containerID);
+ return;
+ }
+
+ updateProvider.applyUpdate(this, data);
+ if (updateConsumer.consumeUpdate(this, containerID))
+ this.version = version.getNext(containerID);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.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.identity.ID)
+ */
+ public synchronized void dispose(ID containerID) {
+ if (config != null
+ && config.getContext().getLocalContainerID()
+ .equals(containerID))
+ config = null;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("SharedDataGraph[");
+ buf.append("config=").append(config).append(";");
+ buf.append("dataGraph=").append(dataGraph).append(";");
+ buf.append("version=").append(version).append(";");
+ buf.append("debug=").append(debug).append("]");
+ return buf.toString();
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/UpdateDataGraphMessage.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/UpdateDataGraphMessage.java
new file mode 100644
index 000000000..02ac5f59d
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/UpdateDataGraphMessage.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import java.io.Serializable;
+
+/**
+ * @author pnehrer
+ */
+public class UpdateDataGraphMessage implements Serializable {
+
+ private final Version version;
+
+ private final byte[] data;
+
+ public UpdateDataGraphMessage(Version version, byte[] data) {
+ this.version = version;
+ this.data = data;
+ }
+
+ public Version getVersion() {
+ return version;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof UpdateDataGraphMessage) {
+ UpdateDataGraphMessage o = (UpdateDataGraphMessage) other;
+ return version.equals(o.version) && data.equals(o.data);
+ } else
+ return false;
+ }
+
+ public int hashCode() {
+ int c = 17;
+ c = 37 * c + version.hashCode();
+ c = 37 * c + data.hashCode();
+ return c;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("UpdateDataGraphMessage[");
+ buf.append("version=").append(version).append(";");
+ buf.append("data=").append(data).append("]");
+ return buf.toString();
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/Version.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/Version.java
new file mode 100644
index 000000000..9cf10db99
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/internal/sdo/Version.java
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.internal.sdo;
+
+import java.io.Serializable;
+
+import org.eclipse.ecf.core.identity.ID;
+
+/**
+ * @author pnehrer
+ */
+public class Version implements Serializable {
+
+ private final long sequence;
+
+ private final ID containerID;
+
+ public Version(ID sourceID) {
+ this(0, sourceID);
+ }
+
+ private Version(long sequence, ID sourceID) {
+ this.sequence = sequence;
+ this.containerID = sourceID;
+ }
+
+ public long getSequence() {
+ return sequence;
+ }
+
+ public ID getContainerID() {
+ return containerID;
+ }
+
+ public Version getNext(ID sourceID) {
+ return new Version(sequence + 1, sourceID);
+ }
+
+ public boolean equals(Object other) {
+ if (other instanceof Version) {
+ Version o = (Version) other;
+ return sequence == o.sequence && containerID.equals(o.containerID);
+ } else
+ return false;
+ }
+
+ public int hashCode() {
+ int c = 17;
+ c = 37 * c + (int) sequence;
+ c = 37 * c + containerID.hashCode();
+ return c;
+ }
+
+ public String toString() {
+ StringBuffer buf = new StringBuffer("Version[");
+ buf.append("sequence=").append(sequence).append(";");
+ buf.append("containerID=").append(containerID).append("]");
+ return buf.toString();
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharing.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharing.java
new file mode 100644
index 000000000..82756f3ab
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IDataGraphSharing.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ecf.core.identity.ID;
+
+import commonj.sdo.DataGraph;
+
+/**
+ * Allows clients to participate in data graph sharing. A container-specific
+ * instance may be obtained by calling
+ * {@link org.eclipse.ecf.sdo.SDOPlugin#getDataGraphSharing(org.eclipse.ecf.ISharedObjectContainer) SDOPlugin.getDataGraphSharing(&lt;container&gt;)}.
+ *
+ * @author pnehrer
+ */
+public interface IDataGraphSharing {
+
+ /**
+ * Publishes the given data graph under the given id.
+ *
+ * @param dataGraph
+ * local data graph instance to share
+ * @param id
+ * identifier under which to share this data graph
+ * @param provider
+ * update provider compatible with the given data graph's
+ * implementation
+ * @param consumer
+ * application-specific update consumer
+ * @return shared data graph
+ * @throws CoreException
+ */
+ ISharedDataGraph publish(DataGraph dataGraph, ID id,
+ IUpdateProvider provider, IUpdateConsumer consumer)
+ throws CoreException;
+
+ /**
+ * Subscribes to a data graph with the given id.
+ *
+ * @param id
+ * identifier of a previously-published data graph
+ * @param callback
+ * callback used to notify the caller when the subscription
+ * completes
+ * @param provider
+ * update provider compatible with the given data graph's
+ * implementation
+ * @param consumer
+ * application-specific update consumer
+ * @return shared data graph
+ * @throws CoreException
+ */
+ ISharedDataGraph subscribe(ID id, ISubscriptionCallback callback,
+ IUpdateProvider provider, IUpdateConsumer consumer)
+ throws CoreException;
+
+ /**
+ * Disposes this instance, after which it will be no longer possible to
+ * publish or subscribe.
+ */
+ void dispose();
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISharedDataGraph.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISharedDataGraph.java
new file mode 100644
index 000000000..80c5e2533
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISharedDataGraph.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.util.ECFException;
+
+import commonj.sdo.DataGraph;
+
+/**
+ * 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 ISharedDataGraph {
+
+ /**
+ * 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
+ */
+ DataGraph getDataGraph();
+
+ /**
+ * 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/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISubscriptionCallback.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISubscriptionCallback.java
new file mode 100644
index 000000000..f1149c797
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/ISubscriptionCallback.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.ecf.core.identity.ID;
+
+/**
+ * Interface used by service implementations to notify subscribing applications
+ * when the initial copy of the data graph has been obtained.
+ *
+ * @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 dataGraphSubscribed(ISharedDataGraph graph, ID containerID);
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateConsumer.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateConsumer.java
new file mode 100644
index 000000000..2cf0c1279
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateConsumer.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+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 IUpdateConsumer {
+
+ /**
+ * Consumes the remote update. The implementor is expected to leave behind
+ * an empty Change Summary.
+ *
+ * @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(ISharedDataGraph 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
+ */
+ void updateFailed(ISharedDataGraph graph, ID containerID);
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateProvider.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateProvider.java
new file mode 100644
index 000000000..7aceb9150
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/IUpdateProvider.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import java.io.IOException;
+
+import org.eclipse.ecf.core.util.ECFException;
+
+import commonj.sdo.DataGraph;
+
+/**
+ * <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 witin ECF are resolved, the service also
+ * needs to delegate data graph (de)serialization during subscription.
+ * </p>
+ *
+ * @author pnehrer
+ */
+public interface IUpdateProvider {
+
+ /**
+ * Creates an update from the given data graph, which will be forwarded to
+ * other group members. The implementor may use the graph's Change Summary
+ * to find out what changed.
+ *
+ * @param graph
+ * shared data graph from whose changes to create the update
+ * @return serialized update data
+ * @throws ECFException
+ */
+ byte[] createUpdate(ISharedDataGraph 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
+ */
+ void applyUpdate(ISharedDataGraph graph, byte[] data);
+
+ /**
+ * Serializes the given data graph.
+ *
+ * @param graph
+ * data graph instance to serialize
+ * @return serialized data graph
+ * @throws IOException
+ */
+ byte[] serializeDataGraph(DataGraph graph) throws IOException;
+
+ /**
+ * Deserializes the given data graph.
+ *
+ * @param data
+ * serialized data graph
+ * @return deserialized instance of data graph
+ * @throws ClassNotFoundException
+ */
+ DataGraph deserializeDataGraph(byte[] data) throws ClassNotFoundException;
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java
new file mode 100644
index 000000000..0b815b41f
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SDOPlugin.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.ISharedObjectManager;
+import org.eclipse.ecf.core.SharedObjectAddException;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.IDInstantiationException;
+import org.eclipse.ecf.internal.sdo.DataGraphSharing;
+import org.osgi.framework.BundleContext;
+
+/**
+ * (Temporary) entry point into the Shared Data Graph API. Serves as an
+ * {@link org.eclipse.ecf.sdo.IDataGraphSharing IDataGraphSharing}factory.
+ *
+ * @author pnehrer
+ */
+public class SDOPlugin extends Plugin {
+
+ // The shared instance.
+ private static SDOPlugin plugin;
+
+ private boolean debug;
+
+ /**
+ * The constructor.
+ */
+ public SDOPlugin() {
+ super();
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static SDOPlugin getDefault() {
+ return plugin;
+ }
+
+ public IDataGraphSharing getDataGraphSharing(
+ ISharedObjectContainer container) throws CoreException {
+
+ ISharedObjectManager mgr = container.getSharedObjectManager();
+ ID id;
+ try {
+ id = IDFactory.makeStringID(DataGraphSharing.DATA_GRAPH_SHARING_ID);
+ } catch (IDInstantiationException e) {
+ throw new CoreException(new Status(Status.ERROR, getBundle()
+ .getSymbolicName(), 0,
+ "Could not create data graph sharing ID.", e));
+ }
+
+ synchronized (container) {
+ DataGraphSharing result = (DataGraphSharing) mgr
+ .getSharedObject(id);
+ if (result == null) {
+ result = new DataGraphSharing();
+ result.setDebug(debug);
+ try {
+ mgr.addSharedObject(id, result, null, null);
+ } catch (SharedObjectAddException e) {
+ throw new CoreException(new Status(Status.ERROR,
+ getBundle().getSymbolicName(), 0,
+ "Could not add data sharing to the container.", e));
+ }
+ }
+
+ return result;
+ }
+ }
+
+ /**
+ * Sets the debug flag.
+ *
+ * @param debug
+ * @deprecated Use Eclipse plug-in tracing support instead.
+ */
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SubscriptionBlocker.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SubscriptionBlocker.java
new file mode 100644
index 000000000..bdfad8415
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/SubscriptionBlocker.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo;
+
+import org.eclipse.ecf.core.identity.ID;
+
+/**
+ * Convenience callback implementation that can be used to block the calling
+ * thread until the data graph is obtained.
+ *
+ * @author pnehrer
+ */
+public class SubscriptionBlocker implements ISubscriptionCallback {
+
+ private boolean subscribed;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.ISubscriptionCallback#dataGraphObtained(org.eclipse.ecf.sdo.ISharedDataGraph,
+ * org.eclipse.ecf.core.identity.ID)
+ */
+ public synchronized void dataGraphSubscribed(ISharedDataGraph graph,
+ ID containerID) {
+ subscribed = true;
+ notifyAll();
+ }
+
+ /**
+ * Blocks the calling thread until the data graph is obtained.
+ *
+ * @param timeout
+ * period, in milliseconds, to wait for subscription
+ * @return <code>true</code> if the data graph has been obtained
+ * @throws InterruptedException
+ */
+ public synchronized boolean waitForSubscription(long timeout)
+ throws InterruptedException {
+ if (!subscribed)
+ wait(timeout);
+
+ return subscribed;
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/emf/EMFUpdateProvider.java b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/emf/EMFUpdateProvider.java
new file mode 100644
index 000000000..94a8e4ef7
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/emf/EMFUpdateProvider.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2004 Peter Nehrer and Composent, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Peter Nehrer - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.ecf.sdo.emf;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.sdo.ISharedDataGraph;
+import org.eclipse.ecf.sdo.IUpdateProvider;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.sdo.EChangeSummary;
+import org.eclipse.emf.ecore.sdo.EDataGraph;
+import org.eclipse.emf.ecore.sdo.util.SDOUtil;
+
+import commonj.sdo.DataGraph;
+
+/**
+ * Update provider capable of handling EMF-based SDO data graphs.
+ *
+ * @author pnehrer
+ */
+public class EMFUpdateProvider implements IUpdateProvider {
+
+ private boolean debug;
+
+ /**
+ * Sets the debug flag.
+ *
+ * @param debug
+ * @deprecated Use Eclipse's plugin tracing support instead.
+ */
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ private EDataGraph clone(EDataGraph source) throws IOException {
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ source.getDataGraphResource().save(buf, null);
+ return SDOUtil.loadDataGraph(
+ new ByteArrayInputStream(buf.toByteArray()), null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IUpdateProvider#createUpdate(org.eclipse.ecf.sdo.ISharedDataGraph)
+ */
+ public byte[] createUpdate(ISharedDataGraph graph) throws ECFException {
+ EDataGraph clone;
+ try {
+ clone = clone((EDataGraph) graph.getDataGraph());
+ } catch (IOException e) {
+ throw new ECFException(e);
+ }
+
+ EChangeSummary changes = (EChangeSummary) clone.getChangeSummary();
+ changes.applyAndReverse();
+
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ try {
+ changes.eResource().save(buf, null);
+ if (debug) {
+ System.out.println("commit:");
+ changes.eResource().save(System.out, null);
+ }
+ } catch (IOException e) {
+ throw new ECFException(e);
+ }
+
+ return buf.toByteArray();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IUpdateProvider#applyUpdate(org.eclipse.ecf.sdo.ISharedDataGraph,
+ * byte[])
+ */
+ public void applyUpdate(ISharedDataGraph graph, byte[] data) {
+ EDataGraph dataGraph = (EDataGraph) graph.getDataGraph();
+ EChangeSummary changeSummary = (EChangeSummary) dataGraph
+ .getChangeSummary();
+ changeSummary.endLogging();
+ changeSummary.apply();
+
+ Resource res = changeSummary.eResource();
+ res.unload();
+
+ // apply changes from the event
+ try {
+ res.load(new ByteArrayInputStream(data), null);
+ if (debug) {
+ System.out.println("processUpdate:");
+ res.save(System.out, null);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ changeSummary = (EChangeSummary) res.getContents().get(0);
+ dataGraph.setEChangeSummary(changeSummary);
+ changeSummary.applyAndReverse();
+ changeSummary.resumeLogging();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IUpdateProvider#serializeDataGraph(commonj.sdo.DataGraph)
+ */
+ public byte[] serializeDataGraph(DataGraph dataGraph) throws IOException {
+ EDataGraph clone = clone((EDataGraph) dataGraph);
+ EChangeSummary changeSummary = clone.getEChangeSummary();
+ if (changeSummary != null)
+ changeSummary.apply();
+
+ ByteArrayOutputStream buf = new ByteArrayOutputStream();
+ clone.getDataGraphResource().save(buf, null);
+ return buf.toByteArray();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ecf.sdo.IUpdateProvider#deserializeDataGraph(byte[])
+ */
+ public DataGraph deserializeDataGraph(byte[] data)
+ throws ClassNotFoundException {
+ try {
+ return SDOUtil.loadDataGraph(new ByteArrayInputStream(data), null);
+ } catch (IOException e) {
+ throw new ClassNotFoundException(
+ "Could not deserialize data graph.", e);
+ }
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/package.html b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/package.html
new file mode 100644
index 000000000..15286a3d8
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.sdo/src/org/eclipse/ecf/sdo/package.html
@@ -0,0 +1,65 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+ <meta content="text/html; charset=ISO-8859-1"
+ http-equiv="content-type">
+ <title>org.eclipse.ecf.sdo</title>
+ <meta content="Peter Nehrer" name="author">
+</head>
+<body>
+<p>Provides the ability to share structured data graphs among Shared
+Object Containers joined in the same group. The shared data graphs must
+comply with the Service Data Objects API.</p>
+<h2>Package Specification</h2>
+<p>This package provides the API to support replication of structured
+object state (represented by SDO data graphs) across multiple
+processes. Specifically, it allows the clients to:</p>
+<ol>
+ <li>publish SDO data graphs to the group, thus making them available
+for subscription</li>
+ <li>subscribe to data graphs published by other group members</li>
+</ol>
+<p>Subsequently, both publishers and subscribers are:</p>
+<ol>
+ <li>able to commit changes they make locally, thus making them
+visible to the whole group</li>
+ <li>notified when other group members make changes</li>
+</ol>
+<p>In terms of SDO, the group (or network) acts as a Data Mediator to
+clients committing a change. That is, the network logs any changes that
+are made to the data graph by the client between commits. When the
+client commits, the network uses the data graph's Change Summary to
+determine what has changed and make it available to other group members
+(the specifics of how this is done depend on the chosen
+implementation).
+</p>
+<p>When a client listens to changes from the network, the client itself
+acts as a Data Mediator to the network; that is, the client logs any
+changes that are made to the data graph by the network between updates.
+When an update is received, the client is notified and may use the data
+graph's Change Summary to determine what has changed (at which point it
+may process the changes in an application-specific manner).
+</p>
+<p>In the generic case, a client may both commit and receive updates at
+the same time; it may make changes to the local data graph (with the
+intention to commit at some point) and decide what to do when a remote
+update is received (e.g., it may choose to discard its local changes,
+or merge them in, etc.)
+</p>
+<p>To get started, the client must have a container instance and make
+sure it is connected (i.e., part of a group) before changes can be made
+and/or received. With this the client may obtain the service facade,
+which will allow it to publish/subscribe to data graphs; for instance:
+</p>
+<pre>ISharedObjectContainer container = &lt;container instance&gt;;<br>IDataGraphSharing svc = SDOPlugin.getDefault().getDataGraphSharing(container);<br>// publish existing data graph instance<br>ISharedDataGraph sharedDataGraph = svc.publish(dataGraph, id, provider, consumer);<br>// --OR-- subscribe to a published data graph<br>ISharedDataGraph sharedDataGraph = svc.subscribe(id, callback, provider, consumer);<br>DataGraph dataGraph = sharedDataGraph.getDataGraph();<br>// make changes to the data graph<br>// ...<br>sharedDataGraph.commit();<br></pre>
+<p>Notes:
+</p>
+<ul>
+ <li>the container need not be connected until publications or
+subscriptions are attempted</li>
+ <li>committing changes and receiving updates will not be possible
+once the container disconnects</li>
+ <li>data graph IDs must be unique within the given container</li>
+</ul>
+</body>
+</html>

Back to the top