summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-14 13:23:31 (EST)
committerEike Stepper2007-02-14 13:23:31 (EST)
commitf649f5c71635a524992d733a29c68fc0f2d3223b (patch)
tree5e51627c991b1e488ea40dfb9d4fa056f393ba25
parent8bbad56489994baf6d8021043735639e7cb70fc0 (diff)
downloadcdo-f649f5c71635a524992d733a29c68fc0f2d3223b.zip
cdo-f649f5c71635a524992d733a29c68fc0f2d3223b.tar.gz
cdo-f649f5c71635a524992d733a29c68fc0f2d3223b.tar.bz2
Introduced containers
-rw-r--r--plugins/org.eclipse.net4j.debug/src/org/eclipse/net4j/internal/debug/RemoteTraceManager.java4
-rw-r--r--plugins/org.eclipse.net4j/META-INF/MANIFEST.MF11
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java8
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocol.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocolFactory.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java15
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ProtocolFactoryIDImpl.java12
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/AbstractContainer.java105
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterIDImpl.java75
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterImpl.java41
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerImpl.java135
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java353
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java57
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java188
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java60
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java344
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorFactoryImpl.java31
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java372
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java127
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ConnectorFactory.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java243
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/Container.java47
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapter.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorFactory.java)10
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterFactory.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java)15
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterID.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptorListener.java)17
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerUtil.java249
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java33
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelector.java36
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelectorListener.java43
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/package.html43
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java235
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java4
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Value.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorDescription.java)22
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleImpl.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java)8
35 files changed, 734 insertions, 2307 deletions
diff --git a/plugins/org.eclipse.net4j.debug/src/org/eclipse/net4j/internal/debug/RemoteTraceManager.java b/plugins/org.eclipse.net4j.debug/src/org/eclipse/net4j/internal/debug/RemoteTraceManager.java
index 818a62a..b5a63a5 100644
--- a/plugins/org.eclipse.net4j.debug/src/org/eclipse/net4j/internal/debug/RemoteTraceManager.java
+++ b/plugins/org.eclipse.net4j.debug/src/org/eclipse/net4j/internal/debug/RemoteTraceManager.java
@@ -11,7 +11,7 @@
package org.eclipse.net4j.internal.debug;
import org.eclipse.net4j.internal.debug.views.RemoteTraceView;
-import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
import org.eclipse.net4j.util.lifecycle.Singleton;
import org.eclipse.net4j.util.om.trace.RemoteTraceServer;
import org.eclipse.net4j.util.om.trace.RemoteTraceServer.Event;
@@ -23,7 +23,7 @@ import java.util.List;
/**
* @author Eike Stepper
*/
-public class RemoteTraceManager extends AbstractLifecycle implements Listener
+public class RemoteTraceManager extends LifecycleImpl implements Listener
{
@Singleton
public static final RemoteTraceManager INSTANCE = new RemoteTraceManager();
diff --git a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
index 089033d..ed51d5e 100644
--- a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
@@ -10,17 +10,20 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.eclipse.osgi.service.debug;version="1.0.0";resolution:=optional,
org.osgi.framework;version="1.3.0";resolution:=optional,
org.osgi.service.log;version="1.3.0";resolution:=optional,
- org.osgi.util.tracker;version="1.3.2";resolution:=optional
-Export-Package: org.eclipse.internal.net4j.transport;version="0.8.0",
+ org.osgi.util.tracker;version="1.3.0";resolution:=optional
+Export-Package: org.eclipse.internal.net4j.bundle;version="0.8.0",
+ org.eclipse.internal.net4j.transport;version="0.8.0",
+ org.eclipse.internal.net4j.transport.container;version="0.8.0",
org.eclipse.internal.net4j.transport.embedded;version="0.8.0",
- org.eclipse.internal.net4j.transport.tcp;version="0.8.0",
+ org.eclipse.internal.net4j.util;version="0.8.0",
org.eclipse.net4j;version="0.8.0",
org.eclipse.net4j.message;version="0.8.0",
org.eclipse.net4j.remote;version="0.8.0",
org.eclipse.net4j.signal;version="0.8.0",
org.eclipse.net4j.stream;version="0.8.0",
org.eclipse.net4j.transport;version="0.8.0",
- org.eclipse.net4j.transport.tcp;version="0.8.0",
+ org.eclipse.net4j.transport.container;version="0.8.0",
+ org.eclipse.net4j.user;version="0.8.0",
org.eclipse.net4j.util;version="0.8.0",
org.eclipse.net4j.util.concurrent;version="0.8.0",
org.eclipse.net4j.util.lifecycle;version="0.8.0",
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 b69fe54..b2571c4 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
@@ -20,8 +20,8 @@ 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.transport.container.ContainerUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
import org.eclipse.net4j.util.lifecycle.LifecycleListener;
import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -41,7 +41,7 @@ import java.util.concurrent.TimeUnit;
/**
* @author Eike Stepper
*/
-public abstract class AbstractConnector extends AbstractLifecycle implements Connector, BufferProvider
+public abstract class AbstractConnector extends LifecycleImpl implements Connector, BufferProvider
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR, AbstractConnector.class);
@@ -506,7 +506,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
return null;
}
- ProtocolFactoryID protocolFactoryID = Net4jUtil.createProtocolFactoryID(getType(), protocolID);
+ ProtocolFactoryID protocolFactoryID = ContainerUtil.createProtocolFactoryID(getType(), protocolID);
ProtocolFactory factory = protocolFactoryRegistry.get(protocolFactoryID);
if (factory == null)
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocol.java
index 2ed8e41..9bf308a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractProtocol.java
@@ -14,12 +14,12 @@ import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.transport.Protocol;
-import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
/**
* @author Eike Stepper
*/
-public abstract class AbstractProtocol extends AbstractLifecycle implements Protocol, BufferProvider
+public abstract class AbstractProtocol extends LifecycleImpl implements Protocol, BufferProvider
{
private Channel channel;
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 e6630bc..1a8a6df 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
@@ -13,7 +13,7 @@ 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 org.eclipse.net4j.transport.container.ContainerUtil;
import java.text.MessageFormat;
@@ -43,7 +43,7 @@ public abstract class AbstractProtocolFactory implements ProtocolFactory
public ProtocolFactoryID createID(Type type)
{
- return Net4jUtil.createProtocolFactoryID(type, getProtocolID());
+ return ContainerUtil.createProtocolFactoryID(type, getProtocolID());
}
@Override
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 0e8ee07..5989a21 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
@@ -17,10 +17,11 @@ import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.transport.ChannelID;
import org.eclipse.net4j.transport.Connector;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.Value;
import org.eclipse.net4j.util.concurrent.AsynchronousWorkSerializer;
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.lifecycle.LifecycleImpl;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.registry.IRegistry;
@@ -34,7 +35,7 @@ import java.util.concurrent.ExecutorService;
/**
* @author Eike Stepper
*/
-public class ChannelImpl extends AbstractLifecycle implements Channel, BufferProvider
+public class ChannelImpl extends LifecycleImpl implements Channel, BufferProvider
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CHANNEL, ChannelImpl.class);
@@ -255,8 +256,10 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
/**
* @author Eike Stepper
*/
- private final class ChannelIDImpl implements ChannelID
+ private final class ChannelIDImpl extends Value implements ChannelID
{
+ private static final long serialVersionUID = 1L;
+
public ChannelIDImpl()
{
}
@@ -272,6 +275,12 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
}
@Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ return this;
+ }
+
+ @Override
public boolean equals(Object obj)
{
if (obj instanceof ChannelID)
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
index 4374d75..b3f7f9d 100644
--- 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
@@ -10,31 +10,31 @@
**************************************************************************/
package org.eclipse.internal.net4j.transport;
+import org.eclipse.net4j.transport.Connector;
import org.eclipse.net4j.transport.ProtocolFactoryID;
-import org.eclipse.net4j.transport.Connector.Type;
import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.Value;
-import java.io.Serializable;
import java.text.MessageFormat;
/**
* @author Eike Stepper
*/
-public class ProtocolFactoryIDImpl implements ProtocolFactoryID, Cloneable, Serializable
+public class ProtocolFactoryIDImpl extends Value implements ProtocolFactoryID
{
private static final long serialVersionUID = 1L;
- private Type type;
+ private Connector.Type type;
private String protocolID;
- public ProtocolFactoryIDImpl(Type type, String protocolID)
+ public ProtocolFactoryIDImpl(Connector.Type type, String protocolID)
{
this.type = type;
this.protocolID = protocolID;
}
- public Type getType()
+ public Connector.Type getType()
{
return type;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/AbstractContainer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/AbstractContainer.java
new file mode 100644
index 0000000..ff877cf
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/AbstractContainer.java
@@ -0,0 +1,105 @@
+/***************************************************************************
+ * 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.container;
+
+import org.eclipse.net4j.transport.container.Container;
+import org.eclipse.net4j.transport.container.ContainerAdapter;
+import org.eclipse.net4j.transport.container.ContainerAdapterFactory;
+import org.eclipse.net4j.transport.container.ContainerAdapterID;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractContainer extends LifecycleImpl implements Container
+{
+ private IRegistry<ContainerAdapterID, ContainerAdapterFactory> adapterFactoryRegistry;
+
+ private IRegistry<ContainerAdapterID, ContainerAdapter> adapters = new HashMapRegistry();
+
+ protected AbstractContainer(IRegistry<ContainerAdapterID, ContainerAdapterFactory> adapterFactoryRegistry)
+ {
+ this.adapterFactoryRegistry = adapterFactoryRegistry;
+ }
+
+ protected AbstractContainer()
+ {
+ this(ContainerAdapterFactory.REGISTRY);
+ }
+
+ @Override
+ protected void onAboutToActivate() throws Exception
+ {
+ super.onAboutToActivate();
+ if (adapterFactoryRegistry == null)
+ {
+ throw new IllegalStateException("adapterFactoryRegistry == null");
+ }
+ }
+
+ @Override
+ protected void onDeactivate() throws Exception
+ {
+ for (ContainerAdapter adapter : adapters.values())
+ {
+ LifecycleUtil.deactivate(adapter);
+ }
+
+ super.onDeactivate();
+ }
+
+ public IRegistry<ContainerAdapterID, ContainerAdapterFactory> getAdapterFactoryRegistry()
+ {
+ return adapterFactoryRegistry;
+ }
+
+ public IRegistry<ContainerAdapterID, ContainerAdapter> getAdapters()
+ {
+ return adapters;
+ }
+
+ public ContainerAdapter getAdapter(ContainerAdapterID adapterID)
+ {
+ ContainerAdapter adapter = adapters.get(adapterID);
+ if (adapter == null)
+ {
+ ContainerAdapterFactory factory = adapterFactoryRegistry.get(adapterID);
+ if (factory != null)
+ {
+ adapter = createAdapter(factory);
+ if (adapter != null)
+ {
+ adapters.put(adapterID, adapter);
+ }
+ }
+ }
+
+ return adapter;
+ }
+
+ private ContainerAdapter createAdapter(ContainerAdapterFactory factory)
+ {
+ try
+ {
+ ContainerAdapter adapter = factory.createAdapter(this);
+ LifecycleUtil.activate(adapter);
+ return adapter;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterIDImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterIDImpl.java
new file mode 100644
index 0000000..b57dd7c
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterIDImpl.java
@@ -0,0 +1,75 @@
+/***************************************************************************
+ * 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.container;
+
+import org.eclipse.net4j.transport.container.ContainerAdapterID;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.Value;
+
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ContainerAdapterIDImpl extends Value implements ContainerAdapterID
+{
+ private static final long serialVersionUID = 1L;
+
+ private Type type;
+
+ private String name;
+
+ public ContainerAdapterIDImpl(Type type, String name)
+ {
+ this.type = type;
+ this.name = name;
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ protected Object clone() throws CloneNotSupportedException
+ {
+ return new ContainerAdapterIDImpl(type, name);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj instanceof ContainerAdapterID)
+ {
+ ContainerAdapterID that = (ContainerAdapterID)obj;
+ return this.type.equals(that.getType()) && ObjectUtil.equals(this.name, that.getName());
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return type.hashCode() ^ name.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("{0}:{1}", type, name);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterImpl.java
new file mode 100644
index 0000000..e2e970b
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerAdapterImpl.java
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * 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.container;
+
+import org.eclipse.net4j.transport.container.Container;
+import org.eclipse.net4j.transport.container.ContainerAdapter;
+import org.eclipse.net4j.transport.container.ContainerAdapterID;
+
+/**
+ * @author Eike Stepper
+ */
+public class ContainerAdapterImpl implements ContainerAdapter
+{
+ private Container container;
+
+ private ContainerAdapterID id;
+
+ public ContainerAdapterImpl(Container container, ContainerAdapterID id)
+ {
+ this.container = container;
+ this.id = id;
+ }
+
+ public Container getContainer()
+ {
+ return container;
+ }
+
+ public ContainerAdapterID getID()
+ {
+ return id;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerImpl.java
new file mode 100644
index 0000000..1d57879
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/container/ContainerImpl.java
@@ -0,0 +1,135 @@
+/***************************************************************************
+ * 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.container;
+
+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.ConnectorFactory;
+import org.eclipse.net4j.transport.Protocol;
+import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.transport.container.ContainerAdapterFactory;
+import org.eclipse.net4j.transport.container.ContainerAdapterID;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public class ContainerImpl extends AbstractContainer
+{
+ private ExecutorService executorService;
+
+ private BufferProvider bufferProvider;
+
+ private IRegistry<String, ConnectorFactory> connectorFactoryRegistry;
+
+ private IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry;
+
+ private IRegistry<Integer, Connector> connectorRegistry;
+
+ private IRegistry<ChannelID, Channel> channelRegistry;
+
+ public ContainerImpl()
+ {
+ }
+
+ public ContainerImpl(IRegistry<ContainerAdapterID, ContainerAdapterFactory> adapterFactoryRegistry)
+ {
+ super(adapterFactoryRegistry);
+ }
+
+ public ExecutorService getExecutorService()
+ {
+ return executorService;
+ }
+
+ public void setExecutorService(ExecutorService executorService)
+ {
+ this.executorService = executorService;
+ }
+
+ public BufferProvider getBufferProvider()
+ {
+ return bufferProvider;
+ }
+
+ public void setBufferProvider(BufferProvider bufferProvider)
+ {
+ this.bufferProvider = bufferProvider;
+ }
+
+ public IRegistry<String, ConnectorFactory> getConnectorFactoryRegistry()
+ {
+ return connectorFactoryRegistry;
+ }
+
+ public void setConnectorFactoryRegistry(IRegistry<String, ConnectorFactory> connectorFactoryRegistry)
+ {
+ this.connectorFactoryRegistry = connectorFactoryRegistry;
+ }
+
+ public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry()
+ {
+ return protocolFactoryRegistry;
+ }
+
+ public void setProtocolFactoryRegistry(IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry)
+ {
+ this.protocolFactoryRegistry = protocolFactoryRegistry;
+ }
+
+ public IRegistry<Integer, Connector> getConnectorRegistry()
+ {
+ return connectorRegistry;
+ }
+
+ public void setConnectorRegistry(IRegistry<Integer, Connector> connectorRegistry)
+ {
+ this.connectorRegistry = connectorRegistry;
+ }
+
+ public IRegistry<ChannelID, Channel> getChannelRegistry()
+ {
+ return channelRegistry;
+ }
+
+ public void setChannelRegistry(IRegistry<ChannelID, Channel> channelRegistry)
+ {
+ this.channelRegistry = channelRegistry;
+ }
+
+ public Connector createConnector(String connectorFactoryID)
+ {
+ IRegistry<String, ConnectorFactory> registry = getConnectorFactoryRegistry();
+ if (registry == null)
+ {
+ return null;
+ }
+
+ ConnectorFactory connectorFactory = registry.get(connectorFactoryID);
+ if (connectorFactory == null)
+ {
+ return null;
+ }
+
+ return connectorFactory.createConnector(this);
+ }
+
+ public Protocol createProtocol(String protocolID)
+ {
+ // TODO Implement method ContainerUtil.createProtocol()
+ throw new UnsupportedOperationException("Not yet implemented");
+ }
+}
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
deleted file mode 100644
index edf647d..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java
+++ /dev/null
@@ -1,353 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.Buffer;
-import org.eclipse.net4j.transport.Channel;
-import org.eclipse.net4j.transport.Connector;
-import org.eclipse.net4j.transport.ConnectorException;
-import org.eclipse.net4j.transport.tcp.TCPSelector;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener;
-import org.eclipse.net4j.util.Net4jUtil;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.Net4j;
-import org.eclipse.internal.net4j.transport.AbstractConnector;
-import org.eclipse.internal.net4j.transport.ChannelImpl;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.SocketChannel;
-import java.util.List;
-import java.util.Queue;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractTCPConnector extends AbstractConnector implements Connector, TCPSelectorListener.Active
-{
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR, AbstractTCPConnector.class);
-
- private SocketChannel socketChannel;
-
- private TCPSelector selector;
-
- private SelectionKey selectionKey;
-
- private Buffer inputBuffer;
-
- private ControlChannelImpl controlChannel;
-
- public AbstractTCPConnector()
- {
- try
- {
- socketChannel = SocketChannel.open();
- socketChannel.configureBlocking(false);
- }
- catch (IOException ex)
- {
- Net4j.LOG.error(ex);
- }
- }
-
- /**
- * SocketChannel must already be non-blocking!
- */
- protected AbstractTCPConnector(SocketChannel socketChannel)
- {
- this.socketChannel = socketChannel;
- }
-
- public TCPSelector getSelector()
- {
- return selector;
- }
-
- public void setSelector(TCPSelector selector)
- {
- this.selector = selector;
- }
-
- public SocketChannel getSocketChannel()
- {
- return socketChannel;
- }
-
- /**
- * Called by {@link ChannelImpl} each time a new buffer is available for
- * multiplexing. This or another buffer can be dequeued from the outputQueue
- * of the {@link ChannelImpl}.
- */
- public void multiplexBuffer(Channel channel)
- {
- checkSelectionKey();
- selector.setWriteInterest(selectionKey, true);
- }
-
- public void registered(SelectionKey selectionKey)
- {
- this.selectionKey = selectionKey;
- if (getType() == Type.SERVER)
- {
- selector.setConnectInterest(selectionKey, false);
- }
- }
-
- public void handleConnect(TCPSelector selector, SocketChannel channel)
- {
- try
- {
- if (!channel.finishConnect())
- {
- return;
- }
- }
- catch (Exception ex)
- {
- return;
- }
-
- try
- {
- checkSelectionKey();
- selector.setConnectInterest(selectionKey, false);
- setState(State.NEGOTIATING);
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- deactivate();
- }
- }
-
- public void handleRead(TCPSelector selector, SocketChannel socketChannel)
- {
- try
- {
- if (inputBuffer == null)
- {
- inputBuffer = getBufferProvider().provideBuffer();
- }
-
- ByteBuffer byteBuffer = inputBuffer.startGetting(socketChannel);
- if (byteBuffer != null)
- {
- short channelIndex = inputBuffer.getChannelIndex();
- ChannelImpl channel = channelIndex == ControlChannelImpl.CONTROL_CHANNEL_ID ? controlChannel
- : getChannel(channelIndex);
- if (channel != null)
- {
- channel.handleBufferFromMultiplexer(inputBuffer);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Discarding buffer from unknown channel"); //$NON-NLS-1$
- }
-
- inputBuffer.release();
- }
-
- inputBuffer = null;
- }
- }
- catch (ClosedChannelException ex)
- {
- deactivate();
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- deactivate();
- }
- }
-
- public void handleWrite(TCPSelector selector, SocketChannel socketChannel)
- {
- try
- {
- boolean moreToWrite = false;
- for (Queue<Buffer> bufferQueue : getChannelBufferQueues())
- {
- Buffer buffer = bufferQueue.peek();
- if (buffer != null)
- {
- if (buffer.write(socketChannel))
- {
- bufferQueue.poll();
- buffer.release();
-
- if (!moreToWrite)
- {
- moreToWrite = !bufferQueue.isEmpty();
- }
- }
- else
- {
- moreToWrite = true;
- break;
- }
- }
- }
-
- if (!moreToWrite)
- {
- checkSelectionKey();
- selector.setWriteInterest(selectionKey, false);
- }
- }
- catch (NullPointerException ignore)
- {
- ;
- }
- catch (ClosedChannelException ex)
- {
- deactivate();
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- deactivate();
- }
- }
-
- @Override
- protected List<Queue<Buffer>> getChannelBufferQueues()
- {
- List<Queue<Buffer>> queues = super.getChannelBufferQueues();
- Queue<Buffer> controlQueue = controlChannel.getSendQueue();
- if (!controlQueue.isEmpty())
- {
- queues.add(controlQueue);
- }
-
- return queues;
- }
-
- @Override
- protected void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException
- {
- try
- {
- if (!controlChannel.registerChannel(channelIndex, protocolID))
- {
- throw new ConnectorException("Failed to register channel with peer"); //$NON-NLS-1$
- }
- }
- catch (ConnectorException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
- }
-
- @Override
- protected void removeChannel(ChannelImpl channel)
- {
- if (isConnected())
- {
- controlChannel.deregisterChannel(channel.getChannelIndex());
- }
-
- super.removeChannel(channel);
- }
-
- @Override
- protected void onAboutToActivate() throws Exception
- {
- super.onAboutToActivate();
- if (selector == null)
- {
- selector = Net4jUtil.createTCPSelector();
- LifecycleUtil.activate(selector);
- }
- }
-
- @Override
- protected void onActivate() throws Exception
- {
- super.onActivate();
- controlChannel = new ControlChannelImpl(this);
- controlChannel.activate();
- selector.registerAsync(socketChannel, this);
- }
-
- @Override
- protected void onDeactivate() throws Exception
- {
- Exception exception = null;
-
- try
- {
- controlChannel.deactivate();
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- controlChannel = null;
- }
-
- try
- {
- socketChannel.close();
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- socketChannel = null;
- }
-
- try
- {
- super.onDeactivate();
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
-
- if (exception != null)
- {
- throw exception;
- }
- }
-
- private void checkSelectionKey()
- {
- if (selectionKey == null)
- {
- throw new IllegalStateException("selectionKey == null");
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java
deleted file mode 100644
index de69f94..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ClientTCPConnectorImpl.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.tcp.TCPConnectorDescription;
-
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-
-/**
- * @author Eike Stepper
- */
-public class ClientTCPConnectorImpl extends AbstractTCPConnector
-{
- public ClientTCPConnectorImpl()
- {
- }
-
- public Type getType()
- {
- return Type.CLIENT;
- }
-
- @Override
- public String toString()
- {
- return "ClientTCPConnector[" + getDescription() + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Override
- protected void onAboutToActivate() throws Exception
- {
- super.onAboutToActivate();
- if (getDescription() == null)
- {
- throw new IllegalStateException("getDescription() == null"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void onActivate() throws Exception
- {
- super.onActivate();
- TCPConnectorDescription description = (TCPConnectorDescription)getDescription();
- InetAddress addr = InetAddress.getByName(description.getHost());
- InetSocketAddress sAddr = new InetSocketAddress(addr, description.getPort());
- getSocketChannel().connect(sAddr);
- }
-}
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
deleted file mode 100644
index 4020dbe..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.Buffer;
-import org.eclipse.net4j.util.concurrent.Synchronizer;
-import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.Net4j;
-import org.eclipse.internal.net4j.transport.BufferUtil;
-import org.eclipse.internal.net4j.transport.ChannelImpl;
-
-import java.nio.ByteBuffer;
-
-/**
- * @author Eike Stepper
- */
-public final class ControlChannelImpl extends ChannelImpl
-{
- public static final short CONTROL_CHANNEL_ID = -1;
-
- public static final long REGISTRATION_TIMEOUT = 500000;
-
- public static final byte OPCODE_REGISTRATION = 1;
-
- public static final byte OPCODE_REGISTRATION_ACK = 2;
-
- public static final byte OPCODE_DEREGISTRATION = 3;
-
- public static final byte SUCCESS = 1;
-
- public static final byte FAILURE = 0;
-
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CHANNEL, ControlChannelImpl.class);
-
- private SynchronizingCorrelator<Short, Boolean> registrations = new SynchronizingCorrelator();
-
- public ControlChannelImpl(AbstractTCPConnector connector)
- {
- super(connector.getReceiveExecutor());
- setChannelIndex(CONTROL_CHANNEL_ID);
- setConnector(connector);
- }
-
- @Override
- public boolean isInternal()
- {
- return true;
- }
-
- public boolean registerChannel(short channelIndex, String protocolID)
- {
- assertValidChannelIndex(channelIndex);
- Synchronizer<Boolean> registration = registrations.correlate(channelIndex);
-
- Buffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_ID);
- byteBuffer.put(OPCODE_REGISTRATION);
- byteBuffer.putShort(channelIndex);
- BufferUtil.putUTF8(byteBuffer, protocolID);
- handleBuffer(buffer);
-
- return registration.get(REGISTRATION_TIMEOUT);
- }
-
- public void deregisterChannel(short channelIndex)
- {
- assertValidChannelIndex(channelIndex);
-
- Buffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_ID);
- byteBuffer.put(OPCODE_DEREGISTRATION);
- byteBuffer.putShort(channelIndex);
- handleBuffer(buffer);
- }
-
- public void handleBufferFromMultiplexer(Buffer buffer)
- {
- try
- {
- ByteBuffer byteBuffer = buffer.getByteBuffer();
- byte opcode = byteBuffer.get();
- switch (opcode)
- {
- case OPCODE_REGISTRATION:
- {
- short channelIndex = byteBuffer.getShort();
- assertValidChannelIndex(channelIndex);
- boolean success = true;
-
- try
- {
- byte[] handlerFactoryUTF8 = BufferUtil.getByteArray(byteBuffer);
- String protocolID = BufferUtil.fromUTF8(handlerFactoryUTF8);
- ChannelImpl channel = ((AbstractTCPConnector)getConnector()).createChannel(channelIndex, protocolID, null);
- if (channel != null)
- {
- channel.activate();
- }
- else
- {
- success = false;
- }
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- success = false;
- }
-
- sendStatus(OPCODE_REGISTRATION_ACK, channelIndex, success);
- break;
- }
-
- case OPCODE_REGISTRATION_ACK:
- {
- short channelIndex = byteBuffer.getShort();
- boolean success = byteBuffer.get() == SUCCESS;
- registrations.put(channelIndex, success);
- break;
- }
-
- case OPCODE_DEREGISTRATION:
- {
- short channelIndex = byteBuffer.getShort();
- assertValidChannelIndex(channelIndex);
-
- try
- {
- ChannelImpl channel = ((AbstractTCPConnector)getConnector()).getChannel(channelIndex);
- if (channel != null)
- {
- channel.deactivate();
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Invalid channel id: " + channelIndex); //$NON-NLS-1$
- }
- }
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- }
-
- break;
- }
-
- default:
- Net4j.LOG.error("Invalid opcode: " + opcode); //$NON-NLS-1$
- ((AbstractTCPConnector)getConnector()).deactivate();
- }
- }
- finally
- {
- buffer.release();
- }
- }
-
- private void sendStatus(byte opcode, short channelIndex, boolean status)
- {
- Buffer buffer = provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(CONTROL_CHANNEL_ID);
- byteBuffer.put(opcode);
- byteBuffer.putShort(channelIndex);
- 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
deleted file mode 100644
index 187f7f5..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ServerTCPConnectorImpl.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import java.net.SocketAddress;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public class ServerTCPConnectorImpl extends AbstractTCPConnector
-{
- public ServerTCPConnectorImpl(SocketChannel socketChannel)
- {
- super(socketChannel);
- }
-
- public Type getType()
- {
- return Type.SERVER;
- }
-
- public String getHost()
- {
- return getSocketChannel().socket().getInetAddress().getHostAddress();
- }
-
- public int getPort()
- {
- return getSocketChannel().socket().getPort();
- }
-
- @Override
- public String toString()
- {
- try
- {
- SocketAddress address = getSocketChannel().socket().getRemoteSocketAddress();
- return "ServerTCPConnector[" + address + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
- catch (Exception ex)
- {
- return "ServerTCPConnector"; //$NON-NLS-1$
- }
- }
-
- @Override
- protected void onDeactivate() throws Exception
- {
- super.onDeactivate();
- }
-}
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
deleted file mode 100644
index 9112182..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-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;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener;
-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.IRegistry;
-
-import org.eclipse.internal.net4j.bundle.Net4j;
-import org.eclipse.internal.net4j.transport.ChannelImpl;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.nio.channels.Channel;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Queue;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, BufferProvider,
- TCPSelectorListener.Passive, LifecycleListener
-{
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, TCPAcceptorImpl.class);
-
- private IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry;
-
- private BufferProvider bufferProvider;
-
- private TCPSelector selector;
-
- private String listenAddr = DEFAULT_ADDRESS;
-
- private int listenPort = DEFAULT_PORT;
-
- private ServerSocketChannel serverSocketChannel;
-
- private Set<Connector> acceptedConnectors = new HashSet(0);
-
- /**
- * An optional executor to be used by the {@link Channel}s to process their
- * {@link ChannelImpl#receiveQueue} instead of the current thread. If not
- * <code>null</code> the calling thread of
- * {@link ChannelImpl#handleBufferFromMultiplexer(Buffer)} becomes decoupled.
- * <p>
- */
- private ExecutorService receiveExecutor;
-
- /**
- * Don't initialize lazily to circumvent synchronization!
- */
- private Queue<TCPAcceptorListener> listeners = new ConcurrentLinkedQueue();
-
- public TCPAcceptorImpl()
- {
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- this.receiveExecutor = receiveExecutor;
- }
-
- public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry()
- {
- return protocolFactoryRegistry;
- }
-
- public void setProtocolFactoryRegistry(IRegistry<ProtocolFactoryID, ProtocolFactory> protocolFactoryRegistry)
- {
- this.protocolFactoryRegistry = protocolFactoryRegistry;
- }
-
- public BufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(BufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public short getBufferCapacity()
- {
- return bufferProvider.getBufferCapacity();
- }
-
- public Buffer provideBuffer()
- {
- return bufferProvider.provideBuffer();
- }
-
- public void retainBuffer(Buffer buffer)
- {
- bufferProvider.retainBuffer(buffer);
- }
-
- public TCPSelector getSelector()
- {
- return selector;
- }
-
- public void setSelector(TCPSelector selector)
- {
- this.selector = selector;
- }
-
- public String getAddress()
- {
- return listenAddr;
- }
-
- public void setListenAddr(String listenAddr)
- {
- this.listenAddr = listenAddr;
- }
-
- public int getPort()
- {
- return listenPort;
- }
-
- public void setListenPort(int listenPort)
- {
- this.listenPort = listenPort;
- }
-
- public Connector[] getAcceptedConnectors()
- {
- ArrayList<Connector> result;
- synchronized (acceptedConnectors)
- {
- result = new ArrayList(acceptedConnectors);
- }
-
- return result.toArray(new Connector[result.size()]);
- }
-
- public void addAcceptorListener(TCPAcceptorListener listener)
- {
- listeners.add(listener);
- }
-
- public void removeAcceptorListener(TCPAcceptorListener listener)
- {
- listeners.remove(listener);
- }
-
- public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier)
- {
- // Do nothing
- }
-
- public void notifyLifecycleActivated(LifecycleNotifier notifier)
- {
- // Do nothing
- }
-
- public void notifyLifecycleDeactivating(LifecycleNotifier notifier)
- {
- synchronized (acceptedConnectors)
- {
- notifier.removeLifecycleListener(this);
- acceptedConnectors.remove(notifier);
- }
- }
-
- public void handleAccept(TCPSelector selector, ServerSocketChannel serverSocketChannel)
- {
- try
- {
- SocketChannel socketChannel = serverSocketChannel.accept();
- if (socketChannel != null)
- {
- socketChannel.configureBlocking(false);
- addConnector(socketChannel);
- }
- }
- catch (ClosedChannelException ex)
- {
- deactivate();
- }
- catch (Exception ex)
- {
- if (isActive())
- {
- Net4j.LOG.error(ex);
- }
-
- deactivate();
- }
- }
-
- @Override
- public String toString()
- {
- return "TCPAcceptor[" + "/" + listenAddr + ":" + listenPort + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
- protected void addConnector(SocketChannel socketChannel)
- {
- try
- {
- AbstractTCPConnector connector = createConnector(socketChannel);
- connector.activate();
- connector.addLifecycleListener(this);
-
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.add(connector);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Accepted connector " + connector); //$NON-NLS-1$
- }
-
- fireConnectorAccepted(connector);
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
-
- try
- {
- socketChannel.close();
- }
- catch (IOException ignore)
- {
- ;
- }
- }
- }
-
- protected AbstractTCPConnector createConnector(SocketChannel socketChannel)
- {
- ServerTCPConnectorImpl connector = new ServerTCPConnectorImpl(socketChannel);
- connector.setReceiveExecutor(receiveExecutor);
- connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
- connector.setBufferProvider(bufferProvider);
- connector.setSelector(selector);
- return connector;
- }
-
- protected void fireConnectorAccepted(Connector connector)
- {
- for (TCPAcceptorListener listener : listeners)
- {
- try
- {
- listener.notifyConnectorAccepted(this, connector);
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- }
- }
- }
-
- @Override
- protected void onAboutToActivate() throws Exception
- {
- super.onAboutToActivate();
- if (bufferProvider == null)
- {
- throw new IllegalStateException("bufferProvider == null"); //$NON-NLS-1$
- }
-
- if (protocolFactoryRegistry == null && TRACER.isEnabled())
- {
- TRACER.trace("No protocol factory registry!"); //$NON-NLS-1$
- }
-
- if (receiveExecutor == null && TRACER.isEnabled())
- {
- TRACER.trace("No receive executor!"); //$NON-NLS-1$
- }
-
- if (selector == null)
- {
- selector = Net4jUtil.createTCPSelector();
- LifecycleUtil.activate(selector);
- }
- }
-
- @Override
- protected void onActivate() throws Exception
- {
- super.onActivate();
- InetAddress addr = InetAddress.getByName(listenAddr);
- InetSocketAddress sAddr = new InetSocketAddress(addr, listenPort);
-
- serverSocketChannel = ServerSocketChannel.open();
- serverSocketChannel.configureBlocking(false);
- serverSocketChannel.socket().bind(sAddr);
-
- selector.registerAsync(serverSocketChannel, this);
- }
-
- @Override
- protected void onDeactivate() throws Exception
- {
- for (Connector connector : getAcceptedConnectors())
- {
- LifecycleUtil.deactivate(connector);
- }
-
- serverSocketChannel.close();
- }
-}
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
deleted file mode 100644
index 5861650..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorDescriptionImpl.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.tcp.TCPConnectorDescription;
-import org.eclipse.net4j.transport.tcp.TCPConnectorFactory;
-import org.eclipse.net4j.util.ObjectUtil;
-
-import java.io.Serializable;
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public class TCPConnectorDescriptionImpl implements TCPConnectorDescription, Cloneable, Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private String host;
-
- private int port = DEFAULT_PORT;
-
- public TCPConnectorDescriptionImpl(String host, int port)
- {
- this.host = host;
- this.port = port;
- }
-
- public String getFactoryID()
- {
- return TCPConnectorFactory.ID;
- }
-
- public String getHost()
- {
- return host;
- }
-
- public int getPort()
- {
- return port;
- }
-
- public String getDisplayName()
- {
- return MessageFormat.format("{0}:{1}", host, port);
- }
-
- @Override
- protected Object clone() throws CloneNotSupportedException
- {
- return new TCPConnectorDescriptionImpl(host, port);
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj instanceof TCPConnectorDescription)
- {
- TCPConnectorDescription that = (TCPConnectorDescription)obj;
- return this.port == that.getPort() && ObjectUtil.equals(this.host, that.getHost());
- }
-
- return false;
- }
-
- @Override
- public int hashCode()
- {
- return port ^ host.hashCode();
- }
-
- @Override
- public String toString()
- {
- return getDisplayName();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorFactoryImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorFactoryImpl.java
deleted file mode 100644
index eb0748d..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPConnectorFactoryImpl.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.Connector;
-import org.eclipse.net4j.transport.tcp.TCPConnectorFactory;
-
-/**
- * @author Eike Stepper
- */
-public class TCPConnectorFactoryImpl implements TCPConnectorFactory
-{
- public String getID()
- {
- return ID;
- }
-
- public Connector createConnector()
- {
- ClientTCPConnectorImpl connector = new ClientTCPConnectorImpl();
- return connector;
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java
deleted file mode 100644
index 72a7a6a..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java
+++ /dev/null
@@ -1,372 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.tcp.TCPSelector;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener.Active;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener.Passive;
-import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.Net4j;
-
-import java.io.IOException;
-import java.nio.channels.CancelledKeyException;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.ClosedSelectorException;
-import java.nio.channels.SelectableChannel;
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-import java.util.Iterator;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/**
- * @author Eike Stepper
- */
-public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, Runnable
-{
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_SELECTOR, TCPSelectorImpl.class);
-
- private Selector selector;
-
- private Queue<Runnable> pendingOperations = new ConcurrentLinkedQueue();
-
- private Thread thread;
-
- public TCPSelectorImpl()
- {
- }
-
- public void invokeAsync(final Runnable operation)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Pending operation " + operation);
- }
-
- pendingOperations.add(operation);
- selector.wakeup();
- }
-
- public void registerAsync(final ServerSocketChannel channel, final Passive listener)
- {
- assertValidListener(listener);
- invokeAsync(new Runnable()
- {
- public void run()
- {
- doRegister(channel, listener);
- }
-
- @Override
- public String toString()
- {
- return "REGISTER " + TCPUtil.toString(channel);
- }
- });
- }
-
- public void registerAsync(final SocketChannel channel, final Active listener)
- {
- assertValidListener(listener);
- invokeAsync(new Runnable()
- {
- public void run()
- {
- doRegister(channel, listener);
- }
-
- @Override
- public String toString()
- {
- return "REGISTER " + TCPUtil.toString(channel);
- }
- });
- }
-
- public void setConnectInterest(final SelectionKey selectionKey, final boolean on)
- {
- invokeAsync(new Runnable()
- {
- public void run()
- {
- TCPUtil.setConnectInterest(selectionKey, on);
- }
-
- @Override
- public String toString()
- {
- return "INTEREST CONNECT " + selectionKey + " = " + on;
- }
- });
- }
-
- public void setReadInterest(final SelectionKey selectionKey, final boolean on)
- {
- invokeAsync(new Runnable()
- {
- public void run()
- {
- TCPUtil.setReadInterest(selectionKey, on);
- }
-
- @Override
- public String toString()
- {
- return "INTEREST READ " + selectionKey + " = " + on;
- }
- });
- }
-
- public void setWriteInterest(final SelectionKey selectionKey, final boolean on)
- {
- invokeAsync(new Runnable()
- {
- public void run()
- {
- TCPUtil.setWriteInterest(selectionKey, on);
- }
-
- @Override
- public String toString()
- {
- return "INTEREST WRITE " + selectionKey + " = " + on;
- }
-
- });
- }
-
- public void run()
- {
- while (isActive())
- {
- if (Thread.interrupted())
- {
- deactivate();
- break;
- }
-
- try
- {
- Runnable operation;
- while ((operation = pendingOperations.poll()) != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Executing operation " + operation);
- }
-
- operation.run();
- }
-
- if (selector.select() > 0)
- {
- Iterator<SelectionKey> it = selector.selectedKeys().iterator();
- while (it.hasNext())
- {
- SelectionKey selKey = it.next();
- it.remove();
-
- try
- {
- handleSelection(selKey);
- }
- catch (CancelledKeyException ignore)
- {
- ; // Do nothing
- }
- catch (NullPointerException ignore)
- {
- ; // Do nothing
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- selKey.cancel();
- }
- }
- }
- }
- catch (ClosedSelectorException ex)
- {
- break;
- }
- catch (Exception ex)
- {
- Net4j.LOG.error(ex);
- deactivate();
- break;
- }
- }
- }
-
- @Override
- public String toString()
- {
- return "TCPSelector"; //$NON-NLS-1$
- }
-
- protected void handleSelection(SelectionKey selKey) throws IOException
- {
- SelectableChannel channel = selKey.channel();
- if (channel instanceof ServerSocketChannel)
- {
- ServerSocketChannel ssChannel = (ServerSocketChannel)selKey.channel();
- TCPSelectorListener.Passive listener = (TCPSelectorListener.Passive)selKey.attachment();
-
- if (selKey.isAcceptable())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Accepting " + TCPUtil.toString(ssChannel)); //$NON-NLS-1$
- }
-
- listener.handleAccept(this, ssChannel);
- }
- }
- else if (channel instanceof SocketChannel)
- {
- SocketChannel sChannel = (SocketChannel)channel;
- TCPSelectorListener.Active listener = (TCPSelectorListener.Active)selKey.attachment();
-
- if (selKey.isConnectable())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Connecting " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
- }
-
- listener.handleConnect(this, sChannel);
- }
-
- if (selKey.isReadable())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Reading " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
- }
-
- listener.handleRead(this, sChannel);
- }
-
- if (selKey.isWritable())
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Writing " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
- }
-
- listener.handleWrite(this, sChannel);
- }
- }
- }
-
- @Override
- protected void onActivate() throws Exception
- {
- selector = Selector.open();
- thread = new Thread(this, "selector"); //$NON-NLS-1$
- thread.setDaemon(true);
- thread.start();
- }
-
- @Override
- protected void onDeactivate() throws Exception
- {
- selector.wakeup();
- Exception exception = null;
-
- try
- {
- thread.join(200);
- }
- catch (RuntimeException ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- thread = null;
- }
-
- try
- {
- selector.close();
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- selector = null;
- }
-
- if (exception != null)
- {
- throw exception;
- }
- }
-
- private void assertValidListener(Object listener)
- {
- if (listener == null)
- {
- throw new IllegalArgumentException("listener == null"); //$NON-NLS-1$
- }
- }
-
- private void doRegister(final ServerSocketChannel channel, final TCPSelectorListener.Passive listener)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
- }
-
- try
- {
- channel.register(selector, SelectionKey.OP_ACCEPT, listener);
- }
- catch (ClosedChannelException ignore)
- {
- ;
- }
- }
-
- private void doRegister(final SocketChannel channel, final TCPSelectorListener.Active listener)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
- }
-
- try
- {
- int interest = SelectionKey.OP_CONNECT | SelectionKey.OP_READ;
- SelectionKey selectionKey = channel.register(selector, interest, listener);
- listener.registered(selectionKey);
- }
- catch (ClosedChannelException ignore)
- {
- ;
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java
deleted file mode 100644
index e095225..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.Net4j;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public final class TCPUtil
-{
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_SELECTOR, TCPUtil.class);
-
- private TCPUtil()
- {
- }
-
- public static String toString(ServerSocketChannel channel)
- {
- return channel.toString();
- }
-
- public static String toString(SocketChannel channel)
- {
- return channel.toString();
- }
-
- public static String formatInterestOps(int newOps)
- {
- StringBuilder builder = new StringBuilder();
- if ((newOps & SelectionKey.OP_ACCEPT) != 0)
- {
- addInterestOp(builder, "ACCEPT"); //$NON-NLS-1$
- }
-
- if ((newOps & SelectionKey.OP_CONNECT) != 0)
- {
- addInterestOp(builder, "CONNECT"); //$NON-NLS-1$
- }
-
- if ((newOps & SelectionKey.OP_READ) != 0)
- {
- addInterestOp(builder, "READ"); //$NON-NLS-1$
- }
-
- if ((newOps & SelectionKey.OP_WRITE) != 0)
- {
- addInterestOp(builder, "WRITE"); //$NON-NLS-1$
- }
-
- return builder.toString();
- }
-
- public static void setInterest(SelectionKey selectionKey, int operation, boolean interested)
- {
- if (selectionKey == null || !selectionKey.isValid())
- {
- return;
- }
-
- int newOps;
- int oldOps = selectionKey.interestOps();
- if (interested)
- {
- newOps = oldOps | operation;
- }
- else
- {
- newOps = oldOps & ~operation;
- }
-
- if (oldOps != newOps)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Setting interest " //$NON-NLS-1$
- + formatInterestOps(newOps) + " (was " + formatInterestOps(oldOps).toLowerCase() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- selectionKey.interestOps(newOps);
- }
- }
-
- public static void setAcceptInterest(SelectionKey selectionKey, boolean interested)
- {
- setInterest(selectionKey, SelectionKey.OP_ACCEPT, interested);
- }
-
- public static void setConnectInterest(SelectionKey selectionKey, boolean interested)
- {
- setInterest(selectionKey, SelectionKey.OP_CONNECT, interested);
- }
-
- public static void setReadInterest(SelectionKey selectionKey, boolean interested)
- {
- setInterest(selectionKey, SelectionKey.OP_READ, interested);
- }
-
- public static void setWriteInterest(SelectionKey selectionKey, boolean interested)
- {
- setInterest(selectionKey, SelectionKey.OP_WRITE, interested);
- }
-
- private static void addInterestOp(StringBuilder builder, String op)
- {
- if (builder.length() != 0)
- {
- builder.append("|"); //$NON-NLS-1$
- }
-
- builder.append(op);
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ConnectorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ConnectorFactory.java
index 3d0b6e6..540b1ca 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ConnectorFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/ConnectorFactory.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.transport;
+import org.eclipse.net4j.transport.container.Container;
+
/**
* @author Eike Stepper
*/
@@ -17,5 +19,5 @@ public interface ConnectorFactory
{
public String getID();
- public Connector createConnector();
+ public Connector createConnector(Container container);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java
deleted file mode 100644
index 82600c4..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportUtil.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/***************************************************************************
- * 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;
-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;
-import org.eclipse.internal.net4j.transport.tcp.TCPConnectorDescriptionImpl;
-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
- */
-public final class TransportUtil
-{
- private TransportUtil()
- {
- }
-
- public static BufferProvider createBufferFactory(short bufferCapacity)
- {
- return new BufferFactoryImpl(bufferCapacity);
- }
-
- public static BufferProvider createBufferFactory()
- {
- return new BufferFactoryImpl(BufferUtil.DEFAULT_BUFFER_CAPACITY);
- }
-
- public static BufferPool createBufferPool(BufferProvider factory)
- {
- return new BufferPoolImpl(factory);
- }
-
- public static BufferPool createBufferPool(short bufferCapacity)
- {
- return createBufferPool(createBufferFactory(bufferCapacity));
- }
-
- public static BufferPool createBufferPool()
- {
- return createBufferPool(createBufferFactory());
- }
-
- public static ProtocolFactoryID createProtocolFactoryID(Type type, String protocolID)
- {
- return new ProtocolFactoryIDImpl(type, protocolID);
- }
-
- public static Connector createConnector(TransportContainer container, String connectorFactoryID)
- {
- IRegistry<String, ConnectorFactory> registry = container.getConnectorFactoryRegistry();
- if (registry == null)
- {
- return null;
- }
-
- ConnectorFactory connectorFactory = registry.get(connectorFactoryID);
- if (connectorFactory == null)
- {
- return null;
- }
-
- return connectorFactory.createConnector();
- }
-
- public static Connector createEmbeddedConnector(BufferProvider bufferProvider)
- {
- ClientEmbeddedConnectorImpl connector = new ClientEmbeddedConnectorImpl();
- connector.setBufferProvider(bufferProvider);
- return connector;
- }
-
- public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider, TCPSelector selector, String address,
- int port)
- {
- TCPAcceptorImpl acceptor = new TCPAcceptorImpl();
- acceptor.setBufferProvider(bufferProvider);
- acceptor.setSelector(selector);
- acceptor.setListenPort(port);
- acceptor.setListenAddr(address);
- return acceptor;
- }
-
- public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider, TCPSelector selector)
- {
- return createTCPAcceptor(bufferProvider, selector, TCPAcceptor.DEFAULT_ADDRESS, TCPAcceptor.DEFAULT_PORT);
- }
-
- public static Connector createTCPConnector(BufferProvider bufferProvider, TCPSelector selector, String host, int port)
- {
- ClientTCPConnectorImpl connector = new ClientTCPConnectorImpl();
- connector.setBufferProvider(bufferProvider);
- connector.setSelector(selector);
- connector.setDescription(new TCPConnectorDescriptionImpl(host, port));
- return connector;
- }
-
- public static Connector createTCPConnector(BufferProvider bufferProvider, TCPSelector selector, String host)
- {
- return createTCPConnector(bufferProvider, selector, host, TCPConnectorDescription.DEFAULT_PORT);
- }
-
- public static TCPSelector createTCPSelector()
- {
- return new TCPSelectorImpl();
- }
-
- public static Collection<Channel> getChannels(TransportContainer container, String protocolID, Set<Type> types)
- {
- if (types == null)
- {
- types = ProtocolFactory.SYMMETRIC;
- }
-
- 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)
- {
- if (types.contains(channel.getConnector().getType()))
- {
- if (protocolID == null || protocolID.length() == 0)
- {
- result.add(channel);
- }
- else
- {
- if (channel.getReceiveHandler() instanceof Protocol)
- {
- Protocol protocol = (Protocol)channel.getReceiveHandler();
- if (protocolID.equals(protocol.getProtocolID()))
- {
- result.add(channel);
- }
- }
- }
- }
- }
-
- return result;
- }
-
- 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(container, null, types);
- }
-
- public static Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> createProtocolFactoryRegistries(Set<Type> 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;
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/Container.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/Container.java
new file mode 100644
index 0000000..01ba53d
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/Container.java
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * 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.container;
+
+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.ConnectorFactory;
+import org.eclipse.net4j.transport.Protocol;
+import org.eclipse.net4j.transport.ProtocolFactory;
+import org.eclipse.net4j.transport.ProtocolFactoryID;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public interface Container
+{
+ public ContainerAdapter getAdapter(ContainerAdapterID adapterID);
+
+ public ExecutorService getExecutorService();
+
+ public BufferProvider getBufferProvider();
+
+ public IRegistry<String, ConnectorFactory> getConnectorFactoryRegistry();
+
+ public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry();
+
+ public IRegistry<Integer, Connector> getConnectorRegistry();
+
+ public IRegistry<ChannelID, Channel> getChannelRegistry();
+
+ public Connector createConnector(String connectorFactoryID);
+
+ public Protocol createProtocol(String protocolID);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapter.java
index e98f8d4..a7d74fa 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapter.java
@@ -8,14 +8,14 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.transport.tcp;
-
-import org.eclipse.net4j.transport.ConnectorFactory;
+package org.eclipse.net4j.transport.container;
/**
* @author Eike Stepper
*/
-public interface TCPConnectorFactory extends ConnectorFactory
+public interface ContainerAdapter
{
- public static final String ID = "TCP";
+ public Container getContainer();
+
+ public ContainerAdapterID getID();
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterFactory.java
index 01be042..9707be6 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/TransportContainer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterFactory.java
@@ -8,22 +8,19 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.transport;
+package org.eclipse.net4j.transport.container;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
/**
* @author Eike Stepper
*/
-public interface TransportContainer
+public interface ContainerAdapterFactory
{
- public BufferPool getBufferPool();
+ public static final IRegistry<ContainerAdapterID, ContainerAdapterFactory> REGISTRY = new HashMapRegistry();
- public IRegistry<String, ConnectorFactory> getConnectorFactoryRegistry();
+ public ContainerAdapterID getID();
- public IRegistry<ProtocolFactoryID, ProtocolFactory> getProtocolFactoryRegistry();
-
- public IRegistry<Integer, Connector> getConnectorRegistry();
-
- public IRegistry<ChannelID, Channel> getChannelRegistry();
+ public ContainerAdapter createAdapter(Container container);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptorListener.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterID.java
index c075457..ee5b52f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptorListener.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerAdapterID.java
@@ -8,14 +8,19 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.transport.tcp;
-
-import org.eclipse.net4j.transport.Connector;
+package org.eclipse.net4j.transport.container;
/**
* @author Eike Stepper
*/
-public interface TCPAcceptorListener
+public interface ContainerAdapterID
{
- public void notifyConnectorAccepted(TCPAcceptor acceptor, Connector connector);
-} \ No newline at end of file
+ public Type getType();
+
+ public String getName();
+
+ public enum Type
+ {
+ ACCEPTOR, CONNECTOR, PROTOCOL
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerUtil.java
new file mode 100644
index 0000000..80965d8
--- /dev/null
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/container/ContainerUtil.java
@@ -0,0 +1,249 @@
+/***************************************************************************
+ * 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.container;
+
+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.container.ContainerAdapterID.Type;
+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.container.ContainerAdapterIDImpl;
+import org.eclipse.internal.net4j.transport.container.ContainerImpl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public final class ContainerUtil
+{
+ private ContainerUtil()
+ {
+ }
+
+ public static ContainerAdapterID createContainerAdapterID(Type type, String name)
+ {
+ return new ContainerAdapterIDImpl(type, name);
+ }
+
+ public static ProtocolFactoryID createProtocolFactoryID(Connector.Type type, String protocolID)
+ {
+ return new ProtocolFactoryIDImpl(type, protocolID);
+ }
+
+ public static Container createContainer(IRegistry<ContainerAdapterID, ContainerAdapterFactory> adapterFactoryRegistry)
+ {
+ return new ContainerImpl(adapterFactoryRegistry);
+ }
+
+ public static Container createContainer()
+ {
+ return new ContainerImpl();
+ }
+
+ public static BufferProvider createBufferFactory(short bufferCapacity)
+ {
+ return new BufferFactoryImpl(bufferCapacity);
+ }
+
+ public static BufferProvider createBufferFactory()
+ {
+ return new BufferFactoryImpl(BufferUtil.DEFAULT_BUFFER_CAPACITY);
+ }
+
+ public static BufferPool createBufferPool(BufferProvider factory)
+ {
+ return new BufferPoolImpl(factory);
+ }
+
+ public static BufferPool createBufferPool(short bufferCapacity)
+ {
+ return createBufferPool(createBufferFactory(bufferCapacity));
+ }
+
+ public static BufferPool createBufferPool()
+ {
+ return createBufferPool(createBufferFactory());
+ }
+
+ // public static Connector createEmbeddedConnector(BufferProvider
+ // bufferProvider)
+ // {
+ // ClientEmbeddedConnectorImpl connector = new ClientEmbeddedConnectorImpl();
+ // connector.setBufferProvider(bufferProvider);
+ // return connector;
+ // }
+ //
+ // public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider,
+ // TCPSelector selector, String address,
+ // int port)
+ // {
+ // TCPAcceptorImpl acceptor = new TCPAcceptorImpl();
+ // acceptor.setBufferProvider(bufferProvider);
+ // acceptor.setSelector(selector);
+ // acceptor.setListenPort(port);
+ // acceptor.setListenAddr(address);
+ // return acceptor;
+ // }
+ //
+ // public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider,
+ // TCPSelector selector)
+ // {
+ // return createTCPAcceptor(bufferProvider, selector,
+ // TCPAcceptor.DEFAULT_ADDRESS, TCPAcceptor.DEFAULT_PORT);
+ // }
+ //
+ // public static Connector createTCPConnector(BufferProvider bufferProvider,
+ // TCPSelector selector, String host, int port)
+ // {
+ // ClientTCPConnectorImpl connector = new ClientTCPConnectorImpl();
+ // connector.setBufferProvider(bufferProvider);
+ // connector.setSelector(selector);
+ // connector.setDescription(new TCPConnectorDescriptionImpl(host, port));
+ // return connector;
+ // }
+ //
+ // public static Connector createTCPConnector(BufferProvider bufferProvider,
+ // TCPSelector selector, String host)
+ // {
+ // return createTCPConnector(bufferProvider, selector, host,
+ // TCPConnectorDescription.DEFAULT_PORT);
+ // }
+ //
+ // public static TCPSelector createTCPSelector()
+ // {
+ // return new TCPSelectorImpl();
+ // }
+
+ public static Collection<Channel> getChannels(Container container, String protocolID, Set<Connector.Type> types)
+ {
+ if (types == null)
+ {
+ types = ProtocolFactory.SYMMETRIC;
+ }
+
+ 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)
+ {
+ if (types.contains(channel.getConnector().getType()))
+ {
+ if (protocolID == null || protocolID.length() == 0)
+ {
+ result.add(channel);
+ }
+ else
+ {
+ if (channel.getReceiveHandler() instanceof Protocol)
+ {
+ Protocol protocol = (Protocol)channel.getReceiveHandler();
+ if (protocolID.equals(protocol.getProtocolID()))
+ {
+ result.add(channel);
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public static Collection<Channel> getChannels(Container container, String protocolID)
+ {
+ return getChannels(container, protocolID, null);
+ }
+
+ public static Collection<Channel> getChannels(Container container, Set<Connector.Type> types)
+ {
+ return getChannels(container, null, types);
+ }
+
+ // public static Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>>
+ // createProtocolFactoryRegistries(Set<Type> 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;
+ // }
+}
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
deleted file mode 100644
index 90b9393..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPAcceptor.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.Connector;
-
-/**
- * @author Eike Stepper
- */
-public interface TCPAcceptor
-{
- public static final String DEFAULT_ADDRESS = "0.0.0.0"; //$NON-NLS-1$
-
- public static final int DEFAULT_PORT = 2036;
-
- public String getAddress();
-
- public int getPort();
-
- public Connector[] getAcceptedConnectors();
-
- public void addAcceptorListener(TCPAcceptorListener listener);
-
- public void removeAcceptorListener(TCPAcceptorListener listener);
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelector.java
deleted file mode 100644
index 633a97f..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelector.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener.Active;
-import org.eclipse.net4j.transport.tcp.TCPSelectorListener.Passive;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public interface TCPSelector
-{
- public void invokeAsync(Runnable operation);
-
- public void registerAsync(ServerSocketChannel channel, Passive listener);
-
- public void registerAsync(SocketChannel channel, Active listener);
-
- public void setConnectInterest(SelectionKey selectionKey, boolean on);
-
- public void setReadInterest(SelectionKey selectionKey, boolean on);
-
- public void setWriteInterest(SelectionKey selectionKey, boolean on);
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelectorListener.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelectorListener.java
deleted file mode 100644
index ea4df36..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelectorListener.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * 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.tcp;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public interface TCPSelectorListener
-{
- /**
- * @author Eike Stepper
- */
- public interface Passive
- {
- public void handleAccept(TCPSelector selector, ServerSocketChannel serverSocketChannel);
- }
-
- /**
- * @author Eike Stepper
- */
- public interface Active
- {
- public void registered(SelectionKey selectionKey);
-
- public void handleConnect(TCPSelector selector, SocketChannel channel);
-
- public void handleRead(TCPSelector selector, SocketChannel socketChannel);
-
- public void handleWrite(TCPSelector selector, SocketChannel socketChannel);
- }
-} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/package.html b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/package.html
deleted file mode 100644
index b2f6093..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/package.html
+++ /dev/null
@@ -1,43 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
-<html>
-<head>
-<!--
-
- 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
-
--->
-</head>
-<body bgcolor="white">
-
-Interfaces for the transport layer specialized for TCP socket connections.
-<p>
-
-<!--
-
-<h2>Package Specification</h2>
-
-##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
-<ul>
- <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
-</ul>
-
-<h2>Related Documentation</h2>
-
-For overviews, tutorials, examples, guides, and tool documentation, please see:
-<ul>
- <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
-</ul>
-
--->
-
-<!-- Put @see and @since tags down here. -->
-
-</body>
-</html>
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
deleted file mode 100644
index 86afa5a..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Net4jUtil.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/***************************************************************************
- * 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.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;
-import org.eclipse.internal.net4j.transport.tcp.TCPConnectorDescriptionImpl;
-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
- */
-public final class Net4jUtil
-{
- private Net4jUtil()
- {
- }
-
- public static BufferProvider createBufferFactory(short bufferCapacity)
- {
- return new BufferFactoryImpl(bufferCapacity);
- }
-
- public static BufferProvider createBufferFactory()
- {
- return new BufferFactoryImpl(BufferUtil.DEFAULT_BUFFER_CAPACITY);
- }
-
- public static BufferPool createBufferPool(BufferProvider factory)
- {
- return new BufferPoolImpl(factory);
- }
-
- public static BufferPool createBufferPool(short bufferCapacity)
- {
- return createBufferPool(createBufferFactory(bufferCapacity));
- }
-
- public static BufferPool createBufferPool()
- {
- 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();
- connector.setBufferProvider(bufferProvider);
- return connector;
- }
-
- public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider, TCPSelector selector, String address,
- int port)
- {
- TCPAcceptorImpl acceptor = new TCPAcceptorImpl();
- acceptor.setBufferProvider(bufferProvider);
- acceptor.setSelector(selector);
- acceptor.setListenPort(port);
- acceptor.setListenAddr(address);
- return acceptor;
- }
-
- public static TCPAcceptor createTCPAcceptor(BufferProvider bufferProvider, TCPSelector selector)
- {
- return createTCPAcceptor(bufferProvider, selector, TCPAcceptor.DEFAULT_ADDRESS, TCPAcceptor.DEFAULT_PORT);
- }
-
- public static Connector createTCPConnector(BufferProvider bufferProvider, TCPSelector selector, String host, int port)
- {
- ClientTCPConnectorImpl connector = new ClientTCPConnectorImpl();
- connector.setBufferProvider(bufferProvider);
- connector.setSelector(selector);
- connector.setDescription(new TCPConnectorDescriptionImpl(host, port));
- return connector;
- }
-
- public static Connector createTCPConnector(BufferProvider bufferProvider, TCPSelector selector, String host)
- {
- return createTCPConnector(bufferProvider, selector, host, TCPConnectorDescription.DEFAULT_PORT);
- }
-
- public static TCPSelector createTCPSelector()
- {
- return new TCPSelectorImpl();
- }
-
- public static Collection<Channel> getChannels(TransportContainer container, String protocolID, Set<Type> types)
- {
- if (types == null)
- {
- types = ProtocolFactory.SYMMETRIC;
- }
-
- 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)
- {
- if (types.contains(channel.getConnector().getType()))
- {
- if (protocolID == null || protocolID.length() == 0)
- {
- result.add(channel);
- }
- else
- {
- if (channel.getReceiveHandler() instanceof Protocol)
- {
- Protocol protocol = (Protocol)channel.getReceiveHandler();
- if (protocolID.equals(protocol.getProtocolID()))
- {
- result.add(channel);
- }
- }
- }
- }
- }
-
- return result;
- }
-
- 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(container, null, types);
- }
-
- public static Map<Type, IRegistry<ProtocolFactoryID, ProtocolFactory>> createProtocolFactoryRegistries(Set<Type> 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;
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
index 8fe246b..866735a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
@@ -10,7 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.util;
-import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleImpl;
import java.io.PrintStream;
import java.lang.reflect.Field;
@@ -174,7 +174,7 @@ public final class ReflectUtil
private static void toString(Class<? extends Object> segment, Object object, String prefix, StringBuilder builder)
{
- if (segment == ROOT_CLASS || segment == AbstractLifecycle.class)
+ if (segment == ROOT_CLASS || segment == LifecycleImpl.class)
{
return;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorDescription.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Value.java
index b1ee32a..44965d8 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPConnectorDescription.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/Value.java
@@ -8,18 +8,28 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.transport.tcp;
+package org.eclipse.net4j.util;
-import org.eclipse.net4j.transport.ConnectorDescription;
+import java.io.Serializable;
/**
* @author Eike Stepper
*/
-public interface TCPConnectorDescription extends ConnectorDescription
+public abstract class Value implements Cloneable, Serializable
{
- public static final int DEFAULT_PORT = TCPAcceptor.DEFAULT_PORT;
+ protected Value()
+ {
+ }
- public String getHost();
+ @Override
+ protected abstract Object clone() throws CloneNotSupportedException;
- public int getPort();
+ @Override
+ public abstract boolean equals(Object obj);
+
+ @Override
+ public abstract int hashCode();
+
+ @Override
+ public abstract String toString();
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleImpl.java
index 013494d..2cb4de0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/LifecycleImpl.java
@@ -21,13 +21,13 @@ import java.util.concurrent.ConcurrentLinkedQueue;
/**
* @author Eike Stepper
*/
-public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
+public class LifecycleImpl implements Lifecycle, LifecycleNotifier
{
public static boolean USE_LABEL = true;
- private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_LIFECYCLE, AbstractLifecycle.class);
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_LIFECYCLE, LifecycleImpl.class);
- private static final ContextTracer DUMPER = new ContextTracer(Net4j.DEBUG_LIFECYCLE_DUMP, AbstractLifecycle.class);
+ private static final ContextTracer DUMPER = new ContextTracer(Net4j.DEBUG_LIFECYCLE_DUMP, LifecycleImpl.class);
private boolean active;
@@ -36,7 +36,7 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
*/
private Queue<LifecycleListener> listeners = new ConcurrentLinkedQueue();
- protected AbstractLifecycle()
+ protected LifecycleImpl()
{
}