diff options
| author | slewis | 2004-12-30 22:44:07 +0000 |
|---|---|---|
| committer | slewis | 2004-12-30 22:44:07 +0000 |
| commit | 267caa3dee7d5fac85ea3e16f177c96941f7f9ae (patch) | |
| tree | 20eca4c28fda7ff0bb617446f238e31d386a06a1 | |
| parent | 59125d7e97c5bb108c440b3a89e78112cd567a4e (diff) | |
| download | org.eclipse.ecf-267caa3dee7d5fac85ea3e16f177c96941f7f9ae.tar.gz org.eclipse.ecf-267caa3dee7d5fac85ea3e16f177c96941f7f9ae.tar.xz org.eclipse.ecf-267caa3dee7d5fac85ea3e16f177c96941f7f9ae.zip | |
Added copyright notice to all .java files
37 files changed, 2185 insertions, 1720 deletions
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/ProviderPlugin.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/ProviderPlugin.java index ad41dba1f..635fd2914 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/ProviderPlugin.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/ProviderPlugin.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider; import org.eclipse.core.runtime.Plugin; @@ -8,62 +19,63 @@ import java.util.*; * The main plugin class to be used in the desktop. */ public class ProviderPlugin extends Plugin { - //The shared instance. - private static ProviderPlugin plugin; - //Resource bundle. - private ResourceBundle resourceBundle; - - /** - * The constructor. - */ - public ProviderPlugin() { - super(); - plugin = this; - try { - resourceBundle = ResourceBundle.getBundle("org.eclipse.ecf.provider.ProviderPluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - } + //The shared instance. + private static ProviderPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + /** + * The constructor. + */ + public ProviderPlugin() { + super(); + plugin = this; + try { + resourceBundle = ResourceBundle + .getBundle("org.eclipse.ecf.provider.ProviderPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + } - /** - * This method is called upon plug-in activation - */ - public void start(BundleContext context) throws Exception { - super.start(context); - } + /** + * 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); - } + /** + * 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 ProviderPlugin getDefault() { - return plugin; - } + /** + * Returns the shared instance. + */ + public static ProviderPlugin getDefault() { + return plugin; + } - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String key) { - ResourceBundle bundle = ProviderPlugin.getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key) : key; - } catch (MissingResourceException e) { - return key; - } - } + /** + * Returns the string from the plugin's resource bundle, or 'key' if not + * found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = ProviderPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - return resourceBundle; - } -} + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/Trace.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/Trace.java index 8b49b1ee1..a5b6fbe10 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/Trace.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/Trace.java @@ -1,64 +1,79 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider; import java.text.SimpleDateFormat; import java.util.Date; - import org.eclipse.core.runtime.Platform; public class Trace { + public static boolean ON = false; + protected static boolean isEclipse = false; + protected static String pluginName = ""; + protected static String debugPrefix = "/debug/"; + static { + try { + ON = Platform.inDebugMode(); + isEclipse = true; + pluginName = ProviderPlugin.getDefault().getBundle() + .getSymbolicName(); + } catch (Exception e) { + // No eclipse Platform available + } + } + + public static void setTrace(boolean on) { + ON = on; + } + + public static Trace create(String key) { + if (isEclipse) { + String res = Platform + .getDebugOption(pluginName + debugPrefix + key); + if (res != null) { + Boolean on = new Boolean(res); + if (on.booleanValue()) + return new Trace(pluginName + "(" + key + ")"); + else + return null; + } else { + return null; + } + } else + return new Trace(key); + } + + String name; + + public void dumpStack(Throwable e, String msg) { + msg(msg); + e.printStackTrace(System.err); + } + + public void msg(String msg) { + System.err.println(name + "[" + getTimeString() + "]" + msg); + } + + protected static String getTimeString() { + Date d = new Date(); + SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy;HH:mm:ss:SSS"); + return df.format(d); + } - public static boolean ON = false; - protected static boolean isEclipse = false; - protected static String pluginName = ""; - protected static String debugPrefix = "/debug/"; - - static { - try { - ON = Platform.inDebugMode(); - isEclipse = true; - pluginName = ProviderPlugin.getDefault().getBundle().getSymbolicName(); - } catch (Exception e) { - // No eclipse Platform available - } - } - - public static void setTrace(boolean on) { - ON = on; - } - - public static Trace create(String key) { - if (isEclipse) { - String res = Platform.getDebugOption(pluginName+debugPrefix+key); - if (res != null) { - Boolean on = new Boolean(res); - if (on.booleanValue()) return new Trace(pluginName+"("+key+")"); - else return null; - } else { - return null; - } - } else return new Trace(key); - } - - String name; - - public void dumpStack(Throwable e, String msg) { - msg(msg); - e.printStackTrace(System.err); - } - public void msg(String msg) { - System.err.println(name+"["+getTimeString()+"]"+msg); - } - - protected static String getTimeString() { - Date d = new Date(); - SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy;HH:mm:ss:SSS"); - return df.format(d); - } - protected Trace(String str) { - name = str; - } - public static void setThreadDebugGroup(Object obj) { - // Do nothing - } + protected Trace(String str) { + name = str; + } -} + public static void setThreadDebugGroup(Object obj) { + // Do nothing + } +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/AsynchMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/AsynchMessage.java index 53adeb6fd..9ee4a677f 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/AsynchMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/AsynchMessage.java @@ -1,9 +1,19 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; public class AsynchMessage implements Serializable { - Serializable data; protected AsynchMessage() { @@ -12,12 +22,14 @@ public class AsynchMessage implements Serializable { protected AsynchMessage(Serializable data) { this.data = data; } + Serializable getData() { return data; } + public String toString() { - StringBuffer buf = new StringBuffer("AsynchMessage["); - buf.append(data).append("]"); - return buf.toString(); + StringBuffer buf = new StringBuffer("AsynchMessage["); + buf.append(data).append("]"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java index d855d07c6..5b6bc483f 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Client.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.BufferedOutputStream; @@ -15,7 +26,6 @@ import java.util.Enumeration; import java.util.Map; import java.util.Properties; import java.util.Vector; - import org.eclipse.ecf.core.comm.AsynchConnectionEvent; import org.eclipse.ecf.core.comm.ConnectionEvent; import org.eclipse.ecf.core.comm.ConnectionInstantiationException; @@ -31,84 +41,79 @@ import org.eclipse.ecf.core.util.SimpleQueueImpl; import org.eclipse.ecf.provider.Trace; public final class Client implements ISynchAsynchConnection { - public static class Creator implements ISynchAsynchConnectionInstantiator { - public ISynchAsynchConnection makeInstance(ISynchAsynchConnectionEventHandler handler, Class[] clazzes, + public ISynchAsynchConnection makeInstance( + ISynchAsynchConnectionEventHandler handler, Class[] clazzes, Object[] args) throws ConnectionInstantiationException { try { Integer ka = new Integer(0); if (args != null && args.length > 0) { ka = (Integer) args[0]; } - return new Client(handler, - ka); + return new Client(handler, ka); } catch (RuntimeException e) { throw new ConnectionInstantiationException( - "Exception in creating connection "+Client.class.getName(), e); + "Exception in creating connection " + + Client.class.getName(), e); } } - } - public static final String PROTOCOL = "ecftcp"; + public static final String PROTOCOL = "ecftcp"; public static final Trace debug = Trace.create("connection"); - public static final int SNDR_PRIORITY = Thread.NORM_PRIORITY; public static final int RCVR_PRIORITY = Thread.NORM_PRIORITY; // Default close timeout is 1.5 seconds public static final long CLOSE_TIMEOUT = 1500; - public static final int DEF_MAX_MSG = 50; - protected String address; protected int port; protected Socket socket; protected ObjectOutputStream outputStream; protected ObjectInputStream inputStream; - protected ISynchAsynchConnectionEventHandler handler; protected SimpleQueueImpl queue = new SimpleQueueImpl(); protected int keepAlive = 0; - protected Thread sendThread; protected Thread rcvThread; protected Thread keepAliveThread; - protected boolean isClosing = false; protected boolean waitForPing = false; protected PingMessage ping = new PingMessage(); protected PingResponseMessage pingResp = new PingResponseMessage(); protected long nextPingTime; - protected int maxMsg = DEF_MAX_MSG; protected long closeTimeout = CLOSE_TIMEOUT; - protected Vector eventNotify = null; - protected Map properties; public Map getProperties() { return properties; } + protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } + public void setProperties(Map props) { this.properties = props; } + public Client(Socket aSocket, ObjectInputStream iStream, ObjectOutputStream oStream, ISynchAsynchConnectionEventHandler handler, int keepAlive) throws IOException { this(aSocket, iStream, oStream, handler, keepAlive, DEF_MAX_MSG); } + public Client(Socket aSocket, ObjectInputStream iStream, ObjectOutputStream oStream, ISynchAsynchConnectionEventHandler handler, int keepAlive, @@ -126,12 +131,15 @@ public final class Client implements ISynchAsynchConnection { properties = new Properties(); setupThreads(); } + public Client(ISynchAsynchConnectionEventHandler handler, Integer keepAlive) { this(handler, keepAlive.intValue()); } + public Client(ISynchAsynchConnectionEventHandler handler, int keepAlive) { this(handler, keepAlive, DEF_MAX_MSG); } + public Client(ISynchAsynchConnectionEventHandler handler, int keepAlive, int maxmsgs) { this.handler = handler; @@ -152,21 +160,25 @@ public final class Client implements ISynchAsynchConnection { } return retID; } + public synchronized void removeCommEventListener(IConnectionEventHandler l) { eventNotify.remove(l); } + public synchronized void addCommEventListener(IConnectionEventHandler l) { if (eventNotify == null) { eventNotify = new Vector(); } eventNotify.add(l); } + public synchronized boolean isConnected() { if (socket != null) { return socket.isConnected(); } return false; } + public synchronized boolean isStarted() { if (sendThread != null) { return sendThread.isAlive(); @@ -190,12 +202,9 @@ public final class Client implements ISynchAsynchConnection { public synchronized Object connect(ID remote, Object data, int timeout) throws IOException { - - debug("connect("+remote+","+data+","+timeout+")"); - + debug("connect(" + remote + "," + data + "," + timeout + ")"); if (socket != null) throw new ConnectException("Client already connected"); - URI anURI = null; try { anURI = remote.toURI(); @@ -203,15 +212,13 @@ public final class Client implements ISynchAsynchConnection { throw new IOException("Can't connect to address " + remote.getName() + ". Invalid URL"); } - address = anURI.getHost(); port = anURI.getPort(); - SocketFactory fact = SocketFactory.getSocketFactory(); if (fact == null) { fact = SocketFactory.getDefaultSocketFactory(); - } - debug("socket connecting to "+address+":"+port); + } + debug("socket connecting to " + address + ":" + port); // Actually connect to remote using socket from socket factory. socket = fact.createSocket(address, port, timeout); // Set TCP no delay @@ -225,10 +232,9 @@ public final class Client implements ISynchAsynchConnection { compatibility); // send connect data sendIt(new ConnectRequestMessage(anURI, (Serializable) data)); - ConnectResultMessage res = null; res = (ConnectResultMessage) readObject(); - debug("recv:"+address+":"+port+":"+res); + debug("recv:" + address + ":" + port + ":" + res); // Setup threads setupThreads(); // Return results. @@ -268,7 +274,6 @@ public final class Client implements ISynchAsynchConnection { sendIt(aMsg); // Successful...remove message from queue queue.removeHead(); - if (msgCount > maxMsg) { synchronized (outputStream) { outputStream.reset(); @@ -277,7 +282,7 @@ public final class Client implements ISynchAsynchConnection { } else msgCount++; } catch (IOException e) { - //dumpStack("read",e); + //dumpStack("read",e); if (isClosing) { isClosing = false; synchronized (Client.this) { @@ -294,7 +299,7 @@ public final class Client implements ISynchAsynchConnection { break; } } - debug("sender:"+address+":"+port+" terminating"); + debug("sender:" + address + ":" + port + " terminating"); } }, "sndr:" + address + ":" + port); // Set priority for new thread @@ -312,7 +317,7 @@ public final class Client implements ISynchAsynchConnection { private void sendIt(Serializable snd) throws IOException { // Write object to output stream - debug("send:"+address+":"+port+":"+snd); + debug("send:" + address + ":" + port + ":" + snd); synchronized (outputStream) { outputStream.writeObject(snd); outputStream.flush(); @@ -343,7 +348,7 @@ public final class Client implements ISynchAsynchConnection { } // Before returning, actually remove remote objects //handler.handleDisconnectEvent(new DisconnectConnectionEvent( - //Client.this, null, queue)); + //Client.this, null, queue)); } private Thread getRcvThread() { @@ -357,7 +362,7 @@ public final class Client implements ISynchAsynchConnection { try { handleRcv(readObject()); } catch (IOException e) { - //dumpStack("read",e); + //dumpStack("read",e); if (isClosing) { isClosing = false; synchronized (Client.this) { @@ -374,7 +379,7 @@ public final class Client implements ISynchAsynchConnection { break; } } - debug("read:"+address+":"+port+" terminating"); + debug("read:" + address + ":" + port + " terminating"); } }, "rcvr:" + address + ":" + port); // Set priority and return @@ -386,7 +391,7 @@ public final class Client implements ISynchAsynchConnection { try { // We've received some data, so the connection is alive receiveResp(); - debug("recv:"+address+":"+port+":"+rcv); + debug("recv:" + address + ":" + port + ":" + rcv); // Handle all messages if (rcv instanceof SynchMessage) { // Handle synch message. The only valid synch message is @@ -411,7 +416,7 @@ public final class Client implements ISynchAsynchConnection { } public synchronized void start() { - debug("start("+address+":"+port+")"); + debug("start(" + address + ":" + port + ")"); if (sendThread != null) sendThread.start(); if (rcvThread != null) @@ -422,8 +427,10 @@ public final class Client implements ISynchAsynchConnection { if (keepAliveThread != null) keepAliveThread.start(); } + public void stop() { } + private Thread setupPing() { return new Thread(new Runnable() { public void run() { @@ -460,7 +467,7 @@ public final class Client implements ISynchAsynchConnection { } } } catch (Exception e) { - //dumpStack("ping",e); + //dumpStack("ping",e); if (isClosing) { isClosing = false; synchronized (Client.this) { @@ -477,13 +484,13 @@ public final class Client implements ISynchAsynchConnection { break; } } - debug("ping:"+address+":"+port+" terminating"); + debug("ping:" + address + ":" + port + " terminating"); } }, "ping:" + address + ":" + port); } public synchronized void disconnect() throws IOException { - debug("disconnect("+address+":"+port+")"); + debug("disconnect(" + address + ":" + port + ")"); // Close send queue and socket queue.close(); closeSocket(); @@ -508,15 +515,18 @@ public final class Client implements ISynchAsynchConnection { public void sendAsynch(ID recipient, byte[] obj) throws IOException { queueObject(recipient, obj); } + public void sendAsynch(ID recipient, Object obj) throws IOException { queueObject(recipient, (Serializable) obj); } + public synchronized void queueObject(ID recipient, Serializable obj) throws IOException { if (queue.isStopped() || isClosing) throw new ConnectException("Not connected"); queue.enqueue(new AsynchMessage(obj)); } + public synchronized Serializable sendObject(ID recipient, Serializable obj) throws IOException { if (queue.isStopped() || isClosing) @@ -532,17 +542,17 @@ public final class Client implements ISynchAsynchConnection { public Object sendSynch(ID rec, byte[] obj) throws IOException { return sendObject(rec, obj); } + private Serializable readObject() throws IOException { Serializable ret = null; try { ret = (Serializable) inputStream.readObject(); } catch (ClassNotFoundException e) { - dumpStack("ClassNotFoundException",e); + dumpStack("ClassNotFoundException", e); throw new IOException( "Protocol violation due to class load failure. " + e.getMessage()); } return ret; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectRequestMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectRequestMessage.java index 293946746..3d059484d 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectRequestMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectRequestMessage.java @@ -1,10 +1,20 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; import java.net.URI; public class ConnectRequestMessage implements Serializable { - URI target; Serializable data; @@ -22,8 +32,8 @@ public class ConnectRequestMessage implements Serializable { } public String toString() { - StringBuffer buf = new StringBuffer("ConnectRequestMessage["); - buf.append(target).append(";").append(data).append("]"); - return buf.toString(); + StringBuffer buf = new StringBuffer("ConnectRequestMessage["); + buf.append(target).append(";").append(data).append("]"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectResultMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectResultMessage.java index 08572d311..982256480 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectResultMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ConnectResultMessage.java @@ -1,9 +1,19 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; public class ConnectResultMessage implements Serializable { - Serializable data; public ConnectResultMessage(Serializable data) { @@ -13,10 +23,10 @@ public class ConnectResultMessage implements Serializable { public Serializable getData() { return data; } - + public String toString() { - StringBuffer buf = new StringBuffer("ConnectResultMessage["); - buf.append(data).append("]"); - return buf.toString(); + StringBuffer buf = new StringBuffer("ConnectResultMessage["); + buf.append(data).append("]"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectInputStream.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectInputStream.java index 206706b17..ea6483d87 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectInputStream.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectInputStream.java @@ -1,15 +1,23 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; - import org.eclipse.ecf.provider.Trace; public class ExObjectInputStream extends ObjectInputStream { - private boolean replace = false; - public static final Trace debug = Trace.create("connection"); public ExObjectInputStream(InputStream in) throws IOException, @@ -35,11 +43,12 @@ public class ExObjectInputStream extends ObjectInputStream { protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectOutputStream.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectOutputStream.java index c2be430e0..980499efd 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectOutputStream.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ExObjectOutputStream.java @@ -1,15 +1,23 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; - import org.eclipse.ecf.provider.Trace; public class ExObjectOutputStream extends ObjectOutputStream { - private boolean replace = false; - public static final Trace debug = Trace.create("connection"); public ExObjectOutputStream(OutputStream out) throws IOException { @@ -30,14 +38,16 @@ public class ExObjectOutputStream extends ObjectOutputStream { } } } + protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IClientSocketFactory.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IClientSocketFactory.java index 46e775ee7..683870dce 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IClientSocketFactory.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IClientSocketFactory.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IServerSocketFactory.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IServerSocketFactory.java index ab6a443f8..a62dd35ab 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IServerSocketFactory.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/IServerSocketFactory.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; @@ -5,5 +16,4 @@ import java.net.ServerSocket; public interface IServerSocketFactory { ServerSocket createServerSocket(int port, int backlog) throws IOException; -} - +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ISocketAcceptHandler.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ISocketAcceptHandler.java index 74a5f4eea..576ce14ec 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ISocketAcceptHandler.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/ISocketAcceptHandler.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.net.Socket; diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingMessage.java index 822b48d73..a9f11ee6e 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingMessage.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; @@ -5,8 +16,9 @@ import java.io.Serializable; public class PingMessage implements Serializable { protected PingMessage() { } + public String toString() { - StringBuffer buf = new StringBuffer("PingMessage"); - return buf.toString(); + StringBuffer buf = new StringBuffer("PingMessage"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingResponseMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingResponseMessage.java index 49290a5ec..d3ab184dd 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingResponseMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/PingResponseMessage.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; @@ -5,8 +16,9 @@ import java.io.Serializable; public class PingResponseMessage implements Serializable { protected PingResponseMessage() { } + public String toString() { - StringBuffer buf = new StringBuffer("PingResponseMessage"); - return buf.toString(); + StringBuffer buf = new StringBuffer("PingResponseMessage"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Server.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Server.java index 624ee2744..865e61f32 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Server.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/Server.java @@ -1,29 +1,39 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; - import org.eclipse.ecf.provider.Trace; public class Server extends ServerSocket { public static Trace debug = Trace.create("connection"); - ISocketAcceptHandler acceptHandler; - Thread listenerThread; ThreadGroup threadGroup; protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } + public Server(ThreadGroup group, int port, ISocketAcceptHandler handler) throws IOException { super(port); @@ -65,10 +75,11 @@ public class Server extends ServerSocket { new Thread(threadGroup, new Runnable() { public void run() { try { - debug("accept:"+aSocket.getInetAddress()); + debug("accept:" + aSocket.getInetAddress()); acceptHandler.handleAccept(aSocket); } catch (Exception e) { - dumpStack("Unexpected exception in handleAccept...closing",e); + dumpStack("Unexpected exception in handleAccept...closing", + e); try { aSocket.close(); } catch (IOException e1) { diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SocketFactory.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SocketFactory.java index 6e7f437ce..cbaa79345 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SocketFactory.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SocketFactory.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.IOException; @@ -7,7 +18,6 @@ import java.net.Socket; public class SocketFactory implements IClientSocketFactory, IServerSocketFactory { - protected static SocketFactory defaultFactory; protected static SocketFactory factory = null; @@ -46,5 +56,4 @@ public class SocketFactory implements IClientSocketFactory, factory = fact; } } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SynchMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SynchMessage.java index ad6e7d0be..b4b1ae2a6 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SynchMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/comm/tcp/SynchMessage.java @@ -1,18 +1,30 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.comm.tcp; import java.io.Serializable; public class SynchMessage extends AsynchMessage { - protected SynchMessage(Serializable data) { super(data); } + protected SynchMessage() { super(); } + public String toString() { - StringBuffer buf = new StringBuffer("SynchMessage["); - buf.append(data).append("]"); - return buf.toString(); + StringBuffer buf = new StringBuffer("SynchMessage["); + buf.append(data).append("]"); + return buf.toString(); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java index 1e81e666a..7f44e7966 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ClientSOContainer.java @@ -1,10 +1,20 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.IOException; import java.io.InvalidObjectException; import java.io.Serializable; import java.net.ConnectException; - import org.eclipse.ecf.core.ISharedObjectContainerConfig; import org.eclipse.ecf.core.SharedObjectContainerJoinException; import org.eclipse.ecf.core.SharedObjectDescription; @@ -25,8 +35,10 @@ public abstract class ClientSOContainer extends SOContainer { public static final byte UNCONNECTED = 0; public static final byte CONNECTING = 1; public static final byte CONNECTED = 2; + static final class Lock { } + Lock connectLock; public ClientSOContainer(ISharedObjectContainerConfig config) { @@ -35,35 +47,40 @@ public abstract class ClientSOContainer extends SOContainer { connectionState = UNCONNECTED; connectLock = new Lock(); } + public void dispose(long wait) { - synchronized (connectLock) { - isClosing = true; - if (isConnected()) { - this.leaveGroup(); - } else if (isConnecting()) { - killConnection(connection); - } - remoteServerID = null; - } - super.dispose(wait); + synchronized (connectLock) { + isClosing = true; + if (isConnected()) { + this.leaveGroup(); + } else if (isConnecting()) { + killConnection(connection); + } + remoteServerID = null; + } + super.dispose(wait); } + public final boolean isGroupServer() { return false; } + public final boolean isGroupManager() { return false; } + public ID getGroupID() { return remoteServerID; } + public void joinGroup(ID remote, Object data) throws SharedObjectContainerJoinException { try { if (isClosing) throw new IllegalStateException("container is closing"); - debug("joingroup:"+remote+":"+data); - ISynchAsynchConnection aConnection = getClientConnection( - remote, data); + debug("joingroup:" + remote + ":" + data); + ISynchAsynchConnection aConnection = getClientConnection(remote, + data); if (aConnection == null) { ConnectException c = new ConnectException("join failed to" + ":" + remote.getName()); @@ -91,8 +108,8 @@ public abstract class ClientSOContainer extends SOContainer { synchronized (aConnection) { try { Object connectData = getConnectData(remote, data); - response = (ContainerMessage) aConnection.connect( - remote, connectData, 0); + response = (ContainerMessage) aConnection.connect(remote, + connectData, 0); } catch (IOException e) { synchronized (connectLock) { killConnection(aConnection); @@ -138,42 +155,49 @@ public abstract class ClientSOContainer extends SOContainer { } } - protected void handleViewChangeMessage(ContainerMessage mess) throws IOException { - debug("handleViewChangeMessage("+mess+")"); - ContainerMessage.ViewChangeMessage vc = (ContainerMessage.ViewChangeMessage) mess.getData(); - if (vc == null) throw new IOException("view change message is null"); - ID fromID = mess.getFromContainerID(); - ID toID = mess.getToContainerID(); - if (fromID == null || !fromID.equals(remoteServerID)) { - throw new IOException("view change message from "+fromID+" is not same as "+remoteServerID); - } - ID [] changeIDs = vc.getChangeIDs(); - if (changeIDs == null) { - // do nothing if we've got no changes - } else { - for(int i=0; i < changeIDs.length; i++) { - if (vc.isAdd()) { - groupManager.addMember(new Member(changeIDs[i])); - } else { - groupManager.removeMember(changeIDs[i]); - } - } - } - } + protected void handleViewChangeMessage(ContainerMessage mess) + throws IOException { + debug("handleViewChangeMessage(" + mess + ")"); + ContainerMessage.ViewChangeMessage vc = (ContainerMessage.ViewChangeMessage) mess + .getData(); + if (vc == null) + throw new IOException("view change message is null"); + ID fromID = mess.getFromContainerID(); + ID toID = mess.getToContainerID(); + if (fromID == null || !fromID.equals(remoteServerID)) { + throw new IOException("view change message from " + fromID + + " is not same as " + remoteServerID); + } + ID[] changeIDs = vc.getChangeIDs(); + if (changeIDs == null) { + // do nothing if we've got no changes + } else { + for (int i = 0; i < changeIDs.length; i++) { + if (vc.isAdd()) { + groupManager.addMember(new Member(changeIDs[i])); + } else { + groupManager.removeMember(changeIDs[i]); + } + } + } + } protected void forwardExcluding(ID from, ID excluding, ContainerMessage data) throws IOException { // NOP } + protected Serializable getConnectData(ID target, Object data) { return ContainerMessage.makeJoinGroupMessage(getID(), target, getNextSequenceNumber(), (Serializable) data); } + protected Serializable getLeaveData(ID target) { return null; } + public void leaveGroup() { - debug("leaveGroup"); + debug("leaveGroup"); synchronized (connectLock) { // If we are currently connected if (isConnected()) { @@ -199,7 +223,8 @@ public abstract class ClientSOContainer extends SOContainer { } protected abstract ISynchAsynchConnection getClientConnection( - ID remoteSpace, Object data) throws ConnectionInstantiationException; + ID remoteSpace, Object data) + throws ConnectionInstantiationException; protected void handleChangeMsg(ID fromID, ID toID, long seqNum, Serializable data) throws IOException { @@ -234,15 +259,19 @@ public abstract class ClientSOContainer extends SOContainer { connection.sendAsynch(message.getToContainerID(), getBytesForObject(message)); } + protected void forwardExcluding(ID from, ID excluding, byte msg, Serializable data) throws IOException { /* NOP */ } + protected void forwardToRemote(ID from, ID to, ContainerMessage message) throws IOException { /* NOP */ } + protected ID getIDForConnection(IAsynchConnection conn) { return remoteServerID; } + protected void memberLeave(ID fromID, IAsynchConnection conn) { if (fromID.equals(remoteServerID)) { groupManager.removeAllMembers(); @@ -254,6 +283,7 @@ public abstract class ClientSOContainer extends SOContainer { super.memberLeave(fromID, conn); } } + protected void sendMessage(ContainerMessage data) throws IOException { // Get connect lock, then call super version synchronized (connectLock) { @@ -261,6 +291,7 @@ public abstract class ClientSOContainer extends SOContainer { super.sendMessage(data); } } + protected ID[] sendCreateMsg(ID toID, SharedObjectDescription createInfo) throws IOException { // Get connect lock, then call super version @@ -269,6 +300,7 @@ public abstract class ClientSOContainer extends SOContainer { return super.sendCreateSharedObjectMessage(toID, createInfo); } } + protected void processDisconnect(DisconnectConnectionEvent evt) { // Get connect lock, and just return if this connection has been // terminated @@ -276,6 +308,7 @@ public abstract class ClientSOContainer extends SOContainer { super.processDisconnect(evt); } } + protected void processAsynchPacket(AsynchConnectionEvent evt) throws IOException { // Get connect lock, then call super version @@ -284,6 +317,7 @@ public abstract class ClientSOContainer extends SOContainer { super.processAsynch(evt); } } + protected Serializable processSynch(SynchConnectionEvent evt) throws IOException { synchronized (connectLock) { @@ -298,20 +332,21 @@ public abstract class ClientSOContainer extends SOContainer { protected boolean isConnected() { return (connectionState == CONNECTED); } + protected boolean isConnecting() { return (connectionState == CONNECTING); } + private void checkConnected() throws ConnectException { if (!isConnected()) throw new ConnectException("not connected"); } + protected ID acceptNewServer(ContainerMessage serverData) throws Exception { ContainerMessage aPacket = serverData; ID fromID = aPacket.getFromContainerID(); - if (fromID == null) throw new InvalidObjectException("server id is null"); - ID[] ids = ((ContainerMessage.ViewChangeMessage) aPacket.getData()).changeIDs; if (ids == null) throw new java.io.InvalidObjectException("id array null"); diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerInstantiator.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerInstantiator.java index b39ab30c6..90ef49f31 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerInstantiator.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerInstantiator.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import org.eclipse.ecf.core.ISharedObjectContainer; @@ -6,8 +17,8 @@ import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDFactory; import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator; -public class ContainerInstantiator implements ISharedObjectContainerInstantiator { - +public class ContainerInstantiator implements + ISharedObjectContainerInstantiator { public ContainerInstantiator() { super(); } @@ -18,14 +29,14 @@ public class ContainerInstantiator implements ISharedObjectContainerInstantiator Boolean isClient = new Boolean(true); ID id = null; if (args != null) { - if (args.length == 2) { - isClient = (Boolean) args[0]; - id = (ID) args[1]; - } else if (args.length == 1) { - id = (ID) args[0]; - } + if (args.length == 2) { + isClient = (Boolean) args[0]; + id = (ID) args[1]; + } else if (args.length == 1) { + id = (ID) args[0]; + } } else { - id = IDFactory.makeGUID(); + id = IDFactory.makeGUID(); } ISharedObjectContainer result = null; if (isClient.booleanValue()) { @@ -34,8 +45,8 @@ public class ContainerInstantiator implements ISharedObjectContainerInstantiator return new TCPServerSOContainer(new SOContainerConfig(id)); } } catch (Exception e) { - throw new SharedObjectContainerInstantiationException("Exception creating generic container",e); + throw new SharedObjectContainerInstantiationException( + "Exception creating generic container", e); } } - -} +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerMessage.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerMessage.java index 2babbe0f7..a21c70865 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerMessage.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ContainerMessage.java @@ -1,318 +1,334 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.Serializable; import org.eclipse.ecf.core.identity.ID; public class ContainerMessage implements Serializable { - - ID fromContainerID; - - public ID toContainerID; - - long sequence; - - Serializable data; - - /** - * @return Returns the data. - */ - public Serializable getData() { - return data; - } - - /** - * @param data - * The data to set. - */ - public void setData(Serializable data) { - this.data = data; - } - - /** - * @return Returns the fromContainerID. - */ - public ID getFromContainerID() { - return fromContainerID; - } - - /** - * @param fromContainerID - * The fromContainerID to set. - */ - public void setFromContainerID(ID fromContainerID) { - this.fromContainerID = fromContainerID; - } - - /** - * @return Returns the sequence. - */ - public long getSequence() { - return sequence; - } - - /** - * @param sequence - * The sequence to set. - */ - public void setSequence(long sequence) { - this.sequence = sequence; - } - - /** - * @return Returns the toContainerID. - */ - public ID getToContainerID() { - return toContainerID; - } - - /** - * @param toContainerID - * The toContainerID to set. - */ - public void setToContainerID(ID toContainerID) { - this.toContainerID = toContainerID; - } - - static ContainerMessage makeViewChangeMessage(ID from, ID to, long seq, - ID ids[], boolean add, Serializable data) { - return new ContainerMessage(from, to, seq, new ViewChangeMessage(ids, - add, data)); - } - - static ContainerMessage makeJoinGroupMessage(ID from, ID to, long seq, - Serializable data) { - return new ContainerMessage(from, to, seq, new JoinGroupMessage(data)); - } - - static ContainerMessage makeLeaveGroupMessage(ID from, ID to, long seq, - Serializable data) { - return new ContainerMessage(from, to, seq, new LeaveGroupMessage(data)); - } - - static ContainerMessage makeSharedObjectCreateMessage(ID from, ID to, - long seq, Serializable data) { - return new ContainerMessage(from, to, seq, new CreateMessage(data)); - } - - static ContainerMessage makeSharedObjectCreateResponseMessage(ID from, - ID to, long contSeq, ID soID, Throwable e, long sequence) { - return new ContainerMessage(from, to, contSeq, - new CreateResponseMessage(soID, e, sequence)); - } - - static ContainerMessage makeSharedObjectMessage(ID from, ID to, long seq, - ID fromSharedObject, Serializable data) { - return new ContainerMessage(from, to, seq, new SharedObjectMessage( - fromSharedObject, data)); - } - - static ContainerMessage makeSharedObjectDisposeMessage(ID from, ID to, - long seq, ID sharedObjectID) { - return new ContainerMessage(from, to, seq, - new SharedObjectDisposeMessage(sharedObjectID)); - } - - protected ContainerMessage(ID from, ID to, long seq, Serializable data) { - this.fromContainerID = from; - this.toContainerID = to; - this.sequence = seq; - this.data = data; - } - - public String toString() { - StringBuffer sb = new StringBuffer("ContainerMessage["); - sb.append(fromContainerID).append(";").append(toContainerID) - .append(";"); - sb.append(sequence).append(";").append(data).append("]"); - return sb.toString(); - } - - public static final class ViewChangeMessage implements Serializable { - ID changeIDs[]; - - boolean add; - - Serializable data; - - ViewChangeMessage(ID id[], boolean a, Serializable data) { - this.changeIDs = id; - this.add = a; - this.data = data; - } - - protected String printChangeIDs() { - if (changeIDs == null) - return "null"; - StringBuffer buf = new StringBuffer(); - for (int i = 0; i < changeIDs.length; i++) { - buf.append(changeIDs[i]); - if (i != (changeIDs.length - 1)) - buf.append(","); - } - return buf.toString(); - } - - public String toString() { - StringBuffer sb = new StringBuffer("ViewChangeMessage["); - sb.append(printChangeIDs()).append(";").append(add).append(";").append(data) - .append("]"); - return sb.toString(); - } - /** - * @return Returns the add. - */ - public boolean isAdd() { - return add; - } - /** - * @return Returns the changeIDs. - */ - public ID[] getChangeIDs() { - return changeIDs; - } - /** - * @return Returns the data. - */ - public Serializable getData() { - return data; - } - } - - public static final class CreateMessage implements Serializable { - Serializable data; - - CreateMessage(Serializable data) { - this.data = data; - } - public Serializable getData() { - return data; - } - public String toString() { - StringBuffer sb = new StringBuffer("CreateMessage["); - sb.append(data).append("]"); - return sb.toString(); - } - } - - public static final class CreateResponseMessage implements Serializable { - ID sharedObjectID; - - Throwable exception; - - long sequence; - - public CreateResponseMessage(ID objID, Throwable except, long sequence) { - this.sharedObjectID = objID; - this.exception = except; - this.sequence = sequence; - } - - public String toString() { - StringBuffer sb = new StringBuffer("CreateResponseMessage["); - sb.append(sharedObjectID).append(";").append(exception).append(";") - .append(sequence).append("]"); - return sb.toString(); - } - /** - * @return Returns the exception. - */ - public Throwable getException() { - return exception; - } - /** - * @return Returns the sequence. - */ - public long getSequence() { - return sequence; - } - /** - * @return Returns the sharedObjectID. - */ - public ID getSharedObjectID() { - return sharedObjectID; - } - } - - public static final class SharedObjectMessage implements Serializable { - Serializable data; - - ID fromSharedObjectID; - - SharedObjectMessage(ID fromSharedObject, Serializable data) { - this.fromSharedObjectID = fromSharedObject; - this.data = data; - } - - public String toString() { - StringBuffer sb = new StringBuffer("SharedObjectMessage["); - sb.append(fromSharedObjectID).append(";").append(data).append("]"); - return sb.toString(); - } - /** - * @return Returns the data. - */ - public Serializable getData() { - return data; - } - /** - * @return Returns the fromSharedObjectID. - */ - public ID getFromSharedObjectID() { - return fromSharedObjectID; - } - } - - public static final class SharedObjectDisposeMessage implements - Serializable { - ID sharedObjectID; - - SharedObjectDisposeMessage(ID objID) { - this.sharedObjectID = objID; - } - public String toString() { - StringBuffer sb = new StringBuffer("SharedObjectDisposeMessage["); - sb.append(sharedObjectID).append("]"); - return sb.toString(); - } - /** - * @return Returns the sharedObjectID. - */ - public ID getSharedObjectID() { - return sharedObjectID; - } - } - - public static final class JoinGroupMessage implements Serializable { - Serializable data; - - public JoinGroupMessage(Serializable data) { - this.data = data; - } - - public Serializable getData() { - return data; - } - public String toString() { - StringBuffer sb = new StringBuffer("JoinGroupMessage["); - sb.append(data).append("]"); - return sb.toString(); - } - } - - public static final class LeaveGroupMessage implements Serializable { - Serializable data; - - public LeaveGroupMessage(Serializable data) { - this.data = data; - } - - public Serializable getData() { - return data; - } - public String toString() { - StringBuffer sb = new StringBuffer("LeaveGroupMessage["); - sb.append(data).append("]"); - return sb.toString(); - } - } + ID fromContainerID; + public ID toContainerID; + long sequence; + Serializable data; + + /** + * @return Returns the data. + */ + public Serializable getData() { + return data; + } + + /** + * @param data + * The data to set. + */ + public void setData(Serializable data) { + this.data = data; + } + + /** + * @return Returns the fromContainerID. + */ + public ID getFromContainerID() { + return fromContainerID; + } + + /** + * @param fromContainerID + * The fromContainerID to set. + */ + public void setFromContainerID(ID fromContainerID) { + this.fromContainerID = fromContainerID; + } + + /** + * @return Returns the sequence. + */ + public long getSequence() { + return sequence; + } + + /** + * @param sequence + * The sequence to set. + */ + public void setSequence(long sequence) { + this.sequence = sequence; + } + + /** + * @return Returns the toContainerID. + */ + public ID getToContainerID() { + return toContainerID; + } + + /** + * @param toContainerID + * The toContainerID to set. + */ + public void setToContainerID(ID toContainerID) { + this.toContainerID = toContainerID; + } + + static ContainerMessage makeViewChangeMessage(ID from, ID to, long seq, + ID ids[], boolean add, Serializable data) { + return new ContainerMessage(from, to, seq, new ViewChangeMessage(ids, + add, data)); + } + + static ContainerMessage makeJoinGroupMessage(ID from, ID to, long seq, + Serializable data) { + return new ContainerMessage(from, to, seq, new JoinGroupMessage(data)); + } + + static ContainerMessage makeLeaveGroupMessage(ID from, ID to, long seq, + Serializable data) { + return new ContainerMessage(from, to, seq, new LeaveGroupMessage(data)); + } + + static ContainerMessage makeSharedObjectCreateMessage(ID from, ID to, + long seq, Serializable data) { + return new ContainerMessage(from, to, seq, new CreateMessage(data)); + } + + static ContainerMessage makeSharedObjectCreateResponseMessage(ID from, + ID to, long contSeq, ID soID, Throwable e, long sequence) { + return new ContainerMessage(from, to, contSeq, + new CreateResponseMessage(soID, e, sequence)); + } + + static ContainerMessage makeSharedObjectMessage(ID from, ID to, long seq, + ID fromSharedObject, Serializable data) { + return new ContainerMessage(from, to, seq, new SharedObjectMessage( + fromSharedObject, data)); + } + + static ContainerMessage makeSharedObjectDisposeMessage(ID from, ID to, + long seq, ID sharedObjectID) { + return new ContainerMessage(from, to, seq, + new SharedObjectDisposeMessage(sharedObjectID)); + } + + protected ContainerMessage(ID from, ID to, long seq, Serializable data) { + this.fromContainerID = from; + this.toContainerID = to; + this.sequence = seq; + this.data = data; + } + + public String toString() { + StringBuffer sb = new StringBuffer("ContainerMessage["); + sb.append(fromContainerID).append(";").append(toContainerID) + .append(";"); + sb.append(sequence).append(";").append(data).append("]"); + return sb.toString(); + } + + public static final class ViewChangeMessage implements Serializable { + ID changeIDs[]; + boolean add; + Serializable data; + + ViewChangeMessage(ID id[], boolean a, Serializable data) { + this.changeIDs = id; + this.add = a; + this.data = data; + } + + protected String printChangeIDs() { + if (changeIDs == null) + return "null"; + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < changeIDs.length; i++) { + buf.append(changeIDs[i]); + if (i != (changeIDs.length - 1)) + buf.append(","); + } + return buf.toString(); + } + + public String toString() { + StringBuffer sb = new StringBuffer("ViewChangeMessage["); + sb.append(printChangeIDs()).append(";").append(add).append(";") + .append(data).append("]"); + return sb.toString(); + } + + /** + * @return Returns the add. + */ + public boolean isAdd() { + return add; + } + + /** + * @return Returns the changeIDs. + */ + public ID[] getChangeIDs() { + return changeIDs; + } + + /** + * @return Returns the data. + */ + public Serializable getData() { + return data; + } + } + + public static final class CreateMessage implements Serializable { + Serializable data; + + CreateMessage(Serializable data) { + this.data = data; + } + + public Serializable getData() { + return data; + } + + public String toString() { + StringBuffer sb = new StringBuffer("CreateMessage["); + sb.append(data).append("]"); + return sb.toString(); + } + } + + public static final class CreateResponseMessage implements Serializable { + ID sharedObjectID; + Throwable exception; + long sequence; + + public CreateResponseMessage(ID objID, Throwable except, long sequence) { + this.sharedObjectID = objID; + this.exception = except; + this.sequence = sequence; + } + + public String toString() { + StringBuffer sb = new StringBuffer("CreateResponseMessage["); + sb.append(sharedObjectID).append(";").append(exception).append(";") + .append(sequence).append("]"); + return sb.toString(); + } + + /** + * @return Returns the exception. + */ + public Throwable getException() { + return exception; + } + + /** + * @return Returns the sequence. + */ + public long getSequence() { + return sequence; + } + + /** + * @return Returns the sharedObjectID. + */ + public ID getSharedObjectID() { + return sharedObjectID; + } + } + + public static final class SharedObjectMessage implements Serializable { + Serializable data; + ID fromSharedObjectID; + + SharedObjectMessage(ID fromSharedObject, Serializable data) { + this.fromSharedObjectID = fromSharedObject; + this.data = data; + } + + public String toString() { + StringBuffer sb = new StringBuffer("SharedObjectMessage["); + sb.append(fromSharedObjectID).append(";").append(data).append("]"); + return sb.toString(); + } + + /** + * @return Returns the data. + */ + public Serializable getData() { + return data; + } + + /** + * @return Returns the fromSharedObjectID. + */ + public ID getFromSharedObjectID() { + return fromSharedObjectID; + } + } + + public static final class SharedObjectDisposeMessage implements + Serializable { + ID sharedObjectID; + + SharedObjectDisposeMessage(ID objID) { + this.sharedObjectID = objID; + } + + public String toString() { + StringBuffer sb = new StringBuffer("SharedObjectDisposeMessage["); + sb.append(sharedObjectID).append("]"); + return sb.toString(); + } + + /** + * @return Returns the sharedObjectID. + */ + public ID getSharedObjectID() { + return sharedObjectID; + } + } + + public static final class JoinGroupMessage implements Serializable { + Serializable data; + + public JoinGroupMessage(Serializable data) { + this.data = data; + } + + public Serializable getData() { + return data; + } + + public String toString() { + StringBuffer sb = new StringBuffer("JoinGroupMessage["); + sb.append(data).append("]"); + return sb.toString(); + } + } + + public static final class LeaveGroupMessage implements Serializable { + Serializable data; + + public LeaveGroupMessage(Serializable data) { + this.data = data; + } + + public Serializable getData() { + return data; + } + + public String toString() { + StringBuffer sb = new StringBuffer("LeaveGroupMessage["); + sb.append(data).append("]"); + return sb.toString(); + } + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/QueueEnqueueImpl.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/QueueEnqueueImpl.java index 8dceedd7c..3c3f248ee 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/QueueEnqueueImpl.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/QueueEnqueueImpl.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + /* * Created on Dec 6, 2004 * @@ -11,7 +22,6 @@ import org.eclipse.ecf.core.util.QueueException; import org.eclipse.ecf.core.util.SimpleQueueImpl; public class QueueEnqueueImpl implements QueueEnqueue { - SimpleQueueImpl queue = null; public QueueEnqueueImpl(SimpleQueueImpl impl) { @@ -65,7 +75,6 @@ public class QueueEnqueueImpl implements QueueEnqueue { e.printStackTrace(System.err); } } - } /* @@ -115,5 +124,4 @@ public class QueueEnqueueImpl implements QueueEnqueue { public int size() { return queue.size(); } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConfig.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConfig.java index a4b48b7cf..d3dff837e 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConfig.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConfig.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + /* * Created on Nov 29, 2004 * @@ -5,14 +16,12 @@ package org.eclipse.ecf.provider.generic; import java.util.Map; - import org.eclipse.ecf.core.ISharedObjectConfig; import org.eclipse.ecf.core.ISharedObjectContext; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.util.QueueEnqueue; public class SOConfig implements ISharedObjectConfig { - SOContainer container = null; ID sharedObjectID; ID homeContainerID; @@ -80,5 +89,4 @@ public class SOConfig implements ISharedObjectConfig { public Map getProperties() { return properties; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConnector.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConnector.java index c5d78bf8f..8362483dc 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConnector.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOConnector.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + /* * Created on Dec 20, 2004 * @@ -6,7 +17,6 @@ package org.eclipse.ecf.provider.generic; import java.util.Enumeration; import java.util.Hashtable; - import org.eclipse.ecf.core.ISharedObjectConnector; import org.eclipse.ecf.core.events.ISharedObjectEvent; import org.eclipse.ecf.core.identity.ID; @@ -16,7 +26,6 @@ import org.eclipse.ecf.core.util.QueueException; import org.eclipse.ecf.provider.generic.events.SharedObjectCallEvent; public class SOConnector implements ISharedObjectConnector { - ID sender; Hashtable receiverQueues = null; @@ -34,6 +43,7 @@ public class SOConnector implements ISharedObjectConnector { queue.enqueue(event); } } + protected void fireEvents(ISharedObjectEvent[] event) throws QueueException { for (Enumeration e = receiverQueues.elements(); e.hasMoreElements();) { QueueEnqueue queue = (QueueEnqueue) e.nextElement(); @@ -42,6 +52,7 @@ public class SOConnector implements ISharedObjectConnector { } } } + protected AsynchResult[] fireCallEvent(ISharedObjectEvent event) throws QueueException { AsynchResult[] results = new AsynchResult[receiverQueues.size()]; @@ -54,6 +65,7 @@ public class SOConnector implements ISharedObjectConnector { } return results; } + /* * (non-Javadoc) * @@ -112,5 +124,4 @@ public class SOConnector implements ISharedObjectConnector { } sender = null; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java index 3124b6afa..0b3b5a13e 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainer.java @@ -1,7 +1,14 @@ -/* - * Created on Dec 16, 2004 - * - */ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.ByteArrayInputStream; @@ -16,7 +23,6 @@ import java.security.PrivilegedAction; import java.util.Iterator; import java.util.Map; import java.util.Vector; - import org.eclipse.ecf.core.IOSGIService; import org.eclipse.ecf.core.ISharedObject; import org.eclipse.ecf.core.ISharedObjectConfig; @@ -42,887 +48,894 @@ import org.eclipse.ecf.provider.Trace; import org.eclipse.ecf.provider.generic.gmm.Member; public abstract class SOContainer implements ISharedObjectContainer { - - static Trace debug = Trace.create("container"); - - public static final String DEFAULT_OBJECT_ARG_KEY = SOContainer.class - .getName() - + ".sharedobjectargs"; - - public static final String DEFAULT_OBJECT_ARGTYPES_KEY = SOContainer.class - .getName() - + ".sharedobjectargs"; - - private long sequenceNumber = 0L; - - private Vector listeners = null; - - protected ISharedObjectContainerConfig config = null; - - protected SOContainerGMM groupManager = null; - - protected ThreadGroup loadingThreadGroup = null; - - protected ThreadGroup sharedObjectThreadGroup = null; - - protected SOManager sharedObjectManager = null; - - protected boolean isClosing = false; - - protected MessageReceiver receiver; - - protected void debug(String msg) { - if (Trace.ON && debug != null) { - debug.msg(msg + ":" + config.getID()); - } - } - - protected void dumpStack(String msg, Throwable e) { - if (Trace.ON && debug != null) { - debug.dumpStack(e, msg + ":" + config.getID()); - } - } - - protected byte[] getBytesForObject(Serializable obj) throws IOException { - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); - oos.writeObject(obj); - return bos.toByteArray(); - } - - protected ContainerMessage getObjectFromBytes(byte[] bytes) - throws IOException { - ByteArrayInputStream bis = new ByteArrayInputStream(bytes); - ObjectInputStream ois = new ObjectInputStream(bis); - Object obj = null; - try { - obj = ois.readObject(); - } catch (ClassNotFoundException e) { - // what to do? - dumpStack("class not found for message", e); - return null; - } - if (obj instanceof ContainerMessage) { - return (ContainerMessage) obj; - } else { - // what to do - return null; - } - } - - protected void killConnection(IConnection conn) { - debug("killconnection"); - try { - if (conn != null) - conn.disconnect(); - } catch (IOException e) { - logException("Exception in killConnection",e); - } - } - protected void logException(String msg, Throwable e) { - dumpStack(msg,e); - } - protected void log(String msg) { - debug(msg); - } - protected void memberLeave(ID target, IConnection conn) { - debug("memberLeave:" + target + ":" + conn); - if (conn != null) - killConnection(conn); - } - - protected void fireContainerEvent(IContainerEvent event) { - synchronized (listeners) { - for (Iterator i = listeners.iterator(); i.hasNext();) - ((ISharedObjectContainerListener) i.next()).handleEvent(event); - } - } - - protected long getNextSequenceNumber() { - if (sequenceNumber == Long.MAX_VALUE) { - sequenceNumber = 0; - return sequenceNumber; - } else - return sequenceNumber++; - } - - protected Object getGroupMembershipLock() { - return groupManager; - } - - public ID[] getOtherMemberIDs() { - return groupManager.getOtherMemberIDs(); - } - - protected ISharedObject getSharedObject(ID id) { - SOWrapper wrap = getSharedObjectWrapper(id); - if (wrap == null) - return null; - else - return wrap.getSharedObject(); - } - - protected ISharedObject addSharedObjectAndWait(SharedObjectDescription sd, - ISharedObject s, ISharedObjectContainerTransaction t) - throws Exception { - if (sd.getID() == null || s == null) - return null; - ISharedObject so = addSharedObject0(sd, s); - // Wait right here until committed - if (t != null) - t.waitToCommit(); - return s; - } - - protected ISharedObject addSharedObject0(SharedObjectDescription sd, - ISharedObject s) throws Exception { - addSharedObjectWrapper(makeNewSharedObjectWrapper(sd, s)); - return s; - } - - protected SOWrapper makeNewSharedObjectWrapper(SharedObjectDescription sd, - ISharedObject s) { - SOConfig newConfig = makeNewSharedObjectConfig(sd, this); - return new SOWrapper(newConfig, s, this); - } - - protected SOConfig makeNewSharedObjectConfig(SharedObjectDescription sd, - SOContainer cont) { - ID homeID = sd.getHomeID(); - if (homeID == null) - homeID = getID(); - return new SOConfig(sd.getID(), homeID, this, sd.getProperties()); - } - - protected SOWrapper getSharedObjectWrapper(ID id) { - return groupManager.getFromActive(id); - } - - protected void addSharedObjectWrapper(SOWrapper wrapper) throws Exception { - if (wrapper == null) - return; - ID id = wrapper.getObjID(); - synchronized (getGroupMembershipLock()) { - Object obj = groupManager.getFromAny(id); - if (obj != null) { - throw new SharedObjectAddException("SharedObject with id " - + id.getName() + " already in container"); - } - // Call initialize. If this throws it halts everything - wrapper.init(); - // Put in table - groupManager.addSharedObjectToActive(wrapper); - } - } - - protected ISharedObject removeSharedObject(ID id) { - synchronized (getGroupMembershipLock()) { - SOWrapper wrap = groupManager.getFromActive(id); - if (wrap == null) - return null; - groupManager.removeSharedObject(id); - return wrap.getSharedObject(); - } - } - - protected boolean addNewRemoteMember(ID memberID, Object data) { - debug("addNewRemoteMember:" + memberID); - return groupManager.addMember(new Member(memberID, data)); - } - - abstract protected void queueContainerMessage(ContainerMessage mess) - throws IOException; - - abstract protected void forwardToRemote(ID from, ID to, - ContainerMessage data) throws IOException; - - abstract protected void forwardExcluding(ID from, ID excluding, - ContainerMessage data) throws IOException; - - protected final void forward(ID fromID, ID toID, ContainerMessage data) - throws IOException { - if (toID == null) { - forwardExcluding(fromID, fromID, data); - } else { - forwardToRemote(fromID, toID, data); - } - } - - protected boolean removeRemoteMember(ID remoteMember) { - return groupManager.removeMember(remoteMember); - } - - protected void sendMessage(ContainerMessage data) throws IOException { - debug("sendcontainermessage:" + data); - synchronized (getGroupMembershipLock()) { - ID ourID = getID(); - // We don't send to ourselves - if (!ourID.equals(data.getToContainerID())) - queueContainerMessage(data); - } - } - - protected ID[] sendCreateSharedObjectMessage(ID toContainerID, - SharedObjectDescription sd) throws IOException { - ID[] returnIDs = null; - if (toContainerID == null) { - synchronized (getGroupMembershipLock()) { - // Send message to all - sendMessage(ContainerMessage.makeSharedObjectCreateMessage( - getID(), toContainerID, getNextSequenceNumber(), sd)); - returnIDs = getOtherMemberIDs(); - } - } else { - // If the create msg is directed to this space, no msg will be sent - if (getID().equals(toContainerID)) { - returnIDs = new ID[0]; - } else { - sendMessage(ContainerMessage.makeSharedObjectCreateMessage( - getID(), toContainerID, getNextSequenceNumber(), sd)); - returnIDs = new ID[1]; - returnIDs[0] = toContainerID; - } - } - return returnIDs; - } - - protected void sendCreateResponseSharedObjectMessage(ID toContainerID, - ID fromSharedObject, Throwable t, long ident) throws IOException { - sendMessage(ContainerMessage.makeSharedObjectCreateResponseMessage( - getID(), toContainerID, getNextSequenceNumber(), - fromSharedObject, t, ident)); - } - - protected void sendSharedObjectMessage(ID toContainerID, - ID fromSharedObject, Serializable data) throws IOException { - sendMessage(ContainerMessage.makeSharedObjectMessage(getID(), - toContainerID, getNextSequenceNumber(), fromSharedObject, data)); - } - - protected void sendDisposeSharedObjectMessage(ID toContainerID, - ID fromSharedObject) throws IOException { - sendMessage(ContainerMessage.makeSharedObjectDisposeMessage(getID(), - toContainerID, getNextSequenceNumber(), fromSharedObject)); - } - - public SOContainer(ISharedObjectContainerConfig config) { - if (config == null) - throw new InstantiationError("config must not be null"); - this.config = config; - groupManager = new SOContainerGMM(this, new Member(config.getID())); - sharedObjectManager = new SOManager(this); - loadingThreadGroup = getLoadingThreadGroup(); - sharedObjectThreadGroup = getSharedObjectThreadGroup(); - listeners = new Vector(); - receiver = new MessageReceiver(); - debug("<init>"); - } - - protected ISynchAsynchConnectionEventHandler getReceiver() { - return receiver; - } - - protected boolean isClosing() { - return isClosing; - } - - protected void setIsClosing() { - isClosing = true; - } - - protected ThreadGroup getLoadingThreadGroup() { - return new ThreadGroup(getID() + ":Loading"); - } - - protected ThreadGroup getSharedObjectThreadGroup() { - return new ThreadGroup(getID() + ":SOs"); - } - - public ID getID() { - return config.getID(); - } - - protected int getMaxGroupMembers() { - return groupManager.getMaxMembers(); - } - - protected void setMaxGroupMembers(int max) { - groupManager.setMaxMembers(max); - } - - protected void notifySharedObjectActivated(ID sharedObjectID) { - groupManager.notifyOthersActivated(sharedObjectID); - } - - protected void notifySharedObjectDeactivated(ID sharedObjectID) { - groupManager.notifyOthersDeactivated(sharedObjectID); - } - - protected boolean destroySharedObject(ID sharedObjectID) { - return groupManager.removeSharedObject(sharedObjectID); - } - - protected IOSGIService getOSGIServiceInterface() { - return null; - } - - protected void sendCreate(ID sharedObjectID, ID toContainerID, - SharedObjectDescription sd) throws IOException { - sendCreateSharedObjectMessage(toContainerID, sd); - } - - protected void sendDispose(ID toContainerID, ID sharedObjectID) - throws IOException { - sendDisposeSharedObjectMessage(toContainerID, sharedObjectID); - } - - protected void sendMessage(ID toContainerID, ID sharedObjectID, - Object message) throws IOException { - if (message == null) - return; - if (message instanceof Serializable) - throw new NotSerializableException(message.getClass().getName()); - sendSharedObjectMessage(toContainerID, sharedObjectID, - (Serializable) message); - } - - protected void sendCreateResponse(ID homeID, ID sharedObjectID, - Throwable t, long identifier) throws IOException { - sendCreateResponseSharedObjectMessage(homeID, sharedObjectID, t, - identifier); - } - - protected Thread getNewSharedObjectThread(ID sharedObjectID, - Runnable runnable) { - return new Thread(sharedObjectThreadGroup, runnable, getID().getName() - + ";" + sharedObjectID.getName()); - } - - protected ISharedObject load(SharedObjectDescription sd) throws Exception { - return sharedObjectManager.loadSharedObject(sd); - } - - protected ID[] getSharedObjectIDs() { - return groupManager.getSharedObjectIDs(); - } - - protected SOConfig makeSharedObjectConfig(SharedObjectDescription sd, - ISharedObject obj) { - return new SOConfig(sd.getID(), sd.getHomeID(), this, sd - .getProperties()); - } - - protected void moveFromLoadingToActive(SOWrapper wrap) { - groupManager.moveSharedObjectFromLoadingToActive(wrap); - } - - protected void removeFromLoading(ID id) { - groupManager.removeSharedObjectFromLoading(id); - } - - protected void processDisconnect(DisconnectConnectionEvent e) { - debug("processDisconnect:" + e); - try { - ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); - } catch (IOException except) { - logException("Exception in processDisconnect ",except); - } - } - protected Object checkCreate(ID fromID, ID toID, long seq, SharedObjectDescription desc) { - debug("checkCreate("+fromID+","+toID+","+seq+","+desc+")"); - // XXX TODO - return desc; - } - protected boolean addToLoading(LoadingSharedObject lso) { - return groupManager.addLoadingSharedObject(lso); - } - protected void handleCreateMessage(ContainerMessage mess) throws IOException { - debug("handleCreateMessage:"+mess); - - SharedObjectDescription desc = (SharedObjectDescription) mess.getData(); - ID fromID = mess.getFromContainerID(); - ID toID = mess.getToContainerID(); - long seq = mess.getSequence(); - Object result = checkCreate(fromID,toID,seq,desc); - if (result != null && (toID == null || toID.equals(getID()))) { - LoadingSharedObject lso = new LoadingSharedObject(desc,result); - synchronized (getGroupMembershipLock()) { - if (!addToLoading(lso)) { - ID sharedObjectID = desc.getID(); - try { - sendCreateResponse(fromID,sharedObjectID,new SharedObjectAddException("shared object "+sharedObjectID),desc.getIdentifier()); - } catch (IOException e) { - logException("Exception in handleCreateMessage",e); - } - } - forward(fromID, toID, mess); - return; - } - } - synchronized (getGroupMembershipLock()) { - forward(fromID,toID,mess); - } - } - protected void handleCreateResponseMessage(ContainerMessage mess) throws IOException { - debug("handleCreateResponseMessage:"+mess); - ID fromID = mess.getFromContainerID(); - ID toID = mess.getToContainerID(); - long seq = mess.getSequence(); - ContainerMessage.CreateResponseMessage resp = (ContainerMessage.CreateResponseMessage) mess.getData(); - if (toID != null && toID.equals(getID())) { - ID sharedObjectID = resp.getSharedObjectID(); - SOWrapper sow = getSharedObjectWrapper(sharedObjectID); - if (sow != null) { - sow.deliverCreateResponse(fromID,resp); - } else { - log("handleCreateResponseMessage...wrapper now found for "+sharedObjectID); - } - } else { - forwardToRemote(fromID,toID,mess); - } - } - protected void handleSharedObjectDisposeMessage(ContainerMessage mess) throws IOException { - debug("handleSharedObjectDisposeMessage:"+mess); - ID fromID = mess.getFromContainerID(); - ID toID = mess.getToContainerID(); - long seq = mess.getSequence(); - ContainerMessage.SharedObjectDisposeMessage resp = (ContainerMessage.SharedObjectDisposeMessage) mess.getData(); - ID sharedObjectID = resp.getSharedObjectID(); - synchronized (getGroupMembershipLock()) { - if (groupManager.isLoading(sharedObjectID)) { - groupManager.removeSharedObjectFromLoading(sharedObjectID); - } else { - groupManager.removeSharedObject(sharedObjectID); - } - forward(fromID, toID, mess); - } - } - protected void handleSharedObjectMessage(ContainerMessage mess) throws IOException { - debug("handleSharedObjectMessage:"+mess); - ID fromID = mess.getFromContainerID(); - ID toID = mess.getToContainerID(); - long seq = mess.getSequence(); - ContainerMessage.SharedObjectMessage resp = (ContainerMessage.SharedObjectMessage) mess.getData(); - synchronized (getGroupMembershipLock()) { - if (toID == null || toID.equals(getID())) { - SOWrapper sow = getSharedObjectWrapper(resp.getFromSharedObjectID()); - if (sow != null) { - sow.deliverSharedObjectMessage(fromID,resp.getData()); - } - } - forward(fromID,toID,mess); - } - } - protected abstract void handleViewChangeMessage(ContainerMessage mess) throws IOException; - - protected void handleUnidentifiedMessage(ContainerMessage mess) throws IOException { - // do nothing - } - protected void handleAsynchIOException(IOException except, AsynchConnectionEvent e) { - // If we get IO Exception, we'll disconnect...if we can - killConnection(e.getConnection()); - } - protected void processAsynch(AsynchConnectionEvent e) { - debug("processAsynch:" + e); - try { - ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); - Serializable submess = mess.getData(); - if (submess != null) { - if (submess instanceof ContainerMessage.CreateMessage) { - handleCreateMessage(mess); - } else if (submess instanceof ContainerMessage.CreateResponseMessage) { - handleCreateResponseMessage(mess); - } else if (submess instanceof ContainerMessage.SharedObjectDisposeMessage) { - handleSharedObjectDisposeMessage(mess); - } else if (submess instanceof ContainerMessage.SharedObjectMessage) { - handleSharedObjectMessage(mess); - } else if (submess instanceof ContainerMessage.ViewChangeMessage) { - handleViewChangeMessage(mess); - } else { - handleUnidentifiedMessage(mess); - } - } else { - handleUnidentifiedMessage(mess); - } - } catch (IOException except) { - handleAsynchIOException(except,e); - } - } - - protected Serializable processSynch(SynchConnectionEvent e) - throws IOException { - debug("processSynch:" + e); - ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); - ID fromID = mess.getFromContainerID(); - notifyGroupLeave(mess); - synchronized (getGroupMembershipLock()) { - memberLeave(fromID, e.getConnection()); - } - return null; - } - - protected void notifyGroupLeave(ContainerMessage mess) { - // XXX todo - debug("notifyGroupLeave("+mess+")"); - } - - class LoadingSharedObject implements ISharedObject { - - SharedObjectDescription description; - Object credentials; - - Thread runner = null; - - LoadingSharedObject(SharedObjectDescription sd, Object credentials) { - this.description = sd; - this.credentials = credentials; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public void init(ISharedObjectConfig initData) - throws SharedObjectInitException { - } - - ID getID() { - return description.getID(); - } - - ID getHomeID() { - return description.getHomeID(); - } - - void start() { - if (runner == null) { - runner = (Thread) AccessController - .doPrivileged(new PrivilegedAction() { - public Object run() { - return getThread(); - } - }); - runner.setDaemon(true); - runner.start(); - } - - } - - /* - * (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) { - } - - /* - * (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; - } - - Thread getThread() { - return new Thread(loadingThreadGroup, new Runnable() { - public void run() { - try { - if (Thread.currentThread().isInterrupted() - || isClosing()) - throw new InterruptedException( - "Loading interrupted for object " - + getID().getName()); - // First load given object - ISharedObject obj = load(description); - // Get config info for new object - SOConfig aConfig = makeSharedObjectConfig(description, - obj); - // Call init method on new object. - obj.init(aConfig); - // Check to make sure thread has not been - // interrupted...if it has, throw - if (Thread.currentThread().isInterrupted() - || isClosing()) - throw new InterruptedException( - "Loading interrupted for object " - + getID().getName()); - - // Create meta object and move from loading to active - // list. - SOContainer.this.moveFromLoadingToActive(new SOWrapper( - aConfig, obj, SOContainer.this)); - } catch (Exception e) { - SOContainer.this.removeFromLoading(getID()); - try { - sendCreateResponse(getHomeID(), getID(), e, - description.getIdentifier()); - } catch (Exception e1) { - } - } - } - }, "LRunner" + getID().getName()); - } - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getConfig() - */ - public ISharedObjectContainerConfig getConfig() { - return config; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#addListener(org.eclipse.ecf.core.ISharedObjectContainerListener, - * java.lang.String) - */ - public void addListener(ISharedObjectContainerListener l, String filter) { - synchronized (listeners) { - listeners.add(l); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#removeListener(org.eclipse.ecf.core.ISharedObjectContainerListener) - */ - public void removeListener(ISharedObjectContainerListener l) { - synchronized (listeners) { - listeners.remove(l); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#dispose(long) - */ - public void dispose(long waittime) { - debug("dispose:" + waittime); - isClosing = true; - // XXX Notify listeners that we're going away - // Clear group manager - if (groupManager != null) { - groupManager.removeAllMembers(); - groupManager = null; - } - // Clear shared object manager - if (sharedObjectManager != null) { - sharedObjectManager.dispose(); - sharedObjectManager = null; - } - if (sharedObjectThreadGroup != null) { - sharedObjectThreadGroup.interrupt(); - sharedObjectThreadGroup = null; - } - if (loadingThreadGroup != null) { - loadingThreadGroup.interrupt(); - loadingThreadGroup = null; - } - if (listeners != null) { - listeners.clear(); - listeners = null; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.core.identity.ID, - * java.lang.Object) - */ - public abstract void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException; - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() - */ - public abstract void leaveGroup(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() - */ - public abstract ID getGroupID(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMemberIDs() - */ - public ID[] getGroupMemberIDs() { - return groupManager.getMemberIDs(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() - */ - public abstract boolean isGroupManager(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() - */ - public abstract boolean isGroupServer(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectManager() - */ - public ISharedObjectManager getSharedObjectManager() { - return sharedObjectManager; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - return null; - } - - protected ClassLoader getClassLoaderForContainer() { - return this.getClass().getClassLoader(); - } - - /** - * @param sd - * @return - */ - protected ClassLoader getClassLoaderForSharedObject( - SharedObjectDescription sd) { - if (sd != null) { - ClassLoader cl = sd.getClassLoader(); - if (cl != null) - return cl; - else - return getClassLoaderForContainer(); - } else - return getClassLoaderForContainer(); - } - - /** - * @param sd - * @return - */ - public Object[] getArgsFromProperties(SharedObjectDescription sd) { - if (sd == null) - return null; - Map aMap = sd.getProperties(); - if (aMap == null) - return null; - Object obj = aMap.get(DEFAULT_OBJECT_ARG_KEY); - if (obj == null) - return null; - if (obj instanceof Object[]) { - Object[] ret = (Object[]) obj; - aMap.remove(DEFAULT_OBJECT_ARG_KEY); - return ret; - } else - return null; - } - - /** - * @param sd - * @return - */ - public String[] getArgTypesFromProperties(SharedObjectDescription sd) { - if (sd == null) - return null; - Map aMap = sd.getProperties(); - if (aMap == null) - return null; - Object obj = aMap.get(DEFAULT_OBJECT_ARGTYPES_KEY); - if (obj == null) - return null; - if (obj instanceof String[]) { - String[] ret = (String[]) obj; - aMap.remove(DEFAULT_OBJECT_ARGTYPES_KEY); - return ret; - } else - return null; - } - - class MessageReceiver implements ISynchAsynchConnectionEventHandler { - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.comm.ISynchConnectionEventHandler#handleSynchEvent(org.eclipse.ecf.internal.comm.SynchConnectionEvent) - */ - public Object handleSynchEvent(SynchConnectionEvent event) - throws IOException { - return processSynch(event); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#handleSuspectEvent(org.eclipse.ecf.internal.comm.ConnectionEvent) - */ - public boolean handleSuspectEvent(ConnectionEvent event) { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#handleDisconnectEvent(org.eclipse.ecf.internal.comm.ConnectionEvent) - */ - public void handleDisconnectEvent(DisconnectConnectionEvent event) { - processDisconnect(event); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.internal.comm.IAsynchConnectionEventHandler#handleAsynchEvent(org.eclipse.ecf.internal.comm.AsynchConnectionEvent) - */ - public void handleAsynchEvent(AsynchConnectionEvent event) - throws IOException { - processAsynch(event); - } - - } + static Trace debug = Trace.create("container"); + public static final String DEFAULT_OBJECT_ARG_KEY = SOContainer.class + .getName() + + ".sharedobjectargs"; + public static final String DEFAULT_OBJECT_ARGTYPES_KEY = SOContainer.class + .getName() + + ".sharedobjectargs"; + private long sequenceNumber = 0L; + private Vector listeners = null; + protected ISharedObjectContainerConfig config = null; + protected SOContainerGMM groupManager = null; + protected ThreadGroup loadingThreadGroup = null; + protected ThreadGroup sharedObjectThreadGroup = null; + protected SOManager sharedObjectManager = null; + protected boolean isClosing = false; + protected MessageReceiver receiver; + + protected void debug(String msg) { + if (Trace.ON && debug != null) { + debug.msg(msg + ":" + config.getID()); + } + } + + protected void dumpStack(String msg, Throwable e) { + if (Trace.ON && debug != null) { + debug.dumpStack(e, msg + ":" + config.getID()); + } + } + + protected byte[] getBytesForObject(Serializable obj) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(obj); + return bos.toByteArray(); + } + + protected ContainerMessage getObjectFromBytes(byte[] bytes) + throws IOException { + ByteArrayInputStream bis = new ByteArrayInputStream(bytes); + ObjectInputStream ois = new ObjectInputStream(bis); + Object obj = null; + try { + obj = ois.readObject(); + } catch (ClassNotFoundException e) { + dumpStack("class not found for message", e); + return null; + } + if (obj instanceof ContainerMessage) { + return (ContainerMessage) obj; + } else { + debug("message received is not containermessage:"+obj); + return null; + } + } + + protected void killConnection(IConnection conn) { + debug("killconnection"); + try { + if (conn != null) + conn.disconnect(); + } catch (IOException e) { + logException("Exception in killConnection", e); + } + } + + protected void logException(String msg, Throwable e) { + dumpStack(msg, e); + } + + protected void log(String msg) { + debug(msg); + } + + protected void memberLeave(ID target, IConnection conn) { + debug("memberLeave:" + target + ":" + conn); + if (conn != null) + killConnection(conn); + } + + protected void fireContainerEvent(IContainerEvent event) { + synchronized (listeners) { + for (Iterator i = listeners.iterator(); i.hasNext();) + ((ISharedObjectContainerListener) i.next()).handleEvent(event); + } + } + + protected long getNextSequenceNumber() { + if (sequenceNumber == Long.MAX_VALUE) { + sequenceNumber = 0; + return sequenceNumber; + } else + return sequenceNumber++; + } + + protected Object getGroupMembershipLock() { + return groupManager; + } + + public ID[] getOtherMemberIDs() { + return groupManager.getOtherMemberIDs(); + } + + protected ISharedObject getSharedObject(ID id) { + SOWrapper wrap = getSharedObjectWrapper(id); + if (wrap == null) + return null; + else + return wrap.getSharedObject(); + } + + protected ISharedObject addSharedObjectAndWait(SharedObjectDescription sd, + ISharedObject s, ISharedObjectContainerTransaction t) + throws Exception { + if (sd.getID() == null || s == null) + return null; + ISharedObject so = addSharedObject0(sd, s); + // Wait right here until committed + if (t != null) + t.waitToCommit(); + return s; + } + + protected ISharedObject addSharedObject0(SharedObjectDescription sd, + ISharedObject s) throws Exception { + addSharedObjectWrapper(makeNewSharedObjectWrapper(sd, s)); + return s; + } + + protected SOWrapper makeNewSharedObjectWrapper(SharedObjectDescription sd, + ISharedObject s) { + SOConfig newConfig = makeNewSharedObjectConfig(sd, this); + return new SOWrapper(newConfig, s, this); + } + + protected SOConfig makeNewSharedObjectConfig(SharedObjectDescription sd, + SOContainer cont) { + ID homeID = sd.getHomeID(); + if (homeID == null) + homeID = getID(); + return new SOConfig(sd.getID(), homeID, this, sd.getProperties()); + } + + protected SOWrapper getSharedObjectWrapper(ID id) { + return groupManager.getFromActive(id); + } + + protected void addSharedObjectWrapper(SOWrapper wrapper) throws Exception { + if (wrapper == null) + return; + ID id = wrapper.getObjID(); + synchronized (getGroupMembershipLock()) { + Object obj = groupManager.getFromAny(id); + if (obj != null) { + throw new SharedObjectAddException("SharedObject with id " + + id.getName() + " already in container"); + } + // Call initialize. If this throws it halts everything + wrapper.init(); + // Put in table + groupManager.addSharedObjectToActive(wrapper); + } + } + + protected ISharedObject removeSharedObject(ID id) { + synchronized (getGroupMembershipLock()) { + SOWrapper wrap = groupManager.getFromActive(id); + if (wrap == null) + return null; + groupManager.removeSharedObject(id); + return wrap.getSharedObject(); + } + } + + protected boolean addNewRemoteMember(ID memberID, Object data) { + debug("addNewRemoteMember:" + memberID); + return groupManager.addMember(new Member(memberID, data)); + } + + abstract protected void queueContainerMessage(ContainerMessage mess) + throws IOException; + + abstract protected void forwardToRemote(ID from, ID to, + ContainerMessage data) throws IOException; + + abstract protected void forwardExcluding(ID from, ID excluding, + ContainerMessage data) throws IOException; + + protected final void forward(ID fromID, ID toID, ContainerMessage data) + throws IOException { + if (toID == null) { + forwardExcluding(fromID, fromID, data); + } else { + forwardToRemote(fromID, toID, data); + } + } + + protected boolean removeRemoteMember(ID remoteMember) { + return groupManager.removeMember(remoteMember); + } + + protected void sendMessage(ContainerMessage data) throws IOException { + debug("sendcontainermessage:" + data); + synchronized (getGroupMembershipLock()) { + ID ourID = getID(); + // We don't send to ourselves + if (!ourID.equals(data.getToContainerID())) + queueContainerMessage(data); + } + } + + protected ID[] sendCreateSharedObjectMessage(ID toContainerID, + SharedObjectDescription sd) throws IOException { + ID[] returnIDs = null; + if (toContainerID == null) { + synchronized (getGroupMembershipLock()) { + // Send message to all + sendMessage(ContainerMessage.makeSharedObjectCreateMessage( + getID(), toContainerID, getNextSequenceNumber(), sd)); + returnIDs = getOtherMemberIDs(); + } + } else { + // If the create msg is directed to this space, no msg will be sent + if (getID().equals(toContainerID)) { + returnIDs = new ID[0]; + } else { + sendMessage(ContainerMessage.makeSharedObjectCreateMessage( + getID(), toContainerID, getNextSequenceNumber(), sd)); + returnIDs = new ID[1]; + returnIDs[0] = toContainerID; + } + } + return returnIDs; + } + + protected void sendCreateResponseSharedObjectMessage(ID toContainerID, + ID fromSharedObject, Throwable t, long ident) throws IOException { + sendMessage(ContainerMessage.makeSharedObjectCreateResponseMessage( + getID(), toContainerID, getNextSequenceNumber(), + fromSharedObject, t, ident)); + } + + protected void sendSharedObjectMessage(ID toContainerID, + ID fromSharedObject, Serializable data) throws IOException { + sendMessage(ContainerMessage.makeSharedObjectMessage(getID(), + toContainerID, getNextSequenceNumber(), fromSharedObject, data)); + } + + protected void sendDisposeSharedObjectMessage(ID toContainerID, + ID fromSharedObject) throws IOException { + sendMessage(ContainerMessage.makeSharedObjectDisposeMessage(getID(), + toContainerID, getNextSequenceNumber(), fromSharedObject)); + } + + public SOContainer(ISharedObjectContainerConfig config) { + if (config == null) + throw new InstantiationError("config must not be null"); + this.config = config; + groupManager = new SOContainerGMM(this, new Member(config.getID())); + sharedObjectManager = new SOManager(this); + loadingThreadGroup = getLoadingThreadGroup(); + sharedObjectThreadGroup = getSharedObjectThreadGroup(); + listeners = new Vector(); + receiver = new MessageReceiver(); + debug("<init>"); + } + + protected ISynchAsynchConnectionEventHandler getReceiver() { + return receiver; + } + + protected boolean isClosing() { + return isClosing; + } + + protected void setIsClosing() { + isClosing = true; + } + + protected ThreadGroup getLoadingThreadGroup() { + return new ThreadGroup(getID() + ":Loading"); + } + + protected ThreadGroup getSharedObjectThreadGroup() { + return new ThreadGroup(getID() + ":SOs"); + } + + public ID getID() { + return config.getID(); + } + + protected int getMaxGroupMembers() { + return groupManager.getMaxMembers(); + } + + protected void setMaxGroupMembers(int max) { + groupManager.setMaxMembers(max); + } + + protected void notifySharedObjectActivated(ID sharedObjectID) { + groupManager.notifyOthersActivated(sharedObjectID); + } + + protected void notifySharedObjectDeactivated(ID sharedObjectID) { + groupManager.notifyOthersDeactivated(sharedObjectID); + } + + protected boolean destroySharedObject(ID sharedObjectID) { + return groupManager.removeSharedObject(sharedObjectID); + } + + protected IOSGIService getOSGIServiceInterface() { + return null; + } + + protected void sendCreate(ID sharedObjectID, ID toContainerID, + SharedObjectDescription sd) throws IOException { + sendCreateSharedObjectMessage(toContainerID, sd); + } + + protected void sendDispose(ID toContainerID, ID sharedObjectID) + throws IOException { + sendDisposeSharedObjectMessage(toContainerID, sharedObjectID); + } + + protected void sendMessage(ID toContainerID, ID sharedObjectID, + Object message) throws IOException { + if (message == null) + return; + if (message instanceof Serializable) + throw new NotSerializableException(message.getClass().getName()); + sendSharedObjectMessage(toContainerID, sharedObjectID, + (Serializable) message); + } + + protected void sendCreateResponse(ID homeID, ID sharedObjectID, + Throwable t, long identifier) throws IOException { + sendCreateResponseSharedObjectMessage(homeID, sharedObjectID, t, + identifier); + } + + protected Thread getNewSharedObjectThread(ID sharedObjectID, + Runnable runnable) { + return new Thread(sharedObjectThreadGroup, runnable, getID().getName() + + ";" + sharedObjectID.getName()); + } + + protected ISharedObject load(SharedObjectDescription sd) throws Exception { + return sharedObjectManager.loadSharedObject(sd); + } + + protected ID[] getSharedObjectIDs() { + return groupManager.getSharedObjectIDs(); + } + + protected SOConfig makeSharedObjectConfig(SharedObjectDescription sd, + ISharedObject obj) { + return new SOConfig(sd.getID(), sd.getHomeID(), this, sd + .getProperties()); + } + + protected void moveFromLoadingToActive(SOWrapper wrap) { + groupManager.moveSharedObjectFromLoadingToActive(wrap); + } + + protected void removeFromLoading(ID id) { + groupManager.removeSharedObjectFromLoading(id); + } + + protected void processDisconnect(DisconnectConnectionEvent e) { + debug("processDisconnect:" + e); + try { + ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); + } catch (IOException except) { + logException("Exception in processDisconnect ", except); + } + } + + protected Object checkCreate(ID fromID, ID toID, long seq, + SharedObjectDescription desc) { + debug("checkCreate(" + fromID + "," + toID + "," + seq + "," + desc + + ")"); + // XXX TODO + return desc; + } + + protected boolean addToLoading(LoadingSharedObject lso) { + return groupManager.addLoadingSharedObject(lso); + } + + protected void handleCreateMessage(ContainerMessage mess) + throws IOException { + debug("handleCreateMessage:" + mess); + SharedObjectDescription desc = (SharedObjectDescription) mess.getData(); + ID fromID = mess.getFromContainerID(); + ID toID = mess.getToContainerID(); + long seq = mess.getSequence(); + Object result = checkCreate(fromID, toID, seq, desc); + if (result != null && (toID == null || toID.equals(getID()))) { + LoadingSharedObject lso = new LoadingSharedObject(desc, result); + synchronized (getGroupMembershipLock()) { + if (!addToLoading(lso)) { + ID sharedObjectID = desc.getID(); + try { + sendCreateResponse(fromID, sharedObjectID, + new SharedObjectAddException("shared object " + + sharedObjectID), desc.getIdentifier()); + } catch (IOException e) { + logException("Exception in handleCreateMessage", e); + } + } + forward(fromID, toID, mess); + return; + } + } + synchronized (getGroupMembershipLock()) { + forward(fromID, toID, mess); + } + } + + protected void handleCreateResponseMessage(ContainerMessage mess) + throws IOException { + debug("handleCreateResponseMessage:" + mess); + ID fromID = mess.getFromContainerID(); + ID toID = mess.getToContainerID(); + long seq = mess.getSequence(); + ContainerMessage.CreateResponseMessage resp = (ContainerMessage.CreateResponseMessage) mess + .getData(); + if (toID != null && toID.equals(getID())) { + ID sharedObjectID = resp.getSharedObjectID(); + SOWrapper sow = getSharedObjectWrapper(sharedObjectID); + if (sow != null) { + sow.deliverCreateResponse(fromID, resp); + } else { + log("handleCreateResponseMessage...wrapper now found for " + + sharedObjectID); + } + } else { + forwardToRemote(fromID, toID, mess); + } + } + + protected void handleSharedObjectDisposeMessage(ContainerMessage mess) + throws IOException { + debug("handleSharedObjectDisposeMessage:" + mess); + ID fromID = mess.getFromContainerID(); + ID toID = mess.getToContainerID(); + long seq = mess.getSequence(); + ContainerMessage.SharedObjectDisposeMessage resp = (ContainerMessage.SharedObjectDisposeMessage) mess + .getData(); + ID sharedObjectID = resp.getSharedObjectID(); + synchronized (getGroupMembershipLock()) { + if (groupManager.isLoading(sharedObjectID)) { + groupManager.removeSharedObjectFromLoading(sharedObjectID); + } else { + groupManager.removeSharedObject(sharedObjectID); + } + forward(fromID, toID, mess); + } + } + + protected void handleSharedObjectMessage(ContainerMessage mess) + throws IOException { + debug("handleSharedObjectMessage:" + mess); + ID fromID = mess.getFromContainerID(); + ID toID = mess.getToContainerID(); + long seq = mess.getSequence(); + ContainerMessage.SharedObjectMessage resp = (ContainerMessage.SharedObjectMessage) mess + .getData(); + synchronized (getGroupMembershipLock()) { + if (toID == null || toID.equals(getID())) { + SOWrapper sow = getSharedObjectWrapper(resp + .getFromSharedObjectID()); + if (sow != null) { + sow.deliverSharedObjectMessage(fromID, resp.getData()); + } + } + forward(fromID, toID, mess); + } + } + + protected abstract void handleViewChangeMessage(ContainerMessage mess) + throws IOException; + + protected void handleUnidentifiedMessage(ContainerMessage mess) + throws IOException { + // do nothing + } + + protected void handleAsynchIOException(IOException except, + AsynchConnectionEvent e) { + // If we get IO Exception, we'll disconnect...if we can + killConnection(e.getConnection()); + } + + protected void processAsynch(AsynchConnectionEvent e) { + debug("processAsynch:" + e); + try { + ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); + Serializable submess = mess.getData(); + if (submess != null) { + if (submess instanceof ContainerMessage.CreateMessage) { + handleCreateMessage(mess); + } else if (submess instanceof ContainerMessage.CreateResponseMessage) { + handleCreateResponseMessage(mess); + } else if (submess instanceof ContainerMessage.SharedObjectDisposeMessage) { + handleSharedObjectDisposeMessage(mess); + } else if (submess instanceof ContainerMessage.SharedObjectMessage) { + handleSharedObjectMessage(mess); + } else if (submess instanceof ContainerMessage.ViewChangeMessage) { + handleViewChangeMessage(mess); + } else { + handleUnidentifiedMessage(mess); + } + } else { + handleUnidentifiedMessage(mess); + } + } catch (IOException except) { + handleAsynchIOException(except, e); + } + } + + protected Serializable processSynch(SynchConnectionEvent e) + throws IOException { + debug("processSynch:" + e); + ContainerMessage mess = getObjectFromBytes((byte[]) e.getData()); + ID fromID = mess.getFromContainerID(); + notifyGroupLeave(mess); + synchronized (getGroupMembershipLock()) { + memberLeave(fromID, e.getConnection()); + } + return null; + } + + protected void notifyGroupLeave(ContainerMessage mess) { + // XXX todo + debug("notifyGroupLeave(" + mess + ")"); + } + + class LoadingSharedObject implements ISharedObject { + SharedObjectDescription description; + Object credentials; + Thread runner = null; + + LoadingSharedObject(SharedObjectDescription sd, Object credentials) { + this.description = sd; + this.credentials = credentials; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) + */ + public void init(ISharedObjectConfig initData) + throws SharedObjectInitException { + } + + ID getID() { + return description.getID(); + } + + ID getHomeID() { + return description.getHomeID(); + } + + void start() { + if (runner == null) { + runner = (Thread) AccessController + .doPrivileged(new PrivilegedAction() { + public Object run() { + return getThread(); + } + }); + runner.setDaemon(true); + runner.start(); + } + } + + /* + * (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) { + } + + /* + * (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; + } + + Thread getThread() { + return new Thread(loadingThreadGroup, new Runnable() { + public void run() { + try { + if (Thread.currentThread().isInterrupted() + || isClosing()) + throw new InterruptedException( + "Loading interrupted for object " + + getID().getName()); + // First load given object + ISharedObject obj = load(description); + // Get config info for new object + SOConfig aConfig = makeSharedObjectConfig(description, + obj); + // Call init method on new object. + obj.init(aConfig); + // Check to make sure thread has not been + // interrupted...if it has, throw + if (Thread.currentThread().isInterrupted() + || isClosing()) + throw new InterruptedException( + "Loading interrupted for object " + + getID().getName()); + // Create meta object and move from loading to active + // list. + SOContainer.this.moveFromLoadingToActive(new SOWrapper( + aConfig, obj, SOContainer.this)); + } catch (Exception e) { + SOContainer.this.removeFromLoading(getID()); + try { + sendCreateResponse(getHomeID(), getID(), e, + description.getIdentifier()); + } catch (Exception e1) { + } + } + } + }, "LRunner" + getID().getName()); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getConfig() + */ + public ISharedObjectContainerConfig getConfig() { + return config; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#addListener(org.eclipse.ecf.core.ISharedObjectContainerListener, + * java.lang.String) + */ + public void addListener(ISharedObjectContainerListener l, String filter) { + synchronized (listeners) { + listeners.add(l); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#removeListener(org.eclipse.ecf.core.ISharedObjectContainerListener) + */ + public void removeListener(ISharedObjectContainerListener l) { + synchronized (listeners) { + listeners.remove(l); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#dispose(long) + */ + public void dispose(long waittime) { + debug("dispose:" + waittime); + isClosing = true; + // XXX Notify listeners that we're going away + // Clear group manager + if (groupManager != null) { + groupManager.removeAllMembers(); + groupManager = null; + } + // Clear shared object manager + if (sharedObjectManager != null) { + sharedObjectManager.dispose(); + sharedObjectManager = null; + } + if (sharedObjectThreadGroup != null) { + sharedObjectThreadGroup.interrupt(); + sharedObjectThreadGroup = null; + } + if (loadingThreadGroup != null) { + loadingThreadGroup.interrupt(); + loadingThreadGroup = null; + } + if (listeners != null) { + listeners.clear(); + listeners = null; + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.core.identity.ID, + * java.lang.Object) + */ + public abstract void joinGroup(ID groupID, Object loginData) + throws SharedObjectContainerJoinException; + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() + */ + public abstract void leaveGroup(); + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() + */ + public abstract ID getGroupID(); + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMemberIDs() + */ + public ID[] getGroupMemberIDs() { + return groupManager.getMemberIDs(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() + */ + public abstract boolean isGroupManager(); + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() + */ + public abstract boolean isGroupServer(); + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectManager() + */ + public ISharedObjectManager getSharedObjectManager() { + return sharedObjectManager; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObjectContainer#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + return null; + } + + protected ClassLoader getClassLoaderForContainer() { + return this.getClass().getClassLoader(); + } + + /** + * @param sd + * @return + */ + protected ClassLoader getClassLoaderForSharedObject( + SharedObjectDescription sd) { + if (sd != null) { + ClassLoader cl = sd.getClassLoader(); + if (cl != null) + return cl; + else + return getClassLoaderForContainer(); + } else + return getClassLoaderForContainer(); + } + + /** + * @param sd + * @return + */ + public Object[] getArgsFromProperties(SharedObjectDescription sd) { + if (sd == null) + return null; + Map aMap = sd.getProperties(); + if (aMap == null) + return null; + Object obj = aMap.get(DEFAULT_OBJECT_ARG_KEY); + if (obj == null) + return null; + if (obj instanceof Object[]) { + Object[] ret = (Object[]) obj; + aMap.remove(DEFAULT_OBJECT_ARG_KEY); + return ret; + } else + return null; + } + + /** + * @param sd + * @return + */ + public String[] getArgTypesFromProperties(SharedObjectDescription sd) { + if (sd == null) + return null; + Map aMap = sd.getProperties(); + if (aMap == null) + return null; + Object obj = aMap.get(DEFAULT_OBJECT_ARGTYPES_KEY); + if (obj == null) + return null; + if (obj instanceof String[]) { + String[] ret = (String[]) obj; + aMap.remove(DEFAULT_OBJECT_ARGTYPES_KEY); + return ret; + } else + return null; + } + + class MessageReceiver implements ISynchAsynchConnectionEventHandler { + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.internal.comm.ISynchConnectionEventHandler#handleSynchEvent(org.eclipse.ecf.internal.comm.SynchConnectionEvent) + */ + public Object handleSynchEvent(SynchConnectionEvent event) + throws IOException { + return processSynch(event); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#handleSuspectEvent(org.eclipse.ecf.internal.comm.ConnectionEvent) + */ + public boolean handleSuspectEvent(ConnectionEvent event) { + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#handleDisconnectEvent(org.eclipse.ecf.internal.comm.ConnectionEvent) + */ + public void handleDisconnectEvent(DisconnectConnectionEvent event) { + processDisconnect(event); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.internal.comm.IConnectionEventHandler#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class clazz) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.internal.comm.IAsynchConnectionEventHandler#handleAsynchEvent(org.eclipse.ecf.internal.comm.AsynchConnectionEvent) + */ + public void handleAsynchEvent(AsynchConnectionEvent event) + throws IOException { + processAsynch(event); + } + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerConfig.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerConfig.java index dd493c2b7..bfecd6885 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerConfig.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerConfig.java @@ -1,13 +1,22 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.util.HashMap; import java.util.Map; - import org.eclipse.ecf.core.ISharedObjectContainerConfig; import org.eclipse.ecf.core.identity.ID; public class SOContainerConfig implements ISharedObjectContainerConfig { - ID id; Map properties; @@ -15,10 +24,12 @@ public class SOContainerConfig implements ISharedObjectContainerConfig { this.id = id; this.properties = props; } + public SOContainerConfig(ID id) { this.id = id; this.properties = new HashMap(); } + /* * (non-Javadoc) * @@ -45,5 +56,4 @@ public class SOContainerConfig implements ISharedObjectContainerConfig { public ID getID() { return id; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGMM.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGMM.java index e44fc2362..45d7fa1d5 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGMM.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGMM.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.util.HashSet; @@ -5,7 +16,6 @@ import java.util.Iterator; import java.util.Observable; import java.util.Observer; import java.util.TreeMap; - import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.provider.Trace; import org.eclipse.ecf.provider.generic.gmm.GMMImpl; @@ -13,10 +23,8 @@ import org.eclipse.ecf.provider.generic.gmm.Member; import org.eclipse.ecf.provider.generic.gmm.MemberChanged; class SOContainerGMM implements Observer { - - static Trace debug = Trace.create("gmm"); - - SOContainer container; + static Trace debug = Trace.create("gmm"); + SOContainer container; Member localMember; GMMImpl groupManager; // Maximum number of members. Default is -1 (no maximum). @@ -34,40 +42,44 @@ class SOContainerGMM implements Observer { debug("<init>"); } - protected void debug(String msg) { - if (Trace.ON && debug != null) { - debug.msg(msg + ":" + container.getID()); - } - } + protected void debug(String msg) { + if (Trace.ON && debug != null) { + debug.msg(msg + ":" + container.getID()); + } + } + + protected void dumpStack(String msg, Throwable e) { + if (Trace.ON && debug != null) { + debug.dumpStack(e, msg + ":" + container.getID()); + } + } - protected void dumpStack(String msg, Throwable e) { - if (Trace.ON && debug != null) { - debug.dumpStack(e, msg + ":" + container.getID()); - } - } ID[] getSharedObjectIDs() { return getActiveKeys(); } + synchronized boolean addMember(Member m) { - debug("addMember("+m.getID()+")"); + debug("addMember(" + m.getID() + ")"); if (maxMembers > 0 && getSize() > maxMembers) { return false; } else { return groupManager.addMember(m); } } + synchronized int setMaxMembers(int max) { - debug("setMaxMembers("+max+")"); + debug("setMaxMembers(" + max + ")"); int old = maxMembers; maxMembers = max; return old; } + synchronized int getMaxMembers() { return maxMembers; } synchronized boolean removeMember(Member m) { - debug("removeMember("+m.getID()+")"); + debug("removeMember(" + m.getID() + ")"); boolean res = groupManager.removeMember(m); if (res) { removeSharedObjects(m); @@ -76,7 +88,7 @@ class SOContainerGMM implements Observer { } synchronized boolean removeMember(ID id) { - debug("removeMember("+id+")"); + debug("removeMember(" + id + ")"); Member m = getMemberForID(id); if (m == null) return false; @@ -92,11 +104,11 @@ class SOContainerGMM implements Observer { } synchronized void removeAllMembers(Member exception) { - if (exception == null) { - debug("removeAllMembers()"); - } else { - debug("removeAllMembers("+exception.getID()+")"); - } + if (exception == null) { + debug("removeAllMembers()"); + } else { + debug("removeAllMembers(" + exception.getID() + ")"); + } Object m[] = getMembers(); for (int i = 0; i < m.length; i++) { Member mem = (Member) m[i]; @@ -118,7 +130,7 @@ class SOContainerGMM implements Observer { } synchronized Member getMemberForID(ID id) { - debug("getMemberForID("+id+")"); + debug("getMemberForID(" + id + ")"); Member newMem = new Member(id); for (Iterator i = iterator(); i.hasNext();) { Member oldMem = (Member) i.next(); @@ -133,9 +145,9 @@ class SOContainerGMM implements Observer { } synchronized boolean containsMember(Member m) { - if (m != null) { - debug("containsMember("+m.getID()+")"); - } + if (m != null) { + debug("containsMember(" + m.getID() + ")"); + } return groupManager.containsMember(m); } @@ -144,9 +156,9 @@ class SOContainerGMM implements Observer { } // End group membership change methods - synchronized boolean addSharedObject(SOWrapper ro) { - if (ro != null) debug("addSharedObject("+ro.getObjID()+")"); + if (ro != null) + debug("addSharedObject(" + ro.getObjID() + ")"); if (getFromAny(ro.getObjID()) != null) return false; addSharedObjectToActive(ro); @@ -155,7 +167,8 @@ class SOContainerGMM implements Observer { synchronized boolean addLoadingSharedObject( SOContainer.LoadingSharedObject lso) { - if (lso != null) debug("addLoadingSharedObject("+lso.getID()+")"); + if (lso != null) + debug("addLoadingSharedObject(" + lso.getID() + ")"); if (getFromAny(lso.getID()) != null) return false; loading.put(lso.getID(), new SOWrapper(lso, container)); @@ -165,13 +178,14 @@ class SOContainerGMM implements Observer { } synchronized void moveSharedObjectFromLoadingToActive(SOWrapper ro) { - if (ro != null) debug("moveSharedObjectFromLoadingToActive("+ro.getObjID()+")"); + if (ro != null) + debug("moveSharedObjectFromLoadingToActive(" + ro.getObjID() + ")"); if (removeSharedObjectFromLoading(ro.getObjID())) addSharedObjectToActive(ro); } boolean removeSharedObjectFromLoading(ID id) { - debug("removeSharedObjectFromLoading("+id+")"); + debug("removeSharedObjectFromLoading(" + id + ")"); if (loading.remove(id) != null) { return true; } else @@ -183,19 +197,20 @@ class SOContainerGMM implements Observer { } void addSharedObjectToActive(SOWrapper so) { - if (so != null) debug("addSharedObjectToActive("+so.getObjID()+")"); + if (so != null) + debug("addSharedObjectToActive(" + so.getObjID() + ")"); ID[] ids = getActiveKeys(); active.put(so.getObjID(), so); so.activated(ids); } synchronized void notifyOthersActivated(ID id) { - debug("notifyOthersActivated("+id+")"); + debug("notifyOthersActivated(" + id + ")"); notifyOtherChanged(id, active, true); } synchronized void notifyOthersDeactivated(ID id) { - debug("notifyOthersActivated("+id+")"); + debug("notifyOthersActivated(" + id + ")"); notifyOtherChanged(id, active, false); } @@ -209,7 +224,7 @@ class SOContainerGMM implements Observer { } synchronized boolean removeSharedObject(ID id) { - debug("removeSharedObject("+id+")"); + debug("removeSharedObject(" + id + ")"); SOWrapper ro = removeFromMap(id, active); if (ro == null) return false; @@ -259,14 +274,13 @@ class SOContainerGMM implements Observer { } synchronized void clear() { - debug("clear()"); + debug("clear()"); removeSharedObjects(null, true); } void removeSharedObjects(Member m, boolean match) { HashSet set = getRemoveIDs(m.getID(), match); Iterator i = set.iterator(); - while (i.hasNext()) { ID removeID = (ID) i.next(); if (isLoading(removeID)) { @@ -306,7 +320,6 @@ class SOContainerGMM implements Observer { sb.append(";active:").append(active).append("]"); return sb.toString(); } - } class DestroyIterator implements Iterator { diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGroup.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGroup.java index 01eb178be..de6273e02 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGroup.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContainerGroup.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.util.TreeMap; @@ -6,7 +17,6 @@ import java.util.Map; import java.util.Iterator; public class SOContainerGroup { - String name; protected Map map; @@ -14,6 +24,7 @@ public class SOContainerGroup { this.name = name; map = Collections.synchronizedMap(new TreeMap()); } + public String add(String key, SOContainer aSpace) { if (key == null || aSpace == null) return null; @@ -26,19 +37,23 @@ public class SOContainerGroup { return null; return (SOContainer) map.get(key); } + public SOContainer remove(String key) { if (key == null) return null; return (SOContainer) map.remove(key); } + public boolean contains(String key) { if (key == null) return false; return map.containsKey(key); } + public String getName() { return name; } + public Iterator elements() { return map.values().iterator(); } diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java index 8501bd105..4d399daba 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOContext.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + /* * Created on Dec 6, 2004 * @@ -6,7 +17,6 @@ package org.eclipse.ecf.provider.generic; import java.io.IOException; import java.util.Map; - import org.eclipse.ecf.core.IOSGIService; import org.eclipse.ecf.core.ISharedObjectContext; import org.eclipse.ecf.core.ISharedObjectManager; @@ -16,7 +26,6 @@ import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.util.QueueEnqueue; public class SOContext implements ISharedObjectContext { - SOContainer container = null; ID sharedObjectID; ID homeContainerID; @@ -33,14 +42,17 @@ public class SOContext implements ISharedObjectContext { this.properties = props; this.queue = queue; } + protected synchronized void makeInactive() { container = null; properties = null; queue = null; } + protected synchronized boolean isInactive() { return (container == null); } + /* * (non-Javadoc) * @@ -214,5 +226,4 @@ public class SOContext implements ISharedObjectContext { return container.getOSGIServiceInterface(); } } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOManager.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOManager.java index 0e965262c..5a134ace0 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOManager.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOManager.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + /* * Created on Dec 20, 2004 * @@ -12,7 +23,6 @@ import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.Vector; - import org.eclipse.ecf.core.ISharedObject; import org.eclipse.ecf.core.ISharedObjectConnector; import org.eclipse.ecf.core.ISharedObjectContainerTransaction; @@ -31,10 +41,8 @@ import org.eclipse.ecf.provider.Trace; * */ public class SOManager implements ISharedObjectManager { - - static Trace debug = Trace.create("sharedobjectmanager"); - - SOContainer container = null; + static Trace debug = Trace.create("sharedobjectmanager"); + SOContainer container = null; Vector connectors = null; public SOManager(SOContainer cont) { @@ -43,26 +51,30 @@ public class SOManager implements ISharedObjectManager { connectors = new Vector(); } - protected void debug(String msg) { - if (Trace.ON && debug != null) { - debug.msg(msg + ":" + container.getID()); - } - } + protected void debug(String msg) { + if (Trace.ON && debug != null) { + debug.msg(msg + ":" + container.getID()); + } + } + + protected void dumpStack(String msg, Throwable e) { + if (Trace.ON && debug != null) { + debug.dumpStack(e, msg + ":" + container.getID()); + } + } - protected void dumpStack(String msg, Throwable e) { - if (Trace.ON && debug != null) { - debug.dumpStack(e, msg + ":" + container.getID()); - } - } protected void addConnector(ISharedObjectConnector conn) { connectors.add(conn); } + protected boolean removeConnector(ISharedObjectConnector conn) { return connectors.remove(conn); } + protected List getConnectors() { return connectors; } + protected Class[] getArgTypes(String[] argTypes, Object[] args, ClassLoader cl) throws ClassNotFoundException { return AbstractFactory.getClassesForTypes(argTypes, args, cl); @@ -86,6 +98,7 @@ public class SOManager implements ISharedObjectManager { } return verifySharedObject(newObject); } + protected ISharedObject verifySharedObject(Object newSharedObject) { if (newSharedObject instanceof ISharedObject) return (ISharedObject) newSharedObject; @@ -94,6 +107,7 @@ public class SOManager implements ISharedObjectManager { + newSharedObject.toString() + " does not implement " + ISharedObject.class.getName()); } + protected ISharedObject loadSharedObject(SharedObjectDescription sd) throws Exception { // First get classloader @@ -107,13 +121,14 @@ public class SOManager implements ISharedObjectManager { final Class newClass = Class.forName(sd.getClassname(), true, cl); return makeSharedObjectInstance(newClass, argTypes, args); } + /* * (non-Javadoc) * * @see org.eclipse.ecf.core.ISharedObjectManager#getSharedObjectIDs() */ public ID[] getSharedObjectIDs() { - debug("getSharedObjectIDs()"); + debug("getSharedObjectIDs()"); return container.getSharedObjectIDs(); } @@ -126,7 +141,7 @@ public class SOManager implements ISharedObjectManager { public ID createSharedObject(SharedObjectDescription sd, ISharedObjectContainerTransaction trans) throws SharedObjectCreateException { - debug("createSharedObject("+sd+","+trans+")"); + debug("createSharedObject(" + sd + "," + trans + ")"); ISharedObject newObject = null; Throwable t = null; ID result = sd.getID(); @@ -148,7 +163,8 @@ public class SOManager implements ISharedObjectManager { public ID addSharedObject(ID sharedObjectID, ISharedObject sharedObject, Map properties, ISharedObjectContainerTransaction trans) throws SharedObjectAddException { - debug("addSharedObject("+sharedObjectID+","+sharedObject+","+properties+","+trans+")"); + debug("addSharedObject(" + sharedObjectID + "," + sharedObject + "," + + properties + "," + trans + ")"); Throwable t = null; ID result = sharedObjectID; try { @@ -170,7 +186,7 @@ public class SOManager implements ISharedObjectManager { * @see org.eclipse.ecf.core.ISharedObjectManager#getSharedObject(org.eclipse.ecf.core.identity.ID) */ public ISharedObject getSharedObject(ID sharedObjectID) { - debug("getSharedObject("+sharedObjectID+")"); + debug("getSharedObject(" + sharedObjectID + ")"); return container.getSharedObject(sharedObjectID); } @@ -180,7 +196,7 @@ public class SOManager implements ISharedObjectManager { * @see org.eclipse.ecf.core.ISharedObjectManager#removeSharedObject(org.eclipse.ecf.core.identity.ID) */ public ISharedObject removeSharedObject(ID sharedObjectID) { - debug("getSharedObject("+sharedObjectID+")"); + debug("getSharedObject(" + sharedObjectID + ")"); return container.removeSharedObject(sharedObjectID); } @@ -192,7 +208,8 @@ public class SOManager implements ISharedObjectManager { */ public ISharedObjectConnector connectSharedObjects(ID sharedObjectFrom, ID[] sharedObjectsTo) throws SharedObjectConnectException { - debug("connectSharedObjects("+sharedObjectFrom+","+sharedObjectsTo+")"); + debug("connectSharedObjects(" + sharedObjectFrom + "," + + sharedObjectsTo + ")"); if (sharedObjectFrom == null) throw new SharedObjectConnectException("sender cannot be null"); if (sharedObjectsTo == null) @@ -226,7 +243,8 @@ public class SOManager implements ISharedObjectManager { */ public void disconnectSharedObjects(ISharedObjectConnector connector) throws SharedObjectDisconnectException { - if (connector != null) debug("disconnectSharedObjects("+connector.getSender()+")"); + if (connector != null) + debug("disconnectSharedObjects(" + connector.getSender() + ")"); if (connector == null) throw new SharedObjectDisconnectException("connect cannot be null"); if (!removeConnector(connector)) { @@ -235,8 +253,9 @@ public class SOManager implements ISharedObjectManager { } connector.dispose(); } + protected void dispose() { - debug("dispose()"); + debug("dispose()"); for (Enumeration e = connectors.elements(); e.hasMoreElements();) { ISharedObjectConnector conn = (ISharedObjectConnector) e .nextElement(); @@ -244,13 +263,14 @@ public class SOManager implements ISharedObjectManager { } connectors.clear(); } + /* * (non-Javadoc) * * @see org.eclipse.ecf.core.ISharedObjectManager#getSharedObjectConnectors(org.eclipse.ecf.core.identity.ID) */ public List getSharedObjectConnectors(ID sharedObjectFrom) { - debug("getSharedObjectConnectors("+sharedObjectFrom+")"); + debug("getSharedObjectConnectors(" + sharedObjectFrom + ")"); List results = new ArrayList(); for (Enumeration e = connectors.elements(); e.hasMoreElements();) { ISharedObjectConnector conn = (ISharedObjectConnector) e @@ -283,5 +303,4 @@ public class SOManager implements ISharedObjectManager { } return clazzes; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOWrapper.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOWrapper.java index 720d1d952..8f6a90e69 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOWrapper.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/SOWrapper.java @@ -1,9 +1,19 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.Serializable; import java.security.AccessController; import java.security.PrivilegedAction; - import org.eclipse.ecf.core.ISharedObject; import org.eclipse.ecf.core.SharedObjectInitException; import org.eclipse.ecf.core.events.RemoteSharedObjectCreateResponseEvent; @@ -20,7 +30,6 @@ import org.eclipse.ecf.provider.generic.gmm.Member; final class SOWrapper { static Trace debug = Trace.create("sharedobjectwrapper"); - protected ISharedObject sharedObject; private SOConfig sharedObjectConfig; private ID sharedObjectID; @@ -40,6 +49,7 @@ final class SOWrapper { thread = null; queue = new SimpleQueueImpl(); } + SOWrapper(SOConfig aConfig, ISharedObject obj, SOContainer cont) { sharedObjectConfig = aConfig; sharedObjectID = sharedObjectConfig.getSharedObjectID(); @@ -52,9 +62,10 @@ final class SOWrapper { } void init() throws SharedObjectInitException { - debug("init()"); + debug("init()"); sharedObject.init(sharedObjectConfig); } + ID getObjID() { return sharedObjectConfig.getSharedObjectID(); } @@ -64,7 +75,7 @@ final class SOWrapper { } void activated(ID[] ids) { - debug("activated"); + debug("activated"); // First, make space reference accessible to use by RepObject sharedObjectConfig.makeActive(new QueueEnqueueImpl(queue)); thread = (Thread) AccessController.doPrivileged(new PrivilegedAction() { @@ -77,14 +88,15 @@ final class SOWrapper { thread.start(); send(new SharedObjectActivatedEvent(containerID, sharedObjectID, ids)); container.notifySharedObjectActivated(sharedObjectID); - } + void deactivated() { - debug("deactivated()"); + debug("deactivated()"); send(new SharedObjectDeactivatedEvent(containerID, sharedObjectID)); container.notifySharedObjectDeactivated(sharedObjectID); destroyed(); } + private void destroyed() { if (!queue.isStopped()) { sharedObjectConfig.makeInactive(); @@ -95,18 +107,19 @@ final class SOWrapper { // point on. queue.close(); } - } + void otherChanged(ID otherID, boolean activated) { - debug("otherChanged("+otherID+","+activated); + debug("otherChanged(" + otherID + "," + activated); if (activated && thread != null) { send(new SharedObjectActivatedEvent(containerID, otherID, null)); } else { send(new SharedObjectDeactivatedEvent(containerID, otherID)); } } + void memberChanged(Member m, boolean add) { - debug("memberChanged("+m+","+add); + debug("memberChanged(" + m + "," + add); if (thread != null) { if (add) { send(new SharedObjectContainerJoinedEvent(containerID, m @@ -117,22 +130,21 @@ final class SOWrapper { } } } + Thread getThread() { // Get new thread instance from space. return container.getNewSharedObjectThread(sharedObjectID, new Runnable() { public void run() { - debug("runner("+sharedObjectID+")"); + debug("runner(" + sharedObjectID + ")"); Event evt = null; for (;;) { if (Thread.currentThread().isInterrupted()) break; - evt = (Event) queue.dequeue(); if (Thread.currentThread().isInterrupted() || evt == null) break; - try { if (evt instanceof ProcEvent) { SOWrapper.this.svc(((ProcEvent) evt) @@ -147,43 +159,56 @@ final class SOWrapper { // If the thread was interrupted, then show appropriate // spam if (Thread.currentThread().isInterrupted()) { - debug("runner("+sharedObjectID+") terminating interrupted"); + debug("runner(" + sharedObjectID + + ") terminating interrupted"); } else { - debug("runner("+sharedObjectID+") terminating normally"); + debug("runner(" + sharedObjectID + + ") terminating normally"); } } }); } + private void send(Event evt) { queue.enqueue(new ProcEvent(evt)); } protected static class ProcEvent implements Event { Event theEvent = null; + ProcEvent(Event event) { theEvent = event; } + Event getEvent() { return theEvent; } } + protected static class DisposeEvent implements Event { DisposeEvent() { } } + void svc(Event evt) { sharedObject.handleEvent(evt); } + void doDestroy() { sharedObject.dispose(containerID); } void deliverSharedObjectMessage(ID fromID, Serializable data) { - send(new RemoteSharedObjectEvent(getObjID(),fromID,data)); + send(new RemoteSharedObjectEvent(getObjID(), fromID, data)); } - void deliverCreateResponse(ID fromID, ContainerMessage.CreateResponseMessage resp) { - send(new RemoteSharedObjectCreateResponseEvent(resp.getSharedObjectID(),fromID,resp.getSequence(),resp.getException())); + + void deliverCreateResponse(ID fromID, + ContainerMessage.CreateResponseMessage resp) { + send(new RemoteSharedObjectCreateResponseEvent( + resp.getSharedObjectID(), fromID, resp.getSequence(), resp + .getException())); } + void deliverEventFromSharedObject(ID fromID, Event evt) { /* * if (myContainerID != null) { forwardToContainer(Msg.makeMsg(null, @@ -193,6 +218,7 @@ final class SOWrapper { * null) { send(Msg.makeMsg(null, REPOBJ_MSG, fromID, msg)); } */ } + void deliverForwardedMsg(ID fromID, Event evt) { /* * if (myContainerID != null) { forwardToContainer(Msg.makeMsg(null, @@ -201,6 +227,7 @@ final class SOWrapper { * null) { send(Msg.makeMsg(null, REPOBJ_FOR, fromID, msg)); } */ } + void deliverRemoteMessageFailed(ID toID, Serializable object, Throwable e) { /* * if (sharedObjectConfig.getMsgMask().get(MsgMask.REPOBJMSG) && thread != @@ -220,30 +247,36 @@ final class SOWrapper { sb.append("SharedObjectWrapper[").append(getObjID()).append("]"); return sb.toString(); } + protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } + void handleRuntimeException(Throwable except) { - dumpStack("runner:unhandledexception("+sharedObjectID.getName()+")",except); + dumpStack( + "runner:unhandledexception(" + sharedObjectID.getName() + ")", + except); } + /** * @return */ protected ISharedObject getSharedObject() { return sharedObject; } + /** * @return */ public SimpleQueueImpl getQueue() { return queue; } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java index d8b7aa687..26345a1c9 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/ServerSOContainer.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.IOException; @@ -5,7 +16,6 @@ import java.io.InvalidObjectException; import java.io.Serializable; import java.net.ConnectException; import java.net.Socket; - import org.eclipse.ecf.core.ISharedObjectContainerConfig; import org.eclipse.ecf.core.SharedObjectContainerJoinException; import org.eclipse.ecf.core.comm.IAsynchConnection; @@ -14,19 +24,22 @@ import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.provider.generic.gmm.Member; public class ServerSOContainer extends SOContainer { - public ServerSOContainer(ISharedObjectContainerConfig config) { super(config); } + public boolean isGroupServer() { return true; } + public boolean isGroupManager() { return true; } + public ID getGroupID() { return getID(); } + protected void queueContainerMessage(ContainerMessage message) throws IOException { if (message.getToContainerID() == null) { @@ -39,11 +52,13 @@ public class ServerSOContainer extends SOContainer { getBytesForObject(message)); } } + protected void forwardToRemote(ID from, ID to, ContainerMessage data) throws IOException { queueContainerMessage(new ContainerMessage(from, to, getNextSequenceNumber(), data.getData())); } + protected void forwardExcluding(ID from, ID excluding, ContainerMessage data) throws IOException { if (excluding == null) { @@ -64,16 +79,19 @@ public class ServerSOContainer extends SOContainer { getNextSequenceNumber(), data .getData()))); } catch (IOException e) { - logException("Exception in forwardExcluding from "+from+" with oldID "+oldID,e); + logException("Exception in forwardExcluding from " + + from + " with oldID " + oldID, e); } } } } } } - protected void handleViewChangeMessage(ContainerMessage mess) throws IOException { + + protected void handleViewChangeMessage(ContainerMessage mess) + throws IOException { // Server should never receive change messages - } + } public void joinGroup(ID group, Object data) throws SharedObjectContainerJoinException { @@ -81,6 +99,7 @@ public class ServerSOContainer extends SOContainer { "Server cannot join group " + group.getName()); throw e; } + public void leaveGroup() { ejectAllGroupMembers(); } @@ -94,20 +113,17 @@ public class ServerSOContainer extends SOContainer { ID remoteID = mess.getFromContainerID(); if (remoteID == null) throw new InvalidObjectException("remote id is null"); - ContainerMessage.JoinGroupMessage jgm = (ContainerMessage.JoinGroupMessage) mess .getData(); if (jgm == null) throw new IOException("join group message is null"); ID memberIDs[] = null; - synchronized (getGroupMembershipLock()) { if (isClosing) { Exception e = new InvalidObjectException( "container is closing"); throw e; } - if (addNewRemoteMember(remoteID, conn)) { // Notify existing remotes about new member try { @@ -130,7 +146,8 @@ public class ServerSOContainer extends SOContainer { return ContainerMessage.makeViewChangeMessage(getID(), remoteID, getNextSequenceNumber(), memberIDs, true, null); } catch (Exception e) { - logException("Exception in acceptNewClient("+socket+","+target+","+data+","+conn,e); + logException("Exception in acceptNewClient(" + socket + "," + + target + "," + data + "," + conn, e); // And then return null...which means refusal return null; } @@ -166,9 +183,7 @@ public class ServerSOContainer extends SOContainer { if (conn == null) return; try { - conn.sendAsynch( - - memberID, getBytesForObject(ContainerMessage + conn.sendAsynch(memberID, getBytesForObject(ContainerMessage .makeLeaveGroupMessage(getID(), memberID, getNextSequenceNumber(), null))); } catch (Exception e) { @@ -196,6 +211,7 @@ public class ServerSOContainer extends SOContainer { } return null; } + protected IAsynchConnection getConnectionForID(ID memberID) { Member mem = groupManager.getMemberForID(memberID); if (mem == null) @@ -224,5 +240,4 @@ public class ServerSOContainer extends SOContainer { ejectAllGroupMembers(); super.dispose(timeout); } - }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java index 607a157ac..4901b99e9 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPClientSOContainer.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import org.eclipse.ecf.core.ISharedObjectContainerConfig; @@ -9,9 +20,9 @@ import org.eclipse.ecf.core.identity.IDFactory; public class TCPClientSOContainer extends ClientSOContainer { int keepAlive = 0; + public static final String DEFAULT_COMM_NAME = org.eclipse.ecf.provider.comm.tcp.Client.class + .getName(); - public static final String DEFAULT_COMM_NAME = org.eclipse.ecf.provider.comm.tcp.Client.class.getName(); - public TCPClientSOContainer(ISharedObjectContainerConfig config) { super(config); } @@ -23,14 +34,14 @@ public class TCPClientSOContainer extends ClientSOContainer { protected ISynchAsynchConnection getClientConnection(ID remoteSpace, Object data) throws ConnectionInstantiationException { - - debug("getClientConnection:"+remoteSpace+":"+data); + debug("getClientConnection:" + remoteSpace + ":" + data); Object[] args = { new Integer(keepAlive) }; ISynchAsynchConnection conn = null; - conn = ConnectionFactory.makeSynchAsynchConnection(receiver, DEFAULT_COMM_NAME, args); + conn = ConnectionFactory.makeSynchAsynchConnection(receiver, + DEFAULT_COMM_NAME, args); return conn; } - + public static final void main(String[] args) throws Exception { ISharedObjectContainerConfig config = new SOContainerConfig(IDFactory .makeGUID()); diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainer.java index 586a9d1b9..539a9019a 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainer.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainer.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.IOException; @@ -5,7 +16,6 @@ import java.io.Serializable; import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; - import org.eclipse.ecf.core.ISharedObjectContainerConfig; import org.eclipse.ecf.core.comm.ConnectionRequestHandler; import org.eclipse.ecf.core.comm.ISynchAsynchConnection; @@ -14,7 +24,6 @@ import org.eclipse.ecf.core.identity.IDFactory; public class TCPServerSOContainer extends ServerSOContainer implements ConnectionRequestHandler { - public static final String DEFAULT_PROTOCOL = "ecftcp"; public static final int DEFAULT_PORT = 3282; public static final int DEFAULT_KEEPALIVE = 30000; @@ -26,13 +35,16 @@ public class TCPServerSOContainer extends ServerSOContainer implements protected int getKeepAlive() { return keepAlive; } + public static String getServerURL(String host, String name) { return DEFAULT_PROTOCOL + "://" + host + ":" + DEFAULT_PORT + "/" + name; } + public static String getDefaultServerURL() { return getServerURL("localhost", DEFAULT_NAME); } + public TCPServerSOContainer(ISharedObjectContainerConfig config, TCPServerSOContainerGroup grp, int keepAlive) throws IOException, URISyntaxException { @@ -55,12 +67,14 @@ public class TCPServerSOContainer extends ServerSOContainer implements super(config); initialize(listener, path, keepAlive); } + protected void initialize(TCPServerSOContainerGroup listener, String path, int keepAlive) { this.keepAlive = keepAlive; this.group = listener; this.group.add(path, this); } + public void dispose(long timeout) { URI aURI = null; try { @@ -73,10 +87,12 @@ public class TCPServerSOContainer extends ServerSOContainer implements group = null; super.dispose(timeout); } + public TCPServerSOContainer(ISharedObjectContainerConfig config) throws IOException, URISyntaxException { this(config, null, DEFAULT_PORT); } + public Serializable checkConnect(Socket socket, String target, Serializable data, ISynchAsynchConnection conn) { return acceptNewClient(socket, target, data, conn); @@ -91,7 +107,6 @@ public class TCPServerSOContainer extends ServerSOContainer implements ID server = IDFactory.makeStringID(getDefaultServerURL()); TCPServerSOContainer cont = new TCPServerSOContainer( new SOContainerConfig(server)); - Thread.sleep(3000000); } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainerGroup.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainerGroup.java index 7387c21f0..e04e61bfe 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainerGroup.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/TCPServerSOContainerGroup.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic; import java.io.BufferedOutputStream; @@ -8,7 +19,6 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.net.Socket; import java.net.URI; - import org.eclipse.ecf.provider.Trace; import org.eclipse.ecf.core.comm.ConnectionRequestHandler; import org.eclipse.ecf.provider.comm.tcp.Client; @@ -21,14 +31,10 @@ import org.eclipse.ecf.provider.comm.tcp.Server; public class TCPServerSOContainerGroup extends SOContainerGroup implements ISocketAcceptHandler { - public static final String INVALID_CONNECT = "Invalid connect request. "; - - public static final Trace debug = Trace - .create("connection"); + public static final Trace debug = Trace.create("connection"); public static final String DEFAULT_GROUP_NAME = TCPServerSOContainerGroup.class .getName(); - protected int port; Server listener; boolean isOnTheAir = false; @@ -51,15 +57,17 @@ public class TCPServerSOContainerGroup extends SOContainerGroup implements protected void debug(String msg) { if (Trace.ON && debug != null) { debug.msg(msg); - } + } } + protected void dumpStack(String msg, Throwable e) { if (Trace.ON && debug != null) { - debug.dumpStack(e,msg); - } + debug.dumpStack(e, msg); + } } + public synchronized void putOnTheAir() throws IOException { - debug("group at port "+port+" on the air"); + debug("group at port " + port + " on the air"); listener = new Server(threadGroup, port, this); port = listener.getLocalPort(); isOnTheAir = true; @@ -73,10 +81,8 @@ public class TCPServerSOContainerGroup extends SOContainerGroup implements ObjectOutputStream oStream = new ExObjectOutputStream( new BufferedOutputStream(aSocket.getOutputStream())); oStream.flush(); - ObjectInputStream iStream = new ExObjectInputStream(aSocket .getInputStream()); - ConnectRequestMessage req = (ConnectRequestMessage) iStream .readObject(); if (Trace.ON && debug != null) { @@ -85,7 +91,6 @@ public class TCPServerSOContainerGroup extends SOContainerGroup implements if (req == null) throw new InvalidObjectException(INVALID_CONNECT + "ConnectRequestMessage is null"); - URI uri = req.getTarget(); if (uri == null) throw new InvalidObjectException(INVALID_CONNECT @@ -94,17 +99,14 @@ public class TCPServerSOContainerGroup extends SOContainerGroup implements if (path == null) throw new InvalidObjectException(INVALID_CONNECT + "Target path is null"); - TCPServerSOContainer srs = (TCPServerSOContainer) get(path); - debug("found container:"+srs.getID().getName()+" for target "+uri); + debug("found container:" + srs.getID().getName() + " for target " + uri); if (srs == null) throw new InvalidObjectException("Container for target " + path + " not found!"); - // Create our local messaging interface Client newClient = new Client(aSocket, iStream, oStream, srs .getReceiver(), srs.keepAlive); - // No other threads can access messaging interface until space has // accepted/rejected // connect request diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/events/SharedObjectCallEvent.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/events/SharedObjectCallEvent.java index 816828aa4..e3b64fc73 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/events/SharedObjectCallEvent.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/events/SharedObjectCallEvent.java @@ -1,3 +1,14 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic.events; import org.eclipse.ecf.core.events.ISharedObjectCallEvent; @@ -6,11 +17,10 @@ import org.eclipse.ecf.core.util.AsynchResult; import org.eclipse.ecf.core.util.Event; public class SharedObjectCallEvent implements ISharedObjectCallEvent { - ID sender; Event event; AsynchResult result; - + public SharedObjectCallEvent(ID sender, Event evt, AsynchResult res) { super(); this.sender = sender; @@ -18,25 +28,30 @@ public class SharedObjectCallEvent implements ISharedObjectCallEvent { this.result = res; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ecf.core.events.ISharedObjectCallEvent#getAsynchResult() */ public AsynchResult getAsynchResult() { return result; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ecf.core.events.ISharedObjectEvent#getSenderSharedObjectID() */ public ID getSenderSharedObjectID() { return sender; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.ecf.core.events.ISharedObjectEvent#getEvent() */ public Event getEvent() { return event; } - -} +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/GMMImpl.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/GMMImpl.java index 48fd07a23..bdd946e2c 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/GMMImpl.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/GMMImpl.java @@ -1,80 +1,89 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic.gmm; import java.util.Observable; import java.util.TreeSet; import java.util.Iterator; - import org.eclipse.ecf.core.identity.ID; public class GMMImpl extends Observable { - - TreeSet mySet; + TreeSet mySet; - public GMMImpl() { - mySet = new TreeSet(); - } + public GMMImpl() { + mySet = new TreeSet(); + } - public boolean addMember(Member m) { - boolean res = mySet.add(m); - if (res) { - setChanged(); - notifyObservers(new MemberChanged(m, true)); - } - return res; - } + public boolean addMember(Member m) { + boolean res = mySet.add(m); + if (res) { + setChanged(); + notifyObservers(new MemberChanged(m, true)); + } + return res; + } - public boolean removeMember(Member m) { - boolean res = mySet.remove(m); - if (res) { - setChanged(); - notifyObservers(new MemberChanged(m, false)); - } - return res; - } + public boolean removeMember(Member m) { + boolean res = mySet.remove(m); + if (res) { + setChanged(); + notifyObservers(new MemberChanged(m, false)); + } + return res; + } - public void removeAllMembers() { - Object members[] = getMembers(); - for (int i = 0; i < members.length; i++) { - removeMember((Member) members[i]); - } - } + public void removeAllMembers() { + Object members[] = getMembers(); + for (int i = 0; i < members.length; i++) { + removeMember((Member) members[i]); + } + } - public Object[] getMembers() { - return mySet.toArray(); - } + public Object[] getMembers() { + return mySet.toArray(); + } - public ID[] getMemberIDs(ID exclude) { - TreeSet newSet = null; - if (exclude != null) { - newSet = (TreeSet) mySet.clone(); - newSet.remove(new Member(exclude)); - } else { - newSet = mySet; - } - ID ids[] = new ID[newSet.size()]; - Iterator iter = newSet.iterator(); - int j = 0; - while (iter.hasNext()) { - ids[j++] = (ID) ((Member) iter.next()).getID(); - } - return ids; - } + public ID[] getMemberIDs(ID exclude) { + TreeSet newSet = null; + if (exclude != null) { + newSet = (TreeSet) mySet.clone(); + newSet.remove(new Member(exclude)); + } else { + newSet = mySet; + } + ID ids[] = new ID[newSet.size()]; + Iterator iter = newSet.iterator(); + int j = 0; + while (iter.hasNext()) { + ids[j++] = (ID) ((Member) iter.next()).getID(); + } + return ids; + } - public int getSize() { - return mySet.size(); - } + public int getSize() { + return mySet.size(); + } - public boolean containsMember(Member m) { - return mySet.contains(m); - } + public boolean containsMember(Member m) { + return mySet.contains(m); + } - public Iterator iterator() { - return mySet.iterator(); - } + public Iterator iterator() { + return mySet.iterator(); + } - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("GMM").append(mySet); - return sb.toString(); - } + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("GMM").append(mySet); + return sb.toString(); + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/Member.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/Member.java index 35dcd7656..6f416606e 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/Member.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/Member.java @@ -1,53 +1,61 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic.gmm; import org.eclipse.ecf.core.identity.ID; public class Member implements Comparable { - - ID member; - Object data; - - public Member(ID member) { - this(member, null); - } - - public Member(ID member, Object data) { - this.member = member; - this.data = data; - } - - public boolean equals(Object o) { - if (o != null && o instanceof Member) { - return member.equals(((Member) o).member); - } else - return false; - } - - public int hashCode() { - return member.hashCode(); - } - - public int compareTo(Object o) { - if (o != null && o instanceof Member) { - return member.compareTo(((Member) o).member); - } else - return 0; - } - - public ID getID() { - return member; - } - - public Object getData() { - return data; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("Member[").append(member).append(";").append( - data).append( - "]"); - return sb.toString(); - } - + ID member; + Object data; + + public Member(ID member) { + this(member, null); + } + + public Member(ID member, Object data) { + this.member = member; + this.data = data; + } + + public boolean equals(Object o) { + if (o != null && o instanceof Member) { + return member.equals(((Member) o).member); + } else + return false; + } + + public int hashCode() { + return member.hashCode(); + } + + public int compareTo(Object o) { + if (o != null && o instanceof Member) { + return member.compareTo(((Member) o).member); + } else + return 0; + } + + public ID getID() { + return member; + } + + public Object getData() { + return data; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("Member[").append(member).append(";").append(data) + .append("]"); + return sb.toString(); + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/MemberChanged.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/MemberChanged.java index 3db3ed410..4e1f7df2b 100644 --- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/MemberChanged.java +++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/generic/gmm/MemberChanged.java @@ -1,19 +1,30 @@ +/**************************************************************************** +* Copyright (c) 2004 Composent, Inc. and others. +* 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: +* Composent, Inc. - initial API and implementation +*****************************************************************************/ + package org.eclipse.ecf.provider.generic.gmm; public class MemberChanged { - Member member; - boolean added; + Member member; + boolean added; - public MemberChanged(Member member, boolean added) { - this.member = member; - this.added = added; - } + public MemberChanged(Member member, boolean added) { + this.member = member; + this.added = added; + } - public Member getMember() { - return member; - } + public Member getMember() { + return member; + } - public boolean getAdded() { - return added; - } + public boolean getAdded() { + return added; + } }
\ No newline at end of file |
