+
+
+
+
+
+
+
diff --git a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
index da07909fc1..c304620bed 100644
--- a/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.net4j.tcp
Bundle-Version: 0.8.0.qualifier
-Bundle-Activator: org.eclipse.net4j.internal.tcp.bundle.Activator
+Bundle-Activator: org.eclipse.net4j.internal.tcp.bundle.TCP$Activator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.net4j;visibility:=reexport
Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.net4j.tcp/plugin.properties b/plugins/org.eclipse.net4j.tcp/plugin.properties
index b430287b01..3a2007d294 100644
--- a/plugins/org.eclipse.net4j.tcp/plugin.properties
+++ b/plugins/org.eclipse.net4j.tcp/plugin.properties
@@ -24,7 +24,7 @@
# append it to the end of the file, and change the code to use the new name.
# ==============================================================================
-pluginName=Net4j TCP Support
+pluginName=Net4j TCP Transport
providerName=Eclipse.org
# ==============================================================================
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/AbstractTCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/AbstractTCPConnector.java
index a8adbc4215..86cd5e280e 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/AbstractTCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/AbstractTCPConnector.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.tcp;
+import org.eclipse.net4j.tcp.TCPConnector;
import org.eclipse.net4j.tcp.TCPSelector;
import org.eclipse.net4j.tcp.TCPSelectorListener;
import org.eclipse.net4j.transport.Buffer;
@@ -21,6 +22,7 @@ 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 org.eclipse.internal.net4j.transport.DescriptionUtil;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
@@ -32,7 +34,8 @@ import java.util.Queue;
/**
* @author Eike Stepper
*/
-public abstract class AbstractTCPConnector extends AbstractConnector implements TCPSelectorListener.Active
+public abstract class AbstractTCPConnector extends AbstractConnector implements TCPConnector,
+ TCPSelectorListener.Active
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR, AbstractTCPConnector.class);
@@ -46,10 +49,24 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
private ControlChannelImpl controlChannel;
+ private String host;
+
+ private int port;
+
public AbstractTCPConnector()
{
}
+ public String getHost()
+ {
+ return host;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+
public TCPSelector getSelector()
{
return selector;
@@ -269,6 +286,19 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
{
throw new IllegalStateException("selector == null");
}
+
+ String[] elements = DescriptionUtil.getElements(getDescription());
+ host = elements[2];
+ if (host == null)
+ {
+ throw new IllegalStateException("host == null");
+ }
+
+ port = Integer.parseInt(elements[3]);
+ if (port == 0)
+ {
+ throw new IllegalStateException("port == 0");
+ }
}
@Override
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ClientTCPConnectorImpl.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ClientTCPConnectorImpl.java
index 0d8d7c1822..060ac6c071 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ClientTCPConnectorImpl.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ClientTCPConnectorImpl.java
@@ -13,7 +13,6 @@ package org.eclipse.net4j.internal.tcp;
import org.eclipse.net4j.transport.ConnectorLocation;
import org.eclipse.internal.net4j.bundle.Net4j;
-import org.eclipse.internal.net4j.transport.DescriptionUtil;
import java.io.IOException;
import java.net.InetAddress;
@@ -51,27 +50,12 @@ public class ClientTCPConnectorImpl extends AbstractTCPConnector
return MessageFormat.format("ClientTCPConnector[{0}]", getDescription()); //$NON-NLS-1$
}
- @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();
-
- String[] elements = DescriptionUtil.getElements(getDescription());
- String host = elements[1];
- int port = Integer.parseInt(elements[2]);
-
- InetAddress addr = InetAddress.getByName(host);
- InetSocketAddress sAddr = new InetSocketAddress(addr, port);
+ InetAddress addr = InetAddress.getByName(getHost());
+ InetSocketAddress sAddr = new InetSocketAddress(addr, getPort());
getSocketChannel().connect(sAddr);
}
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
index 7e94c2630f..86930f6e0c 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java
@@ -10,8 +10,10 @@
**************************************************************************/
package org.eclipse.net4j.internal.tcp;
+import org.eclipse.net4j.tcp.TCPAcceptor;
import org.eclipse.net4j.tcp.TCPSelector;
import org.eclipse.net4j.tcp.TCPSelectorListener;
+import org.eclipse.net4j.tcp.TCPUtil;
import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.internal.net4j.bundle.Net4j;
@@ -20,6 +22,8 @@ import org.eclipse.internal.net4j.transport.DescriptionUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.SocketAddress;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
@@ -28,7 +32,7 @@ import java.text.MessageFormat;
/**
* @author Eike Stepper
*/
-public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorListener.Passive
+public class TCPAcceptorImpl extends AbstractAcceptor implements TCPAcceptor, TCPSelectorListener.Passive
{
private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, TCPAcceptorImpl.class);
@@ -36,10 +40,24 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorList
private ServerSocketChannel serverSocketChannel;
+ private String address;
+
+ private int port;
+
public TCPAcceptorImpl()
{
}
+ public String getAddress()
+ {
+ return address;
+ }
+
+ public int getPort()
+ {
+ return port;
+ }
+
public TCPSelector getSelector()
{
return selector;
@@ -90,7 +108,10 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorList
protected ServerTCPConnectorImpl createConnector(SocketChannel socketChannel)
{
+ String description = createConnectorDescription(socketChannel);
+
ServerTCPConnectorImpl connector = new ServerTCPConnectorImpl();
+ connector.setDescription(description);
connector.setSocketChannel(socketChannel);
connector.setReceiveExecutor(getReceiveExecutor());
connector.setProtocolFactoryRegistry(getProtocolFactoryRegistry());
@@ -105,7 +126,13 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorList
super.onAboutToActivate();
if (getDescription() == null)
{
- throw new IllegalStateException("getDescription() == null"); //$NON-NLS-1$
+ throw new IllegalStateException("description == null"); //$NON-NLS-1$
+ }
+ else
+ {
+ String[] elements = DescriptionUtil.getElements(getDescription());
+ address = elements[1];
+ port = Integer.parseInt(elements[2]);
}
if (selector == null)
@@ -118,17 +145,33 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorList
protected void onActivate() throws Exception
{
super.onActivate();
-
- String[] elements = DescriptionUtil.getElements(getDescription());
- String address = elements[1];
- int port = Integer.parseInt(elements[2]);
-
- InetAddress addr = InetAddress.getByName(address);
- InetSocketAddress sAddr = new InetSocketAddress(addr, port);
+ InetSocketAddress addr = null;
+ if (address != null)
+ {
+ addr = new InetSocketAddress(InetAddress.getByName(address), port);
+ }
serverSocketChannel = ServerSocketChannel.open();
serverSocketChannel.configureBlocking(false);
- serverSocketChannel.socket().bind(sAddr);
+
+ ServerSocket socket = serverSocketChannel.socket();
+ socket.bind(addr);
+
+ if (address == null)
+ {
+ address = socket.getInetAddress().toString();
+ if (address.startsWith("/"))
+ {
+ address = address.substring(1);
+ }
+
+ int colon = address.indexOf(':');
+ if (colon != -1)
+ {
+ port = Integer.parseInt(address.substring(colon + 1));
+ address = address.substring(0, colon);
+ }
+ }
selector.registerAsync(serverSocketChannel, this);
}
@@ -139,4 +182,24 @@ public class TCPAcceptorImpl extends AbstractAcceptor implements TCPSelectorList
serverSocketChannel.close();
super.onDeactivate();
}
+
+ private String createConnectorDescription(SocketChannel socketChannel)
+ {
+ SocketAddress addr = socketChannel.socket().getRemoteSocketAddress();
+ String host = addr.toString();
+ if (host.startsWith("/"))
+ {
+ host = host.substring(1);
+ }
+
+ int port = 0;
+ int colon = host.indexOf(':');
+ if (colon != -1)
+ {
+ port = Integer.parseInt(host.substring(colon + 1));
+ host = host.substring(0, colon);
+ }
+
+ return TCPUtil.createConnectorDescription(host, port);
+ }
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java
deleted file mode 100644
index 40e631d43d..0000000000
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004-2007 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.internal.tcp.bundle;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Eike Stepper
- */
-public class Activator implements BundleActivator
-{
- public void start(BundleContext context) throws Exception
- {
- TCP.BUNDLE.setBundleContext(context);
- }
-
- public void stop(BundleContext context) throws Exception
- {
- TCP.BUNDLE.setBundleContext(null);
- }
-}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java
index 0f9dfb15cb..18bbfc46ff 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java
@@ -15,6 +15,9 @@ import org.eclipse.net4j.util.om.OMLogger;
import org.eclipse.net4j.util.om.OMPlatform;
import org.eclipse.net4j.util.om.OMTracer;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
/**
* @author Eike Stepper
*/
@@ -31,4 +34,19 @@ public final class TCP
private TCP()
{
}
+ /**
+ * @author Eike Stepper
+ */
+ public static class Activator implements BundleActivator
+ {
+ public void start(BundleContext context) throws Exception
+ {
+ BUNDLE.setBundleContext(context);
+ }
+
+ public void stop(BundleContext context) throws Exception
+ {
+ BUNDLE.setBundleContext(null);
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPAcceptor.java
new file mode 100644
index 0000000000..97931ffc38
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPAcceptor.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 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.tcp;
+
+import org.eclipse.net4j.transport.Acceptor;
+
+/**
+ * @author Eike Stepper
+ */
+public interface TCPAcceptor extends Acceptor
+{
+ public String getAddress();
+
+ public int getPort();
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConnector.java
new file mode 100644
index 0000000000..6fc00de4cd
--- /dev/null
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConnector.java
@@ -0,0 +1,23 @@
+/***************************************************************************
+ * Copyright (c) 2004-2007 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.tcp;
+
+import org.eclipse.net4j.transport.Connector;
+
+/**
+ * @author Eike Stepper
+ */
+public interface TCPConnector extends Connector
+{
+ public String getHost();
+
+ public int getPort();
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConstants.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConstants.java
index 747dac4968..5637c77a51 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConstants.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConstants.java
@@ -15,11 +15,9 @@ package org.eclipse.net4j.tcp;
*/
public interface TCPConstants
{
-
- public static final String TYPE = "TCP";
+ public static final String TYPE = "tcp";
public static final String DEFAULT_ADDRESS = "0.0.0.0"; //$NON-NLS-1$
public static final int DEFAULT_PORT = 2036;
-
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPUtil.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPUtil.java
index 0802cd8948..ceb545631c 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPUtil.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPUtil.java
@@ -39,22 +39,22 @@ public final class TCPUtil
public static String createConnectorDescription(String host)
{
- return createConnectorDescription(host, null);
+ return createConnectorDescription(null, host);
}
public static String createConnectorDescription(String host, int port)
{
- return createConnectorDescription(host, port, null);
+ return createConnectorDescription(null, host, port);
}
- public static String createConnectorDescription(String host, String userName)
+ public static String createConnectorDescription(String userName, String host)
{
- return createConnectorDescription(host, TCPConstants.DEFAULT_PORT, userName);
+ return createConnectorDescription(userName, host, TCPConstants.DEFAULT_PORT);
}
- public static String createConnectorDescription(String host, int port, String userName)
+ public static String createConnectorDescription(String userName, String host, int port)
{
- Object[] elements = { host, port, userName };
+ Object[] elements = { userName, host, port };
return DescriptionUtil.getDescription(TCPConstants.TYPE, elements);
}
}
diff --git a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
index 8af046cb43..7c2876ea2c 100644
--- a/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.net4j/META-INF/MANIFEST.MF
@@ -13,7 +13,6 @@ Import-Package: org.eclipse.osgi.service.debug;version="1.0.0";resolution:=optio
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.embedded;version="0.8.0",
org.eclipse.internal.net4j.util;version="0.8.0",
org.eclipse.internal.net4j.util.concurrent;version="0.8.0",
org.eclipse.internal.net4j.util.event;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 726cfbca4f..0b781f3866 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
@@ -60,6 +60,8 @@ public abstract class AbstractConnector extends LifecycleImpl implements Connect
private int connectorID = getNextConnectorID();
+ private String userID;
+
private String description;
private ConnectorCredentials credentials;
@@ -161,6 +163,11 @@ public abstract class AbstractConnector extends LifecycleImpl implements Connect
return getLocation() == ConnectorLocation.SERVER;
}
+ public String getUserID()
+ {
+ return userID;
+ }
+
public String getDescription()
{
return description;
@@ -499,6 +506,15 @@ public abstract class AbstractConnector extends LifecycleImpl implements Connect
protected void onAboutToActivate() throws Exception
{
super.onAboutToActivate();
+ if (description == null)
+ {
+ throw new IllegalStateException("description == null"); //$NON-NLS-1$
+ }
+ else
+ {
+ userID = DescriptionUtil.getElement(description, 1);
+ }
+
if (bufferProvider == null)
{
throw new IllegalStateException("bufferProvider == null"); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java
deleted file mode 100644
index 583a59fb86..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004-2007 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.embedded;
-
-import org.eclipse.net4j.transport.Buffer;
-import org.eclipse.net4j.transport.Channel;
-import org.eclipse.net4j.transport.ConnectorException;
-
-import org.eclipse.internal.net4j.transport.AbstractConnector;
-import org.eclipse.internal.net4j.transport.ChannelImpl;
-
-import java.util.Queue;
-
-/**
- * TODO Remove peer channels
- *
- * @author Eike Stepper
- */
-public abstract class AbstractEmbeddedConnector extends AbstractConnector
-{
- private AbstractEmbeddedConnector peer;
-
- public AbstractEmbeddedConnector()
- {
- }
-
- public AbstractEmbeddedConnector getPeer()
- {
- return peer;
- }
-
- public void setPeer(AbstractEmbeddedConnector peer)
- {
- this.peer = peer;
- }
-
- @Override
- protected void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException
- {
- try
- {
- ChannelImpl channel = getPeer().createChannel(channelIndex, protocolID, null);
- if (channel == null)
- {
- throw new ConnectorException("Failed to register channel with peer"); //$NON-NLS-1$
- }
-
- channel.activate();
- }
- catch (ConnectorException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
- }
-
- public void multiplexBuffer(Channel localChannel)
- {
- short channelIndex = localChannel.getChannelIndex();
- ChannelImpl peerChannel = peer.getChannel(channelIndex);
- if (peerChannel == null)
- {
- throw new IllegalStateException("peerChannel == null"); //$NON-NLS-1$
- }
-
- Queue