summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-02-16 03:59:57 (EST)
committerEike Stepper2007-02-16 03:59:57 (EST)
commita628ce141f2456f1d1326f701bd4728960b432d9 (patch)
treef26c24bd7829f673a06f29da23dabed2d2b1bb4f
parent88f53fb38b5d289a850faf0fc473aa3bbd9ee283 (diff)
downloadcdo-a628ce141f2456f1d1326f701bd4728960b432d9.zip
cdo-a628ce141f2456f1d1326f701bd4728960b432d9.tar.gz
cdo-a628ce141f2456f1d1326f701bd4728960b432d9.tar.bz2
Factored jvm container out
-rw-r--r--plugins/org.eclipse.net4j.jvm/.classpath7
-rw-r--r--plugins/org.eclipse.net4j.jvm/.cvsignore2
-rw-r--r--plugins/org.eclipse.net4j.jvm/.options1
-rw-r--r--plugins/org.eclipse.net4j.jvm/.project28
-rw-r--r--plugins/org.eclipse.net4j.jvm/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF14
-rw-r--r--plugins/org.eclipse.net4j.jvm/build.properties6
-rw-r--r--plugins/org.eclipse.net4j.jvm/plugin.properties33
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/AbstractJVMConnector.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java)31
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ClientJVMConnectorImpl.java95
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorFactoryImpl.java (renamed from plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java)17
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorImpl.java83
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorManagerImpl.java57
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnectorFactoryImpl.java31
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ServerJVMConnectorImpl.java (renamed from plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ServerEmbeddedConnectorImpl.java)6
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/bundle/JVM.java52
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptor.java21
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptorManager.java26
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConnector.java21
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConstants.java21
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMUtil.java50
-rw-r--r--plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/package.html43
-rw-r--r--plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.net4j.tcp/plugin.properties2
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/AbstractTCPConnector.java32
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/ClientTCPConnectorImpl.java20
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorImpl.java83
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java18
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPAcceptor.java23
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConnector.java23
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPConstants.java4
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/tcp/TCPUtil.java12
-rw-r--r--plugins/org.eclipse.net4j/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java16
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ClientEmbeddedConnectorImpl.java69
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java7
37 files changed, 839 insertions, 127 deletions
diff --git a/plugins/org.eclipse.net4j.jvm/.classpath b/plugins/org.eclipse.net4j.jvm/.classpath
new file mode 100644
index 0000000..304e861
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.net4j.jvm/.cvsignore b/plugins/org.eclipse.net4j.jvm/.cvsignore
new file mode 100644
index 0000000..6938697
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/.cvsignore
@@ -0,0 +1,2 @@
+bin
+doc
diff --git a/plugins/org.eclipse.net4j.jvm/.options b/plugins/org.eclipse.net4j.jvm/.options
new file mode 100644
index 0000000..830fa02
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/.options
@@ -0,0 +1 @@
+org.eclipse.net4j.jvm/debug = true
diff --git a/plugins/org.eclipse.net4j.jvm/.project b/plugins/org.eclipse.net4j.jvm/.project
new file mode 100644
index 0000000..7faa074
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.net4j.jvm</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.eclipse.net4j.jvm/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.net4j.jvm/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..7709eca
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Wed Feb 14 18:44:49 CET 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e668dad
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.net4j.jvm
+Bundle-Version: 0.8.0.qualifier
+Bundle-Activator: org.eclipse.net4j.internal.jvm.bundle.JVM$Activator
+Bundle-Vendor: %providerName
+Require-Bundle: org.eclipse.net4j;visibility:=reexport
+Eclipse-LazyStart: true
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Import-Package: org.osgi.framework;version="1.3.0";resolution:=optional
+Export-Package: org.eclipse.net4j.internal.jvm;version="0.8.0",
+ org.eclipse.net4j.internal.jvm.bundle;version="0.8.0",
+ org.eclipse.net4j.jvm;version="0.8.0"
diff --git a/plugins/org.eclipse.net4j.jvm/build.properties b/plugins/org.eclipse.net4j.jvm/build.properties
new file mode 100644
index 0000000..d801b47
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ .options,\
+ plugin.properties
diff --git a/plugins/org.eclipse.net4j.jvm/plugin.properties b/plugins/org.eclipse.net4j.jvm/plugin.properties
new file mode 100644
index 0000000..493b3e7
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/plugin.properties
@@ -0,0 +1,33 @@
+# /**
+# * <copyright>
+# *
+# * 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
+# *
+# * </copyright>
+# *
+# * $Id$
+# */
+
+# NLS_MESSAGEFORMAT_VAR
+
+# ==============================================================================
+# Do not change the properties between this line and the last line containing:
+# %%% END OF TRANSLATED PROPERTIES %%%
+# Instead, either redefine an existing property, or create a new property,
+# append it to the end of the file, and change the code to use the new name.
+# ==============================================================================
+
+pluginName=Net4j JVM Transport
+providerName=Eclipse.org
+
+# ==============================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# The above properties have been shipped for translation.
+# ==============================================================================
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/AbstractJVMConnector.java
index 583a59f..5b17b91 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/AbstractEmbeddedConnector.java
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/AbstractJVMConnector.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.transport.embedded;
+package org.eclipse.net4j.internal.jvm;
import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.Channel;
@@ -16,6 +16,7 @@ import org.eclipse.net4j.transport.ConnectorException;
import org.eclipse.internal.net4j.transport.AbstractConnector;
import org.eclipse.internal.net4j.transport.ChannelImpl;
+import org.eclipse.internal.net4j.transport.DescriptionUtil;
import java.util.Queue;
@@ -24,20 +25,27 @@ import java.util.Queue;
*
* @author Eike Stepper
*/
-public abstract class AbstractEmbeddedConnector extends AbstractConnector
+public abstract class AbstractJVMConnector extends AbstractConnector
{
- private AbstractEmbeddedConnector peer;
+ private AbstractJVMConnector peer;
- public AbstractEmbeddedConnector()
+ private String name;
+
+ public AbstractJVMConnector()
{
}
- public AbstractEmbeddedConnector getPeer()
+ public String getName()
+ {
+ return name;
+ }
+
+ public AbstractJVMConnector getPeer()
{
return peer;
}
- public void setPeer(AbstractEmbeddedConnector peer)
+ public void setPeer(AbstractJVMConnector peer)
{
this.peer = peer;
}
@@ -79,4 +87,15 @@ public abstract class AbstractEmbeddedConnector extends AbstractConnector
buffer.flip();
peerChannel.handleBufferFromMultiplexer(buffer);
}
+
+ @Override
+ protected void onAboutToActivate() throws Exception
+ {
+ super.onAboutToActivate();
+ name = DescriptionUtil.getElement(getDescription(), 2);
+ if (name == null)
+ {
+ throw new IllegalStateException("name == null");
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ClientJVMConnectorImpl.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ClientJVMConnectorImpl.java
new file mode 100644
index 0000000..d1c1e60
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ClientJVMConnectorImpl.java
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.jvm.JVMAcceptor;
+import org.eclipse.net4j.jvm.JVMAcceptorManager;
+import org.eclipse.net4j.transport.ConnectorLocation;
+import org.eclipse.net4j.util.lifecycle.LifecycleListener;
+import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+import org.eclipse.internal.net4j.transport.DescriptionUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class ClientJVMConnectorImpl extends AbstractJVMConnector
+{
+ private JVMAcceptorImpl acceptor;
+
+ private LifecycleListener peerLifecycleListener = new LifecycleListener()
+ {
+ public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier)
+ {
+ }
+
+ public void notifyLifecycleActivated(LifecycleNotifier notifier)
+ {
+ }
+
+ public void notifyLifecycleDeactivating(LifecycleNotifier notifier)
+ {
+ setPeer(null);
+ deactivate();
+ }
+ };
+
+ public ClientJVMConnectorImpl()
+ {
+ }
+
+ public ConnectorLocation getLocation()
+ {
+ return ConnectorLocation.CLIENT;
+ }
+
+ public JVMAcceptorImpl getAcceptor()
+ {
+ return acceptor;
+ }
+
+ @Override
+ protected void onAboutToActivate() throws Exception
+ {
+ super.onAboutToActivate();
+ acceptor = JVMAcceptorManagerImpl.INSTANCE.getAcceptor(getName());
+ if (acceptor == null)
+ {
+ throw new IllegalStateException("acceptor == null");
+ }
+ }
+
+ @Override
+ protected void onActivate() throws Exception
+ {
+ super.onActivate();
+ AbstractJVMConnector peer = acceptor.handleAccept(this);
+ setPeer(peer);
+ }
+
+ @Override
+ protected void onDeactivate() throws Exception
+ {
+ LifecycleUtil.deactivateNoisy(getPeer());
+ super.onDeactivate();
+ }
+
+ protected AbstractJVMConnector createServerPeer() throws Exception
+ {
+ ServerJVMConnectorImpl server = new ServerJVMConnectorImpl(this);
+ server.setBufferProvider(getBufferProvider());
+ server.setReceiveExecutor(getReceiveExecutor());
+ server.addLifecycleListener(peerLifecycleListener);
+ server.activate();
+ return server;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorFactoryImpl.java
index 40e631d..8b77272 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/Activator.java
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorFactoryImpl.java
@@ -8,23 +8,24 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.net4j.internal.tcp.bundle;
+package org.eclipse.net4j.internal.jvm;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
+import org.eclipse.net4j.jvm.JVMConstants;
+import org.eclipse.net4j.transport.Acceptor;
+import org.eclipse.net4j.transport.AcceptorFactory;
/**
* @author Eike Stepper
*/
-public class Activator implements BundleActivator
+public class JVMAcceptorFactoryImpl implements AcceptorFactory
{
- public void start(BundleContext context) throws Exception
+ public String getType()
{
- TCP.BUNDLE.setBundleContext(context);
+ return JVMConstants.TYPE;
}
- public void stop(BundleContext context) throws Exception
+ public Acceptor createAcceptor()
{
- TCP.BUNDLE.setBundleContext(null);
+ return new JVMAcceptorImpl();
}
}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorImpl.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorImpl.java
new file mode 100644
index 0000000..98506e9
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorImpl.java
@@ -0,0 +1,83 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.jvm.JVMAcceptor;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
+import org.eclipse.internal.net4j.transport.AbstractAcceptor;
+import org.eclipse.internal.net4j.transport.DescriptionUtil;
+
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public class JVMAcceptorImpl extends AbstractAcceptor implements JVMAcceptor
+{
+ @SuppressWarnings("unused")
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR, JVMAcceptorImpl.class);
+
+ private String name;
+
+ public JVMAcceptorImpl()
+ {
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public ServerJVMConnectorImpl handleAccept(ClientJVMConnectorImpl client)
+ {
+ ServerJVMConnectorImpl connector = new ServerJVMConnectorImpl(client);
+ connector.setReceiveExecutor(getReceiveExecutor());
+ connector.setProtocolFactoryRegistry(getProtocolFactoryRegistry());
+ connector.setBufferProvider(getBufferProvider());
+ return connector;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("JVMAcceptor[{0}]", getDescription()); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void onAboutToActivate() throws Exception
+ {
+ super.onAboutToActivate();
+ if (getDescription() == null)
+ {
+ throw new IllegalStateException("getDescription() == null"); //$NON-NLS-1$
+ }
+ else
+ {
+ name = DescriptionUtil.getElement(getDescription(), 1);
+ }
+ }
+
+ @Override
+ protected void onActivate() throws Exception
+ {
+ super.onActivate();
+ JVMAcceptorManagerImpl.INSTANCE.registerAcceptor(this);
+ }
+
+ @Override
+ protected void onDeactivate() throws Exception
+ {
+ JVMAcceptorManagerImpl.INSTANCE.deregisterAcceptor(this);
+ super.onDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorManagerImpl.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorManagerImpl.java
new file mode 100644
index 0000000..8d057f3
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMAcceptorManagerImpl.java
@@ -0,0 +1,57 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.jvm.JVMAcceptor;
+import org.eclipse.net4j.jvm.JVMAcceptorManager;
+import org.eclipse.net4j.util.lifecycle.Singleton;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import org.eclipse.internal.net4j.util.registry.HashMapRegistry;
+
+/**
+ * @author Eike Stepper
+ */
+public class JVMAcceptorManagerImpl implements JVMAcceptorManager
+{
+ @Singleton
+ public static final JVMAcceptorManagerImpl INSTANCE = new JVMAcceptorManagerImpl();
+
+ private IRegistry<String, JVMAcceptor> acceptorRegistry = new HashMapRegistry();
+
+ public IRegistry<String, JVMAcceptor> getAcceptorRegistry()
+ {
+ // TODO Introduce UnmodifiableRegistry
+ return acceptorRegistry;
+ }
+
+ public JVMAcceptorImpl getAcceptor(String name)
+ {
+ return (JVMAcceptorImpl)acceptorRegistry.get(name);
+ }
+
+ public boolean registerAcceptor(JVMAcceptorImpl acceptor)
+ {
+ String name = acceptor.getName();
+ if (!acceptorRegistry.containsKey(name))
+ {
+ acceptorRegistry.put(name, acceptor);
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean deregisterAcceptor(JVMAcceptorImpl acceptor)
+ {
+ return acceptorRegistry.remove(acceptor.getName()) != null;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnectorFactoryImpl.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnectorFactoryImpl.java
new file mode 100644
index 0000000..630def6
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/JVMConnectorFactoryImpl.java
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.jvm.JVMConstants;
+import org.eclipse.net4j.transport.Connector;
+import org.eclipse.net4j.transport.ConnectorFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class JVMConnectorFactoryImpl implements ConnectorFactory
+{
+ public String getType()
+ {
+ return JVMConstants.TYPE;
+ }
+
+ public Connector createConnector()
+ {
+ return new ClientJVMConnectorImpl();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ServerEmbeddedConnectorImpl.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ServerJVMConnectorImpl.java
index 0161c90..5bcfe4d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ServerEmbeddedConnectorImpl.java
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/ServerJVMConnectorImpl.java
@@ -8,7 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
**************************************************************************/
-package org.eclipse.internal.net4j.transport.embedded;
+package org.eclipse.net4j.internal.jvm;
import org.eclipse.net4j.transport.ConnectorLocation;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
@@ -16,9 +16,9 @@ import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
/**
* @author Eike Stepper
*/
-public class ServerEmbeddedConnectorImpl extends AbstractEmbeddedConnector
+public class ServerJVMConnectorImpl extends AbstractJVMConnector
{
- public ServerEmbeddedConnectorImpl(ClientEmbeddedConnectorImpl clientPeer)
+ public ServerJVMConnectorImpl(ClientJVMConnectorImpl clientPeer)
{
setPeer(clientPeer);
}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/bundle/JVM.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/bundle/JVM.java
new file mode 100644
index 0000000..41af554
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/internal/jvm/bundle/JVM.java
@@ -0,0 +1,52 @@
+/***************************************************************************
+ * 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.jvm.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+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
+ */
+public final class JVM
+{
+ public static final String BUNDLE_ID = "org.eclipse.net4j.jvm"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, JVM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ private JVM()
+ {
+ }
+ /**
+ * @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.jvm/src/org/eclipse/net4j/jvm/JVMAcceptor.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptor.java
new file mode 100644
index 0000000..591f18f
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptor.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.transport.Acceptor;
+
+/**
+ * @author Eike Stepper
+ */
+public interface JVMAcceptor extends Acceptor
+{
+ public String getName();
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptorManager.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptorManager.java
new file mode 100644
index 0000000..5709133
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMAcceptorManager.java
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.internal.jvm.JVMAcceptorManagerImpl;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+/**
+ * @author Eike Stepper
+ */
+public interface JVMAcceptorManager
+{
+ public static final JVMAcceptorManager INSTANCE = JVMAcceptorManagerImpl.INSTANCE;
+
+ public IRegistry<String, JVMAcceptor> getAcceptorRegistry();
+
+ public JVMAcceptor getAcceptor(String name);
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConnector.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConnector.java
new file mode 100644
index 0000000..402c9d2
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConnector.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.net4j.transport.Connector;
+
+/**
+ * @author Eike Stepper
+ */
+public interface JVMConnector extends Connector
+{
+ public String getName();
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConstants.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConstants.java
new file mode 100644
index 0000000..7c61a92
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMConstants.java
@@ -0,0 +1,21 @@
+/***************************************************************************
+ * 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.jvm;
+
+/**
+ * @author Eike Stepper
+ */
+public interface JVMConstants
+{
+ public static final String TYPE = "jvm";
+
+ public static final String DEFAULT_NAME = "default";
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMUtil.java b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMUtil.java
new file mode 100644
index 0000000..0a3aa81
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/JVMUtil.java
@@ -0,0 +1,50 @@
+/***************************************************************************
+ * 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.jvm;
+
+import org.eclipse.internal.net4j.transport.DescriptionUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public final class JVMUtil
+{
+ private JVMUtil()
+ {
+ }
+
+ public static String createAcceptorDescription()
+ {
+ return createAcceptorDescription(JVMConstants.DEFAULT_NAME);
+ }
+
+ public static String createAcceptorDescription(String name)
+ {
+ Object[] elements = { name };
+ return DescriptionUtil.getDescription(JVMConstants.TYPE, elements);
+ }
+
+ public static String createConnectorDescription()
+ {
+ return createConnectorDescription(JVMConstants.DEFAULT_NAME);
+ }
+
+ public static String createConnectorDescription(String name)
+ {
+ return createConnectorDescription(null, name);
+ }
+
+ public static String createConnectorDescription(String userName, String name)
+ {
+ Object[] elements = { userName, name };
+ return DescriptionUtil.getDescription(JVMConstants.TYPE, elements);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/package.html b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/package.html
new file mode 100644
index 0000000..b2f6093
--- /dev/null
+++ b/plugins/org.eclipse.net4j.jvm/src/org/eclipse/net4j/jvm/package.html
@@ -0,0 +1,43 @@
+<!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.tcp/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tcp/META-INF/MANIFEST.MF
index da07909..c304620 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 b430287..3a2007d 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 a8adbc4..86cd5e2 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 0d8d7c1..060ac6c 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;
@@ -52,26 +51,11 @@ public class ClientTCPConnectorImpl extends AbstractTCPConnector
}
@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 7e94c26..86930f6 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/TCP.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/bundle/TCP.java
index 0f9dfb1..18bbfc4 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 0000000..97931ff
--- /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 0000000..6fc00de
--- /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 747dac4..5637c77 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 0802cd8..ceb5456 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 8af046c..7c2876e 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 726cfbc..0b781f3 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/ClientEmbeddedConnectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ClientEmbeddedConnectorImpl.java
deleted file mode 100644
index 314b13d..0000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/embedded/ClientEmbeddedConnectorImpl.java
+++ /dev/null
@@ -1,69 +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.ConnectorLocation;
-import org.eclipse.net4j.util.lifecycle.LifecycleListener;
-import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-/**
- * @author Eike Stepper
- */
-public class ClientEmbeddedConnectorImpl extends AbstractEmbeddedConnector implements LifecycleListener
-{
- public ClientEmbeddedConnectorImpl()
- {
- }
-
- public ConnectorLocation getLocation()
- {
- return ConnectorLocation.CLIENT;
- }
-
- public void notifyLifecycleAboutToActivate(LifecycleNotifier notifier)
- {
- }
-
- public void notifyLifecycleActivated(LifecycleNotifier notifier)
- {
- }
-
- public void notifyLifecycleDeactivating(LifecycleNotifier notifier)
- {
- setPeer(null);
- deactivate();
- }
-
- @Override
- protected void onActivate() throws Exception
- {
- super.onActivate();
- setPeer(createServerPeer());
- }
-
- @Override
- protected void onDeactivate() throws Exception
- {
- LifecycleUtil.deactivateNoisy(getPeer());
- super.onDeactivate();
- }
-
- protected AbstractEmbeddedConnector createServerPeer() throws Exception
- {
- ServerEmbeddedConnectorImpl server = new ServerEmbeddedConnectorImpl(this);
- server.setBufferProvider(getBufferProvider());
- server.setReceiveExecutor(getReceiveExecutor());
- server.addLifecycleListener(this);
- server.activate();
- return server;
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
index de1befa..ab8cb85 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java
@@ -44,6 +44,8 @@ public interface Connector extends INotifier.Introspection
public String getDescription();
+ public String getUserID();
+
public ConnectorCredentials getCredentials();
public ConnectorState getState();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
index 681c7a0..31538d0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistry.java
@@ -30,4 +30,11 @@ public interface IRegistry<K, V> extends Map<K, V>
public void commit();
public void dispose();
+
+ /**
+ * @author Eike Stepper
+ */
+ public interface Unmodifiable<K, V> extends IRegistry<K, V>
+ {
+ }
}