summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-14 09:50:57 (EST)
committerEike Stepper2007-02-14 09:50:57 (EST)
commitcfbb439e13c8403f3dc43ddcb068a709ae53b75a (patch)
tree8727604516bb89a5e0dedba006671702289b1c84
parentbe1781906d8d44d2214a978efc2c159b9ff03bef (diff)
downloadcdo-cfbb439e13c8403f3dc43ddcb068a709ae53b75a.zip
cdo-cfbb439e13c8403f3dc43ddcb068a709ae53b75a.tar.gz
cdo-cfbb439e13c8403f3dc43ddcb068a709ae53b75a.tar.bz2
Removed singletons
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java26
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java10
-rw-r--r--plugins/org.eclipse.net4j/.classpath2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java98
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java7
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java31
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ProtocolFactoryIDImpl.java76
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java22
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java13
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java15
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java19
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Channel.java7
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java32
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactory.java12
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactoryID.java23
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java27
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java12
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java97
19 files changed, 359 insertions, 172 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
index 3380ce9..23a813e 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
@@ -16,9 +16,10 @@ import org.eclipse.net4j.tests.signal.TestSignalProtocol;
import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.transport.Connector.Type;
import org.eclipse.net4j.util.Net4jUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.internal.net4j.transport.tcp.AbstractTCPConnector;
@@ -26,6 +27,7 @@ import org.eclipse.internal.net4j.transport.tcp.TCPAcceptorImpl;
import org.eclipse.internal.net4j.transport.tcp.TCPSelectorImpl;
import java.util.Arrays;
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -113,17 +115,20 @@ public class SignalTest extends AbstractOMTest
public void testInteger() throws Exception
{
ExecutorService threadPool = Executors.newCachedThreadPool();
- IRegistry<String, ProtocolFactory> registry = new HashMapRegistry();
+
+ Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> registries = //
+ Net4jUtil.createProtocolFactoryRegistries(ProtocolFactory.SYMMETRIC);
+
TestSignalProtocol.Factory factory = new TestSignalProtocol.Factory();
- registry.put(factory.getProtocolID(), factory);
+ Net4jUtil.registerProtocolFactory(factory, registries);
acceptor.setReceiveExecutor(threadPool);
- acceptor.setProtocolFactoryRegistry(registry);
+ acceptor.setProtocolFactoryRegistry(registries.get(Type.SERVER));
acceptor.activate();
assertTrue(acceptor.isActive());
connector.setReceiveExecutor(threadPool);
- connector.setProtocolFactoryRegistry(registry);
+ connector.setProtocolFactoryRegistry(registries.get(Type.CLIENT));
assertTrue(connector.connect(1000));
Channel channel = connector.openChannel(TestSignalProtocol.PROTOCOL_ID);
@@ -135,17 +140,20 @@ public class SignalTest extends AbstractOMTest
public void testArray() throws Exception
{
ExecutorService threadPool = Executors.newCachedThreadPool();
- IRegistry<String, ProtocolFactory> registry = new HashMapRegistry();
+
+ Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> registries = //
+ Net4jUtil.createProtocolFactoryRegistries(ProtocolFactory.SYMMETRIC);
+
TestSignalProtocol.Factory factory = new TestSignalProtocol.Factory();
- registry.put(factory.getProtocolID(), factory);
+ Net4jUtil.registerProtocolFactory(factory, registries);
acceptor.setReceiveExecutor(threadPool);
- acceptor.setProtocolFactoryRegistry(registry);
+ acceptor.setProtocolFactoryRegistry(registries.get(Type.SERVER));
acceptor.activate();
assertTrue(acceptor.isActive());
connector.setReceiveExecutor(threadPool);
- connector.setProtocolFactoryRegistry(registry);
+ connector.setProtocolFactoryRegistry(registries.get(Type.CLIENT));
assertTrue(connector.connect(1000));
Channel channel = connector.openChannel(TestSignalProtocol.PROTOCOL_ID);
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
index 39bf62b..8f80b72 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
@@ -17,6 +17,8 @@ import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.transport.Connector;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.transport.Connector.Type;
import org.eclipse.net4j.transport.tcp.TCPAcceptor;
import org.eclipse.net4j.transport.tcp.TCPAcceptorListener;
import org.eclipse.net4j.util.Net4jUtil;
@@ -154,9 +156,9 @@ public class TCPTransportTest extends AbstractOMTest
final int COUNT = 3;
final CountDownLatch counter = new CountDownLatch(COUNT);
- IRegistry<String, ProtocolFactory> protocolFactoryRegistry = new HashMapRegistry();
+ IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry = new HashMapRegistry();
TestProtocolFactory factory = new TestProtocolFactory(counter);
- protocolFactoryRegistry.put(factory.getProtocolID(), factory);
+ protocolFactoryRegistry.put(factory.createID(Type.SERVER), factory);
acceptor.setProtocolFactoryRegistry(protocolFactoryRegistry);
acceptor.activate();
@@ -236,9 +238,9 @@ public class TCPTransportTest extends AbstractOMTest
final int COUNT = 3;
final CountDownLatch counter = new CountDownLatch(COUNT);
- IRegistry<String, ProtocolFactory> protocolFactoryRegistry = new HashMapRegistry();
+ IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry = new HashMapRegistry();
TestProtocolFactory factory = new TestProtocolFactory(counter);
- protocolFactoryRegistry.put(factory.getProtocolID(), factory);
+ protocolFactoryRegistry.put(factory.createID(Type.SERVER), factory);
acceptor.setProtocolFactoryRegistry(protocolFactoryRegistry);
acceptor.setReceiveExecutor(Executors.newCachedThreadPool());
diff --git a/plugins/org.eclipse.net4j/.classpath b/plugins/org.eclipse.net4j/.classpath
index a0d07ad..4ec76c8 100644
--- a/plugins/org.eclipse.net4j/.classpath
+++ b/plugins/org.eclipse.net4j/.classpath
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry excluding="org/eclipse/internal/net4j/component/InactiveException.java|org/eclipse/net4j/transport/ChannelMultiplexer.java|org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java|org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java|org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java|org/eclipse/net4j/transport/tcp/TCPConnector.java" kind="src" path="src"/>
+ <classpathentry excluding="org/eclipse/internal/net4j/component/InactiveException.java|org/eclipse/net4j/transport/ChannelMultiplexer.java|org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java|org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java|org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java|org/eclipse/net4j/transport/tcp/TCPConnector.java|org/eclipse/internal/net4j/transport/ClientProtocolFactoryRegistry.java|org/eclipse/internal/net4j/transport/ServerProtocolFactoryRegistry.java" kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
index 8336bb6..f36c728 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java
@@ -14,8 +14,6 @@ import static org.eclipse.net4j.transport.Connector.State.CONNECTED;
import static org.eclipse.net4j.transport.Connector.State.CONNECTING;
import static org.eclipse.net4j.transport.Connector.State.DISCONNECTED;
import static org.eclipse.net4j.transport.Connector.State.NEGOTIATING;
-import static org.eclipse.net4j.transport.Connector.Type.CLIENT;
-import static org.eclipse.net4j.transport.Connector.Type.SERVER;
import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.BufferProvider;
@@ -26,12 +24,13 @@ import org.eclipse.net4j.transport.ConnectorDescription;
import org.eclipse.net4j.transport.ConnectorException;
import org.eclipse.net4j.transport.Protocol;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.util.Net4jUtil;
import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleListener;
import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.registry.HashMapDelegatingRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.internal.net4j.bundle.Net4j;
@@ -52,14 +51,7 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR, AbstractConnector.class);
- private static final ChannelImpl NULL_CHANNEL = new ChannelImpl(null)
- {
- @Override
- public String toString()
- {
- return "NullChannel"; //$NON-NLS-1$
- }
- };
+ private static final ChannelImpl NULL_CHANNEL = new NullChannel();
private static final int MIN_CONNECTOR_ID = 1;
@@ -73,7 +65,9 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
private ConnectorCredentials credentials;
- private IRegistry<String, ProtocolFactory> protocolFactoryRegistry;
+ private IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry;
+
+ private IRegistry<Integer, Connector> connectorRegistry;
private BufferProvider bufferProvider;
@@ -133,12 +127,12 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
this.receiveExecutor = receiveExecutor;
}
- public IRegistry<String, ProtocolFactory> getProtocolFactoryRegistry()
+ public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry()
{
return protocolFactoryRegistry;
}
- public void setProtocolFactoryRegistry(IRegistry<String, ProtocolFactory> protocolFactoryRegistry)
+ public void setProtocolFactoryRegistry(IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry)
{
this.protocolFactoryRegistry = protocolFactoryRegistry;
}
@@ -163,6 +157,16 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
channelListeners.remove(listener);
}
+ public IRegistry<Integer, Connector> getConnectorRegistry()
+ {
+ return connectorRegistry;
+ }
+
+ public void setConnectorRegistry(IRegistry<Integer, Connector> connectorRegistry)
+ {
+ this.connectorRegistry = connectorRegistry;
+ }
+
public BufferProvider getBufferProvider()
{
return bufferProvider;
@@ -239,8 +243,12 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
switch (newState)
{
case DISCONNECTED:
- REGISTRY.remove(connectorID);
- REGISTRY.commit();
+ if (connectorRegistry != null)
+ {
+ connectorRegistry.remove(connectorID);
+ connectorRegistry.commit();
+ }
+
if (finishedConnecting != null)
{
finishedConnecting.countDown();
@@ -269,8 +277,12 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
break;
case CONNECTED:
- REGISTRY.put(connectorID, this);
- REGISTRY.commit();
+ if (connectorRegistry != null)
+ {
+ connectorRegistry.put(connectorID, this);
+ connectorRegistry.commit();
+ }
+
finishedConnecting.countDown(); // Just in case of suspicion
finishedNegotiating.countDown();
break;
@@ -495,18 +507,14 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
protected Protocol createProtocol(String protocolID, Channel channel, Object protocolData)
{
- if (protocolID == null || protocolID.length() == 0)
+ if (protocolID == null || protocolID.length() == 0 || protocolFactoryRegistry == null)
{
return null;
}
- IRegistry<String, ProtocolFactory> registry = getProtocolFactoryRegistry();
- if (registry == null)
- {
- return null;
- }
+ ProtocolFactoryID protocolFactoryID = Net4jUtil.createProtocolFactoryID(getType(), protocolID);
+ ProtocolFactory factory = protocolFactoryRegistry.get(protocolFactoryID);
- ProtocolFactory factory = registry.get(protocolID);
if (factory == null)
{
if (TRACER.isEnabled())
@@ -589,25 +597,16 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
throw new IllegalStateException("bufferProvider == null"); //$NON-NLS-1$
}
- if (protocolFactoryRegistry == null)
+ if (protocolFactoryRegistry == null && TRACER.isEnabled())
{
- switch (getType())
- {
- case CLIENT:
- protocolFactoryRegistry = ProtocolFactory.CLIENT_REGISTRY;
- break;
- case SERVER:
- protocolFactoryRegistry = ProtocolFactory.SERVER_REGISTRY;
- break;
- }
-
- protocolFactoryRegistry = new HashMapDelegatingRegistry(protocolFactoryRegistry);
+ // Just a reminder during development
+ TRACER.trace("No receive protocolFactoryRegistry!"); //$NON-NLS-1$
}
if (receiveExecutor == null && TRACER.isEnabled())
{
// Just a reminder during development
- TRACER.trace("No receive executor!"); //$NON-NLS-1$
+ TRACER.trace("No receiveExecutor!"); //$NON-NLS-1$
}
}
@@ -658,6 +657,29 @@ public abstract class AbstractConnector<DESCRIPTION extends ConnectorDescription
}
/**
+ * @author Eike Stepper
+ */
+ private static final class NullChannel extends ChannelImpl
+ {
+ private NullChannel()
+ {
+ super(null);
+ }
+
+ @Override
+ public boolean isInternal()
+ {
+ return true;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "NullChannel"; //$NON-NLS-1$
+ }
+ }
+
+ /**
* Is registered with each {@link Channel} of this {@link Connector}.
* <p>
*
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java
index 5b143f9..e6630bc 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java
@@ -11,7 +11,9 @@
package org.eclipse.internal.net4j.transport;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
import org.eclipse.net4j.transport.Connector.Type;
+import org.eclipse.net4j.util.Net4jUtil;
import java.text.MessageFormat;
@@ -39,6 +41,11 @@ public abstract class AbstractProtocolFactory implements ProtocolFactory
return isForClients() && isForServers();
}
+ public ProtocolFactoryID createID(Type type)
+ {
+ return Net4jUtil.createProtocolFactoryID(type, getProtocolID());
+ }
+
@Override
public String toString()
{
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
index 8917ba3..0e8ee07 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
@@ -22,10 +22,10 @@ import org.eclipse.net4j.util.concurrent.SynchronousWorkSerializer;
import org.eclipse.net4j.util.concurrent.WorkSerializer;
import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.internal.net4j.bundle.Net4j;
import org.eclipse.internal.net4j.transport.BufferImpl.State;
-import org.eclipse.internal.net4j.transport.tcp.ControlChannelImpl;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -54,6 +54,8 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
private Queue<Buffer> sendQueue;
+ public IRegistry<ChannelID, Channel> channelRegistry;
+
public ChannelImpl(ExecutorService receiveExecutor)
{
this.receiveExecutor = receiveExecutor;
@@ -109,6 +111,16 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
return sendQueue;
}
+ public IRegistry<ChannelID, Channel> getChannelRegistry()
+ {
+ return channelRegistry;
+ }
+
+ public void setChannelRegistry(IRegistry<ChannelID, Channel> channelRegistry)
+ {
+ this.channelRegistry = channelRegistry;
+ }
+
public BufferHandler getReceiveHandler()
{
return receiveHandler;
@@ -124,6 +136,11 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
return receiveExecutor;
}
+ public boolean isInternal()
+ {
+ return false;
+ }
+
public void close()
{
deactivate();
@@ -209,20 +226,20 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
receiveSerializer = new AsynchronousWorkSerializer(receiveExecutor);
}
- if (!(this instanceof ControlChannelImpl))
+ if (!isInternal() && channelRegistry != null)
{
- Channel.REGISTRY.put(getID(), this);
- Channel.REGISTRY.commit();
+ channelRegistry.put(getID(), this);
+ channelRegistry.commit();
}
}
@Override
protected void onDeactivate() throws Exception
{
- if (!(this instanceof ControlChannelImpl))
+ if (!isInternal() && channelRegistry != null)
{
- Channel.REGISTRY.remove(getID());
- Channel.REGISTRY.commit();
+ channelRegistry.remove(getID());
+ channelRegistry.commit();
}
receiveSerializer = null;
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ProtocolFactoryIDImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ProtocolFactoryIDImpl.java
new file mode 100644
index 0000000..4374d75
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ProtocolFactoryIDImpl.java
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.internal.net4j.transport;
+
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.transport.Connector.Type;
+import org.eclipse.net4j.util.ObjectUtil;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public class ProtocolFactoryIDImpl implements ProtocolFactoryID, Cloneable, Serializable
+{
+ private static final long serialVersionUID = 1L;
+
+ private Type type;
+
+ private String protocolID;
+
+ public ProtocolFactoryIDImpl(Type type, String protocolID)
+ {
+ this.type = type;
+ this.protocolID = protocolID;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public String getProtocolID()
+ {
+ return protocolID;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ return this;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof ProtocolFactoryID)
+ {
+ ProtocolFactoryID that = (ProtocolFactoryID)obj;
+ return this.type == that.getType() && ObjectUtil.equals(this.protocolID, that.getProtocolID());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return type.hashCode() ^ protocolID.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}[{1}]", type, protocolID);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
index 5c2e7dc..e0b6803 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
@@ -67,7 +67,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector<TCPConnecto
/**
* SocketChannel must already be non-blocking!
*/
- public AbstractTCPConnector(SocketChannel socketChannel)
+ protected AbstractTCPConnector(SocketChannel socketChannel)
{
this.socketChannel = socketChannel;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
index 0f2e955..4020dbe 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
@@ -51,6 +51,12 @@ public final class ControlChannelImpl extends ChannelImpl
setConnector(connector);
}
+ @Override
+ public boolean isInternal()
+ {
+ return true;
+ }
+
public boolean registerChannel(short channelIndex, String protocolID)
{
assertValidChannelIndex(channelIndex);
@@ -77,14 +83,6 @@ public final class ControlChannelImpl extends ChannelImpl
handleBuffer(buffer);
}
- private void assertValidChannelIndex(short channelIndex)
- {
- if (channelIndex <= CONTROL_CHANNEL_ID)
- {
- throw new IllegalArgumentException("channelIndex <= CONTROL_CHANNEL_ID"); //$NON-NLS-1$
- }
- }
-
public void handleBufferFromMultiplexer(Buffer buffer)
{
try
@@ -179,4 +177,12 @@ public final class ControlChannelImpl extends ChannelImpl
byteBuffer.put(status ? SUCCESS : FAILURE);
handleBuffer(buffer);
}
+
+ private void assertValidChannelIndex(short channelIndex)
+ {
+ if (channelIndex <= CONTROL_CHANNEL_ID)
+ {
+ throw new IllegalArgumentException("channelIndex <= CONTROL_CHANNEL_ID"); //$NON-NLS-1$
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java
index 5d55adc..187f7f5 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java
@@ -10,28 +10,17 @@
**************************************************************************/
package org.eclipse.internal.net4j.transport.tcp;
-import org.eclipse.net4j.transport.BufferProvider;
-import org.eclipse.net4j.transport.ProtocolFactory;
-import org.eclipse.net4j.transport.tcp.TCPSelector;
-import org.eclipse.net4j.util.registry.IRegistry;
-
import java.net.SocketAddress;
import java.nio.channels.SocketChannel;
-import java.util.concurrent.ExecutorService;
/**
* @author Eike Stepper
*/
public class ServerTCPConnectorImpl extends AbstractTCPConnector
{
- public ServerTCPConnectorImpl(SocketChannel socketChannel, ExecutorService receiveExecutor,
- IRegistry<String, ProtocolFactory> protocolFactoryRegistry, BufferProvider bufferProvider, TCPSelector selector)
+ public ServerTCPConnectorImpl(SocketChannel socketChannel)
{
super(socketChannel);
- setReceiveExecutor(receiveExecutor);
- setProtocolFactoryRegistry(protocolFactoryRegistry);
- setBufferProvider(bufferProvider);
- setSelector(selector);
}
public Type getType()
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
index 16d4256..9112182 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
@@ -14,6 +14,7 @@ import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.transport.Connector;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
import org.eclipse.net4j.transport.tcp.TCPAcceptor;
import org.eclipse.net4j.transport.tcp.TCPAcceptorListener;
import org.eclipse.net4j.transport.tcp.TCPSelector;
@@ -51,7 +52,7 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, TCPAcceptorImpl.class);
- private IRegistry<String, ProtocolFactory> protocolFactoryRegistry;
+ private IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry;
private BufferProvider bufferProvider;
@@ -93,12 +94,12 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
this.receiveExecutor = receiveExecutor;
}
- public IRegistry<String, ProtocolFactory> getProtocolFactoryRegistry()
+ public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry()
{
return protocolFactoryRegistry;
}
- public void setProtocolFactoryRegistry(IRegistry<String, ProtocolFactory> protocolFactoryRegistry)
+ public void setProtocolFactoryRegistry(IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry)
{
this.protocolFactoryRegistry = protocolFactoryRegistry;
}
@@ -267,8 +268,12 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
protected AbstractTCPConnector createConnector(SocketChannel socketChannel)
{
- return new ServerTCPConnectorImpl(socketChannel, getReceiveExecutor(), getProtocolFactoryRegistry(),
- bufferProvider, selector);
+ ServerTCPConnectorImpl connector = new ServerTCPConnectorImpl(socketChannel);
+ connector.setReceiveExecutor(receiveExecutor);
+ connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
+ connector.setBufferProvider(bufferProvider);
+ connector.setSelector(selector);
+ return connector;
}
protected void fireConnectorAccepted(Connector connector)
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java
index fa4b5ed..5c2701f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java
@@ -27,8 +27,10 @@ public class TCPConnectorDescriptionImpl implements TCPConnectorDescription, Clo
private int port = DEFAULT_PORT;
- public TCPConnectorDescriptionImpl()
+ public TCPConnectorDescriptionImpl(String host, int port)
{
+ this.host = host;
+ this.port = port;
}
public String getHost()
@@ -36,21 +38,11 @@ public class TCPConnectorDescriptionImpl implements TCPConnectorDescription, Clo
return host;
}
- public void setHost(String host)
- {
- this.host = host;
- }
-
public int getPort()
{
return port;
}
- public void setPort(int port)
- {
- this.port = port;
- }
-
public String getDisplayName()
{
return MessageFormat.format("{0}:{1}", host, port);
@@ -59,10 +51,7 @@ public class TCPConnectorDescriptionImpl implements TCPConnectorDescription, Clo
@Override
protected Object clone() throws CloneNotSupportedException
{
- TCPConnectorDescriptionImpl description = new TCPConnectorDescriptionImpl();
- description.setHost(host);
- description.setPort(port);
- return description;
+ return new TCPConnectorDescriptionImpl(host, port);
}
@Override
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Channel.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Channel.java
index 2cf2f8d..f06345d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Channel.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Channel.java
@@ -10,10 +10,6 @@
**************************************************************************/
package org.eclipse.net4j.transport;
-import org.eclipse.net4j.util.lifecycle.Singleton;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
/**
* A bidirectional communications channel for the asynchronous exchange of
* {@link Buffer}s. A channel is lightweight and virtual in the sense that it
@@ -28,9 +24,6 @@ import org.eclipse.net4j.util.registry.IRegistry;
*/
public interface Channel extends BufferHandler
{
- @Singleton(stateful = true)
- public static final IRegistry<ChannelID, Channel> REGISTRY = new HashMapRegistry();
-
public short getChannelIndex();
public Connector getConnector();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
index 1ebdcd3..6d07c5a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
@@ -10,15 +10,9 @@
**************************************************************************/
package org.eclipse.net4j.transport;
-import org.eclipse.net4j.util.lifecycle.Singleton;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
import org.eclipse.internal.net4j.transport.AbstractConnector;
import org.eclipse.internal.net4j.transport.ChannelImpl;
-import java.util.concurrent.ExecutorService;
-
/**
* One endpoint of a physical connection of arbitrary nature between two
* communicating parties. A {@link Connector} encapsulates the process of
@@ -37,9 +31,6 @@ import java.util.concurrent.ExecutorService;
*/
public interface Connector<DESCRIPTION extends ConnectorDescription>
{
- @Singleton(stateful = true)
- public static final IRegistry<Integer, Connector> REGISTRY = new HashMapRegistry();
-
public Integer getID();
public Type getType();
@@ -112,29 +103,6 @@ public interface Connector<DESCRIPTION extends ConnectorDescription>
public Channel openChannel(String protocolID, Object protocolData) throws ConnectorException;
- /**
- * Returns the {@link IRegistry} of {@link ProtocolFactory}s associated with
- * this connector.
- * <p>
- *
- * @see #setProtocolFactoryRegistry(IRegistry)
- * @return The registry or <code>null</code>.
- */
- public IRegistry<String, ProtocolFactory> getProtocolFactoryRegistry();
-
- /**
- * Sets the {@link IRegistry} of {@link ProtocolFactory}s for this connector.
- * <p>
- *
- * @param protocolFactoryRegistry
- * The registry or <code>null</code>.
- */
- public void setProtocolFactoryRegistry(IRegistry<String, ProtocolFactory> protocolFactoryRegistry);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
-
public void addStateListener(StateListener listener);
public void removeStateListener(StateListener listener);
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactory.java
index e425039..79c82a1 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactory.java
@@ -11,10 +11,6 @@
package org.eclipse.net4j.transport;
import org.eclipse.net4j.transport.Connector.Type;
-import org.eclipse.net4j.util.lifecycle.Singleton;
-
-import org.eclipse.internal.net4j.transport.ClientProtocolFactoryRegistry;
-import org.eclipse.internal.net4j.transport.ServerProtocolFactoryRegistry;
import java.util.Arrays;
import java.util.Collections;
@@ -26,12 +22,6 @@ import java.util.Set;
*/
public interface ProtocolFactory
{
- @Singleton(stateful = true)
- public static final ClientProtocolFactoryRegistry CLIENT_REGISTRY = new ClientProtocolFactoryRegistry();
-
- @Singleton(stateful = true)
- public static final ServerProtocolFactoryRegistry SERVER_REGISTRY = new ServerProtocolFactoryRegistry();
-
public static final Set<Type> FOR_CLIENTS = Collections.singleton(Type.CLIENT);
public static final Set<Type> FOR_SERVERS = Collections.singleton(Type.SERVER);
@@ -49,5 +39,7 @@ public interface ProtocolFactory
public boolean isSymmetric();
+ public ProtocolFactoryID createID(Type type);
+
public Protocol createProtocol(Channel channel, Object protocolData);
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactoryID.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactoryID.java
new file mode 100644
index 0000000..c308f28
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ProtocolFactoryID.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.transport;
+
+import org.eclipse.net4j.transport.Connector.Type;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ProtocolFactoryID
+{
+ public Type getType();
+
+ public String getProtocolID();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java
new file mode 100644
index 0000000..6e925a0
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 Eike Stepper, Germany.
+ * 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:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.net4j.transport;
+
+import org.eclipse.net4j.util.registry.IRegistry;
+
+/**
+ * @author Eike Stepper
+ */
+public interface TransportContainer
+{
+ public BufferPool getBufferPool();
+
+ public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry();
+
+ public IRegistry<Integer, Connector> getConnectorRegistry();
+
+ public IRegistry<ChannelID, Channel> getChannelRegistry();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java
index 349d89c..90b9393 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java
@@ -11,10 +11,6 @@
package org.eclipse.net4j.transport.tcp;
import org.eclipse.net4j.transport.Connector;
-import org.eclipse.net4j.transport.ProtocolFactory;
-import org.eclipse.net4j.util.registry.IRegistry;
-
-import java.util.concurrent.ExecutorService;
/**
* @author Eike Stepper
@@ -31,15 +27,7 @@ public interface TCPAcceptor
public Connector[] getAcceptedConnectors();
- public IRegistry<String, ProtocolFactory> getProtocolFactoryRegistry();
-
- public void setProtocolFactoryRegistry(IRegistry<String, ProtocolFactory> protocolFactoryRegistry);
-
public void addAcceptorListener(TCPAcceptorListener listener);
public void removeAcceptorListener(TCPAcceptorListener listener);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java
index d0a419d..a119032 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java
@@ -13,17 +13,23 @@ package org.eclipse.net4j.util;
import org.eclipse.net4j.transport.BufferPool;
import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.transport.Channel;
+import org.eclipse.net4j.transport.ChannelID;
import org.eclipse.net4j.transport.Connector;
import org.eclipse.net4j.transport.Protocol;
import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.transport.TransportContainer;
import org.eclipse.net4j.transport.Connector.Type;
import org.eclipse.net4j.transport.tcp.TCPAcceptor;
import org.eclipse.net4j.transport.tcp.TCPConnectorDescription;
import org.eclipse.net4j.transport.tcp.TCPSelector;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
import org.eclipse.internal.net4j.transport.BufferFactoryImpl;
import org.eclipse.internal.net4j.transport.BufferPoolImpl;
import org.eclipse.internal.net4j.transport.BufferUtil;
+import org.eclipse.internal.net4j.transport.ProtocolFactoryIDImpl;
import org.eclipse.internal.net4j.transport.embedded.ClientEmbeddedConnectorImpl;
import org.eclipse.internal.net4j.transport.tcp.ClientTCPConnectorImpl;
import org.eclipse.internal.net4j.transport.tcp.TCPAcceptorImpl;
@@ -32,7 +38,11 @@ import org.eclipse.internal.net4j.transport.tcp.TCPSelectorImpl;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
/**
* @author Eike Stepper
@@ -68,6 +78,11 @@ public final class Net4jUtil
return createBufferPool(createBufferFactory());
}
+ public static ProtocolFactoryID createProtocolFactoryID(Type type, String protocolID)
+ {
+ return new ProtocolFactoryIDImpl(type, protocolID);
+ }
+
public static Connector createEmbeddedConnector(BufferProvider bufferProvider)
{
ClientEmbeddedConnectorImpl connector = new ClientEmbeddedConnectorImpl();
@@ -94,14 +109,10 @@ public final class Net4jUtil
public static Connector<TCPConnectorDescription> createTCPConnector(BufferProvider bufferProvider,
TCPSelector selector, String host, int port)
{
- TCPConnectorDescriptionImpl description = new TCPConnectorDescriptionImpl();
- description.setHost(host);
- description.setPort(port);
-
ClientTCPConnectorImpl connector = new ClientTCPConnectorImpl();
connector.setBufferProvider(bufferProvider);
connector.setSelector(selector);
- connector.setDescription(description);
+ connector.setDescription(new TCPConnectorDescriptionImpl(host, port));
return connector;
}
@@ -116,14 +127,20 @@ public final class Net4jUtil
return new TCPSelectorImpl();
}
- public static Collection<Channel> getChannels(String protocolID, Set<Type> types)
+ public static Collection<Channel> getChannels(TransportContainer container, String protocolID, Set<Type> types)
{
if (types == null)
{
types = ProtocolFactory.SYMMETRIC;
}
- Collection<Channel> channels = Channel.REGISTRY.values();
+ IRegistry<ChannelID, Channel> channelRegistry = container.getChannelRegistry();
+ if (channelRegistry == null)
+ {
+ return null;
+ }
+
+ Collection<Channel> channels = channelRegistry.values();
Collection<Channel> result = new ArrayList(channels.size());
for (Channel channel : channels)
{
@@ -150,13 +167,71 @@ public final class Net4jUtil
return result;
}
- public static Collection<Channel> getChannels(String protocolID)
+ public static Collection<Channel> getChannels(TransportContainer container, String protocolID)
+ {
+ return getChannels(container, protocolID, null);
+ }
+
+ public static Collection<Channel> getChannels(TransportContainer container, Set<Type> types)
{
- return getChannels(protocolID, null);
+ return getChannels(container, null, types);
}
- public static Collection<Channel> getChannels(Set<Type> types)
+ public static Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> createProtocolFactoryRegistries(Set<Type> types)
{
- return getChannels(null, types);
+ Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> result = new HashMap();
+ for (Type type : types)
+ {
+ result.put(type, new HashMapRegistry());
+ }
+
+ return result;
+ }
+
+ public static Set<Type> registerProtocolFactory(ProtocolFactory factory,
+ Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> registries)
+ {
+ Set<Type> result = new HashSet();
+ for (Entry<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> entry : registries.entrySet())
+ {
+ Type type = entry.getKey();
+ IRegistry<ProtocolFactoryID, ProtocolFactory> registry = entry.getValue();
+ if (factory.getConnectorTypes().contains(type))
+ {
+ ProtocolFactoryID id = factory.createID(type);
+ if (!registry.containsKey(id))
+ {
+ registry.put(id, factory);
+ }
+ else
+ {
+ result.add(type);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static Set<Type> deregisterProtocolFactory(ProtocolFactory factory,
+ Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> registries)
+ {
+ Set<Type> result = new HashSet();
+ for (Entry<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> entry : registries.entrySet())
+ {
+ Type type = entry.getKey();
+ IRegistry<ProtocolFactoryID, ProtocolFactory> registry = entry.getValue();
+ if (factory.getConnectorTypes().contains(type))
+ {
+ ProtocolFactoryID id = factory.createID(type);
+ ProtocolFactory old = registry.remove(id);
+ if (old != null)
+ {
+ result.add(type);
+ }
+ }
+ }
+
+ return result;
}
}