diff options
| author | slewis | 2005-01-07 04:19:31 +0000 |
|---|---|---|
| committer | slewis | 2005-01-07 04:19:31 +0000 |
| commit | 8a59fe2038025e20df335b747d35594cb2d44bf5 (patch) | |
| tree | 609cf662bd7f7e28b21c6cd07ccd631d012eddfc | |
| parent | 81408f00d216c6703f7dfd39dc793c1dc1eb8bc2 (diff) | |
| download | org.eclipse.ecf-8a59fe2038025e20df335b747d35594cb2d44bf5.tar.gz org.eclipse.ecf-8a59fe2038025e20df335b747d35594cb2d44bf5.tar.xz org.eclipse.ecf-8a59fe2038025e20df335b747d35594cb2d44bf5.zip | |
Added defaultargument to containerFactory and connectionFactory schema. This will allow extensions to define default values for the respective factories. Also many small improvements, fixed unit test code
35 files changed, 458 insertions, 4067 deletions
diff --git a/framework/bundles/org.eclipse.ecf.provider/.options b/framework/bundles/org.eclipse.ecf.provider/.options index 364821b86..3597b04c3 100644 --- a/framework/bundles/org.eclipse.ecf.provider/.options +++ b/framework/bundles/org.eclipse.ecf.provider/.options @@ -5,4 +5,5 @@ org.eclipse.ecf.provider/debug/connection = true org.eclipse.ecf.provider/debug/container = true org.eclipse.ecf.provider/debug/sharedobjectwrapper = true org.eclipse.ecf.provider/debug/sharedobjectmanager = true -org.eclipse.ecf.provider/debug/gmm = true
\ No newline at end of file +org.eclipse.ecf.provider/debug/gmm = true +org.eclipse.ecf.provider/debug/containerfactory = true
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF index cc6122bc7..bc5bbd5cb 100644 --- a/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Bundle-SymbolicName: org.eclipse.ecf.provider -Bundle-Version: 0.1.0 +Bundle-Version: 0.2.0 Bundle-Name: ECF Provider Plugin Bundle-Vendor: Eclipse.org Bundle-Activator: org.eclipse.ecf.provider.ProviderPlugin diff --git a/framework/bundles/org.eclipse.ecf.provider/plugin.xml b/framework/bundles/org.eclipse.ecf.provider/plugin.xml index 693493d88..d2128a315 100644 --- a/framework/bundles/org.eclipse.ecf.provider/plugin.xml +++ b/framework/bundles/org.eclipse.ecf.provider/plugin.xml @@ -5,14 +5,43 @@ point="org.eclipse.ecf.containerFactory"> <containerFactory class="org.eclipse.ecf.provider.generic.ContainerInstantiator" - description="Generic Container Instantiator" - name="org.eclipse.ecf.provider.generic.ContainerInstantiator"/> + description="Generic Client Container Instantiator" + name="org.eclipse.ecf.provider.generic.Client"> + <defaultargument + type="org.eclipse.ecf.core.identity.ID" + name="id"/> + <defaultargument + value="10000" + type="java.lang.Integer" + name="keepAlive"/> + </containerFactory> </extension> <extension point="org.eclipse.ecf.connectionFactory"> <connectionFactory class="org.eclipse.ecf.provider.comm.tcp.Client$Creator" description="TCP Client Connection Factory" - name="org.eclipse.ecf.provider.comm.tcp.Client"/> + name="org.eclipse.ecf.provider.comm.tcp.Client"> + <defaultargument + value="10000" + type="java.lang.Integer" + name="keepAlive"/> + </connectionFactory> + </extension> + <extension + point="org.eclipse.ecf.containerFactory"> + <containerFactory + class="org.eclipse.ecf.provider.generic.ContainerInstantiator" + description="Generic Server Container Instantiator" + name="org.eclipse.ecf.provider.generic.Server"> + <defaultargument + value="ecftcp://localhost:3282/server" + type="org.eclipse.ecf.core.identity.ID" + name="id"/> + <defaultargument + value="10000" + type="java.lang.Integer" + name="keepAlive"/> + </containerFactory> </extension> </plugin> 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 484c04fc0..7e958fcc1 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 @@ -27,6 +27,7 @@ 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.ConnectionDescription; import org.eclipse.ecf.core.comm.ConnectionEvent; import org.eclipse.ecf.core.comm.ConnectionInstantiationException; import org.eclipse.ecf.core.comm.DisconnectConnectionEvent; @@ -42,16 +43,27 @@ import org.eclipse.ecf.provider.Trace; public final class Client implements ISynchAsynchConnection { public static class Creator implements ISynchAsynchConnectionInstantiator { - public ISynchAsynchConnection makeInstance( + public ISynchAsynchConnection makeInstance(ConnectionDescription description, ISynchAsynchConnectionEventHandler handler, Class[] clazzes, Object[] args) throws ConnectionInstantiationException { try { - Integer ka = new Integer(0); + String [] argVals = description.getArgDefaults(); + Integer ka = null; + if (argVals != null && argVals.length > 0) { + String val = argVals[0]; + if (val != null) { + ka = new Integer(val); + } + } if (args != null && args.length > 0) { - ka = (Integer) args[0]; + if (args[0] instanceof Integer) { + ka = (Integer) args[0]; + } else if (args[0] instanceof String) { + ka = new Integer((String) args[0]); + } } return new Client(handler, ka); - } catch (RuntimeException e) { + } catch (Exception e) { throw new ConnectionInstantiationException( "Exception in creating connection " + Client.class.getName(), e); 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 1a8307a2f..e08fa6508 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,55 +1,106 @@ -/**************************************************************************** -* 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 -*****************************************************************************/ - +/******************************************************************************* + * 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; +import org.eclipse.ecf.core.SharedObjectContainerDescription; import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.identity.IDFactory; +import org.eclipse.ecf.core.identity.IDInstantiationException; import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator; +import org.eclipse.ecf.provider.Trace; public class ContainerInstantiator implements ISharedObjectContainerInstantiator { + public static final String TCPCLIENT_NAME = "org.eclipse.ecf.provider.generic.Client"; + public static final String TCPSERVER_NAME = "org.eclipse.ecf.provider.generic.Server"; + + public static final Trace debug = Trace.create("containerfactory"); public ContainerInstantiator() { super(); } + protected void debug(String msg) { + if (Trace.ON && debug != null) { + debug.msg(msg); + } + } + protected void dumpStack(String msg, Throwable t) { + if (Trace.ON && debug != null) { + debug.dumpStack(t,msg); + } + } + protected ID getIDFromArg(Class type, Object arg) + throws IDInstantiationException { + if (arg instanceof ID) return (ID) arg; + if (arg instanceof String) { + String val = (String) arg; + if (val == null || val.equals("")) { + return IDFactory.makeGUID(); + } else return IDFactory.makeStringID((String) arg); + } else if (arg instanceof Integer) { + return IDFactory.makeGUID(((Integer) arg).intValue()); + } else + return IDFactory.makeGUID(); + } + + protected Integer getIntegerFromArg(Class type, Object arg) + throws NumberFormatException { + if (arg instanceof Integer) + return (Integer) arg; + else if (arg != null) { + return new Integer((String) arg); + } else return new Integer(-1); + } - public ISharedObjectContainer makeInstance(Class[] argTypes, Object[] args) - throws SharedObjectContainerInstantiationException { + public ISharedObjectContainer makeInstance( + SharedObjectContainerDescription description, Class[] argTypes, + Object[] args) throws SharedObjectContainerInstantiationException { + boolean isClient = true; + if (description.getName().equals(TCPSERVER_NAME)) { + debug("creating server"); + isClient = false; + } else { + debug("creating client"); + } try { - Boolean isClient = new Boolean(true); - ID id = null; - Integer keepAlive = new Integer(TCPServerSOContainer.DEFAULT_KEEPALIVE); + String [] argDefaults = description.getArgDefaults(); + ID newID = (argDefaults==null||argDefaults.length==0)?null:getIDFromArg(String.class, + description.getArgDefaults()[0]); + Integer ka = (argDefaults==null||argDefaults.length < 2)?null:getIntegerFromArg(String.class, description + .getArgDefaults()[1]); if (args != null) { - if (args.length == 3) { - isClient = (Boolean) args[0]; - id = (ID) args[1]; - keepAlive = (Integer) args[2]; - } else if (args.length == 2) { - id = (ID) args[0]; - keepAlive = (Integer) args[1]; - } else if (args.length == 1) { - id = (ID) args[0]; + if (args.length > 0) { + newID = getIDFromArg(argTypes[0], args[0]); + if (args.length > 1) { + ka = getIntegerFromArg(argTypes[1],args[1]); + } } - } else { - id = IDFactory.makeGUID(); } - ISharedObjectContainer result = null; - if (isClient.booleanValue()) { - return new TCPClientSOContainer(new SOContainerConfig(id),keepAlive.intValue()); + debug("id="+newID+";keepAlive="+ka); + // new ID must not be null + if (newID == null) + throw new SharedObjectContainerInstantiationException( + "id must be provided"); + if (isClient) { + return new TCPClientSOContainer(new SOContainerConfig(newID), + ka.intValue()); } else { - return new TCPServerSOContainer(new SOContainerConfig(id),keepAlive.intValue()); + return new TCPServerSOContainer(new SOContainerConfig(newID), + ka.intValue()); } + } catch (ClassCastException e) { + dumpStack("ClassCastException",e); + throw new SharedObjectContainerInstantiationException( + "Parameter type problem creating container", e); } catch (Exception e) { + dumpStack("Exception",e); throw new SharedObjectContainerInstantiationException( "Exception creating generic container", e); } diff --git a/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF index 4217fefa1..f04260209 100644 --- a/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF +++ b/framework/bundles/org.eclipse.ecf/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-Name: ECF - Eclipse Communications Framework Core Bundle-SymbolicName: org.eclipse.ecf -Bundle-Version: 0.2.0 +Bundle-Version: 0.3.0 Bundle-ClassPath: ecf.jar Bundle-Activator: org.eclipse.ecf.internal.core.ECFPlugin Bundle-Vendor: Eclipse.org diff --git a/framework/bundles/org.eclipse.ecf/javadoc.xml b/framework/bundles/org.eclipse.ecf/javadoc.xml index c24eb3e7a..338b97f7e 100644 --- a/framework/bundles/org.eclipse.ecf/javadoc.xml +++ b/framework/bundles/org.eclipse.ecf/javadoc.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <project default="javadoc"> <target name="javadoc"> - <javadoc destdir="../ecf website/org.eclipse.ecf.docs/api" access="protected" use="true" notree="false" nonavbar="false" noindex="false" splitindex="true" author="false" version="true" nodeprecatedlist="false" nodeprecated="false" packagenames="org.eclipse.ecf.core.identity.provider,org.eclipse.ecf.core.comm.provider,org.eclipse.ecf.core,org.eclipse.ecf.core.comm,org.eclipse.ecf.provider.app,org.eclipse.ecf.provider.generic.gmm,org.eclipse.ecf.core.events,org.eclipse.ecf.provider,org.eclipse.ecf.core.util,org.eclipse.ecf.core.identity,org.eclipse.ecf.core.provider,org.eclipse.ecf.provider.generic,org.eclipse.ecf.provider.comm.tcp,org.eclipse.ecf.provider.generic.events" sourcepath="src;../org.eclipse.ecf.provider/src" classpath="../org.eclipse.ecf.provider/bin;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\osgi.jar;C:\301\eclipse\plugins\org.eclipse.core.runtime_3.0.1\runtime.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\defaultAdaptor.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\core.jar;bin;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\eclipseAdaptor.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\resolver.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\console.jar" doctitle="Eclipse Communication Framework (ECF) 0.2.0"> + <javadoc destdir="../ecf website/org.eclipse.ecf.docs/api" access="protected" use="true" notree="false" nonavbar="false" noindex="false" splitindex="true" author="false" version="true" nodeprecatedlist="false" nodeprecated="false" packagenames="org.eclipse.ecf.core.identity.provider,org.eclipse.ecf.core,org.eclipse.ecf.core.comm.provider,org.eclipse.ecf.core.comm,org.eclipse.ecf.provider.app,org.eclipse.ecf.provider.generic.gmm,org.eclipse.ecf.core.events,org.eclipse.ecf.provider,org.eclipse.ecf.core.util,org.eclipse.ecf.core.identity,org.eclipse.ecf.core.provider,org.eclipse.ecf.provider.generic,org.eclipse.ecf.provider.comm.tcp,org.eclipse.ecf.provider.generic.events" sourcepath="src;../org.eclipse.ecf.provider/src" classpath="../org.eclipse.ecf.provider/bin;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\osgi.jar;C:\301\eclipse\plugins\org.eclipse.core.runtime_3.0.1\runtime.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\defaultAdaptor.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\core.jar;bin;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\eclipseAdaptor.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\resolver.jar;C:\301\eclipse\plugins\org.eclipse.osgi_3.0.1\console.jar" doctitle="Eclipse Communication Framework (ECF) 0.3.0"> <link href="http://java.sun.com/j2se/1.4.2/docs/api"/> </javadoc> </target> diff --git a/framework/bundles/org.eclipse.ecf/plugin.xml b/framework/bundles/org.eclipse.ecf/plugin.xml index fd99a91d1..2352100cd 100644 --- a/framework/bundles/org.eclipse.ecf/plugin.xml +++ b/framework/bundles/org.eclipse.ecf/plugin.xml @@ -22,12 +22,4 @@ <extension-point id="namespace" name="ECF Namespace" schema="schema/namespace.exsd"/> <extension-point id="connectionFactory" name="connectionFactory" schema="schema/connectionFactory.exsd"/> - <extension - point="org.eclipse.ecf.containerFactory"> - <containerFactory - class="org.eclipse.ecf.internal.impl.standalone.StandaloneContainerInstantiator" - description="Local-only container implementation - for testing" - name="org.eclipse.ecf.internal.impl.standalone.StandaloneContainer"/> - </extension> - </plugin> diff --git a/framework/bundles/org.eclipse.ecf/schema/connectionFactory.exsd b/framework/bundles/org.eclipse.ecf/schema/connectionFactory.exsd index ecede9243..2e8843274 100644 --- a/framework/bundles/org.eclipse.ecf/schema/connectionFactory.exsd +++ b/framework/bundles/org.eclipse.ecf/schema/connectionFactory.exsd @@ -6,7 +6,7 @@ <meta.schema plugin="org.eclipse.ecf" id="comm" name="ECF Connection Factory"/>
</appInfo>
<documentation>
- This extension allows plugins to register themselves as 'providers' of ECF connection factories. Once registered via this extension point, plugins can provide implementations of custom ISynchAsynchConnection instances via the ECF connection factory (<b>org.eclipse.ecf.core.comm.ConnectionFactory</b>).
+ This extension allows plugins to register themselves as 'providers' of ECF connection factories. Once registered via this extension point, plugins can provide implementations of custom ISynchAsynchConnection instances via the ECF connection factory (<b>org.eclipse.ecf.core.comm.ConnectionFactory</b>). <p>Plugins using this extension point can define new implementation classes of the core ISynchAsynchConnection interface. When client requests are made to ECF to create <b>ISynchAsynchConnection</b> instances via the ConnectionFactory.makeSynchAsynchConnection() methods, requests to create instances of the appropriate type will be re-directed to the given extension.
</documentation>
</annotation>
@@ -41,25 +41,64 @@ </element>
<element name="connectionFactory">
+ <annotation>
+ <documentation>
+ Connection factory definition
+ </documentation>
+ </annotation>
<complexType>
+ <sequence>
+ <element ref="defaultargument"/>
+ </sequence>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
-
+ Required class that provides implementation of connection factory. The class must implement <b>org.eclipse.ecf.core.comm.provider.ISynchAsynchConnectionInstantiator</b>
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
-
+ Optional name for connection factory. If this name is not explicitly given, the class will be used for the name.
</documentation>
</annotation>
</attribute>
<attribute name="description" type="string">
<annotation>
<documentation>
-
+ An optional description for the connection factory.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="defaultargument">
+ <annotation>
+ <documentation>
+ Default argument to be passed to makeInstance method. Value of this element (if any) is used to provide a default value for the given argument
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="type" type="string">
+ <annotation>
+ <documentation>
+ The fully qualified type of the argument.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="value" type="string">
+ <annotation>
+ <documentation>
+ The value for the default argument
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ An optional name for the defaultargument
</documentation>
</annotation>
</attribute>
@@ -80,7 +119,53 @@ <meta.section type="examples"/>
</appInfo>
<documentation>
-
+ Here's an extension that associates a class org.eclipse.ecf.test.FooContainerFactory with name 'foo' in the ECF <b>SharedObjectContainerFactory</b>:
+
+<pre>
+ <extension
+ point="org.eclipse.ecf.connectionFactory">
+ <connectionFactory
+ class="org.eclipse.ecf.provider.comm.tcp.Client$Creator"
+ description="TCP Client Connection Factory"
+ name="org.eclipse.ecf.provider.comm.tcp.Client">
+ <defaultargument
+ value="10000"
+ type="java.lang.Integer"
+ name="keepAlive"/>
+ </connectionFactory>
+ </extension>
+</pre>
+
+Here's an example implementation of this extension point:
+
+<pre>
+ public ISynchAsynchConnection makeInstance(ConnectionDescription description,
+ ISynchAsynchConnectionEventHandler handler, Class[] clazzes,
+ Object[] args) throws ConnectionInstantiationException {
+ try {
+ String [] argVals = description.getArgDefaults();
+ Integer ka = null;
+ if (argVals != null && argVals.length != 0) {
+ String val = argVals[0];
+ if (val != null) {
+ ka = new Integer(val);
+ }
+ }
+ if (args != null && args.length != 0) {
+ if (args[0] instanceof Integer) {
+ ka = (Integer) args[0];
+ } else if (args[0] instanceof String) {
+ ka = new Integer((String) args[0]);
+ }
+ }
+ return new Client(handler, ka);
+ } catch (Exception e) {
+ throw new ConnectionInstantiationException(
+ "Exception in creating connection "
+ + Client.class.getName(), e);
+ }
+ }
+</pre>
</documentation>
</annotation>
@@ -98,10 +183,10 @@ <meta.section type="implementation"/>
</appInfo>
<documentation>
- The supplied implementations of this extension point are:
-
-In org.eclipse.ecf.provider plugin:
-
+ The supplied implementations of this extension point are: + +In org.eclipse.ecf.provider plugin: + org.eclipse.ecf.provider.tcp.Client$Creator
</documentation>
</annotation>
@@ -111,7 +196,7 @@ org.eclipse.ecf.provider.tcp.Client$Creator <meta.section type="copyright"/>
</appInfo>
<documentation>
- Copyright (c) 2005 Composent, Inc. and others.
+ Copyright (c) 2005 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
</documentation>
</annotation>
diff --git a/framework/bundles/org.eclipse.ecf/schema/containerFactory.exsd b/framework/bundles/org.eclipse.ecf/schema/containerFactory.exsd index a920ab232..a5a6faf26 100644 --- a/framework/bundles/org.eclipse.ecf/schema/containerFactory.exsd +++ b/framework/bundles/org.eclipse.ecf/schema/containerFactory.exsd @@ -6,8 +6,8 @@ <meta.schema plugin="org.eclipse.ecf" id="containerFactory" name="ECF Container Factory"/>
</appInfo>
<documentation>
- This extension allows plugins to register themselves as 'providers' of ECF shared object containers. Once registered via this extension point, plugins can then provide implementations of custom ISharedObjectContainer instances via the ECF container factory (<b>org.eclipse.ecf.core.SharedObjectContainerFactory</b>). -<p>Plugins using this extension point can define a new implementation of any desired communications protocol, and expose that protocol as an instance of an <b>ISharedObjectContainer</b>. When client requests are made to ECF to create <b>ISharedObjectContainer</b> instances, then requests to create instances of the appropriate type will be re-directed to the given extension.
+ This extension allows plugins to register themselves as 'providers' of ECF shared object containers. Once registered via this extension point, plugins can then provide there own implementations of ISharedObjectContainer in response to client request of the ECF container factory (<b>org.eclipse.ecf.core.SharedObjectContainerFactory</b>). +<p>Plugins using this extension point can define a new implementation of any desired communications protocol, and expose that protocol as an instance of an <b>ISharedObjectContainer</b>. When client requests are made to ECF SharedObjectContainerFactory to create <b>ISharedObjectContainer</b> instances, those requests will be re-directed to the given ISharedObjectContainer implementer.
</documentation>
</annotation>
@@ -43,21 +43,24 @@ <element name="containerFactory">
<annotation>
<documentation>
- The container factory extension point
+ The container factory extension point. Can optionally contain a list of 'defaultargument' elements that describe the arguments (and provide default values) to be passed to provider implementation
</documentation>
</annotation>
<complexType>
+ <sequence>
+ <element ref="defaultargument" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
- The class implementing the containerFactory extension point. This class must implement the org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator interface.
+ The class implementing the containerFactory extension point. The given class must implement the <b>org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator</b> interface
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
- An optional name for the extension. If no name is provided, the fully qualified class name is used as the name. Note that this name must <b>not</b> conflict with any other name in the ECF SharedObjectContainerFactory in order to be successfully registered. Care should therefore be taken in selection of a name such that it does not conflict with other implementations.
+ An optional name for the extension. If no name is explicitly provided by the extension, the containerFactory class name is used as the name. Note that this name must <b>not</b> conflict with any other name in the ECF SharedObjectContainerFactory in order to be successfully registered. Care should therefore be taken in selection of a name such that it does not conflict with other pre-existing names for this factory implementations
</documentation>
</annotation>
</attribute>
@@ -71,12 +74,43 @@ </complexType>
</element>
+ <element name="defaultargument">
+ <annotation>
+ <documentation>
+ Default argument to be passed to <b>org.eclipse.ecf.core.provider.makeInstance()</b> method. Value of this element (if any) is used to indicate a default value for the given argument
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="type" type="string">
+ <annotation>
+ <documentation>
+ The fully qualified type of the default argument
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="value" type="string">
+ <annotation>
+ <documentation>
+ The value for the default argument
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+ An optional name for the defaultargument element
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
<annotation>
<appInfo>
<meta.section type="since"/>
</appInfo>
<documentation>
- 1.0.0
+ 0.0.1
</documentation>
</annotation>
@@ -89,7 +123,8 @@ <pre> <extension point="org.eclipse.ecf.containerFactory"> - <containerFactory name="foo" class="org.eclipse.ecf.test.FooContainerFactory" description="My container factory"/> + <containerFactory name="foo" class="org.eclipse.ecf.test.FooContainerFactory" description="My container factory"> + <defaultargument type="java.lang.String" value="defaultvalue" name="variablename"/> </extension> </pre> @@ -107,7 +142,7 @@ public class FooContainerFactory implements ISharedObjectContainerInstantiator { public FooContainerFactory() { super(); } - public ISharedObjectContainer makeInstance(Class[] argTypes, Object[] args) + public ISharedObjectContainer makeInstance(SharedObjectContainterDescription description, Class[] argTypes, Object[] args) throws SharedObjectContainerInstantiationException { // Create/return instance of FooSharedObjectContainer // Note that FooSharedObjectContainer class must @@ -145,10 +180,9 @@ ISharedObjectContainer newContainer = SharedObjectContainerFactory.makeSharedObj <meta.section type="implementation"/>
</appInfo>
<documentation>
- The supplied implementations of this extension point are:
-
-org.eclipse.ecf.provider.generic.ContainerInstantiator
-<b>TEST</b>: org.eclipse.ecf.internal.impl.standalone.StandaloneContainerInstantiator
+ The supplied implementations of this extension point are: + +org.eclipse.ecf.provider.generic.ContainerInstantiator <b>TEST</b>: org.eclipse.ecf.test.TestContainer
</documentation>
</annotation>
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerDescription.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerDescription.java index 38254e67d..f57150f93 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerDescription.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerDescription.java @@ -6,59 +6,94 @@ * * Contributors: Composent, Inc. - initial API and implementation ******************************************************************************/ - package org.eclipse.ecf.core; +import java.util.Arrays; import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator; /** - * Description of an ISharedObjectContainer factory implementation. + * Description of an ISharedObjectContainer factory implementation. * * @see SharedObjectContainerFactory#addDescription(SharedObjectContainerDescription) - * + * */ public class SharedObjectContainerDescription { - protected String name; protected String instantiatorClass; protected ClassLoader classLoader; protected ISharedObjectContainerInstantiator instantiator; protected String description; - + protected String[] argTypes; + protected String[] argDefaults; + protected String[] argNames; protected int hashCode = 0; + protected static final String[] EMPTY = new String[0]; public SharedObjectContainerDescription(ClassLoader loader, String name, String instantiatorClass, String desc) { + this(loader, name, instantiatorClass, desc, EMPTY, + EMPTY, EMPTY); + } + + public SharedObjectContainerDescription(String name, + String instantiatorClass, String desc) { + this(null, name, instantiatorClass, desc); + } + + public SharedObjectContainerDescription(ClassLoader loader, String name, + String instantiatorClass, String desc, String[] argTypes, + String[] argDefaults, String[] argNames) { this.classLoader = loader; if (name == null) - throw new RuntimeException(new InstantiationException( - "SharedObjectContainerDescription<init> name cannot be null")); + throw new RuntimeException( + new InstantiationException( + "SharedObjectContainerDescription<init> name cannot be null")); this.name = name; if (instantiatorClass == null) - throw new RuntimeException(new InstantiationException( - "SharedObjectContainerDescription<init> instantiatorClass cannot be null")); + throw new RuntimeException( + new InstantiationException( + "SharedObjectContainerDescription<init> instantiatorClass cannot be null")); this.instantiatorClass = instantiatorClass; this.hashCode = name.hashCode(); this.description = desc; + this.argTypes = argTypes; + this.argDefaults = argDefaults; + this.argNames = argNames; } - public SharedObjectContainerDescription(String name, ISharedObjectContainerInstantiator inst, String desc) { + + public SharedObjectContainerDescription(String name, + ISharedObjectContainerInstantiator inst, String desc, + String[] argTypes, String[] argDefaults, String[] argNames) { if (name == null) - throw new RuntimeException(new InstantiationException( - "SharedObjectContainerDescription<init> name cannot be null")); + throw new RuntimeException( + new InstantiationException( + "SharedObjectContainerDescription<init> name cannot be null")); if (inst == null) - throw new RuntimeException(new InstantiationException( - "SharedObjectContainerDescription<init> instantiator instance cannot be null")); + throw new RuntimeException( + new InstantiationException( + "SharedObjectContainerDescription<init> instantiator instance cannot be null")); this.instantiator = inst; this.name = name; this.classLoader = this.instantiator.getClass().getClassLoader(); this.description = desc; + this.argTypes = argTypes; + this.argDefaults = argDefaults; + this.argNames = argNames; + } + + public SharedObjectContainerDescription(String name, + ISharedObjectContainerInstantiator inst, String desc) { + this(name, inst, desc, EMPTY, EMPTY, EMPTY); } + public String getName() { return name; } + public ClassLoader getClassLoader() { return classLoader; } + public boolean equals(Object other) { if (!(other instanceof SharedObjectContainerDescription)) return false; @@ -74,10 +109,13 @@ public class SharedObjectContainerDescription { StringBuffer b = new StringBuffer("SharedObjectContainerDescription["); b.append("name:").append(name).append(";"); if (instantiator == null) - b.append("class:").append(instantiatorClass).append(";"); + b.append("class:").append(instantiatorClass).append(";"); else b.append("instantiator:").append(instantiator).append(";"); - b.append("desc:").append(description).append("]"); + b.append("desc:").append(description).append(";"); + b.append("argtypes:").append(Arrays.asList(argTypes)).append(";"); + b.append("argdefaults:").append(Arrays.asList(argDefaults)).append(";"); + b.append("argnames:").append(Arrays.asList(argNames)).append("]"); return b.toString(); } @@ -108,4 +146,16 @@ public class SharedObjectContainerDescription { public String getDescription() { return description; } + + public String[] getArgDefaults() { + return argDefaults; + } + + public String[] getArgTypes() { + return argTypes; + } + + public String[] getArgNames() { + return argNames; + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerFactory.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerFactory.java index 0d6d5c4cb..44a70293e 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerFactory.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerFactory.java @@ -189,7 +189,7 @@ public class SharedObjectContainerFactory { + cd.getName() + " is null"); // Ask instantiator to actually create instance return (ISharedObjectContainer) instantiator - .makeInstance(clazzes, args); + .makeInstance(desc,clazzes, args); } /** * Make ISharedObjectContainer instance. Given a diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionDescription.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionDescription.java index ad65826a5..d9089af0a 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionDescription.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionDescription.java @@ -1,62 +1,88 @@ -/**************************************************************************** -* 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 -*****************************************************************************/ - +/******************************************************************************* + * 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.core.comm; import org.eclipse.ecf.core.comm.provider.ISynchAsynchConnectionInstantiator; public class ConnectionDescription { - protected String name; protected String instantiatorClass; - protected ISynchAsynchConnectionInstantiator instantiator; protected int hashCode = 0; protected ClassLoader classLoader = null; protected String description; - - public ConnectionDescription(ClassLoader loader, + protected String[] argTypes; + protected String[] argDefaults; + protected String[] argNames; + protected static final String[] EMPTY = new String[0]; - String name, String instantiatorClass, String desc) { + public ConnectionDescription(ClassLoader loader, String name, + String instantiatorClass, String desc, String[] defTypes, + String[] defValues, String[] defNames) { if (name == null) throw new RuntimeException(new InstantiationException( "ConnectionDescription<init> name cannot be null")); if (instantiatorClass == null) - throw new RuntimeException(new InstantiationException( - "ConnectionDescription<init> instantiatorClass cannot be null")); + throw new RuntimeException( + new InstantiationException( + "ConnectionDescription<init> instantiatorClass cannot be null")); this.classLoader = loader; this.name = name; this.instantiatorClass = instantiatorClass; this.hashCode = name.hashCode(); + this.argTypes = defTypes; + this.argDefaults = defValues; + this.argNames = defNames; } - public ConnectionDescription(String name, ISynchAsynchConnectionInstantiator inst, String desc) { + + public ConnectionDescription(ClassLoader loader, String name, + String instantiatorClass, String desc) { + this(loader, name, instantiatorClass, desc, EMPTY, EMPTY, EMPTY); + } + + public ConnectionDescription(String name, String instantiatorClass, + String desc) { + this(null, name, instantiatorClass, desc); + } + + public ConnectionDescription(String name, + ISynchAsynchConnectionInstantiator inst, String desc, + String[] defTypes, String[] defValues, String[] defNames) { if (name == null) throw new RuntimeException(new InstantiationException( "ConnectionDescription<init> name cannot be null")); if (inst == null) - throw new RuntimeException(new InstantiationException( - "ConnectionDescription<init> instantiator instance cannot be null")); + throw new RuntimeException( + new InstantiationException( + "ConnectionDescription<init> instantiator instance cannot be null")); this.instantiator = inst; this.name = name; this.classLoader = this.instantiator.getClass().getClassLoader(); this.instantiatorClass = this.instantiator.getClass().getName(); this.hashCode = name.hashCode(); this.description = desc; + this.argTypes = defTypes; + this.argDefaults = defValues; + this.argNames = defNames; + } + public ConnectionDescription(String name, ISynchAsynchConnectionInstantiator inst, String desc) { + this(name,inst,desc,EMPTY,EMPTY,EMPTY); } + public String getName() { return name; } + public ClassLoader getClassLoader() { return classLoader; } + public boolean equals(Object other) { if (!(other instanceof ConnectionDescription)) return false; @@ -72,7 +98,7 @@ public class ConnectionDescription { StringBuffer b = new StringBuffer("ConnectionDescription["); b.append("name:").append(name).append(";"); if (instantiator == null) - b.append("class:").append(instantiatorClass).append(";"); + b.append("class:").append(instantiatorClass).append(";"); else b.append("instantiator:").append(instantiator).append(";"); b.append("desc:").append(description).append("]"); @@ -103,5 +129,13 @@ public class ConnectionDescription { public String getDescription() { return description; } - + public String[] getArgDefaults() { + return argDefaults; + } + public String[] getArgNames() { + return argNames; + } + public String[] getArgTypes() { + return argTypes; + } }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionFactory.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionFactory.java index 0bfe850b3..8296f4c79 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionFactory.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/ConnectionFactory.java @@ -133,7 +133,7 @@ public class ConnectionFactory { } debug("makeSynchAsynchConnection:got instantiator:" + instantiator); // Ask instantiator to actually create instance - return instantiator.makeInstance(handler, clazzes, args); + return instantiator.makeInstance(desc,handler, clazzes, args); } public static ISynchAsynchConnection makeSynchAsynchConnection( diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/provider/ISynchAsynchConnectionInstantiator.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/provider/ISynchAsynchConnectionInstantiator.java index 6bd01c388..e62c07512 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/provider/ISynchAsynchConnectionInstantiator.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/comm/provider/ISynchAsynchConnectionInstantiator.java @@ -1,20 +1,21 @@ -/**************************************************************************** -* 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 -*****************************************************************************/ - +/******************************************************************************* + * 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.core.comm.provider; +import org.eclipse.ecf.core.comm.ConnectionDescription; import org.eclipse.ecf.core.comm.ConnectionInstantiationException; import org.eclipse.ecf.core.comm.ISynchAsynchConnection; import org.eclipse.ecf.core.comm.ISynchAsynchConnectionEventHandler; public interface ISynchAsynchConnectionInstantiator { - public ISynchAsynchConnection makeInstance(ISynchAsynchConnectionEventHandler handler, Class [] clazzes, Object [] args) throws ConnectionInstantiationException; -} + public ISynchAsynchConnection makeInstance( + ConnectionDescription description, + ISynchAsynchConnectionEventHandler handler, Class[] clazzes, + Object[] args) throws ConnectionInstantiationException; +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/provider/ISharedObjectContainerInstantiator.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/provider/ISharedObjectContainerInstantiator.java index aeafa608d..b679bb8b3 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/provider/ISharedObjectContainerInstantiator.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/provider/ISharedObjectContainerInstantiator.java @@ -10,10 +10,11 @@ package org.eclipse.ecf.core.provider; import org.eclipse.ecf.core.ISharedObjectContainer; +import org.eclipse.ecf.core.SharedObjectContainerDescription; import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; public interface ISharedObjectContainerInstantiator { - public ISharedObjectContainer makeInstance(Class[] argTypes, Object[] args) + public ISharedObjectContainer makeInstance(SharedObjectContainerDescription description, Class[] argTypes, Object[] args) throws SharedObjectContainerInstantiationException; }
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java index 2f8f6a6af..fc6c6f658 100644 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java +++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java @@ -49,7 +49,11 @@ public class ECFPlugin extends Plugin { public static final String CONTAINER_FACTORY_EPOINT_CLASS_ATTRIBUTE = "class"; public static final String CONTAINER_FACTORY_EPOINT_NAME_ATTRIBUTE = "name"; public static final String CONTAINER_FACTORY_EPOINT_DESC_ATTRIBUTE = "description"; - + public static final String ARG_ELEMENT_NAME = "defaultargument"; + public static final String ARG_TYPE_ATTRIBUTE = "type"; + public static final String ARG_VALUE_ATTRIBUTE = "value"; + public static final String ARG_NAME_ATTRIBUTE = "name"; + public static final String COMM_FACTORY_EPOINT = "org.eclipse.ecf.connectionFactory"; public static final String COMM_FACTORY_EPOINT_CLASS_ATTRIBUTE = "class"; public static final String COMM_FACTORY_EPOINT_NAME_ATTRIBUTE = "name"; @@ -135,8 +139,25 @@ public class ECFPlugin extends Plugin { if (description == null) { description = ""; } + // Get any arguments + String[] argTypes = new String[0]; + String[] argDefaults = new String[0]; + String[] argNames = new String[0]; + IConfigurationElement [] argElements = member.getChildren(ARG_ELEMENT_NAME); + if (argElements != null) { + if (argElements.length > 0) { + argTypes = new String[argElements.length]; + argDefaults = new String[argElements.length]; + argNames = new String[argElements.length]; + for(int i=0; i < argElements.length; i++) { + argTypes[i] = argElements[i].getAttribute(ARG_TYPE_ATTRIBUTE); + argDefaults[i] = argElements[i].getAttribute(ARG_VALUE_ATTRIBUTE); + argNames[i] = argElements[i].getAttribute(ARG_NAME_ATTRIBUTE); + } + } + } SharedObjectContainerDescription scd = new SharedObjectContainerDescription( - name, (ISharedObjectContainerInstantiator) exten, description); + name, (ISharedObjectContainerInstantiator) exten, description, argTypes, argDefaults,argNames); if (SharedObjectContainerFactory.containsDescription(scd)) { // It's already there...log and throw as we can't use the // same named factory @@ -305,8 +326,25 @@ public class ECFPlugin extends Plugin { if (description == null) { description = ""; } + // Get any arguments + String[] argTypes = new String[0]; + String[] argDefaults = new String[0]; + String[] argNames = new String[0]; + IConfigurationElement [] argElements = member.getChildren(ARG_ELEMENT_NAME); + if (argElements != null) { + if (argElements.length > 0) { + argTypes = new String[argElements.length]; + argDefaults = new String[argElements.length]; + argNames = new String[argElements.length]; + for(int i=0; i < argElements.length; i++) { + argTypes[i] = argElements[i].getAttribute(ARG_TYPE_ATTRIBUTE); + argDefaults[i] = argElements[i].getAttribute(ARG_VALUE_ATTRIBUTE); + argNames[i] = argElements[i].getAttribute(ARG_NAME_ATTRIBUTE); + } + } + } ConnectionDescription cd = new ConnectionDescription( - name, (ISynchAsynchConnectionInstantiator) exten, description); + name, (ISynchAsynchConnectionInstantiator) exten, description,argTypes,argDefaults,argNames); if (ConnectionFactory.containsDescription(cd)) { // It's already there...log and throw as we can't use the // same named factory diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerMessage.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerMessage.java deleted file mode 100644 index 17b579e71..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerMessage.java +++ /dev/null @@ -1,105 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import java.io.Serializable; - -import org.eclipse.ecf.core.identity.ID; - -public final class ContainerMessage { - public final static byte LEAVE = 1; - public final static byte CHANGE = 2; - public final static byte CREATE_REPOBJ = 3; - public final static byte CREATE_REPOBJ_RESP = 4; - public final static byte REPOBJ_MSG = 5; - public final static byte DESTROY_REPOBJ = 6; - - public static final class CreateResponse implements Serializable { - static final long serialVersionUID = -1159925727012441883L; - /** - * @serial myObjID the RepObject ID this create response message is - * in reference to. - */ - ID myObjID; - /** - * @serial myExcept the Exception associated with this create response - * message. Null if no exception generated and everything was - * created properly. - */ - Throwable myExcept; - /** - * @serial mySeq the sequence number issued in the original create - * message. - */ - long mySeq; - - public CreateResponse(ID objID, Throwable except, long sequence) { - myObjID = objID; - myExcept = except; - mySeq = sequence; - } - - } - - public static final class ContainerItemChange implements Serializable { - static final long serialVersionUID = -491316501905217599L; - /** - * @serial changeIDs IDs of SharedObjectContainer group members that are part of this change message. - */ - ID changeIDs[]; - /** - * @serial add boolean indicating whether this change message is an - * add or delete. - */ - boolean add; - /** - * @serial itemData arbitrary data associated with change message. - */ - Serializable myData; - - ContainerItemChange(ID id, boolean a, Serializable data) { - changeIDs = new ID[1]; - changeIDs[0] = id; - add = a; - myData = data; - } - - ContainerItemChange(ID id, boolean a) { - this(id, a, null); - } - - ContainerItemChange(ID id[], boolean a, Serializable data) { - changeIDs = id; - add = a; - myData = data; - } - - ContainerItemChange(ID id[], boolean a) { - this(id, a, null); - } - } - - public static final class SharedObjectPacket implements Serializable { - static final long serialVersionUID = 7884246114924888824L; - ID myFromID; - Serializable myData; - - SharedObjectPacket(ID fromID, Serializable data) { - myFromID = fromID; - myData = data; - } - - } - - public static final class SharedObjectDestroyInfo implements Serializable { - static final long serialVersionUID = -3314198945413220488L; - /** - * @serial myObjID the RepObject ID that is to be destroyed in response - * to this message. - */ - ID myObjID; - - SharedObjectDestroyInfo(ID objID) { - myObjID = objID; - } - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerPacket.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerPacket.java deleted file mode 100644 index 691e05cb1..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/ContainerPacket.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import org.eclipse.ecf.core.identity.ID; - -import java.io.Serializable; - -public final class ContainerPacket implements Serializable { - static final long serialVersionUID = 8416382883801007164L; - ID fromID; - public ID toID; - long sequence; - byte msg; - Serializable theData; - - ContainerPacket(ID from, ID to, long seq, byte m, Serializable data) { - fromID = from; - toID = to; - sequence = seq; - msg = m; - theData = data; - } -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/Debug.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/Debug.java deleted file mode 100644 index a4340e24c..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/Debug.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -public class Debug { - - public static boolean ON = false; - protected static Debug staticDebug = null; - - public static Debug create(String key) { - return new Debug(key); - } - - static { - try { - staticDebug = Debug.create("org.composent.api.impl.Debug"); - } catch (Throwable t) { - t.printStackTrace(System.err); - } - } - public static void errDumpStack(Throwable e, String msg) { - if (staticDebug != null) staticDebug.dumpStack(e,msg); - } - public void dumpStack(Throwable e, String msg) { - msg(msg); - e.printStackTrace(System.err); - } - public void msg(String msg) { - System.err.println(msg); - } - protected Debug(String key) { - } - public static void setThreadDebugGroup(Object obj) { - // Do nothing - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/OSGIServiceAccessImpl.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/OSGIServiceAccessImpl.java deleted file mode 100644 index 27460f53f..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/OSGIServiceAccessImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Created on Dec 6, 2004 - * - */ -package org.eclipse.ecf.internal.impl.standalone; - -import java.util.Dictionary; - -import org.eclipse.ecf.core.IOSGIService; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; - -public class OSGIServiceAccessImpl implements IOSGIService { - - BundleContext context; - - public OSGIServiceAccessImpl(BundleContext ctx) { - super(); - this.context = ctx; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.IOSGIService#getServiceReference(java.lang.String) - */ - public ServiceReference getServiceReference(String svc) { - return context.getServiceReference(svc); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.IOSGIService#getService(org.osgi.framework.ServiceReference) - */ - public Object getService(ServiceReference reference) { - return context.getService(reference); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.IOSGIService#getServiceReferences(java.lang.String, java.lang.String) - */ - public ServiceReference[] getServiceReferences(String clazz, String filter) - throws InvalidSyntaxException { - return context.getServiceReferences(clazz,filter); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.IOSGIService#registerService(java.lang.String[], java.lang.Object, java.util.Dictionary) - */ - public ServiceRegistration registerService(String[] clazzes, - Object service, Dictionary properties) { - return context.registerService(clazzes,service,properties); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.IOSGIService#registerService(java.lang.String, java.lang.Object, java.util.Dictionary) - */ - public ServiceRegistration registerService(String clazz, Object service, - Dictionary properties) { - return context.registerService(clazz,service,properties); - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/QueueEnqueueImpl.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/QueueEnqueueImpl.java deleted file mode 100644 index cb357e890..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/QueueEnqueueImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Created on Dec 6, 2004 - * - */ -package org.eclipse.ecf.internal.impl.standalone; - -import org.eclipse.ecf.core.util.EnqueuePredicate; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.core.util.QueueEnqueue; -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) { - super(); - this.queue = impl; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue(org.eclipse.ecf.core.util.Event) - */ - public void enqueue(Event element) throws QueueException { - queue.enqueue(element); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue(org.eclipse.ecf.core.util.Event[]) - */ - public void enqueue(Event[] elements) throws QueueException { - if (elements != null) { - for(int i=0; i < elements.length; i++) { - enqueue(elements[i]); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue_prepare(org.eclipse.ecf.core.util.Event[]) - */ - public Object enqueue_prepare(Event[] elements) throws QueueException { - return elements; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue_commit(java.lang.Object) - */ - public void enqueue_commit(Object enqueue_key) { - if (enqueue_key instanceof Event[]) { - Event [] events = (Event []) enqueue_key; - try { - enqueue(events); - } catch (QueueException e) { - // this should not happen - e.printStackTrace(System.err); - } - } - - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue_abort(java.lang.Object) - */ - public void enqueue_abort(Object enqueue_key) { - // Do nothing - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#enqueue_lossy(org.eclipse.ecf.core.util.Event) - */ - public boolean enqueue_lossy(Event element) { - queue.enqueue(element); - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#setEnqueuePredicate(org.eclipse.ecf.core.util.EnqueuePredicate) - */ - public void setEnqueuePredicate(EnqueuePredicate pred) { - // This queue does not support enqueue predicate - // So we do nothing - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#getEnqueuePredicate() - */ - public EnqueuePredicate getEnqueuePredicate() { - // We don't support enqueue predicate, so return null; - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.util.QueueEnqueue#size() - */ - public int size() { - return queue.size(); - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainer.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainer.java deleted file mode 100644 index 23a6e970a..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainer.java +++ /dev/null @@ -1,1454 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import java.io.IOException; -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.net.URL; -import java.net.URLClassLoader; -import java.security.AccessController; -import java.security.Permissions; -import java.security.PrivilegedAction; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.Enumeration; -import java.util.Map; -import java.util.Vector; - -import org.eclipse.ecf.core.ISharedObject; -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.ISharedObjectConnector; -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.ISharedObjectContainerConfig; -import org.eclipse.ecf.core.ISharedObjectContainerListener; -import org.eclipse.ecf.core.ISharedObjectContainerTransaction; -import org.eclipse.ecf.core.ISharedObjectContext; -import org.eclipse.ecf.core.SharedObjectAddException; -import org.eclipse.ecf.core.SharedObjectConnectException; -import org.eclipse.ecf.core.SharedObjectContainerJoinException; -import org.eclipse.ecf.core.SharedObjectCreateException; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectDisconnectException; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.SharedObjectNotFoundException; -import org.eclipse.ecf.core.comm.AsynchConnectionEvent; -import org.eclipse.ecf.core.comm.ConnectionEvent; -import org.eclipse.ecf.core.comm.DisconnectConnectionEvent; -import org.eclipse.ecf.core.comm.IAsynchConnection; -import org.eclipse.ecf.core.comm.IAsynchConnectionEventHandler; -import org.eclipse.ecf.core.comm.ISynchConnectionEventHandler; -import org.eclipse.ecf.core.comm.SynchConnectionEvent; -import org.eclipse.ecf.core.events.IContainerEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.AbstractFactory; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.core.util.SimpleQueueImpl; -import org.eclipse.ecf.internal.impl.standalone.gmm.Item; - -public abstract class SharedObjectContainer implements ISharedObjectContainer { - public static Debug debug = - Debug.create(SharedObjectContainer.class.getName()); - // Messages - public static final String CONTAINERCLOSING = "space is closing"; - public static final String BADPARAMDATA = "invalid parameter"; - public static final String BADDATA = "invalid data"; - public static final String JOINFAIL = "join fail"; - public static final String NOTCONNECTED = "not connected"; - public static final String CONNECTEDFAIL = "currently connected"; - public static final String CONNECTINGFAIL = "currently connecting"; - public static final String CONNECTLOCALLYREFUSED = "join fail locally"; - public static final String SHAREDOBJECTALREADYEXISTS = - "shared object already exists: "; - - protected static final Object[] nullArgs = new Object[0]; - protected static final Class[] nullTypes = new Class[0]; - - ISharedObjectContainerConfig config; - protected SharedObjectContainerManager sharedObjectContainerManager; - long sequenceNumber; - MsgReceiver msgReceiver; - boolean isClosing = false; - ThreadGroup sharedObjectLoadingThreadGroup; - ThreadGroup sharedObjectThreadGroup; - - public SharedObjectContainer(ISharedObjectContainerConfig config) throws SecurityException { - this.config = config; - sharedObjectContainerManager = new SharedObjectContainerManager(this, new Item(config.getID())); - sequenceNumber = 0; - msgReceiver = new MsgReceiver(); - sharedObjectLoadingThreadGroup = getParentLoadingTG(); - sharedObjectThreadGroup = getParentSharedObjectTG(); - } - protected ThreadGroup getParentLoadingTG() { - return new ThreadGroup(getID() + ":LoadingThreads"); - } - protected ThreadGroup getParentSharedObjectTG() { - return new ThreadGroup(getID() + ":SharedObjectThreads"); - } - public final ID getID() { - return config.getID(); - } - public ISharedObjectContainerConfig getConfig() { - return config; - } - public final int getItemSize() { - return sharedObjectContainerManager.getSize(); - } - public final int getMaxItems() { - return sharedObjectContainerManager.getMaxItems(); - } - public final int setMaxItems(int max) { - return sharedObjectContainerManager.setMaxItems(max); - } - public final ID[] getOtherItemsIDs() { - return sharedObjectContainerManager.getOtherItemIDs(); - } - public final ID[] getActiveObjIDs() { - return sharedObjectContainerManager.getActiveKeys(); - } - public final boolean isClosing() { - return isClosing; - } - public abstract boolean isServer(); - public abstract boolean isManager(); - /* - public ID createRepObject( - ID newID, - String className, - URL[] codeBase, - String[] argTypes, - Object[] params) - throws Exception { - if (isClosing) - throw new IllegalStateException(CONTAINERCLOSING); - if (newID == null || className == null) - throw new IllegalAccessError(BADPARAMDATA); - SharedObjectDescription info = - new SharedObjectDescription( - getID(), - className, - codeBase, - argTypes, - params, - 0L); - info.setObjID(newID); - logSpaceEvent(LOGLOCALCREATE, info); - addLocalAndWait(info, load(info)); - return newID; - } - */ - /* - public ID addRepObject(ID objID, URL[] codeBase, ISharedObject obj) - throws RepObjectException, AbortException, IllegalAccessException { - if (isClosing) - throw new IllegalStateException(CONTAINERCLOSING); - if (objID == null || obj == null) - throw new IllegalAccessException(BADPARAMDATA); - if (Debug.ON && debug != null) { - debug.msg( - "addRepObject(" + objID + ", " + codeBase + ", " + obj); - } - // First, create init data for this object - SharedObjectDescription info = - new SharedObjectDescription( - getID(), - obj.getClass().getName(), - codeBase, - null, - 0L); - info.setObjID(objID); - logSpaceEvent(LOGLOCALADD, info); - // Do the real work - addLocalAndWait(info, obj); - return objID; - } - protected void addLocalAndWait(SharedObjectDescription info, ISharedObject obj) - throws IllegalAccessException, RepObjectException, AbortException { - addLocal(info, obj); - // If object implements TransactionRepObject interface, call waitForCompleted method - if (obj instanceof TransactionRepObject - && getID().equals(info.myHomeID)) { - if (Debug.ON && debug != null) { - debug.msg( - "addLocalAndWait. Waiting on TransactionRepObject " - + obj - + " for completion"); - } - // Wait as defined by object - ((TransactionRepObject) obj).waitForCommitted(); - } - } - */ - /* - protected void addLocal(SharedObjectDescription info, ISharedObject obj) - throws IllegalAccessException, RepObjectException { - RepObjConfig aConfig = makeRepObjConfig(info, null); - // Log that this is happening - logSpaceEvent(LOGINIT, aConfig); - // Call init - try { - obj.init(aConfig); - boolean res = - sharedObjectContainerManager.addRepObj( - new SharedObjectWrapper( - aConfig, - obj, - this, - getRepObjectThreadGroup(info, aConfig))); - if (!res) - throw new RepObjectException( - SHAREDOBJECTALREADYEXISTS + aConfig.getID()); - ; - } catch (RepObjectException e) { - logSpaceException(LOGCREATEEXCEPTION, e, info); - throw e; - } - // Create SharedObjectWrapper, and add to local membership manager - logSpaceEvent(LOGACTIVATE, aConfig); - } - */ - protected ISharedObject load(final SharedObjectDescription info) - throws Exception { - ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); - if (contextClassLoader == null) contextClassLoader = SharedObjectContainer.class.getClassLoader(); - Map dict = info.getProperties(); - String [] constructorArgTypes = null; - Object [] constructorArgs = null; - if (dict != null) { - constructorArgTypes = (String []) dict.get("constructorArgTypes"); - constructorArgs = (Object []) dict.get("constructorArgs"); - } - final ClassLoader cl = getClassLoader(contextClassLoader,info); - Class argTypes[] = AbstractFactory.getClassesForTypes(constructorArgTypes,constructorArgs,cl); - final Class[] types = argTypes; - - Object [] args = constructorArgs; - if (args == null) - args = new Object[0]; - - final Object [] theArgs = args; - final Class newClass = Class.forName(info.getClassname(), true, cl); - Object newObject = null; - try { - newObject = - AccessController.doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Constructor aConstructor = newClass.getConstructor(types); - logContainerEvent(null, info); - aConstructor.setAccessible(true); - Thread.currentThread().setContextClassLoader(cl); - return aConstructor.newInstance(theArgs); - } - }); - } catch (java.security.PrivilegedActionException e) { - logContainerException(null, e.getException(), info); - throw e.getException(); - } - return verifyRepObjType(info, newObject); - } - public abstract void joinSpace(ID remoteSpace, Serializable data) - throws IOException; - public abstract void leaveSpace(); - - protected void destroyItems(boolean includeLocal) { - synchronized (sharedObjectContainerManager) { - Object[] members = sharedObjectContainerManager.getItems(); - for (int i = 0; i < members.length; i++) { - ID id = (ID) ((Item) members[i]).getID(); - if (includeLocal || !id.equals(getID())) { - memberLeave( - id, - (IAsynchConnection) ((Item) members[i]).getData()); - } - } - } - } - public final void terminate(long timeout) throws SecurityException { - if (Debug.ON && debug != null) { - debug.msg("terminate(" + timeout + ")"); - } - // First, check to see that caller thread has permission to access - // the two thread groups. - sharedObjectLoadingThreadGroup.checkAccess(); - sharedObjectThreadGroup.checkAccess(); - if (Debug.ON && debug != null) { - debug.msg( - "terminate. Caller thread has access to terminating threads."); - } - logContainerEvent(null, new Long(timeout)); - // No group member or replicated object changes while the member removal is going on - synchronized (sharedObjectContainerManager) { - // First, set closing flag. This prevents other threads from doing things to - // prevent shutdown. Once this is set, this space is a goner. - if (isClosing) { - if (Debug.ON && debug != null) { - debug.msg( - "terminate. Space already terminated."); - } - return; - } else - isClosing = true; - // Allow subclasses to run termination code. - subclassOverrideableTerminate(); - - // Then destroy all members. This will forcibly close all connections to remote spaces, - // destroy client replications, and also destroy host replications if includeHosts is true - if (Debug.ON && debug != null) { - debug.msg("terminate. Calling destroyMembers..."); - } - destroyItems(true); - if (Debug.ON && debug != null) { - debug.msg("terminate. DestroyMembers complete."); - } - } - if (Debug.ON && debug != null) { - debug.msg("terminate. Calling loading group interrupt."); - } - try { - // If any loading threads, just interrupt them...they don't get a chance to complete - sharedObjectLoadingThreadGroup.interrupt(); - synchronized (this) { - notifyAll(); - } - } catch (Exception e) { - } - - long endTime = System.currentTimeMillis() + timeout; - // Everything should now be going away. - // Before we forcibly interrupt executing threads, however, we will wait timeout ms - try { - while (checkForRunningThreads() - && System.currentTimeMillis() < endTime) { - if (Debug.ON && debug != null) { - debug.msg( - "terminate. Waiting for " + timeout / 10 + "ms"); - } - synchronized (this) { - wait(timeout / 10); - } - } - } catch (InterruptedException e) { - } finally { - // Do the nasty - interruptThreads(); - logContainerEvent(null, getID()); - if (Debug.ON && debug != null) { - debug.msg("termination complete for " + getID()); - } - } - } - protected boolean checkForRunningThreads() { - int activeCount = sharedObjectThreadGroup.activeCount(); - int activeGroupCount = sharedObjectThreadGroup.activeGroupCount(); - if (Debug.ON && debug != null) { - debug.msg( - "checkForRunningThreads(). Active is " - + activeCount - + ". ActiveGroup is " - + activeGroupCount); - } - return ((activeCount + activeGroupCount) > 0); - } - - protected void subclassOverrideableTerminate() { - // Allow subclasses to provide termination code - } - - protected void interruptThreads() { - if (Debug.ON && debug != null) { - debug.msg("interruptThreads()"); - } - try { - // Interrupt replicated object threads - sharedObjectThreadGroup.interrupt(); - synchronized (this) { - notifyAll(); - } - } catch (Exception e) { - } - } - - protected void sendMsg(ID toID, byte msg, Serializable data) - throws IOException { - synchronized (sharedObjectContainerManager) { - ID ourID = getID(); - if (!ourID.equals(toID)) - queuePacket(new ContainerPacket(ourID, toID, getSeqNumber(), msg, data)); - } - } - protected ID[] sendCreateMsg(ID toID, SharedObjectDescription createInfo) - throws IOException { - ID[] ids = null; - if (toID == null) { - synchronized (sharedObjectContainerManager) { - // Send message to all - // XXX TODO - //sendMsg(null, ContainerMessage.CREATE_REPOBJ, createInfo); - ids = getOtherItemsIDs(); - } - } else { - if (getID().equals(toID)) { - ids = new ID[0]; - } else { - // XXX TODO - //sendMsg(toID, ContainerMessage.CREATE_REPOBJ, createInfo); - ids = new ID[1]; - ids[0] = toID; - } - } - return ids; - } - protected void deliverEventToSharedObject(ID fromID, ID target, Event msg) - throws SharedObjectNotFoundException { - if (target == null) - throw new SharedObjectNotFoundException(); - synchronized (sharedObjectContainerManager) { - SharedObjectWrapper aMeta = sharedObjectContainerManager.getFromActive(target); - if (aMeta == null) - throw new SharedObjectNotFoundException(target.getName()); - // Deliver message - aMeta.deliverEventFromSharedObject(fromID, msg); - } - } - protected void deliverEventToSharedObjects(ID fromID, ID[] targets, Event msg) { - synchronized (sharedObjectContainerManager) { - if (targets == null) - targets = sharedObjectContainerManager.getActiveKeys(); - for (int i = 0; i < targets.length; i++) { - try { - if (!fromID.equals(targets[i])) { - deliverEventToSharedObject( - fromID, - targets[i], - null - /* - new ISharedObjectEvent( - msg.getClassName(), - msg.getMethodName(), - msg.getArgs()) - */ - ); - - } - } catch (SharedObjectNotFoundException e) { - logContainerException( - null, - e, - targets[i]); - } - } - } - } - abstract protected void queuePacket(ContainerPacket packet) throws IOException; - abstract protected void forwardToRemote( - ID from, - ID to, - byte msg, - Serializable data) - throws IOException; - abstract protected void forwardExcluding( - ID from, - ID excluding, - byte msg, - Serializable data) - throws IOException; - protected final void forward( - ID fromID, - ID toID, - byte msg, - Serializable data) - throws IOException { - if (toID == null) { - forwardExcluding(fromID, fromID, msg, data); - } else { - forwardToRemote(fromID, toID, msg, data); - } - } - - protected void handleAsynchEvent(AsynchConnectionEvent evt) - throws IOException, IllegalAccessException { - if (isClosing) - throw new IllegalStateException(CONTAINERCLOSING); - processAsynchPacket(verifyPacket((Serializable) evt.getData())); - } - protected void processAsynchPacket(ContainerPacket p) throws IOException, IllegalAccessException { - switch (p.msg) { - case ContainerMessage.CHANGE : - handleChangeMsg(p.fromID, p.toID, p.sequence, p.theData); - break; - case ContainerMessage.CREATE_REPOBJ : - handleCreateMsg(p.fromID, p.toID, p.sequence, p.theData); - break; - case ContainerMessage.CREATE_REPOBJ_RESP : - handleCreateRespMsg(p.fromID, p.toID, p.sequence, p.theData); - break; - case ContainerMessage.REPOBJ_MSG : - handleSharedObjectEvent(p.fromID, p.toID, p.sequence, p.theData); - break; - case ContainerMessage.DESTROY_REPOBJ : - handleDestroyMsg(p.fromID, p.toID, p.sequence, p.theData); - break; - default : - if (Debug.ON && debug != null) { - debug.msg("UNRECOGNIZED MESSAGE...throwing"); - } - IllegalAccessException e = - new IllegalAccessException( - BADDATA - + ":" - + p.fromID - + ":" - + p.toID - + ":" - + p.sequence - + ":" - + p.msg); - logContainerException(null, e, null); - throw e; - } - } - - protected ContainerPacket verifyPacket(Serializable data) throws IOException, IllegalAccessException { - ContainerPacket p = null; - try { - p = (ContainerPacket) data; - } catch (ClassCastException e) { - throw new IllegalAccessException(BADDATA + ":" + data); - } - return p; - } - - protected Serializable handleSynchEvent(SynchConnectionEvent evt) - throws IOException, IllegalAccessException { - if (isClosing) - throw new IllegalStateException(CONTAINERCLOSING); - return processSynchPacket((IAsynchConnection) evt.getConnection(), verifyPacket((Serializable) evt.getData())); - } - protected Serializable processSynchPacket( - IAsynchConnection conn, - ContainerPacket aPacket) - throws IOException { - if (aPacket.fromID == null) { - IllegalAccessException e = - new IllegalAccessException( - BADDATA + ":" + aPacket.fromID + ":" + aPacket.toID); - logContainerException(null, e, aPacket); - } - if (aPacket.msg == ContainerMessage.LEAVE) { - handleSpaceLeave(aPacket); - synchronized (sharedObjectContainerManager) { - memberLeave(aPacket.fromID, conn); - } - } - return null; - } - - protected Serializable getLeaveData(ID leaveReceiver) { - /* - RepSpaceLeaveListener l = null; - synchronized (myLeaveListenerLock) { - l = myLeaveListener; - } - Serializable result = null; - if (l != null) { - result = l.getLeaveData(getID(), leaveReceiver); - } - if (Debug.ON && debug != null) { - debug.msg( - "getLeaveData(" + leaveReceiver + ") returns " + result); - } - return result; - */ - return null; - } - protected void handleSpaceLeave(ContainerPacket aPacket) { - if (aPacket == null) - return; - if (Debug.ON && debug != null) { - debug.msg( - "handleSpaceLeave(" - + aPacket.fromID - + "," - + aPacket.theData - + ")"); - } - /* - RepSpaceLeaveListener l = null; - synchronized (myLeaveListenerLock) { - l = myLeaveListener; - } - if (l != null) { - l.handleSpaceLeave(getID(), aPacket.fromID, aPacket.theData); - } - */ - } - protected void handleDisconnectEvent(DisconnectConnectionEvent evt) { - processDisconnect((IAsynchConnection) evt.getConnection(), evt.getException(), (SimpleQueueImpl) evt.getData()); - } - protected void processDisconnect( - IAsynchConnection conn, - Throwable e, - SimpleQueueImpl unsent) { - // Get GMM lock (no group membership changes during this) - synchronized (sharedObjectContainerManager) { - if (e != null) { - ID memID = getIDForConnection(conn); - if (memID != null) { - memberLeave(memID, conn); - } - } - handleUnsent(unsent, e); - } - } - protected abstract void handleChangeMsg( - ID fromID, - ID toID, - long seqNum, - Serializable data) - throws IOException; - protected void handleCreateMsg( - ID fromID, - ID toID, - long seqNum, - Serializable data) - throws IOException, IllegalAccessException { - SharedObjectDescription createInfo = null; - try { - createInfo = (SharedObjectDescription) data; - if (fromID == null - || createInfo == null - || createInfo.getID() == null - || createInfo.getHomeID() == null - || createInfo.getClassname() == null) - throw new Exception(); - } catch (Exception e) { - IllegalAccessException t = - new IllegalAccessException( - BADDATA - + ":" - + fromID - + ":" - + toID - + ":" - + seqNum - + ":" - + ContainerMessage.CREATE_REPOBJ); - logContainerException(null, t, data); - throw t; - } - Object obj = checkCreateObject(fromID, toID, seqNum, createInfo); - if (obj != null && (toID == null || toID.equals(getID()))) { - // Then check to see if returned object was permissions object...if so, then - // pass along to LoadingRepObject - LoadingSharedObject newObj = - new LoadingSharedObject(createInfo, handleObjectCheckResult(obj)); - synchronized (sharedObjectContainerManager) { - // Put into membership manager. This starts thread for retrieving class bytes, etc. - if (!sharedObjectContainerManager.addToLoading(newObj)) { - // Instance of object already there. Send failure msg back. - try { - sendMsg( - fromID, - ContainerMessage.CREATE_REPOBJ_RESP, - new ContainerMessage.CreateResponse( - createInfo.getID(), - new SharedObjectAddException( - createInfo.getID() + " already present"), - createInfo.getIdentifier())); - } catch (Exception e1) { - // If an exception is thrown by this, disconnection has already occurred, - // so no need to rethrow - if (Debug.ON && debug != null) { - debug.dumpStack( - e1, - "Exception sending create failure message back to " - + fromID); - } - logContainerException(null, e1, null); - } - } - // Forward to other remote repspace instances and return. This only has - // effect if this repspace is a server. - forward(fromID, toID, ContainerMessage.CREATE_REPOBJ, data); - return; - } - } - // Even if we don't create the object, if we're a server, we'll forward the message - // to others. Servers can prevent this by throwing an ioexception from checkCreateObject. - synchronized (sharedObjectContainerManager) { - forward(fromID, toID, ContainerMessage.CREATE_REPOBJ, data); - } - } - protected Permissions handleObjectCheckResult(Object obj) { - if (obj == null) - return null; - Permissions p = null; - if (obj instanceof Vector) { - Vector v = (Vector) obj; - for (java.util.Enumeration e = v.elements(); - e.hasMoreElements(); - ) { - Object o = e.nextElement(); - if (o instanceof java.security.Permission) { - if (p == null) - p = new Permissions(); - p.add((java.security.Permission) o); - } - } - } - return p; - } - protected Object checkCreateObject( - ID fromID, - ID toID, - long seqNum, - SharedObjectDescription constructor) - throws IOException { - if (Debug.ON && debug != null) { - debug.msg( - "checkCreateObject(" - + fromID - + ", " - + toID - + ", " - + seqNum - + ", " - + constructor); - } - /* - synchronized (myCreateHandlerLock) { - if (checkCreateHandler != null) { - logSpaceEvent(LOGCHECKCREATE, constructor); - return checkCreateHandler.checkCreateObject( - fromID, - toID, - seqNum, - constructor); - } else - // By default, allow the object to be created by returning reference to self - return this; - } - */ - return this; - } - protected void handleCreateRespMsg( - ID fromID, - ID toID, - long seqNum, - Serializable data) - throws IOException, IllegalAccessException { - ContainerMessage.CreateResponse resp = null; - try { - resp = (ContainerMessage.CreateResponse) data; - if (fromID == null || toID == null || resp == null) - throw new Exception(); - } catch (Exception e) { - IllegalAccessException t = - new IllegalAccessException( - BADDATA - + ":" - + fromID - + ":" - + toID - + ":" - + seqNum - + ":" - + ContainerMessage.CREATE_REPOBJ_RESP); - logContainerException(null, t, data); - throw t; - } - synchronized (sharedObjectContainerManager) { - if (toID != null && toID.equals(getID())) { - // Get SharedObjectWrapper from local membership manager - SharedObjectWrapper aMeta = - sharedObjectContainerManager.getFromActive(resp.myObjID); - if (aMeta == null) { - // Not found...just log; - logContainerException( - null, - new SharedObjectNotFoundException(resp.myObjID.getName()), - null); - return; - } - // Otherwise, deliver message locally - aMeta.createMsgResp(fromID, resp); - } else { - forwardToRemote( - fromID, - toID, - ContainerMessage.CREATE_REPOBJ_RESP, - data); - } - } - } - protected void handleSharedObjectEvent( - ID fromID, - ID toID, - long seqNum, - Serializable data) - throws IOException, IllegalAccessException { - ContainerMessage.SharedObjectPacket aPacket = null; - try { - aPacket = (ContainerMessage.SharedObjectPacket) data; - if (fromID == null || aPacket == null || aPacket.myFromID == null) - throw new Exception(); - } catch (Exception e) { - IllegalAccessException t = - new IllegalAccessException( - BADDATA - + ":" - + fromID - + ":" - + toID - + ":" - + seqNum - + ":" - + ContainerMessage.REPOBJ_MSG); - logContainerException(null, t, null); - throw t; - } - synchronized (sharedObjectContainerManager) { - if (toID == null || toID.equals(getID())) { - SharedObjectWrapper aMeta = - sharedObjectContainerManager.getFromActive(aPacket.myFromID); - if (aMeta == null) { - // Not found...just log; - logContainerException( - null, - new SharedObjectNotFoundException(aPacket.myFromID.getName()), - null); - } else - aMeta.deliverObjectFromRemote(fromID, aPacket.myData); - } - // forward on in either case - forward(fromID, toID, ContainerMessage.REPOBJ_MSG, data); - } - } - protected void handleDestroyMsg( - ID fromID, - ID toID, - long seqNum, - Serializable data) - throws IOException, IllegalAccessException { - ContainerMessage.SharedObjectDestroyInfo info = null; - try { - info = (ContainerMessage.SharedObjectDestroyInfo) data; - if (fromID == null || info == null || info.myObjID == null) - throw new Exception(); - } catch (Exception e) { - IllegalAccessException t = - new IllegalAccessException( - BADDATA - + ":" - + fromID - + ":" - + toID - + ":" - + seqNum - + ":" - + ContainerMessage.DESTROY_REPOBJ); - logContainerException(null, t, null); - throw t; - } - synchronized (sharedObjectContainerManager) { - if (sharedObjectContainerManager.isLoading(info.myObjID)) { - sharedObjectContainerManager.removeSharedObjectFromLoading(info.myObjID); - } else { - try { - sharedObjectContainerManager.destroySharedObject(info.myObjID); - } catch (Exception e) { - logContainerException( - null, - e, - info.myObjID); - } - } - // forward on - forward(fromID, toID, ContainerMessage.DESTROY_REPOBJ, data); - } - } - protected void handleUnsent(SimpleQueueImpl unsent, Throwable e) { - Object[] msgs = unsent.flush(); - if (msgs != null) { - for (int i = 0; i < msgs.length; i++) { - try { - ContainerPacket p = (ContainerPacket) msgs[i]; - if (p.msg == ContainerMessage.REPOBJ_MSG) { - ContainerMessage.SharedObjectPacket repPacket = - (ContainerMessage.SharedObjectPacket) p.theData; - SharedObjectWrapper aMeta = - sharedObjectContainerManager.getFromActive( - repPacket.myFromID); - if (aMeta != null) { - aMeta.deliverRemoteMessageFailed( - p.toID, - repPacket.myData, - e); - } - } - } catch (ClassCastException except) { - // Ignore...wrong type of message - } - } - } - } - protected abstract ID getIDForConnection(IAsynchConnection conn); - - protected ClassLoader getClassLoader(final ClassLoader contextClassLoader, final SharedObjectDescription aConfig) { - final URL[] urls = null; - return ( - ClassLoader) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - ClassLoader loader = null; - if (urls == null) { - // Use same classloader that was used to load this class - loader = contextClassLoader; - } else { - loader = - new URLClassLoader(urls, contextClassLoader); - } - return loader; - } - }); - } - protected ISharedObject verifyRepObjType( - SharedObjectDescription config, - Object newObject) - throws ClassCastException { - return (ISharedObject) newObject; - } - protected ISharedObjectConfig makeRepObjConfig( - SharedObjectDescription aConfig, - Permissions perms) - throws IllegalAccessException { - // XXX TODO - //return new RepObjConfig(aConfig, makeReference(aConfig, perms)); - return null; - } - protected ISharedObjectContext makeReference( - SharedObjectDescription aConfig, - Permissions perms) - throws IllegalAccessException { - if (Debug.ON && debug != null) { - debug.msg( - "makeReference(" + aConfig + ", " + perms + ")"); - } - // XXX TODO - //return new RepSpaceReference(this, aConfig.myObjID, perms); - return null; - } - protected ThreadGroup getLoadingThreadGroup(SharedObjectDescription createData) { - // Return null. Subclasses may override as desired. - return sharedObjectLoadingThreadGroup; - } - protected ThreadGroup getSharedObjectThreadGroup( - SharedObjectDescription info, - ISharedObjectConfig config) { - // Return null. Subclasses may override as desired. - return sharedObjectThreadGroup; - } - protected Thread getSharedObjectThread( - ID identity, - ThreadGroup tg, - Runnable run, - String name) { - return new Thread(tg, run, name); - } - protected void logContainerEvent(String msg, Object param) { - } - protected void logContainerException(String msg, Exception e, Object param) { - } - protected void logSharedObjectEvent(ID repobjID, String msg, Object param) { - } - protected void logSharedObjectException( - ID repobjID, - String msg, - Exception e, - Object param) { - } - - protected void moveFromLoadingToActive(SharedObjectWrapper ro) - throws SharedObjectNotFoundException { - sharedObjectContainerManager.moveFromLoadingToActive(ro); - } - - protected void removeFromLoading(ID id) { - sharedObjectContainerManager.removeSharedObjectFromLoading(id); - } - - synchronized final long getSeqNumber() { - return sequenceNumber++; - } - protected boolean addNewRemoteItem(ID itemID) { - return addNewRemoteItem(itemID, null); - } - protected boolean addNewRemoteItem(ID itemID, Object data) { - return sharedObjectContainerManager.addItem(new Item(itemID, data)); - } - protected boolean removeRemoteItem(ID itemID) { - logContainerEvent(null, itemID); - return sharedObjectContainerManager.removeItem(itemID); - } - protected void memberLeave(ID leaveID, IAsynchConnection conn) { - // No changes to group membership while this is happening - if (removeRemoteItem(leaveID)) { - try { - forwardExcluding( - getID(), - leaveID, - ContainerMessage.CHANGE, - new ContainerMessage.ContainerItemChange(leaveID, false)); - } catch (IOException e) { - if (Debug.ON && debug != null) { - debug.dumpStack( - e, - "memberLeave. Exception calling forwardExcluding"); - } - logContainerException(null, e, null); - - } - } - // disconnect connection - killConnection(conn); - } - protected final void killConnection(IAsynchConnection conn) { - try { - if (conn != null) - conn.disconnect(); - } catch (IOException e) { - if (Debug.ON && debug != null) { - debug.dumpStack(e, "Exception disconnecting " + conn); - } - logContainerException(null, e, conn); - } - } - public ISharedObject getSharedObject(ID objID) { - if (objID == null) return null; - SharedObjectWrapper meta = sharedObjectContainerManager.getFromActive(objID); - if (meta == null) return null; - return meta.sharedObject; - } - - public ISharedObject getSharedObjectFromAny(ID objID) - throws SharedObjectNotFoundException { - if (objID == null) - throw new SharedObjectNotFoundException(); - return sharedObjectContainerManager.getFromAny(objID).sharedObject; - } - public void destroySharedObject(ID id) throws SharedObjectNotFoundException { - if (id == null) - throw new SharedObjectNotFoundException(); - logContainerEvent(null, id); - sharedObjectContainerManager.destroySharedObject(id); - } - public void destroySharedObjectSelf(ID id) throws SharedObjectNotFoundException { - if (id == null) - throw new SharedObjectNotFoundException(); - SharedObjectWrapper meta = sharedObjectContainerManager.getFromActive(id); - if (meta == null) - throw new SharedObjectNotFoundException(); - meta.destroySelf(); - } - protected void notifySharedObjectActivated(ID obj) { - logContainerEvent(null, obj); - sharedObjectContainerManager.notifyOthersActivated(obj); - } - protected void notifySharedObjectDeactivated(ID obj) { - logContainerEvent(null, obj); - sharedObjectContainerManager.notifyOthersDeactivated(obj); - } - protected final class MsgReceiver implements IAsynchConnectionEventHandler, ISynchConnectionEventHandler { - - public void handleDisconnectEvent(DisconnectConnectionEvent evt) { - SharedObjectContainer.this.handleDisconnectEvent( - (DisconnectConnectionEvent) evt); - } - public boolean handleSuspectEvent(ConnectionEvent event) { - // Do nothing - // Returning true indicates that further processing of this - // event should continue - return true; - } - public ClassLoader getClassLoaderForID(ID id) { - return this.getClass().getClassLoader(); - } - public void handleAsynchEvent(AsynchConnectionEvent evt) throws IOException { - // Pass to handler - try { - SharedObjectContainer.this.handleAsynchEvent(evt); - } catch (IllegalAccessException e) { - throw new IOException("Illegal data access handling event "+evt); - } - } - public Object handleSynchEvent(SynchConnectionEvent evt) - throws IOException { - // Handle synch packet - try { - return SharedObjectContainer.this.handleSynchEvent(evt); - } catch (IllegalAccessException e) { - throw new IOException("Illegal data access handling event "+evt); - } - } - - public Object getAdapter(Class clazz) { - return null; - } - } - protected final class LoadingSharedObject implements ISharedObject { - Thread runnerThread; - SharedObjectDescription sharedObjectDescription; - Permissions loadingPerms; - - LoadingSharedObject(SharedObjectDescription create) { - sharedObjectDescription = create; - } - - LoadingSharedObject(SharedObjectDescription create, Permissions perms) { - sharedObjectDescription = create; - loadingPerms = perms; - } - - void start() { - if (runnerThread == null) { - runnerThread = - ( - Thread) AccessController - .doPrivileged(new PrivilegedAction() { - public Object run() { - return getThread(); - } - }); - runnerThread.start(); - } - } - Thread getThread() { - return new Thread(getLoadingThreadGroup(sharedObjectDescription), new Runnable() { - public void run() { - try { - if (Debug.ON && debug != null) { - debug.msg( - "Starting loading of object " - + sharedObjectDescription.getID()); - } - // Check to make sure thread has not been interrupted and space is not closing...if it has, throw - if (Thread.currentThread().isInterrupted() - || isClosing) - throw new InterruptedException("Interrupted"); - logContainerEvent(null, sharedObjectDescription); - // First load given object - ISharedObject obj = load(sharedObjectDescription); - if (Debug.ON && debug != null) { - debug.msg( - "Calling init for object " + sharedObjectDescription.getID()); - } - // Get config info for new object - ISharedObjectConfig aConfig = - makeRepObjConfig(sharedObjectDescription, loadingPerms); - // Log that this is happening - logContainerEvent(null, aConfig); - // 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("Interrupted"); - - if (Debug.ON && debug != null) { - debug.msg( - "Putting object " - + sharedObjectDescription.getID() - + " in local membership manager"); - } - // If not currently *on* loading list, does nothing. - logContainerEvent(null, aConfig); - // Create meta object and move from loading to active list. - SharedObjectContainer.this.moveFromLoadingToActive( - new SharedObjectWrapper( - aConfig, - obj, - SharedObjectContainer.this, - getSharedObjectThreadGroup(sharedObjectDescription, aConfig))); - } catch (Exception e) { - if (Debug.ON && debug != null) { - debug.dumpStack( - e, - "Exception loading new object " - + sharedObjectDescription.getID()); - } - SharedObjectContainer.this.removeFromLoading(sharedObjectDescription.getID()); - try { - SharedObjectContainer.this.sendMsg( - sharedObjectDescription.getID(), - ContainerMessage.CREATE_REPOBJ_RESP, - new ContainerMessage.CreateResponse( - sharedObjectDescription.getID(), - e, - sharedObjectDescription.getIdentifier())); - } catch (Exception e1) { - logContainerException(null, e1, null); - // If this message send fails, we're doomed anyway - if (Debug.ON && debug != null) { - debug.dumpStack( - e1, - "Exception sending create failure message for object " - + sharedObjectDescription.getID()); - } - } - logContainerException( - "loadingRunner. Exception loading for " - + sharedObjectDescription.getID(), - e, - null); - } - } - }, "LoadingRunner for " + sharedObjectDescription.getID()); - } - // ISharedObject - public void init(ISharedObjectConfig aConfig) throws SharedObjectInitException { - // Not relevant for this class - } - public void handleEvent(Event msg) { - // Not relevant for this class...might want to handle a remote destroy message eventually. - } - public void handleEvents(Event [] msgs) { - // Not relevant for this class...might want to handle a remote destroy message eventually. - } - public void dispose(ID spaceID) { - // Not relevant for this class - } - public Object getAdapter(Class clazz) { - return null; - } - public ID getID() { - return sharedObjectDescription.getID(); - } - public ID getHomeID() { - return sharedObjectDescription.getHomeID(); - } - } - - - Vector listeners = new Vector(); - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#addPeerListener(org.eclipse.ecf.core.ISharedObjectContainerListener) - */ - public void addListener(ISharedObjectContainerListener l) { - listeners.add(l); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#removePeerListener(org.eclipse.ecf.core.ISharedObjectContainerListener) - */ - public void removeListener(ISharedObjectContainerListener l) { - listeners.remove(l); - } - protected void fireListeners(IContainerEvent evt) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ISharedObjectContainerListener l = (ISharedObjectContainerListener) e - .nextElement(); - l.handleEvent(evt); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#terminatePeer(long) - */ - public void dispose(long waittime) { - // TODO Auto-generated method stub - - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.identity.ID, - * java.lang.Object) - */ - public void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException { - try { - joinSpace(groupID,(Serializable)loginData); - } catch (IOException e) { - throw new SharedObjectContainerJoinException("IOException joining",e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() - */ - public void leaveGroup() { - leaveSpace(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() - */ - public ID getGroupID() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMembership() - */ - public ID[] getGroupMemberIDs() { - return getOtherItemsIDs(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() - */ - public boolean isGroupManager() { - return isManager(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() - */ - public boolean isGroupServer() { - return isServer(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectIDs() - */ - public ID[] getSharedObjectIDs() { - return getActiveObjIDs(); - } - - protected static Object loadObject(final ClassLoader cl, String className, - String[] argTypes, Object[] a) throws Exception { - final Class[] types = AbstractFactory.getClassesForTypes(argTypes, a, - cl); - final Object[] args = (a == null) ? nullArgs : a; - // Load RepObject class(es), after getting appropriate classloader - final Class newClass = Class.forName(className, true, cl); - Object newObject = null; - try { - // Do privileged operation. Get appropriate constructor from new - // class, - // and create new instance. - newObject = AccessController - .doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Constructor aConstructor = newClass - .getConstructor(types); - aConstructor.setAccessible(true); - // Now actually create the object. - return aConstructor.newInstance(args); - } - }); - } catch (PrivilegedActionException e) { - throw e.getException(); - } - return newObject; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#createSharedObject(org.eclipse.ecf.core.SharedObjectDescription) - */ - public ID createSharedObject(SharedObjectDescription sd, - ISharedObjectContainerTransaction trans) - throws SharedObjectCreateException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#addSharedObject(org.eclipse.ecf.identity.ID, - * org.eclipse.ecf.core.ISharedObject, java.util.Map, - * org.eclipse.ecf.core.ISharedObjectContainerTransaction) - */ - public ID addSharedObject(ID sharedObjectID, ISharedObject sharedObject, - Map dict, ISharedObjectContainerTransaction trans) - throws SharedObjectAddException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectAdapter(org.eclipse.ecf.identity.ID, - * java.lang.Class) - */ - public Object getSharedObjectAdapter(ID sharedObjectID, Class adapterClass) - throws SharedObjectNotFoundException { - synchronized (sharedObjectContainerManager) { - ISharedObject so = getSharedObject(sharedObjectID); - if (so == null) throw new SharedObjectNotFoundException("shared object "+sharedObjectID.getName()+ " not found"); - return so.getAdapter(adapterClass); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#removeSharedObject(org.eclipse.ecf.identity.ID) - */ - public ISharedObject removeSharedObject(ID sharedObjectID) { - synchronized (sharedObjectContainerManager) { - ISharedObject so = getSharedObject(sharedObjectID); - if (so == null) return null; - try { - destroySharedObject(sharedObjectID); - } catch (SharedObjectNotFoundException e) { - return null; - } - return so; - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#connectSharedObjects(org.eclipse.ecf.identity.ID, - * org.eclipse.ecf.identity.ID[]) - */ - public ISharedObjectConnector connectSharedObjects(ID sharedObjectFrom, - ID[] sharedObjectsTo) throws SharedObjectConnectException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#disconnectSharedObjects(org.eclipse.ecf.core.ISharedObjectConnector) - */ - public void disconnectSharedObjects(ISharedObjectConnector connector) - throws SharedObjectDisconnectException { - // TODO Auto-generated method stub - } - - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainerManager.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainerManager.java deleted file mode 100644 index 4ea7c701d..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectContainerManager.java +++ /dev/null @@ -1,341 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import org.eclipse.ecf.core.SharedObjectNotFoundException; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.internal.impl.standalone.Debug; -import org.eclipse.ecf.internal.impl.standalone.gmm.GroupManager; -import org.eclipse.ecf.internal.impl.standalone.gmm.Item; -import org.eclipse.ecf.internal.impl.standalone.gmm.ItemChange; - -import java.util.Observer; -import java.util.Observable; -import java.util.HashSet; -import java.util.TreeMap; -import java.util.Iterator; - -class SharedObjectContainerManager implements Observer { - static Debug myDebug = Debug.create(SharedObjectContainerManager.class.getName()); - - SharedObjectContainer container; - Item containerPeer; - GroupManager groupManager; - int maxItems = -1; - TreeMap loadingSharedObjects, activeSharedObjects; - - SharedObjectContainerManager(SharedObjectContainer space, Item ourMember) { - container = space; - groupManager = new GroupManager(); - groupManager.addObserver(this); - loadingSharedObjects = new TreeMap(); - activeSharedObjects = new TreeMap(); - addItem(ourMember); - containerPeer = ourMember; - } - - synchronized boolean addItem(Item m) { - if (maxItems > 0 && getSize() > maxItems) { - return false; - } else { - return groupManager.addItem(m); - } - } - synchronized int setMaxItems(int max) { - int old = maxItems; - maxItems = max; - return old; - } - synchronized int getMaxItems() { - return maxItems; - } - - synchronized boolean removeItem(Item m) { - boolean res = groupManager.removeItem(m); - if (res) { - destroySharedObjects(m); - } - return res; - } - - synchronized boolean removeItem(ID id) { - Item m = getItemForID(id); - if (m == null) - return false; - return removeItem(m); - } - - void removeAllItems() { - removeAllItems(null); - } - - void removeClientItems() { - removeAllItems(containerPeer); - } - - synchronized void removeAllItems(Item exception) { - Object m[] = getItems(); - for (int i = 0; i < m.length; i++) { - Item mem = (Item) m[i]; - if (exception == null || !exception.equals(mem)) - removeItem(mem); - } - } - - synchronized Object[] getItems() { - return groupManager.getItems(); - } - - synchronized ID[] getOtherItemIDs() { - return groupManager.getItemIDs(containerPeer.getID()); - } - - synchronized ID[] getItemIDs() { - return groupManager.getItemIDs(null); - } - - synchronized Item getItemForID(ID id) { - Item newItem = new Item(id); - for (Iterator i = iterator(); i.hasNext();) { - Item old = (Item) i.next(); - if (newItem.equals(old)) - return old; - } - return null; - } - - synchronized int getSize() { - return groupManager.getSize(); - } - - synchronized boolean containsItem(Item m) { - return groupManager.containsItem(m); - } - - synchronized Iterator iterator() { - return groupManager.iterator(); - } - - // End group membership change methods - - // Methods for adding/removing RepObjs - synchronized boolean addSharedObject(SharedObjectWrapper ro) { - // Verify that it's not already present anywhere - if (getFromAny(ro.getObjID()) != null) - return false; - // Add it to active map - addSharedObjectToActive(ro); - // Notify ro about existing members - return true; - } - - synchronized boolean addToLoading(SharedObjectContainer.LoadingSharedObject lro) { - if (getFromAny(lro.getID()) != null) - return false; - loadingSharedObjects.put( - lro.getID(), - new SharedObjectWrapper(lro.getID(), lro.getHomeID(), lro, container)); - // And start the thing - lro.start(); - return true; - } - - synchronized void moveFromLoadingToActive(SharedObjectWrapper ro) - throws SharedObjectNotFoundException { - if (removeSharedObjectFromLoading(ro.getObjID())) - addSharedObjectToActive(ro); - } - - boolean removeSharedObjectFromLoading(ID id) { - if (loadingSharedObjects.remove(id) != null) { - return true; - } else - return false; - } - - synchronized ID[] getActiveKeys() { - return (ID[]) activeSharedObjects.keySet().toArray(new ID[0]); - } - - void addSharedObjectToActive(SharedObjectWrapper ro) { - // Get current membership in ids array - ID[] ids = getActiveKeys(); - // Actually add to active map - activeSharedObjects.put(ro.getObjID(), ro); - // Pass array of IDs to replicated object - ro.activated(ids); - } - - synchronized void notifyOthersActivated(ID id) { - notifyOtherChanged(id, activeSharedObjects, true); - } - - synchronized void notifyOthersDeactivated(ID id) { - notifyOtherChanged(id, activeSharedObjects, false); - } - - void notifyOtherChanged(ID id, TreeMap aMap, boolean activated) { - for (Iterator i = aMap.values().iterator(); i.hasNext();) { - SharedObjectWrapper other = (SharedObjectWrapper) i.next(); - if (!id.equals(other.getObjID())) { - other.otherChanged(id, activated); - } - } - } - - synchronized void destroySharedObject(ID id) throws SharedObjectNotFoundException { - SharedObjectWrapper ro = removeFromMap(id, activeSharedObjects); - if (ro == null) - throw new SharedObjectNotFoundException(id + " not active"); - ro.deactivated(); - } - - synchronized SharedObjectWrapper getFromMap(ID objID, TreeMap aMap) { - return (SharedObjectWrapper) aMap.get(objID); - } - - synchronized SharedObjectWrapper removeFromMap(ID objID, TreeMap aMap) { - return (SharedObjectWrapper) aMap.remove(objID); - } - - SharedObjectWrapper getFromLoading(ID objID) { - return getFromMap(objID, loadingSharedObjects); - } - - SharedObjectWrapper getFromActive(ID objID) { - return getFromMap(objID, activeSharedObjects); - } - - synchronized SharedObjectWrapper getFromAny(ID objID) { - SharedObjectWrapper ro = getFromMap(objID, activeSharedObjects); - if (ro != null) - return ro; - ro = getFromMap(objID, loadingSharedObjects); - return ro; - } - - // Notification methods - void notifyAllOfItemChange(Item m, TreeMap map, boolean add) { - for (Iterator i = map.values().iterator(); i.hasNext();) { - SharedObjectWrapper ro = (SharedObjectWrapper) i.next(); - ro.memberChanged(m, add); - } - } - - public void update(Observable o, Object arg) { - ItemChange mc = (ItemChange) arg; - notifyAllOfItemChange(mc.getItem(), activeSharedObjects, mc.isAdd()); - } - - synchronized void destroySharedObjects(Item m) { - destroySharedObjects(m, true); - } - - synchronized void clear() { - destroySharedObjects(null, true); - } - - void destroySharedObjects(Item m, boolean match) { - try { - HashSet set = getRemoveIDs(m.getID(), match); - Iterator i = set.iterator(); - - while (i.hasNext()) { - ID removeID = (ID) i.next(); - if (isLoading(removeID)) { - removeSharedObjectFromLoading(removeID); - } else { - container.destroySharedObject(removeID); - } - } - - } catch (SharedObjectNotFoundException e) { - if (debug()) { - myDebug.dumpStack( - e, - "Exception destroying for " + m + ", match: " + match); - } - } - } - - HashSet getRemoveIDs(ID homeID, boolean match) { - HashSet aSet = new HashSet(); - for (Iterator i = new DestroyIterator(loadingSharedObjects, homeID, match); - i.hasNext(); - ) { - aSet.add(i.next()); - } - for (Iterator i = new DestroyIterator(activeSharedObjects, homeID, match); - i.hasNext(); - ) { - aSet.add(i.next()); - } - return aSet; - } - - synchronized boolean isActive(ID id) { - return activeSharedObjects.containsKey(id); - } - - synchronized boolean isLoading(ID id) { - return loadingSharedObjects.containsKey(id); - } - - boolean debug() { - if (myDebug == null) - return false; - return true; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("RSM["); - sb.append(groupManager); - sb.append(";L:").append(loadingSharedObjects); - sb.append(";A:").append(activeSharedObjects).append("]"); - return sb.toString(); - } - -} - -class DestroyIterator implements Iterator { - ID next; - ID homeID; - Iterator i; - boolean match; - - public DestroyIterator(TreeMap map, ID hID, boolean m) { - i = map.values().iterator(); - homeID = hID; - next = null; - match = m; - } - - public boolean hasNext() { - if (next == null) - next = getNext(); - return (next != null); - } - - public Object next() { - if (hasNext()) { - ID value = next; - next = null; - return value; - } else { - throw new java.util.NoSuchElementException(); - } - } - - ID getNext() { - while (i.hasNext()) { - SharedObjectWrapper ro = (SharedObjectWrapper) i.next(); - if (homeID == null || (match ^ !ro.getHomeID().equals(homeID))) { - return ro.getObjID(); - } - } - return null; - } - - public void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectWrapper.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectWrapper.java deleted file mode 100644 index efae671cc..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/SharedObjectWrapper.java +++ /dev/null @@ -1,313 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import java.io.Serializable; -import java.security.AccessController; -import java.security.PrivilegedAction; - -import org.eclipse.ecf.core.ISharedObject; -import org.eclipse.ecf.core.ISharedObjectConfig; -import org.eclipse.ecf.core.SharedObjectInitException; -import org.eclipse.ecf.core.events.SharedObjectActivatedEvent; -import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent; -import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent; -import org.eclipse.ecf.core.events.SharedObjectDeactivatedEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.AsynchResult; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.core.util.SimpleQueueImpl; -import org.eclipse.ecf.internal.impl.standalone.gmm.Item; - -final class SharedObjectWrapper { - static Debug debug = Debug.create(SharedObjectWrapper.class.getName()); - - protected ISharedObject sharedObject; - private ISharedObjectConfig sharedObjectConfig; - private ID sharedObjectID; - private ID sharedObjectHomeID; - private SharedObjectContainer container; - private ID containerID; - private ThreadGroup threadGroup; - private Thread thread; - private SimpleQueueImpl queue; - - SharedObjectWrapper( - ID objID, - ID homeID, - SharedObjectContainer.LoadingSharedObject obj, - SharedObjectContainer space) { - sharedObjectID = objID; - sharedObjectHomeID = homeID; - sharedObject = obj; - container = space; - containerID = space.getID(); - sharedObjectConfig = null; - threadGroup = null; - thread = null; - queue = new SimpleQueueImpl(); - } - SharedObjectWrapper( - ISharedObjectConfig aConfig, - ISharedObject obj, - SharedObjectContainer space, - ThreadGroup group) { - sharedObjectConfig = aConfig; - sharedObjectID = sharedObjectConfig.getSharedObjectID(); - sharedObjectHomeID = sharedObjectConfig.getHomeContainerID(); - sharedObject = obj; - container = space; - containerID = space.getID(); - threadGroup = group; - thread = null; - queue = new SimpleQueueImpl(); - } - - void init() throws SharedObjectInitException { - sharedObject.init(sharedObjectConfig); - } - ID getObjID() { - return sharedObjectID; - } - - ID getHomeID() { - return sharedObjectHomeID; - } - - void activated(ID[] ids) { - // First, make space reference accessible to use by RepObject - //sharedObjectConfig.makeActive(); - thread = - (Thread) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - // Get thread instance - Thread aThread = getThread(); - return aThread; - } - }); - thread.start(); - send(new SharedObjectActivatedEvent(containerID, sharedObjectID, ids)); - container.notifySharedObjectActivated(sharedObjectID); - - } - void deactivated() { - send(new SharedObjectDeactivatedEvent(containerID,sharedObjectID)); - container.notifySharedObjectDeactivated(sharedObjectID); - destroyed(); - } - private void destroyed() { - if (!queue.isStopped()) { - // Enqueue destroy message on our RepObject's queue - if (thread != null) - queue.enqueue(new DisposeEvent()); - // Close queue...RepObject will receive no more messages from this point on. - queue.close(); - } - - } - void otherChanged(ID otherID, boolean activated) { - if (activated && thread != null) { - send(new SharedObjectActivatedEvent(containerID,otherID,null)); - } else { - send(new SharedObjectDeactivatedEvent(containerID,otherID)); - } - } - void memberChanged(Item m, boolean add) { - if (thread != null) { - if (add) { - send(new SharedObjectContainerJoinedEvent(containerID,m.getID())); - } else { - send(new SharedObjectContainerDepartedEvent(containerID,m.getID())); - } - } - } - Thread getThread() { - // Get new thread instance from space. - return container - .getSharedObjectThread(sharedObjectID, threadGroup, new Runnable() { - public void run() { - if (Debug.ON && debug != null) { - debug.msg("Starting runner for " + sharedObjectID); - } - // The debug class will associate this thread with container - Debug.setThreadDebugGroup(container.getID()); - // Then process messages on queue until interrupted or queue closed - //Msg aMsg = null; - Event evt = null; - for (;;) { - // make sure the thread hasn't been interrupted and get Msg from SimpleQueueImpl - if (Thread.currentThread().isInterrupted()) - break; - - evt = (Event) queue.dequeue(); - if (Thread.currentThread().isInterrupted() || evt == null) - break; - - try { - if (evt instanceof ProcEvent) { - SharedObjectWrapper.this.svc(((ProcEvent)evt).getEvent()); - } else if (evt instanceof DisposeEvent) { - SharedObjectWrapper.this.doDestroy(); - } - } catch (Throwable t) { - if (Debug.ON && debug != null) { - debug.dumpStack( - t, - "Exception executing event " - + evt - + " on meta " - + this); - } - handleRuntimeException(t); - } - } - // If the thread was interrupted, then show appropriate spam - if (Thread.currentThread().isInterrupted()) { - if (Debug.ON && debug != null) { - debug.msg( - "Runner for " - + sharedObjectID - + " terminating after being interrupted"); - } - } else { - if (Debug.ON && debug != null) { - debug.msg( - "Runner for " + sharedObjectID + " terminating normally"); - } - } - } - }, "Runner for " + sharedObjectID); - } - 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 createMsgResp(ID fromID, ContainerMessage.CreateResponse resp) { - /* - if (sharedObjectConfig.getMsgMask().get(MsgMask.CREATERESPONSE) - && thread != null) { - send( - Msg.makeMsg( - null, - CREATE_RESP_RCVD, - fromID, - resp.myExcept, - new Long(resp.mySeq))); - } - */ - } - void deliverObjectFromRemote(ID fromID, Serializable data) { - // If we have a container, forward message onto container - /* - if (myContainerID != null) { - forwardToContainer( - Msg.makeMsg(null, REMOTE_REPOBJ_MSG, fromID, data)); - // otherwise, send to our object (assuming it has thread and that it wants to receive message) - } else if ( - sharedObjectConfig.getMsgMask().get(MsgMask.REMOTEDATA) - && thread != null) { - send(Msg.makeMsg(null, REMOTE_REPOBJ_MSG, fromID, data)); - } - */ - } - - void forwardToContainer(Event msg) { - /* - try { - container.deliverForwardToRepObject(sharedObjectID, myContainerID, msg); - } catch (Exception e) { - handleRuntimeException(e); - } - */ - } - void deliverEventFromSharedObject(ID fromID, Event evt) { - /* - if (myContainerID != null) { - forwardToContainer(Msg.makeMsg(null, REPOBJ_MSG, fromID, msg)); - // otherwise, send to our object (assuming it has thread and that it wants to receive message) - } else if ( - sharedObjectConfig.getMsgMask().get(MsgMask.REPOBJMSG) && thread != null) { - send(Msg.makeMsg(null, REPOBJ_MSG, fromID, msg)); - } - */ - } - void deliverRequestFromRepObject(ID fromID, Event evt, AsynchResult future) { - /* - if (myContainerID != null) { - forwardToContainer( - Msg.makeMsg(null, REPOBJ_REQ, fromID, msg, future)); - } else if ( - sharedObjectConfig.getMsgMask().get(MsgMask.REPOBJMSG) && thread != null) { - // Check to see that messages may be received...determined by the REPOBJMSG - // bit in msg mask - send(Msg.makeMsg(null, REPOBJ_REQ, fromID, msg, future)); - } - */ - } - void deliverForwardedMsg(ID fromID, Event evt) { - /* - if (myContainerID != null) { - forwardToContainer(Msg.makeMsg(null, REPOBJ_FOR, fromID, msg)); - } else if ( - sharedObjectConfig.getMsgMask().get(MsgMask.REPOBJMSG) && thread != null) { - send(Msg.makeMsg(null, REPOBJ_FOR, fromID, msg)); - } - */ - } - void deliverRemoteMessageFailed( - ID toID, - Serializable object, - Throwable e) { - /* - if (sharedObjectConfig.getMsgMask().get(MsgMask.REPOBJMSG) && thread != null) { - send(Msg.makeMsg(null, REMOTE_REPOBJ_MSG_FAILED, toID, object, e)); - } - */ - } - - void destroySelf() { - /* - if (thread != null) { - send(Msg.makeMsg(null, REPOBJ_DESTROY_SELF)); - } - */ - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("SharedObjectWrapper[").append(getObjID()).append("]"); - return sb.toString(); - } - void handleRuntimeException(Throwable except) { - if (Debug.ON && debug != null) { - debug.dumpStack( - except, - "handleRuntimeException called for " + sharedObjectID); - } - try { - Debug.errDumpStack( - except, - "handleRuntimeException called for " + sharedObjectID); - } catch (Throwable e) { - } - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneConfig.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneConfig.java deleted file mode 100644 index 00d25ed11..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneConfig.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * 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.internal.impl.standalone; - -import java.util.Map; -import java.util.Hashtable; - -import org.eclipse.ecf.core.ISharedObjectContainerConfig; -import org.eclipse.ecf.core.identity.ID; - -public class StandaloneConfig implements ISharedObjectContainerConfig { - - protected ID id; - - public StandaloneConfig(ID theID) { - this.id = theID; - } - public ID getID() { - return id; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainerConfig#getProperties() - */ - public Map getProperties() { - return new Hashtable(); - } - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainerConfig#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainer.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainer.java deleted file mode 100644 index 194f660dd..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainer.java +++ /dev/null @@ -1,465 +0,0 @@ -/******************************************************************************* - * 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.internal.impl.standalone; - -import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.Hashtable; -import java.util.List; -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.ISharedObjectConnector; -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.ISharedObjectContainerConfig; -import org.eclipse.ecf.core.ISharedObjectContainerListener; -import org.eclipse.ecf.core.ISharedObjectContainerTransaction; -import org.eclipse.ecf.core.ISharedObjectManager; -import org.eclipse.ecf.core.SharedObjectAddException; -import org.eclipse.ecf.core.SharedObjectConnectException; -import org.eclipse.ecf.core.SharedObjectContainerJoinException; -import org.eclipse.ecf.core.SharedObjectCreateException; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.SharedObjectDisconnectException; -import org.eclipse.ecf.core.SharedObjectNotFoundException; -import org.eclipse.ecf.core.events.IContainerEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.AbstractFactory; -import org.osgi.framework.BundleContext; - -public class StandaloneContainer implements ISharedObjectContainer, - ISharedObjectManager { - - protected static final Object[] nullArgs = new Object[0]; - protected static final Class[] nullTypes = new Class[0]; - - ISharedObjectContainerConfig config = null; - Vector listeners = new Vector(); - Hashtable sharedObjectTable; - - BundleContext context = null; - - public static final String STANDALONE_NAME = "standalone"; - - public StandaloneContainer(StandaloneConfig config, BundleContext ctx) { - super(); - this.config = config; - sharedObjectTable = new Hashtable(); - this.context = ctx; - } - - public ISharedObjectManager getSharedObjectManager() { - return this; - } - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getPeerID() - */ - public ID getID() { - return config.getID(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getPeerConfig() - */ - public ISharedObjectContainerConfig getConfig() { - return config; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#addPeerListener(org.eclipse.ecf.core.ISharedObjectContainerListener) - */ - public void addListener(ISharedObjectContainerListener l, String filter) { - listeners.add(l); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#removePeerListener(org.eclipse.ecf.core.ISharedObjectContainerListener) - */ - public void removeListener(ISharedObjectContainerListener l) { - listeners.remove(l); - } - protected void fireListeners(IContainerEvent evt) { - for (Enumeration e = listeners.elements(); e.hasMoreElements();) { - ISharedObjectContainerListener l = (ISharedObjectContainerListener) e - .nextElement(); - l.handleEvent(evt); - } - } - - private void disposeSharedObjects() { - Enumeration e = sharedObjectTable.elements(); - while (e.hasMoreElements()) { - StandaloneSharedObjectWrapper wrapper = (StandaloneSharedObjectWrapper) e - .nextElement(); - wrapper.deactivated(); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#terminatePeer(long) - */ - public void dispose(long waittime) { - synchronized (sharedObjectTable) { - disposeSharedObjects(); - sharedObjectTable.clear(); - } - } - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#joinGroup(org.eclipse.ecf.identity.ID, - * java.lang.Object) - */ - public void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException { - throw new SharedObjectContainerJoinException( - "Standalone container cannot join external groups"); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup() - */ - public void leaveGroup() { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupID() - */ - public ID getGroupID() { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getGroupMembership() - */ - public ID[] getGroupMemberIDs() { - return new ID[] { getID() }; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupManager() - */ - public boolean isGroupManager() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#isGroupServer() - */ - public boolean isGroupServer() { - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectIDs() - */ - public ID[] getSharedObjectIDs() { - return (ID[]) sharedObjectTable.keySet().toArray(new ID[0]); - } - - protected static Object loadObject(final ClassLoader cl, String className, - String[] argTypes, Object[] a) throws Exception { - final Class[] types = AbstractFactory.getClassesForTypes(argTypes, a, - cl); - final Object[] args = (a == null) ? nullArgs : a; - // Load RepObject class(es), after getting appropriate classloader - final Class newClass = Class.forName(className, true, cl); - Object newObject = null; - try { - // Do privileged operation. Get appropriate constructor from new - // class, - // and create new instance. - newObject = AccessController - .doPrivileged(new PrivilegedExceptionAction() { - public Object run() throws Exception { - Constructor aConstructor = newClass - .getConstructor(types); - aConstructor.setAccessible(true); - // Now actually create the object. - return aConstructor.newInstance(args); - } - }); - } catch (PrivilegedActionException e) { - throw e.getException(); - } - return newObject; - } - protected ISharedObject loadSharedObject(SharedObjectDescription desc) - throws Exception { - ClassLoader descClassLoader = desc.getClassLoader(); - Map dict = desc.getProperties(); - String[] constructorArgTypes = null; - Object[] constructorArgs = null; - if (dict != null) { - constructorArgTypes = (String[]) dict.get("constructorArgTypes"); - constructorArgs = (Object[]) dict.get("constructorArgs"); - } - return (ISharedObject) loadObject( - (descClassLoader == null) ? getSharedObjectClassLoader(desc) - : descClassLoader, desc.getClassname(), - constructorArgTypes, constructorArgs); - } - protected ClassLoader getSharedObjectClassLoader( - SharedObjectDescription desc) { - return this.getClass().getClassLoader(); - } - - protected ISharedObject addSharedObjectAndWait(SharedObjectDescription sd, - ISharedObject s, ISharedObjectContainerTransaction t) - throws Exception { - if (sd.getID() == null || s == null) - return null; - // Wait right here until committed - ISharedObject so = addSharedObject0(sd, s); - if (t != null) - t.waitToCommit(); - return s; - } - protected ISharedObject addSharedObject0(SharedObjectDescription sd, - ISharedObject s) throws Exception { - addSharedObjectWrapper(makeNewSharedObjectWrapper(sd, s)); - return s; - } - protected StandaloneSharedObjectWrapper makeNewSharedObjectWrapper( - SharedObjectDescription sd, ISharedObject s) { - StandaloneSharedObjectConfig newConfig = makeNewSharedObjectConfig(sd, - this); - return new StandaloneSharedObjectWrapper(newConfig, s, this); - } - protected StandaloneSharedObjectConfig makeNewSharedObjectConfig( - SharedObjectDescription sd, StandaloneContainer cont) { - ID homeID = sd.getHomeID(); - if (homeID == null) - homeID = getID(); - return new StandaloneSharedObjectConfig(sd.getID(), homeID, this, sd - .getProperties()); - } - protected StandaloneSharedObjectWrapper addSharedObjectWrapper( - StandaloneSharedObjectWrapper wrapper) throws Exception { - if (wrapper == null) - return null; - ID id = wrapper.getObjID(); - synchronized (sharedObjectTable) { - if (sharedObjectTable.get(id) != null) { - throw new SharedObjectAddException("SharedObject with id " + id - + " already in use"); - } - // Put in table - sharedObjectTable.put(id, wrapper); - // Call initialize - wrapper.init(); - // Send activated message - wrapper.activated(getSharedObjectIDs()); - } - return wrapper; - } - - protected void notifySharedObjectActivated(ID activated) { - synchronized (sharedObjectTable) { - for (Enumeration e = sharedObjectTable.elements(); e - .hasMoreElements();) { - StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) e - .nextElement(); - if (!activated.equals(w.getObjID())) { - w.otherChanged(activated, getSharedObjectIDs(), true); - } - } - } - } - protected void notifySharedObjectDeactivated(ID deactivated) { - synchronized (sharedObjectTable) { - for (Enumeration e = sharedObjectTable.elements(); e - .hasMoreElements();) { - StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) e - .nextElement(); - if (!deactivated.equals(w.getObjID())) { - w.otherChanged(deactivated, getSharedObjectIDs(), false); - } - } - } - } - - protected Thread getSharedObjectThread(ID id, Runnable target, String name) { - return new Thread(target, name); - } - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#createSharedObject(org.eclipse.ecf.core.SharedObjectDescription) - */ - public ID createSharedObject(SharedObjectDescription sd, - ISharedObjectContainerTransaction trans) - throws SharedObjectCreateException { - ID result = null; - try { - ISharedObject so = loadSharedObject(sd); - result = sd.getID(); - addSharedObjectAndWait(sd, so, trans); - } catch (Exception e) { - throw new SharedObjectCreateException( - "Exception creating shared object", e); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#addSharedObject(org.eclipse.ecf.identity.ID, - * org.eclipse.ecf.core.ISharedObject, java.util.Map, - * org.eclipse.ecf.core.ISharedObjectContainerTransaction) - */ - public ID addSharedObject(ID sharedObjectID, ISharedObject sharedObject, - Map dict, ISharedObjectContainerTransaction trans) - throws SharedObjectAddException { - ID result = null; - try { - ISharedObject so = sharedObject; - result = sharedObjectID; - SharedObjectDescription sd = new SharedObjectDescription( - sharedObject.getClass().getClassLoader(), sharedObjectID, - getID(), sharedObject.getClass().getName(), dict, 0); - addSharedObjectAndWait(sd, so, trans); - } catch (Exception e) { - throw new SharedObjectAddException( - "Exception creating shared object", e); - } - return result; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectAdapter(org.eclipse.ecf.identity.ID, - * java.lang.Class) - */ - public Object getSharedObjectAdapter(ID sharedObjectID, Class adapterClass) - throws SharedObjectNotFoundException { - ISharedObject so = getSharedObject(sharedObjectID); - if (so == null) - throw new SharedObjectNotFoundException("Shared object " - + sharedObjectID.getName() + " not found"); - return so.getAdapter(adapterClass); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObject(org.eclipse.ecf.identity.ID) - */ - public ISharedObject getSharedObject(ID sharedObjectID) { - StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) sharedObjectTable - .get(sharedObjectID); - if (w == null) - return null; - else - return w.sharedObject; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#removeSharedObject(org.eclipse.ecf.identity.ID) - */ - public ISharedObject removeSharedObject(ID sharedObjectID) { - StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) sharedObjectTable - .remove(sharedObjectID); - if (w == null) - return null; - else - return w.sharedObject; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#connectSharedObjects(org.eclipse.ecf.identity.ID, - * org.eclipse.ecf.identity.ID[]) - */ - public ISharedObjectConnector connectSharedObjects(ID sharedObjectFrom, - ID[] sharedObjectsTo) throws SharedObjectConnectException { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObjectContainer#disconnectSharedObjects(org.eclipse.ecf.core.ISharedObjectConnector) - */ - public void disconnectSharedObjects(ISharedObjectConnector connector) - throws SharedObjectDisconnectException { - // TODO Auto-generated method stub - } - - /** - * Get the sharedObjectConnectors associated with the given sharedObjectID - * - * @return List of ISharedObjectConnector instances - */ - public List getSharedObjectConnectors(ID sharedObjectFrom) { - // TODO return actual list contents - return new ArrayList(); - } - - protected void sendCreate(ID objID, ID containerID, SharedObjectDescription sd) { - System.out.println("Container.sendCreate("+objID+","+containerID+","+sd+")"); - } - - protected void sendMessage(ID objID, ID containerID, Object data) { - System.out.println("Container.sendMessage("+objID+","+containerID+","+data+")"); - } - - protected void sendDispose(ID objID, ID containerID) { - System.out.println("Container.sendDispose("+objID+","+containerID+")"); - } - - protected IOSGIService getServiceAccess() { - if (context == null) return null; - else return new OSGIServiceAccessImpl(context); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerInstantiator.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerInstantiator.java deleted file mode 100644 index 0b0352da6..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerInstantiator.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Created on Dec 6, 2004 - * - */ -package org.eclipse.ecf.internal.impl.standalone; - -import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.identity.IDFactory; -import org.eclipse.ecf.core.identity.IDInstantiationException; -import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator; -import org.eclipse.ecf.internal.core.ECFPlugin; - -public class StandaloneContainerInstantiator implements - ISharedObjectContainerInstantiator { - - public StandaloneContainerInstantiator() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator#makeInstance(java.lang.Class[], java.lang.Object[]) - */ - public ISharedObjectContainer makeInstance(Class[] argTypes, Object[] args) - throws SharedObjectContainerInstantiationException { - ID newID = null; - if (args == null || args.length == 0) { - try { - newID = IDFactory.makeGUID(); - } catch (IDInstantiationException e) { - throw new SharedObjectContainerInstantiationException( - "Cannot create GUID ID for StandaloneContainer"); - } - } else { - try { - newID = IDFactory.makeStringID((String) args[0]); - } catch (IDInstantiationException e) { - throw new SharedObjectContainerInstantiationException( - "Cannot create GUID ID for StandaloneContainer"); - } - } - return new StandaloneContainer(new StandaloneConfig(newID),ECFPlugin.getDefault().getBundleContext()); - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerManager.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerManager.java deleted file mode 100644 index f8cf7efbc..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerManager.java +++ /dev/null @@ -1,335 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -import org.eclipse.ecf.core.SharedObjectNotFoundException; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.internal.impl.standalone.Debug; -import org.eclipse.ecf.internal.impl.standalone.gmm.GroupManager; -import org.eclipse.ecf.internal.impl.standalone.gmm.Item; -import org.eclipse.ecf.internal.impl.standalone.gmm.ItemChange; - -import java.util.Observer; -import java.util.Observable; -import java.util.HashSet; -import java.util.TreeMap; -import java.util.Iterator; - -class StandaloneContainerManager implements Observer { - static Debug myDebug = Debug.create(StandaloneContainerManager.class.getName()); - - StandaloneContainer container; - Item containerPeer; - GroupManager groupManager; - int maxItems = -1; - TreeMap loadingSharedObjects, activeSharedObjects; - - StandaloneContainerManager(StandaloneContainer space, Item ourMember) { - container = space; - groupManager = new GroupManager(); - groupManager.addObserver(this); - loadingSharedObjects = new TreeMap(); - activeSharedObjects = new TreeMap(); - addItem(ourMember); - containerPeer = ourMember; - } - - synchronized boolean addItem(Item m) { - if (maxItems > 0 && getSize() > maxItems) { - return false; - } else { - return groupManager.addItem(m); - } - } - synchronized int setMaxItems(int max) { - int old = maxItems; - maxItems = max; - return old; - } - synchronized int getMaxItems() { - return maxItems; - } - - synchronized boolean removeItem(Item m) { - boolean res = groupManager.removeItem(m); - if (res) { - destroySharedObjects(m); - } - return res; - } - - synchronized boolean removeItem(ID id) { - Item m = getItemForID(id); - if (m == null) - return false; - return removeItem(m); - } - - void removeAllItems() { - removeAllItems(null); - } - - void removeClientItems() { - removeAllItems(containerPeer); - } - - synchronized void removeAllItems(Item exception) { - Object m[] = getItems(); - for (int i = 0; i < m.length; i++) { - Item mem = (Item) m[i]; - if (exception == null || !exception.equals(mem)) - removeItem(mem); - } - } - - synchronized Object[] getItems() { - return groupManager.getItems(); - } - - synchronized ID[] getOtherItemIDs() { - return groupManager.getItemIDs(containerPeer.getID()); - } - - synchronized ID[] getItemIDs() { - return groupManager.getItemIDs(null); - } - - synchronized Item getItemForID(ID id) { - Item newItem = new Item(id); - for (Iterator i = iterator(); i.hasNext();) { - Item old = (Item) i.next(); - if (newItem.equals(old)) - return old; - } - return null; - } - - synchronized int getSize() { - return groupManager.getSize(); - } - - synchronized boolean containsItem(Item m) { - return groupManager.containsItem(m); - } - - synchronized Iterator iterator() { - return groupManager.iterator(); - } - - // End group membership change methods - - // Methods for adding/removing RepObjs - synchronized boolean addSharedObject(SharedObjectWrapper ro) { - // Verify that it's not already present anywhere - if (getFromAny(ro.getObjID()) != null) - return false; - // Add it to active map - addSharedObjectToActive(ro); - // Notify ro about existing members - return true; - } - - synchronized boolean addToLoading(SharedObjectContainer.LoadingSharedObject lro) { - /* - if (getFromAny(lro.getID()) != null) - return false; - loadingSharedObjects.put( - lro.getID(), - new SharedObjectWrapper(lro.getID(), lro.getHomeID(), lro, container)); - // And start the thing - lro.start(); - */ - return true; - } - - synchronized void moveFromLoadingToActive(SharedObjectWrapper ro) - throws SharedObjectNotFoundException { - if (removeSharedObjectFromLoading(ro.getObjID())) - addSharedObjectToActive(ro); - } - - boolean removeSharedObjectFromLoading(ID id) { - if (loadingSharedObjects.remove(id) != null) { - return true; - } else - return false; - } - - synchronized ID[] getActiveKeys() { - return (ID[]) activeSharedObjects.keySet().toArray(new ID[0]); - } - - void addSharedObjectToActive(SharedObjectWrapper ro) { - // Get current membership in ids array - ID[] ids = getActiveKeys(); - // Actually add to active map - activeSharedObjects.put(ro.getObjID(), ro); - // Pass array of IDs to replicated object - ro.activated(ids); - } - - synchronized void notifyOthersActivated(ID id) { - notifyOtherChanged(id, activeSharedObjects, true); - } - - synchronized void notifyOthersDeactivated(ID id) { - notifyOtherChanged(id, activeSharedObjects, false); - } - - void notifyOtherChanged(ID id, TreeMap aMap, boolean activated) { - for (Iterator i = aMap.values().iterator(); i.hasNext();) { - SharedObjectWrapper other = (SharedObjectWrapper) i.next(); - if (!id.equals(other.getObjID())) { - other.otherChanged(id, activated); - } - } - } - - synchronized void destroySharedObject(ID id) throws SharedObjectNotFoundException { - SharedObjectWrapper ro = removeFromMap(id, activeSharedObjects); - if (ro == null) - throw new SharedObjectNotFoundException(id + " not active"); - ro.deactivated(); - } - - synchronized SharedObjectWrapper getFromMap(ID objID, TreeMap aMap) { - return (SharedObjectWrapper) aMap.get(objID); - } - - synchronized SharedObjectWrapper removeFromMap(ID objID, TreeMap aMap) { - return (SharedObjectWrapper) aMap.remove(objID); - } - - SharedObjectWrapper getFromLoading(ID objID) { - return getFromMap(objID, loadingSharedObjects); - } - - SharedObjectWrapper getFromActive(ID objID) { - return getFromMap(objID, activeSharedObjects); - } - - synchronized SharedObjectWrapper getFromAny(ID objID) { - SharedObjectWrapper ro = getFromMap(objID, activeSharedObjects); - if (ro != null) - return ro; - ro = getFromMap(objID, loadingSharedObjects); - return ro; - } - - // Notification methods - void notifyAllOfItemChange(Item m, TreeMap map, boolean add) { - for (Iterator i = map.values().iterator(); i.hasNext();) { - SharedObjectWrapper ro = (SharedObjectWrapper) i.next(); - ro.memberChanged(m, add); - } - } - - public void update(Observable o, Object arg) { - ItemChange mc = (ItemChange) arg; - notifyAllOfItemChange(mc.getItem(), activeSharedObjects, mc.isAdd()); - } - - synchronized void destroySharedObjects(Item m) { - destroySharedObjects(m, true); - } - - synchronized void clear() { - destroySharedObjects(null, true); - } - - void destroySharedObjects(Item m, boolean match) { - HashSet set = getRemoveIDs(m.getID(), match); - Iterator i = set.iterator(); - - while (i.hasNext()) { - ID removeID = (ID) i.next(); - if (isLoading(removeID)) { - removeSharedObjectFromLoading(removeID); - } else { - container.removeSharedObject(removeID); - } - } - } - - HashSet getRemoveIDs(ID homeID, boolean match) { - HashSet aSet = new HashSet(); - for (Iterator i = new DestroyIterator(loadingSharedObjects, homeID, match); - i.hasNext(); - ) { - aSet.add(i.next()); - } - for (Iterator i = new DestroyIterator(activeSharedObjects, homeID, match); - i.hasNext(); - ) { - aSet.add(i.next()); - } - return aSet; - } - - synchronized boolean isActive(ID id) { - return activeSharedObjects.containsKey(id); - } - - synchronized boolean isLoading(ID id) { - return loadingSharedObjects.containsKey(id); - } - - boolean debug() { - if (myDebug == null) - return false; - return true; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("RSM["); - sb.append(groupManager); - sb.append(";L:").append(loadingSharedObjects); - sb.append(";A:").append(activeSharedObjects).append("]"); - return sb.toString(); - } - - class DestroyIterator implements Iterator { - ID next; - ID homeID; - Iterator i; - boolean match; - - public DestroyIterator(TreeMap map, ID hID, boolean m) { - i = map.values().iterator(); - homeID = hID; - next = null; - match = m; - } - - public boolean hasNext() { - if (next == null) - next = getNext(); - return (next != null); - } - - public Object next() { - if (hasNext()) { - ID value = next; - next = null; - return value; - } else { - throw new java.util.NoSuchElementException(); - } - } - - ID getNext() { - while (i.hasNext()) { - SharedObjectWrapper ro = (SharedObjectWrapper) i.next(); - if (homeID == null || (match ^ !ro.getHomeID().equals(homeID))) { - return ro.getObjID(); - } - } - return null; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - } - -} - diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java deleted file mode 100644 index 57036cc0f..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Created on Dec 6, 2004 - * - */ -package org.eclipse.ecf.internal.impl.standalone; - -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; -import org.eclipse.ecf.core.SharedObjectContainerJoinException; -import org.eclipse.ecf.core.SharedObjectDescription; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.QueueEnqueue; - -public class StandaloneContext implements ISharedObjectContext { - - StandaloneContainer container = null; - ID sharedObjectID; - ID homeContainerID; - boolean isActive; - Map properties; - QueueEnqueue queue; - - public StandaloneContext(ID objID, ID homeID, StandaloneContainer cont, Map props, QueueEnqueue queue) { - super(); - this.sharedObjectID = objID; - this.homeContainerID = homeID; - this.container = cont; - 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) - * @see org.eclipse.ecf.core.ISharedObjectContext#getContainerID() - */ - public synchronized ID getLocalContainerID() { - if (isInactive()) { - return null; - } return container.getConfig().getID(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getSharedObjectManager() - */ - public synchronized ISharedObjectManager getSharedObjectManager() { - if (isInactive()) { - return null; - } return container.getSharedObjectManager(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getQueue() - */ - public synchronized QueueEnqueue getQueue() { - if (isInactive()) { - return null; - } return queue; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#joinGroup(org.eclipse.ecf.core.identity.ID, java.lang.Object) - */ - public synchronized void joinGroup(ID groupID, Object loginData) - throws SharedObjectContainerJoinException { - if (isInactive()) { - return; - } else container.joinGroup(groupID,loginData); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#leaveGroup() - */ - public synchronized void leaveGroup() { - if (isInactive()) { - return; - } else container.leaveGroup(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getGroupID() - */ - public synchronized ID getGroupID() { - if (isInactive()) { - return null; - } else return container.getGroupID(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#isGroupManager() - */ - public synchronized boolean isGroupManager() { - if (isInactive()) { - return false; - } else return container.isGroupManager(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#isGroupServer() - */ - public synchronized boolean isGroupServer() { - if (isInactive()) { - return false; - } else return container.isGroupManager(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getGroupMembership() - */ - public synchronized ID[] getGroupMemberIDs() { - if (isInactive()) { - return null; - } else return container.getGroupMemberIDs(); - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#sendCreate(org.eclipse.ecf.core.identity.ID, org.eclipse.ecf.core.SharedObjectDescription) - */ - public synchronized void sendCreate(ID toContainerID, SharedObjectDescription sd) - throws IOException { - if (isInactive()) { - return; - } else { - container.sendCreate(sharedObjectID,toContainerID,sd); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#sendDispose(org.eclipse.ecf.core.identity.ID) - */ - public synchronized void sendDispose(ID toContainerID) throws IOException { - if (isInactive()) { - return; - } else { - container.sendDispose(sharedObjectID,toContainerID); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#sendMessage(org.eclipse.ecf.core.identity.ID, java.lang.Object) - */ - public void sendMessage(ID toContainerID, Object data) - throws IOException { - if (isInactive()) { - return; - } else { - container.sendMessage(sharedObjectID,toContainerID,data); - } - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class clazz) { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectContext#getServiceAccess() - */ - public IOSGIService getServiceAccess() { - if (isInactive()) { - return null; - } else { - return container.getServiceAccess(); - } - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectConfig.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectConfig.java deleted file mode 100644 index abfa9d379..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectConfig.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Created on Nov 29, 2004 - * - */ -package org.eclipse.ecf.internal.impl.standalone; - -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 StandaloneSharedObjectConfig implements ISharedObjectConfig { - - StandaloneContainer container = null; - ID sharedObjectID; - ID homeContainerID; - boolean isActive; - Map properties; - StandaloneContext standAloneContext; - - public StandaloneSharedObjectConfig(ID sharedObjectID, ID homeContainerID, StandaloneContainer cont, Map dict) { - super(); - this.sharedObjectID = sharedObjectID; - this.homeContainerID = homeContainerID; - isActive = false; - properties = dict; - this.container = cont; - } - - protected void makeActive(QueueEnqueue queue) { - isActive = true; - this.standAloneContext = new StandaloneContext(sharedObjectID,homeContainerID,container,properties,queue); - } - - protected void makeInactive() { - this.standAloneContext.makeInactive(); - this.standAloneContext = null; - isActive = false; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectConfig#getSharedObjectID() - */ - public ID getSharedObjectID() { - return sharedObjectID; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectConfig#getHomeContainerID() - */ - public ID getHomeContainerID() { - return homeContainerID; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectConfig#getContext() - */ - public ISharedObjectContext getContext() { - if (isActive) { - return null; - } else return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ecf.core.ISharedObjectConfig#getProperties() - */ - public Map getProperties() { - return properties; - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectWrapper.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectWrapper.java deleted file mode 100644 index 80859e24f..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectWrapper.java +++ /dev/null @@ -1,213 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone; - -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.SharedObjectActivatedEvent; -import org.eclipse.ecf.core.events.SharedObjectContainerDepartedEvent; -import org.eclipse.ecf.core.events.SharedObjectContainerJoinedEvent; -import org.eclipse.ecf.core.events.SharedObjectDeactivatedEvent; -import org.eclipse.ecf.core.identity.ID; -import org.eclipse.ecf.core.util.Event; -import org.eclipse.ecf.core.util.SimpleQueueImpl; -import org.eclipse.ecf.internal.impl.standalone.gmm.Item; - -final class StandaloneSharedObjectWrapper { - static Debug debug = Debug.create(StandaloneSharedObjectWrapper.class.getName()); - - protected ISharedObject sharedObject; - private StandaloneSharedObjectConfig sharedObjectConfig; - private ID sharedObjectID; - private ID sharedObjectHomeID; - private StandaloneContainer container; - private ID containerID; - private Thread thread; - private SimpleQueueImpl queue; - - StandaloneSharedObjectWrapper( - StandaloneSharedObjectConfig aConfig, - ISharedObject obj, - StandaloneContainer space) { - sharedObjectConfig = aConfig; - sharedObjectID = sharedObjectConfig.getSharedObjectID(); - sharedObjectHomeID = sharedObjectConfig.getHomeContainerID(); - sharedObject = obj; - container = space; - containerID = space.getID(); - thread = null; - queue = new SimpleQueueImpl(); - } - - void init() throws SharedObjectInitException { - sharedObject.init(sharedObjectConfig); - } - ID getObjID() { - return sharedObjectID; - } - - ID getHomeID() { - return sharedObjectHomeID; - } - - void activated(ID[] ids) { - // First, make space reference accessible to use by RepObject - sharedObjectConfig.makeActive(new QueueEnqueueImpl(queue)); - thread = - (Thread) AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - // Get thread instance - Thread aThread = getThread(); - return aThread; - } - }); - thread.start(); - send(new SharedObjectActivatedEvent(containerID, sharedObjectID, ids)); - container.notifySharedObjectActivated(sharedObjectID); - - } - void deactivated() { - send(new SharedObjectDeactivatedEvent(containerID,sharedObjectID)); - container.notifySharedObjectDeactivated(sharedObjectID); - destroyed(); - - } - private void destroyed() { - if (!queue.isStopped()) { - - sharedObjectConfig.makeInactive(); - // Enqueue destroy message on our RepObject's queue - if (thread != null) - queue.enqueue(new DisposeEvent()); - // Close queue...RepObject will receive no more messages from this point on. - queue.close(); - } - - } - void otherChanged(ID otherID, ID[] all, boolean activated) { - if (activated && thread != null) { - send(new SharedObjectActivatedEvent(containerID,otherID,all)); - } else { - send(new SharedObjectDeactivatedEvent(containerID,otherID)); - } - } - void memberChanged(Item m, boolean add) { - if (thread != null) { - if (add) { - send(new SharedObjectContainerJoinedEvent(containerID,m.getID())); - } else { - send(new SharedObjectContainerDepartedEvent(containerID,m.getID())); - } - } - } - Thread getThread() { - // Get new thread instance from space. - - return container - .getSharedObjectThread(sharedObjectID, new Runnable() { - public void run() { - if (Debug.ON && debug != null) { - debug.msg("Starting runner for " + sharedObjectID); - } - // The debug class will associate this thread with container - Debug.setThreadDebugGroup(container.getID()); - // Then process messages on queue until interrupted or queue closed - //Msg aMsg = null; - Event evt = null; - for (;;) { - // make sure the thread hasn't been interrupted and get Msg from SimpleQueueImpl - if (Thread.currentThread().isInterrupted()) - break; - - evt = (Event) queue.dequeue(); - if (Thread.currentThread().isInterrupted() || evt == null) - break; - - try { - if (evt instanceof ProcEvent) { - StandaloneSharedObjectWrapper.this.svc(((ProcEvent)evt).getEvent()); - } else if (evt instanceof DisposeEvent) { - StandaloneSharedObjectWrapper.this.doDestroy(); - } - } catch (Throwable t) { - if (Debug.ON && debug != null) { - debug.dumpStack( - t, - "Exception executing event " - + evt - + " on meta " - + this); - } - handleRuntimeException(t); - } - } - // If the thread was interrupted, then show appropriate spam - if (Thread.currentThread().isInterrupted()) { - if (Debug.ON && debug != null) { - debug.msg( - "Runner for " - + sharedObjectID - + " terminating after being interrupted"); - } - } else { - if (Debug.ON && debug != null) { - debug.msg( - "Runner for " + sharedObjectID + " terminating normally"); - } - } - } - }, "SOID:" + sharedObjectID); - } - 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 destroySelf() { - /* - if (thread != null) { - send(Msg.makeMsg(null, REPOBJ_DESTROY_SELF)); - } - */ - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("SharedObjectWrapper[").append(getObjID()).append("]"); - return sb.toString(); - } - void handleRuntimeException(Throwable except) { - if (Debug.ON && debug != null) { - debug.dumpStack( - except, - "handleRuntimeException called for " + sharedObjectID); - } - try { - Debug.errDumpStack( - except, - "handleRuntimeException called for " + sharedObjectID); - } catch (Throwable e) { - } - } - -} diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/GroupManager.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/GroupManager.java deleted file mode 100644 index a81894c3d..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/GroupManager.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone.gmm; - -import java.util.Observable; -import java.util.TreeSet; -import java.util.Iterator; - -import org.eclipse.ecf.core.identity.ID; - -public class GroupManager extends Observable { - TreeSet items; - - public GroupManager() { - items = new TreeSet(); - } - - public boolean addItem(Item m) { - boolean res = items.add(m); - if (res) { - setChanged(); - notifyObservers(new ItemChange(m, true)); - } - return res; - } - - public boolean removeItem(Item m) { - boolean res = items.remove(m); - if (res) { - setChanged(); - notifyObservers(new ItemChange(m, false)); - } - return res; - } - - public void removeAllItems() { - Object items[] = getItems(); - for (int i = 0; i < items.length; i++) { - removeItem((Item) items[i]); - } - } - - public Object[] getItems() { - return items.toArray(); - } - - public ID[] getItemIDs(ID exclude) { - TreeSet newSet = null; - if (exclude != null) { - newSet = (TreeSet) items.clone(); - newSet.remove(new Item(exclude)); - } else { - newSet = items; - } - ID ids[] = new ID[newSet.size()]; - Iterator iter = newSet.iterator(); - int j = 0; - while (iter.hasNext()) { - ids[j++] = (ID) ((Item) iter.next()).getID(); - } - return ids; - } - - public int getSize() { - return items.size(); - } - - public boolean containsItem(Item m) { - return items.contains(m); - } - - public Iterator iterator() { - return items.iterator(); - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("GMM").append(items); - return sb.toString(); - } -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/Item.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/Item.java deleted file mode 100644 index 1ce8c18f1..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/Item.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone.gmm; - -import org.eclipse.ecf.core.identity.ID; - -public class Item implements Comparable { - ID itemID; - Object itemData; - - public Item(ID id) { - this(id, null); - } - - public Item(ID id, Object data) { - itemID = id; - itemData = data; - } - - public boolean equals(Object o) { - if (o != null && o instanceof Item) { - return itemID.equals(((Item) o).itemID); - } else - return false; - } - - public int hashCode() { - return itemID.hashCode(); - } - - public int compareTo(Object o) { - if (o != null && o instanceof Item) { - return itemID.compareTo(((Item) o).itemID); - } else - return 0; - } - - public ID getID() { - return itemID; - } - - public Object getData() { - return itemData; - } - - public String toString() { - StringBuffer sb = new StringBuffer(); - sb.append("Item[").append(itemID).append(";").append( - itemData).append( - "]"); - return sb.toString(); - } - -}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/ItemChange.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/ItemChange.java deleted file mode 100644 index 2e5885d18..000000000 --- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/gmm/ItemChange.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.eclipse.ecf.internal.impl.standalone.gmm; - -public class ItemChange { - Item item; - boolean added; - - public ItemChange(Item item, boolean added) { - this.item = item; - this.added = added; - } - - public Item getItem() { - return item; - } - - public boolean isAdd() { - return added; - } -}
\ No newline at end of file |
