Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2004-12-07 08:03:16 +0000
committerslewis2004-12-07 08:03:16 +0000
commit63c91375d9d270cc6cef1082ecf6cd559d8b31a3 (patch)
treefe99e5e0396f37217b8c250f0d7a481594d1dc30
parent3436ffedb196640665ae8e8bdb8e5c8f5d282905 (diff)
downloadorg.eclipse.ecf-63c91375d9d270cc6cef1082ecf6cd559d8b31a3.tar.gz
org.eclipse.ecf-63c91375d9d270cc6cef1082ecf6cd559d8b31a3.tar.xz
org.eclipse.ecf-63c91375d9d270cc6cef1082ecf6cd559d8b31a3.zip
Removed static references to standalone container implementation.
Added extension point usage (containerFactory) to register standalone container. Added to functionality of standalone container with implementation of ISharedObjectContext in the ISharedObjectConfig instance. Added toString implementation for SharedObjectDescription.
-rw-r--r--framework/bundles/org.eclipse.ecf/.project4
-rw-r--r--framework/bundles/org.eclipse.ecf/plugin.xml7
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java2
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectContainerFactory.java12
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectDescription.java11
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/core/ECFPlugin.java8
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/OSGIServiceAccessImpl.java62
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/QueueEnqueueImpl.java101
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainer.java277
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerInstantiator.java46
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java190
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectConfig.java13
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneSharedObjectWrapper.java11
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/util/queue/SimpleQueueImpl.java3
14 files changed, 591 insertions, 156 deletions
diff --git a/framework/bundles/org.eclipse.ecf/.project b/framework/bundles/org.eclipse.ecf/.project
index a2d4a00a3..4d5cce329 100644
--- a/framework/bundles/org.eclipse.ecf/.project
+++ b/framework/bundles/org.eclipse.ecf/.project
@@ -24,6 +24,6 @@
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
- <nature>com.composent.client.collabnature</nature>
-</natures>
+ <nature>com.composent.client.collabnature</nature>
+ </natures>
</projectDescription>
diff --git a/framework/bundles/org.eclipse.ecf/plugin.xml b/framework/bundles/org.eclipse.ecf/plugin.xml
index b3e456446..7be7c7edf 100644
--- a/framework/bundles/org.eclipse.ecf/plugin.xml
+++ b/framework/bundles/org.eclipse.ecf/plugin.xml
@@ -3,4 +3,11 @@
<plugin>
<extension-point id="containerFactory" name="ECF Container Factory" schema="schema/containerFactory.exsd"/>
<extension-point id="namespace" name="ECF Namespace" schema="schema/namespace.exsd"/>
+ <extension
+ point="org.eclipse.ecf.containerFactory">
+ <containerFactory
+ class="org.eclipse.ecf.internal.impl.standalone.StandaloneContainerInstantiator"
+ description="standalone container implementation for testing"
+ name="standalone"/>
+ </extension>
</plugin>
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java
index 28c8412e1..b92e7b90a 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ISharedObjectContext.java
@@ -65,7 +65,7 @@ public interface ISharedObjectContext {
*
* @see org.eclipse.ecf.core.ISharedObjectContainer#leaveGroup()
*/
- public Object leaveGroup();
+ public void leaveGroup();
/**
* (non-Javadoc)
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 cbf35c02a..0d77c26aa 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
@@ -15,7 +15,6 @@ import java.util.List;
import org.eclipse.ecf.core.provider.ISharedObjectContainerInstantiator;
import org.eclipse.ecf.core.util.AbstractFactory;
-import org.eclipse.ecf.internal.impl.standalone.StandaloneContainer;
/**
* Factory for creating {@link ISharedObjectContainer} instances. This
@@ -36,19 +35,8 @@ import org.eclipse.ecf.internal.impl.standalone.StandaloneContainer;
*/
public class SharedObjectContainerFactory {
- protected static final String DEFAULT_SHAREDOBJECT_CONTAINER = "standalone";
- protected static final String DEFAULT_SHAREDOBJECT_CONTAINER_INSTANTIATOR = StandaloneContainer.Creator.class
- .getName();
- protected static final String DEFAULT_SHAREDOBJECT_CONTAINER_DESCRIPTION = "standalone container";
-
private static Hashtable containerdescriptions = new Hashtable();
- static {
- addDescription0(new SharedObjectContainerDescription(null,
- DEFAULT_SHAREDOBJECT_CONTAINER,
- DEFAULT_SHAREDOBJECT_CONTAINER_INSTANTIATOR,
- DEFAULT_SHAREDOBJECT_CONTAINER_DESCRIPTION));
- }
/*
* Add a SharedObjectContainerDescription to the set of known
* SharedObjectContainerDescriptions.
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectDescription.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectDescription.java
index cd9c8de43..bdb95de2a 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectDescription.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/SharedObjectDescription.java
@@ -111,4 +111,15 @@ public class SharedObjectDescription implements Serializable {
public void setIdentifier(long identifier) {
this.identifier = identifier;
}
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("SharedObjectDescription[");
+ sb.append("cl:").append(classLoader);
+ sb.append("oid:").append((id==null)?"null":(id.getName()));
+ sb.append("hid:").append((homeid==null)?"null":(homeid.getName()));
+ sb.append("cn:").append(className);
+ sb.append("props:").append(properties);
+ sb.append("id:").append(identifier).append("]");
+ return sb.toString();
+ }
} \ 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 4a3df1e52..b1fd4776a 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
@@ -65,6 +65,8 @@ public class ECFPlugin extends Plugin {
//Resource bundle.
private ResourceBundle resourceBundle;
+ BundleContext context = null;
+
public ECFPlugin() {
super();
plugin = this;
@@ -262,6 +264,7 @@ public class ECFPlugin extends Plugin {
super.start(context);
setupContainerExtensionPoint(context);
setupIdentityExtensionPoint(context);
+ this.context = context;
}
/**
@@ -269,6 +272,11 @@ public class ECFPlugin extends Plugin {
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
+ this.context = null;
+ }
+
+ public BundleContext getBundleContext() {
+ return context;
}
/**
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
new file mode 100644
index 000000000..27460f53f
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/OSGIServiceAccessImpl.java
@@ -0,0 +1,62 @@
+/*
+ * 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
new file mode 100644
index 000000000..c860d6069
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/QueueEnqueueImpl.java
@@ -0,0 +1,101 @@
+/*
+ * 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.internal.util.queue.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/StandaloneContainer.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainer.java
index 8e0cb7004..611f60297 100644
--- 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
@@ -9,17 +9,19 @@
package org.eclipse.ecf.internal.impl.standalone;
+import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
-import java.util.Map;
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;
@@ -29,7 +31,6 @@ 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.SharedObjectContainerInstantiationException;
import org.eclipse.ecf.core.SharedObjectContainerJoinException;
import org.eclipse.ecf.core.SharedObjectCreateException;
import org.eclipse.ecf.core.SharedObjectDescription;
@@ -37,12 +38,11 @@ import org.eclipse.ecf.core.SharedObjectDisconnectException;
import org.eclipse.ecf.core.SharedObjectNotFoundException;
import org.eclipse.ecf.core.events.ContainerEvent;
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.core.util.AbstractFactory;
+import org.osgi.framework.BundleContext;
-public class StandaloneContainer implements ISharedObjectContainer, ISharedObjectManager {
+public class StandaloneContainer implements ISharedObjectContainer,
+ ISharedObjectManager {
protected static final Object[] nullArgs = new Object[0];
protected static final Class[] nullTypes = new Class[0];
@@ -51,41 +51,15 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
Vector listeners = new Vector();
Hashtable sharedObjectTable;
+ BundleContext context = null;
+
public static final String STANDALONE_NAME = "standalone";
- public static class Creator implements ISharedObjectContainerInstantiator {
- /*
- * (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));
- }
- }
- public StandaloneContainer(StandaloneConfig config) {
+ public StandaloneContainer(StandaloneConfig config, BundleContext ctx) {
super();
this.config = config;
sharedObjectTable = new Hashtable();
+ this.context = ctx;
}
public ISharedObjectManager getSharedObjectManager() {
@@ -134,13 +108,14 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
}
}
- private void disposeSharedObjects() {
- Enumeration e = sharedObjectTable.elements();
- while (e.hasMoreElements()) {
- SharedObjectWrapper wrapper = (SharedObjectWrapper) e.nextElement();
- wrapper.deactivated();
- }
- }
+ private void disposeSharedObjects() {
+ Enumeration e = sharedObjectTable.elements();
+ while (e.hasMoreElements()) {
+ StandaloneSharedObjectWrapper wrapper = (StandaloneSharedObjectWrapper) e
+ .nextElement();
+ wrapper.deactivated();
+ }
+ }
/*
* (non-Javadoc)
@@ -224,7 +199,7 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
* @see org.eclipse.ecf.core.ISharedObjectContainer#getSharedObjectIDs()
*/
public ID[] getSharedObjectIDs() {
- return (ID[]) sharedObjectTable.keySet().toArray(new ID[0]);
+ return (ID[]) sharedObjectTable.keySet().toArray(new ID[0]);
}
protected static Object loadObject(final ClassLoader cl, String className,
@@ -254,96 +229,103 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
}
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 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();
+ for (Enumeration e = sharedObjectTable.elements(); e
+ .hasMoreElements();) {
+ StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) e
+ .nextElement();
if (!activated.equals(w.getObjID())) {
- w.otherChanged(activated,getSharedObjectIDs(),true);
+ w.otherChanged(activated, getSharedObjectIDs(), true);
}
}
}
}
protected void notifySharedObjectDeactivated(ID deactivated) {
synchronized (sharedObjectTable) {
- for(Enumeration e=sharedObjectTable.elements(); e.hasMoreElements(); ) {
- StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) e.nextElement();
+ for (Enumeration e = sharedObjectTable.elements(); e
+ .hasMoreElements();) {
+ StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) e
+ .nextElement();
if (!deactivated.equals(w.getObjID())) {
- w.otherChanged(deactivated,getSharedObjectIDs(),false);
+ w.otherChanged(deactivated, getSharedObjectIDs(), false);
}
}
}
}
-
+
protected Thread getSharedObjectThread(ID id, Runnable target, String name) {
- return new Thread(target,name);
+ return new Thread(target, name);
}
/*
* (non-Javadoc)
@@ -357,9 +339,10 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
try {
ISharedObject so = loadSharedObject(sd);
result = sd.getID();
- addSharedObjectAndWait(sd,so,trans);
+ addSharedObjectAndWait(sd, so, trans);
} catch (Exception e) {
- throw new SharedObjectCreateException("Exception creating shared object",e);
+ throw new SharedObjectCreateException(
+ "Exception creating shared object", e);
}
return result;
}
@@ -378,11 +361,13 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
try {
ISharedObject so = sharedObject;
result = sharedObjectID;
- SharedObjectDescription sd = new SharedObjectDescription(sharedObject.getClass().getClassLoader(),
- sharedObjectID,getID(),sharedObject.getClass().getName(),dict,0);
- addSharedObjectAndWait(sd,so,trans);
+ 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);
+ throw new SharedObjectAddException(
+ "Exception creating shared object", e);
}
return result;
}
@@ -396,7 +381,9 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
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");
+ if (so == null)
+ throw new SharedObjectNotFoundException("Shared object "
+ + sharedObjectID.getName() + " not found");
return so.getAdapter(adapterClass);
}
@@ -406,9 +393,12 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
* @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;
+ StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) sharedObjectTable
+ .get(sharedObjectID);
+ if (w == null)
+ return null;
+ else
+ return w.sharedObject;
}
/*
@@ -417,9 +407,12 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
* @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;
+ StandaloneSharedObjectWrapper w = (StandaloneSharedObjectWrapper) sharedObjectTable
+ .remove(sharedObjectID);
+ if (w == null)
+ return null;
+ else
+ return w.sharedObject;
}
/*
@@ -446,7 +439,7 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
/**
* Get the sharedObjectConnectors associated with the given sharedObjectID
- *
+ *
* @return List of ISharedObjectConnector instances
*/
public List getSharedObjectConnectors(ID sharedObjectFrom) {
@@ -454,4 +447,24 @@ public class StandaloneContainer implements ISharedObjectContainer, ISharedObjec
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, byte [] data) {
+ System.out.println("Container.sendMessage("+objID+","+containerID+","+new String(data)+")");
+ }
+
+ protected void sendMessage(ID objID, ID containerID, Serializable 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
new file mode 100644
index 000000000..0b0352da6
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContainerInstantiator.java
@@ -0,0 +1,46 @@
+/*
+ * 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/StandaloneContext.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java
new file mode 100644
index 000000000..74b67d597
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/impl/standalone/StandaloneContext.java
@@ -0,0 +1,190 @@
+/*
+ * Created on Dec 6, 2004
+ *
+ */
+package org.eclipse.ecf.internal.impl.standalone;
+
+import java.io.IOException;
+import java.io.Serializable;
+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 getContainerID() {
+ 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[] getGroupMembership() {
+ if (isInactive()) {
+ return null;
+ } else return container.getGroupMembership();
+ }
+
+ /* (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, byte[])
+ */
+ public void sendMessage(ID toContainerID, byte[] data) throws IOException {
+ if (isInactive()) {
+ return;
+ } else {
+ container.sendMessage(sharedObjectID,toContainerID,data);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.ISharedObjectContext#sendMessage(org.eclipse.ecf.core.identity.ID, java.io.Serializable)
+ */
+ public void sendMessage(ID toContainerID, Serializable 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
index b3737d38f..abfa9d379 100644
--- 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
@@ -9,6 +9,7 @@ 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 {
@@ -17,18 +18,26 @@ public class StandaloneSharedObjectConfig implements ISharedObjectConfig {
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;
- this.container = cont;
isActive = false;
properties = dict;
+ this.container = cont;
}
- protected void makeActive() {
+ 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)
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
index 248d55a0a..8a6c471ef 100644
--- 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
@@ -53,7 +53,7 @@ final class StandaloneSharedObjectWrapper {
void activated(ID[] ids) {
// First, make space reference accessible to use by RepObject
- sharedObjectConfig.makeActive();
+ sharedObjectConfig.makeActive(new QueueEnqueueImpl(queue));
thread =
(Thread) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
@@ -71,15 +71,12 @@ final class StandaloneSharedObjectWrapper {
send(new SharedObjectDeactivatedEvent(containerID,sharedObjectID));
container.notifySharedObjectDeactivated(sharedObjectID);
destroyed();
+
}
private void destroyed() {
if (!queue.isStopped()) {
- /*
- RepSpaceReference mySpaceRef = sharedObjectConfig.getSpaceReference();
- if (mySpaceRef != null) {
- mySpaceRef.clear();
- }
- */
+
+ sharedObjectConfig.makeInactive();
// Enqueue destroy message on our RepObject's queue
if (thread != null)
queue.enqueue(new DisposeEvent());
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/util/queue/SimpleQueueImpl.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/util/queue/SimpleQueueImpl.java
index 9b77a6cbf..00d186d20 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/util/queue/SimpleQueueImpl.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/internal/util/queue/SimpleQueueImpl.java
@@ -95,6 +95,9 @@ public class SimpleQueueImpl implements SimpleQueue {
return stopped;
}
+ public synchronized int size() {
+ return list.size();
+ }
public synchronized Object[] flush() {
Object[] out = list.toArray();
list.clear();

Back to the top