diff options
| author | pnehrer | 2005-02-02 04:55:23 +0000 |
|---|---|---|
| committer | pnehrer | 2005-02-02 04:55:23 +0000 |
| commit | 954dda47efdc701d357353760b1a5bb9da9e58f2 (patch) | |
| tree | 55847835788e87e57e437cc0134a81909c251c9a | |
| parent | 4c0b85baa826c563d7553ea6c8e94f07b189c1b3 (diff) | |
| download | org.eclipse.ecf-954dda47efdc701d357353760b1a5bb9da9e58f2.tar.gz org.eclipse.ecf-954dda47efdc701d357353760b1a5bb9da9e58f2.tar.xz org.eclipse.ecf-954dda47efdc701d357353760b1a5bb9da9e58f2.zip | |
Fixed graph tracking.
2 files changed, 81 insertions, 73 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java index fb4aa381b..ad9baf6c8 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java @@ -16,6 +16,7 @@ import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.ISharedObjectContainer; +import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.example.collab.Client; @@ -114,23 +115,30 @@ public class EditorPlugin extends AbstractUIPlugin { ISubscriptionCallback callback, IUpdateConsumer consumer) throws ECFException { initialize(); - return SDOPlugin.getDefault().getDataGraphSharing(container).subscribe( - IDFactory.makeStringID(path), callback, - new EMFUpdateProvider(), consumer); + SDOPlugin.getDefault().setDebug(true); + ID id = IDFactory.makeStringID(path); + ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( + container).subscribe(id, callback, new EMFUpdateProvider(), + consumer); + tracker.add(id); + return result; } public synchronized ISharedDataGraph publish(String path, DataGraph dataGraph, IUpdateConsumer consumer) throws ECFException { initialize(); SDOPlugin.getDefault().setDebug(true); - return SDOPlugin.getDefault().getDataGraphSharing(container).publish( - dataGraph, IDFactory.makeStringID(path), - new EMFUpdateProvider(), consumer); + ID id = IDFactory.makeStringID(path); + ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( + container).publish(dataGraph, id, new EMFUpdateProvider(), + consumer); + tracker.add(id); + return result; } public synchronized boolean isPublished(String path) throws ECFException { initialize(); - return tracker.isPublished(path); + return tracker.isPublished(IDFactory.makeStringID(path)); } public synchronized void checkConnected() throws ECFException { diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java index 394b0702a..ac94c6d06 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java @@ -34,7 +34,7 @@ import org.eclipse.ecf.core.util.Event; */ class PublishedGraphTracker extends PlatformObject implements ISharedObject { - private static final String[] NO_PATHS = {}; + private static final ID[] NO_GRAPHS = {}; private static final int JOIN = 0; @@ -46,68 +46,68 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { private class Table { - private final Hashtable paths = new Hashtable(); + private final Hashtable graphs = new Hashtable(); private final Hashtable containers = new Hashtable(); - public synchronized void add(ID containerID, String[] path) { - HashSet list = (HashSet) paths.get(containerID); + public synchronized void add(ID containerID, ID[] graphs) { + HashSet list = (HashSet) this.graphs.get(containerID); if (list == null) { list = new HashSet(); - paths.put(containerID, list); + this.graphs.put(containerID, list); } - list.addAll(Arrays.asList(path)); - for (int i = 0; i < path.length; ++i) { - list = (HashSet) containers.get(path[i]); + list.addAll(Arrays.asList(graphs)); + for (int i = 0; i < graphs.length; ++i) { + list = (HashSet) containers.get(graphs[i]); if (list == null) { list = new HashSet(); - containers.put(path[i], list); + containers.put(graphs[i], list); } list.add(containerID); } } - public synchronized void remove(ID containerID, String path) { - HashSet list = (HashSet) paths.get(containerID); + public synchronized void remove(ID containerID, ID graph) { + HashSet list = (HashSet) graphs.get(containerID); if (list != null) { - list.remove(path); + list.remove(graph); if (list.isEmpty()) - paths.remove(containerID); + graphs.remove(containerID); } - list = (HashSet) containers.get(path); + list = (HashSet) containers.get(graph); if (list != null) { list.remove(containerID); if (list.isEmpty()) - containers.remove(path); + containers.remove(graph); } } public synchronized void remove(ID containerID) { - HashSet list = (HashSet) paths.get(containerID); + HashSet list = (HashSet) graphs.get(containerID); if (list != null) { for (Iterator i = list.iterator(); i.hasNext();) { - String path = (String) i.next(); - list = (HashSet) containers.get(path); + ID graph = (ID) i.next(); + list = (HashSet) containers.get(graph); if (list != null) { list.remove(containerID); if (list.isEmpty()) - containers.remove(path); + containers.remove(graph); } } } } - public synchronized boolean contains(String path) { - return containers.contains(path); + public synchronized boolean contains(ID graph) { + return containers.contains(graph); } - public synchronized String[] getPaths(ID containerID) { - HashSet list = (HashSet) paths.get(containerID); - return list == null ? NO_PATHS : (String[]) list - .toArray(new String[list.size()]); + public synchronized ID[] getGraphs(ID containerID) { + HashSet list = (HashSet) graphs.get(containerID); + return list == null ? NO_GRAPHS : (ID[]) list.toArray(new ID[list + .size()]); } } @@ -115,37 +115,23 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { private ISharedObjectConfig config; - public synchronized void add(String path) throws ECFException { + public synchronized void add(ID graph) throws ECFException { if (config == null) throw new ECFException("Not connected."); - String[] paths = new String[] { path }; + ID[] graphs = new ID[] { graph }; try { config.getContext().sendMessage(null, - new Object[] { new Integer(ADD), paths }); + new Object[] { new Integer(ADD), graphs }); } catch (IOException e) { throw new ECFException(e); } - handleAdd(config.getContext().getLocalContainerID(), paths); + handleAdd(config.getContext().getLocalContainerID(), graphs); } - public synchronized void remove(String path) throws ECFException { - if (config == null) - throw new ECFException("Not connected."); - - try { - config.getContext().sendMessage(null, - new Object[] { new Integer(REMOVE), path }); - } catch (IOException e) { - throw new ECFException(e); - } - - handleRemove(config.getContext().getLocalContainerID(), path); - } - - public synchronized boolean isPublished(String path) { - return table.contains(path); + public synchronized boolean isPublished(ID graph) { + return table.contains(graph); } /* @@ -174,7 +160,7 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { switch (type.intValue()) { case JOIN: handleJoin(e.getRemoteContainerID(), - data.length > 1 ? (String[]) data[1] : null); + data.length > 1 ? (ID[]) data[1] : null); break; case LEAVE: @@ -182,11 +168,11 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { break; case ADD: - handleAdd(e.getRemoteContainerID(), (String[]) data[1]); + handleAdd(e.getRemoteContainerID(), (ID[]) data[1]); break; case REMOVE: - handleRemove(e.getRemoteContainerID(), (String) data[1]); + handleRemove(e.getRemoteContainerID(), (ID) data[1]); } } else if (event instanceof ISharedObjectContainerJoinedEvent) { if (((ISharedObjectContainerJoinedEvent) event) @@ -199,25 +185,27 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { config.getContext().getLocalContainerID())) handleLeave(e.getDepartedContainerID()); } else if (event instanceof ISharedObjectActivatedEvent) { - if (((ISharedObjectActivatedEvent) event).getActivatedID().equals( - config.getSharedObjectID())) + ISharedObjectActivatedEvent e = (ISharedObjectActivatedEvent) event; + if (e.getActivatedID().equals(config.getSharedObjectID())) handleJoined(); } else if (event instanceof ISharedObjectDeactivatedEvent) { - if (((ISharedObjectDeactivatedEvent) event).getDeactivatedID() - .equals(config.getSharedObjectID())) + ISharedObjectDeactivatedEvent e = (ISharedObjectDeactivatedEvent) event; + if (e.getDeactivatedID().equals(config.getSharedObjectID())) handleDeactivated(); + else if (table.contains(e.getDeactivatedID())) + handleRemoved(e.getDeactivatedID()); } } - private void handleJoin(ID containerID, String[] paths) { - if (paths != null) - table.add(containerID, paths); + private void handleJoin(ID containerID, ID[] graphs) { + if (graphs != null) + table.add(containerID, graphs); - paths = table.getPaths(config.getContext().getLocalContainerID()); - if (paths.length > 0) + graphs = table.getGraphs(config.getContext().getLocalContainerID()); + if (graphs.length > 0) try { config.getContext().sendMessage(containerID, - new Object[] { new Integer(ADD), paths }); + new Object[] { new Integer(ADD), graphs }); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -228,19 +216,19 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { table.remove(containerID); } - private void handleAdd(ID containerID, String[] paths) { - table.add(containerID, paths); + private void handleAdd(ID containerID, ID[] graphs) { + table.add(containerID, graphs); } - private void handleRemove(ID containerID, String path) { - table.remove(containerID, path); + private void handleRemove(ID containerID, ID graph) { + table.remove(containerID, graph); } private void handleJoined() { - String[] paths = table.getPaths(config.getContext() - .getLocalContainerID()); - Object[] data = paths.length == 0 ? new Object[] { new Integer(JOIN) } - : new Object[] { new Integer(JOIN), paths }; + ID[] graphs = table + .getGraphs(config.getContext().getLocalContainerID()); + Object[] data = graphs.length == 0 ? new Object[] { new Integer(JOIN) } + : new Object[] { new Integer(JOIN), graphs }; try { config.getContext().sendMessage(null, data); } catch (IOException e) { @@ -259,6 +247,18 @@ class PublishedGraphTracker extends PlatformObject implements ISharedObject { } } + private void handleRemoved(ID graph) { + try { + config.getContext().sendMessage(null, + new Object[] { new Integer(REMOVE), graph }); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + handleRemove(config.getContext().getLocalContainerID(), graph); + } + /* * (non-Javadoc) * |
