Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-08-06 02:16:29 +0000
committerslewis2007-08-06 02:16:29 +0000
commit9733520c17132c2352e7ffdf7ac2e215c35bbf8a (patch)
tree7685eeae0bdb1c024a3153a50b9396355ce95de8 /framework/bundles/org.eclipse.ecf
parent29e9d3a1de12a06b853d43ea5209e693b40d78ec (diff)
downloadorg.eclipse.ecf-9733520c17132c2352e7ffdf7ac2e215c35bbf8a.tar.gz
org.eclipse.ecf-9733520c17132c2352e7ffdf7ac2e215c35bbf8a.tar.xz
org.eclipse.ecf-9733520c17132c2352e7ffdf7ac2e215c35bbf8a.zip
Added container manager and container manager listener changes. Also refactoring of ContainerFactory.
Diffstat (limited to 'framework/bundles/org.eclipse.ecf')
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerFactory.java163
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManager.java16
-rw-r--r--framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManagerListener.java40
3 files changed, 175 insertions, 44 deletions
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerFactory.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerFactory.java
index 122020205..99938829e 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerFactory.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/ContainerFactory.java
@@ -11,9 +11,7 @@
package org.eclipse.ecf.core;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.HashMap;
-import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -51,11 +49,13 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
public static final String BASE_CONTAINER_NAME = Messages.ContainerFactory_Base_Container_Name;
- private static Hashtable containerdescriptions = new Hashtable();
+ private static final Map containerdescriptions = new HashMap();
- private static IContainerFactory instance = null;
+ private static final Map containers = new HashMap();
- private static Map containers = Collections.synchronizedMap(new HashMap());
+ private static final List managerListeners = new ArrayList();
+
+ private static IContainerFactory instance = null;
static {
instance = new ContainerFactory();
@@ -66,35 +66,34 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
}
protected ContainerFactory() {
- ECFPlugin ecfplugin = ECFPlugin.getDefault();
- if (ecfplugin != null) {
- ecfplugin.addDisposable(new IDisposable() {
- public void dispose() {
- synchronized (containers) {
- for (Iterator i = containers.keySet().iterator(); i
- .hasNext();) {
- IContainer c = (IContainer) containers
- .get(i.next());
- try {
- c.dispose();
- } catch (Throwable e) {
- // Log exception
- ECFPlugin.getDefault().log(
- new Status(Status.ERROR, ECFPlugin
- .getDefault().getBundle()
- .getSymbolicName(),
- Status.ERROR,
- "container dispose error", e)); //$NON-NLS-1$
- Trace.catching(ECFPlugin.PLUGIN_ID,
- ECFDebugOptions.EXCEPTIONS_CATCHING,
- ContainerFactory.class, "doDispose", e); //$NON-NLS-1$
- }
+ ECFPlugin.getDefault().addDisposable(new IDisposable() {
+ public void dispose() {
+ synchronized (containers) {
+ for (Iterator i = containers.keySet().iterator(); i
+ .hasNext();) {
+ IContainer c = (IContainer) containers
+ .get(i.next());
+ try {
+ c.dispose();
+ } catch (Throwable e) {
+ // Log exception
+ ECFPlugin.getDefault().log(
+ new Status(Status.ERROR, ECFPlugin
+ .getDefault().getBundle()
+ .getSymbolicName(),
+ Status.ERROR,
+ "container dispose error", e)); //$NON-NLS-1$
+ Trace.catching(ECFPlugin.PLUGIN_ID,
+ ECFDebugOptions.EXCEPTIONS_CATCHING,
+ ContainerFactory.class, "doDispose", e); //$NON-NLS-1$
}
- containers.clear();
}
+ containers.clear();
}
- });
- }
+ containerdescriptions.clear();
+ managerListeners.clear();
+ }
+ });
}
/*
@@ -107,7 +106,26 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
ID containerID = container.getID();
Assert.isNotNull(containerID,
Messages.ContainerFactory_EXCEPTION_CONTAINER_ID_NOT_NULL);
- return (IContainer) containers.put(containerID, container);
+ IContainer result = null;
+ synchronized (containers) {
+ result = (IContainer) containers.put(containerID, container);
+ }
+ if (result == null) fireContainerAdded(container);
+ return result;
+ }
+
+ /**
+ * @param result
+ */
+ private void fireContainerAdded(IContainer result) {
+ List toNotify = null;
+ synchronized (managerListeners) {
+ toNotify = new ArrayList(managerListeners);
+ }
+ for(Iterator i=toNotify.iterator(); i.hasNext(); ) {
+ IContainerManagerListener cml = (IContainerManagerListener) i.next();
+ cml.containerAdded(result);
+ }
}
/*
@@ -120,7 +138,26 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
ID containerID = container.getID();
if (containerID == null)
return null;
- return (IContainer) containers.remove(containerID);
+ IContainer result = null;
+ synchronized (containers) {
+ result = (IContainer) containers.remove(containerID);
+ }
+ if (result != null) fireContainerRemoved(result);
+ return result;
+ }
+
+ /**
+ * @param result
+ */
+ private void fireContainerRemoved(IContainer result) {
+ List toNotify = null;
+ synchronized (managerListeners) {
+ toNotify = new ArrayList(managerListeners);
+ }
+ for(Iterator i=toNotify.iterator(); i.hasNext(); ) {
+ IContainerManagerListener cml = (IContainerManagerListener) i.next();
+ cml.containerRemoved(result);
+ }
}
/*
@@ -142,15 +179,19 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
}
protected List getDescriptions0() {
- return new ArrayList(containerdescriptions.values());
+ synchronized (containerdescriptions) {
+ return new ArrayList(containerdescriptions.values());
+ }
}
protected ContainerTypeDescription addDescription0(
ContainerTypeDescription n) {
if (n == null)
return null;
- return (ContainerTypeDescription) containerdescriptions.put(
- n.getName(), n);
+ synchronized (containerdescriptions) {
+ return (ContainerTypeDescription) containerdescriptions.put(
+ n.getName(), n);
+ }
}
/*
@@ -165,21 +206,27 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
protected boolean containsDescription0(ContainerTypeDescription scd) {
if (scd == null)
return false;
- return containerdescriptions.containsKey(scd.getName());
+ synchronized (containerdescriptions) {
+ return containerdescriptions.containsKey(scd.getName());
+ }
}
protected ContainerTypeDescription getDescription0(
ContainerTypeDescription scd) {
if (scd == null)
return null;
- return (ContainerTypeDescription) containerdescriptions.get(scd
- .getName());
+ synchronized (containerdescriptions) {
+ return (ContainerTypeDescription) containerdescriptions.get(scd
+ .getName());
+ }
}
protected ContainerTypeDescription getDescription0(String name) {
if (name == null)
return null;
- return (ContainerTypeDescription) containerdescriptions.get(name);
+ synchronized (containerdescriptions) {
+ return (ContainerTypeDescription) containerdescriptions.get(name);
+ }
}
/*
@@ -291,8 +338,10 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
ContainerTypeDescription n) {
if (n == null)
return null;
- return (ContainerTypeDescription) containerdescriptions.remove(n
- .getName());
+ synchronized (containerdescriptions) {
+ return (ContainerTypeDescription) containerdescriptions.remove(n
+ .getName());
+ }
}
/*
@@ -328,7 +377,10 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
* @see org.eclipse.ecf.core.IContainerManager#getAllContainers()
*/
public IContainer[] getAllContainers() {
- List containersList = new ArrayList(containers.values());
+ List containersList = null;
+ synchronized (containers) {
+ containersList = new ArrayList(containers.values());
+ }
return (IContainer[]) containersList.toArray(new IContainer[] {});
}
@@ -356,6 +408,29 @@ public class ContainerFactory implements IContainerFactory, IContainerManager {
* @see org.eclipse.ecf.core.IContainerManager#hasContainer(org.eclipse.ecf.core.identity.ID)
*/
public boolean hasContainer(ID containerID) {
- return containers.containsKey(containerID);
+ Assert.isNotNull(containerID);
+ synchronized (containers) {
+ return containers.containsKey(containerID);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainerManager#addListener(org.eclipse.ecf.core.IContainerManagerListener)
+ */
+ public boolean addListener(IContainerManagerListener listener) {
+ Assert.isNotNull(listener);
+ synchronized (managerListeners) {
+ return managerListeners.add(listener);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.core.IContainerManager#removeListener(org.eclipse.ecf.core.IContainerManagerListener)
+ */
+ public boolean removeListener(IContainerManagerListener listener) {
+ Assert.isNotNull(listener);
+ synchronized (managerListeners) {
+ return managerListeners.remove(listener);
+ }
}
} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManager.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManager.java
index a31d65662..a6a247e90 100644
--- a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManager.java
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManager.java
@@ -74,4 +74,20 @@ public interface IContainerManager {
* then <code>null</code> will be returned.
*/
public IContainer removeContainer(IContainer container);
+
+ /**
+ * Add listener to this {@link IContainerManager}.
+ *
+ * @param listener the listener to add. Must not be <code>null</code>.
+ * @return true if listener successfully added
+ */
+ public boolean addListener(IContainerManagerListener listener);
+
+ /**
+ * Remove listener from this {@link IContainerManager}.
+ *
+ * @param listener the listener to remove. Must not be <code>null</code>.
+ * @return true if listener successfully removed
+ */
+ public boolean removeListener(IContainerManagerListener listener);
}
diff --git a/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManagerListener.java b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManagerListener.java
new file mode 100644
index 000000000..3fffc3e1f
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf/src/org/eclipse/ecf/core/IContainerManagerListener.java
@@ -0,0 +1,40 @@
+/****************************************************************************
+ * 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;
+
+/**
+ * Container manager listener. Instances of this interface may be registered via
+ * calls to {@link IContainerManager#addListener(IContainerManagerListener)}.
+ * When subsequent additions to the {@link IContainerManager} occur, the
+ * {@link #containerAdded(IContainer)} method will be called. When container
+ * removals occur, {@link #containerRemoved(IContainer)}. Note that these
+ * methods will be called by arbitrary threads.
+ *
+ */
+public interface IContainerManagerListener {
+
+ /**
+ * Container added to the implementing IContainerManager.
+ *
+ * @param container
+ * the {@link IContainer} added. Will not be <code>null</code>.
+ */
+ public void containerAdded(IContainer container);
+
+ /**
+ * Container removed from the implementing IContainerManager.
+ *
+ * @param container
+ * the {@link IContainer} removed. Will not be <code>null</code>.
+ */
+ public void containerRemoved(IContainer container);
+}

Back to the top