diff options
17 files changed, 115 insertions, 113 deletions
diff --git a/plugins/org.eclipse.net4j.debug/.classpath b/plugins/org.eclipse.net4j.debug/.classpath index 751c8f2e50..304e86186a 100644 --- a/plugins/org.eclipse.net4j.debug/.classpath +++ b/plugins/org.eclipse.net4j.debug/.classpath @@ -1,7 +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"/> + <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.debug/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.net4j.debug/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..7e892c0ff7 --- /dev/null +++ b/plugins/org.eclipse.net4j.debug/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Sun Dec 17 20:03:12 CET 2006 +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.debug/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.debug/META-INF/MANIFEST.MF index 2e7e0fa0b1..e43907ab76 100644 --- a/plugins/org.eclipse.net4j.debug/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.debug/META-INF/MANIFEST.MF @@ -1,10 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Debug Plug-in Bundle-SymbolicName: org.eclipse.net4j.debug; singleton:=true Bundle-Version: 0.8.0.qualifier +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Bundle-Activator: org.eclipse.net4j.internal.debug.bundle.Activator Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime, org.eclipse.ui, org.eclipse.net4j diff --git a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF index 796371c89a..2b858bd55f 100644 --- a/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.net4j.tests/META-INF/MANIFEST.MF @@ -1,12 +1,12 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.net4j.tests Bundle-Version: 0.8.0.qualifier +Bundle-Name: %pluginName +Bundle-Vendor: %providerName Bundle-Activator: org.eclipse.net4j.tests.bundle.Activator Bundle-Localization: plugin +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.core.runtime, org.eclipse.net4j, org.junit -Bundle-Vendor: %providerName -Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/plugins/org.eclipse.net4j/.classpath b/plugins/org.eclipse.net4j/.classpath index 1ead8224e9..b69fb1541e 100644 --- a/plugins/org.eclipse.net4j/.classpath +++ b/plugins/org.eclipse.net4j/.classpath @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry excluding="org/eclipse/internal/net4j/component/InactiveException.java|org/eclipse/net4j/transport/ChannelMultiplexer.java" kind="src" path="src"/> + <classpathentry excluding="org/eclipse/internal/net4j/component/InactiveException.java|org/eclipse/net4j/transport/ChannelMultiplexer.java|org/eclipse/net4j/util/registry/delegating/AbstractCachingRegistry.java|org/eclipse/net4j/util/registry/delegating/DelegatingRegistry.java|org/eclipse/net4j/util/registry/delegating/HashCacheRegistry.java" kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> diff --git a/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.core.prefs index cedc7e0052..ac8a18e279 100644 --- a/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.core.prefs +++ b/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,4 @@ -#Fri Oct 20 10:25:00 CEST 2006 +#Sun Dec 17 09:38:34 CET 2006 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.compliance=1.5 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 70b0d10ecc..8f0dabef85 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 @@ -249,10 +249,10 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con break; case CONNECTED: - finishedConnecting.countDown(); // Just in case of suspicion - finishedNegotiating.countDown(); REGISTRY.put(connectorID, this); REGISTRY.commit(); + finishedConnecting.countDown(); // Just in case of suspicion + finishedNegotiating.countDown(); break; } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java index 7313b40e14..169bfd14b0 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java @@ -31,7 +31,6 @@ import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.List; import java.util.Queue; -import java.util.concurrent.TimeoutException; /** * @author Eike Stepper @@ -42,8 +41,6 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR, AbstractTCPConnector.class); - private static final long REGISTER_SELECTOR_TIMEOUT = 250000; - private SocketChannel socketChannel; private TCPSelector selector; @@ -97,9 +94,19 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements */ 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 @@ -116,6 +123,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements try { + checkSelectionKey(); selector.setConnectInterest(selectionKey, false); setState(State.NEGOTIATING); } @@ -199,6 +207,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements if (!moreToWrite) { + checkSelectionKey(); selector.setWriteInterest(selectionKey, false); } } @@ -268,17 +277,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements super.onActivate(); controlChannel = new ControlChannelImpl(this); controlChannel.activate(); - - selectionKey = selector.register(socketChannel, this, REGISTER_SELECTOR_TIMEOUT); - if (selectionKey == null) - { - throw new TimeoutException("Unable to register channel with selector"); - } - - if (getType() == Type.SERVER) - { - selector.setConnectInterest(selectionKey, false); - } + selector.registerAsync(socketChannel, this); } @Override @@ -335,4 +334,12 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements 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/TCPSelectorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java index 53f897766c..e75fd180c8 100644 --- 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 @@ -31,8 +31,6 @@ import java.nio.channels.SocketChannel; import java.util.Iterator; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; /** * @author Eike Stepper @@ -42,8 +40,6 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_SELECTOR, TCPSelectorImpl.class); - private static final long SELECT_TIMEOUT = 2; - private Selector selector; private Queue<Runnable> pendingOperations = new ConcurrentLinkedQueue(); @@ -56,6 +52,11 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R public void invokeAsync(final Runnable operation) { + if (TRACER.isEnabled()) + { + TRACER.trace("Pending operation " + operation); + } + pendingOperations.add(operation); selector.wakeup(); } @@ -69,85 +70,31 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R { doRegister(channel, listener); } - }); - } - - public void registerAsync(final SocketChannel channel, final Active listener) - { - assertValidListener(listener); - invokeAsync(new Runnable() - { - public void run() - { - doRegister(channel, listener); - } - }); - } - public boolean invoke(final Runnable operation, long timeout) - { - final CountDownLatch latch = new CountDownLatch(1); - pendingOperations.add(new Runnable() - { - public void run() + @Override + public String toString() { - operation.run(); - latch.countDown(); + return "REGISTER " + TCPUtil.toString(channel); } }); - - selector.wakeup(); - - try - { - boolean result = latch.await(timeout, TimeUnit.MILLISECONDS); - return result; - } - catch (InterruptedException ex) - { - return false; - } } - public SelectionKey register(final ServerSocketChannel channel, final Passive listener, - long timeout) + public void registerAsync(final SocketChannel channel, final Active listener) { assertValidListener(listener); - boolean success = invoke(new Runnable() + invokeAsync(new Runnable() { public void run() { doRegister(channel, listener); } - }, timeout); - - if (!success) - { - return null; - } - - return channel.keyFor(selector); - } - public SelectionKey register(final SocketChannel channel, final Active listener, long timeout) - { - assertValidListener(listener); - boolean success = invoke(new Runnable() - { - public void run() + @Override + public String toString() { - System.out.println("START REGISTER"); - doRegister(channel, listener); - System.out.println("STOP REGISTER"); + return "REGISTER " + TCPUtil.toString(channel); } - }, timeout); - - if (!success) - { - return null; - } - - return channel.keyFor(selector); + }); } public void setConnectInterest(final SelectionKey selectionKey, final boolean on) @@ -158,6 +105,12 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R { TCPUtil.setConnectInterest(selectionKey, on); } + + @Override + public String toString() + { + return "INTEREST CONNECT " + selectionKey + " = " + on; + } }); } @@ -169,6 +122,12 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R { TCPUtil.setReadInterest(selectionKey, on); } + + @Override + public String toString() + { + return "INTEREST READ " + selectionKey + " = " + on; + } }); } @@ -180,6 +139,13 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R { TCPUtil.setWriteInterest(selectionKey, on); } + + @Override + public String toString() + { + return "INTEREST WRITE " + selectionKey + " = " + on; + } + }); } @@ -198,6 +164,11 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R Runnable operation; while ((operation = pendingOperations.poll()) != null) { + if (TRACER.isEnabled()) + { + TRACER.trace("Executing operation " + operation); + } + operation.run(); } @@ -307,7 +278,7 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R protected void onActivate() throws Exception { selector = Selector.open(); - thread = new Thread(this); + thread = new Thread(this, "selector"); //$NON-NLS-1$ thread.setDaemon(true); thread.start(); } @@ -320,7 +291,7 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R try { - thread.join(2 * SELECT_TIMEOUT + 200); + thread.join(200); } catch (RuntimeException ex) { @@ -391,7 +362,9 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R try { - channel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ, listener); + 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/net4j/transport/tcp/TCPSelector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/tcp/TCPSelector.java index 7e35bcec2a..633a97fa48 100644 --- 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 @@ -28,12 +28,6 @@ public interface TCPSelector public void registerAsync(SocketChannel channel, Active listener); - public boolean invoke(Runnable operation, long timeout); - - public SelectionKey register(ServerSocketChannel channel, Passive listener, long timeout); - - public SelectionKey register(SocketChannel channel, Active listener, long timeout); - public void setConnectInterest(SelectionKey selectionKey, boolean on); public void setReadInterest(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 index 1be3034b0c..ea4df36133 100644 --- 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 @@ -10,6 +10,7 @@ **************************************************************************/ package org.eclipse.net4j.transport.tcp; +import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; @@ -31,6 +32,8 @@ public interface TCPSelectorListener */ public interface Active { + public void registered(SelectionKey selectionKey); + public void handleConnect(TCPSelector selector, SocketChannel channel); public void handleRead(TCPSelector selector, SocketChannel socketChannel); 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 ad33239438..ec3f609ea7 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 @@ -159,7 +159,7 @@ public final class ReflectUtil public static String toString(Object object) { - return toString(object, ""); //$NON-NLS-1$ + return toString(object, " "); //$NON-NLS-1$ } public static String toString(Object object, String prefix) diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java index 7668f88388..55d8b132c9 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/concurrent/SynchronizingCorrelator.java @@ -93,4 +93,10 @@ public class SynchronizingCorrelator<CORRELATION, RESULT> implements } }; } + + @Override + public String toString() + { + return "SynchronizingCorrelator" + map; + } } 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/AbstractLifecycle.java index 2b1d5ee4cf..5b311e61d6 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/AbstractLifecycle.java @@ -58,14 +58,14 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier { if (TRACER.isEnabled()) { - TRACER.trace("Activating");//$NON-NLS-1$ + TRACER.trace("Activating " + this);//$NON-NLS-1$ } onAboutToActivate(); fireLifecycleAboutToActivate(); if (DUMPER.isEnabled()) { - DUMPER.trace("DUMP " + ReflectUtil.toString(this)); //$NON-NLS-1$ + DUMPER.trace("DUMP" + ReflectUtil.toString(this)); //$NON-NLS-1$ } onActivate(); @@ -81,7 +81,7 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier { if (TRACER.isEnabled()) { - TRACER.trace("Deactivating");//$NON-NLS-1$ + TRACER.trace("Deactivating " + this);//$NON-NLS-1$ } fireLifecycleDeactivating(); diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java index c4dd14c725..ac12b29fee 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/om/trace/PrintTraceHandler.java @@ -36,7 +36,8 @@ public class PrintTraceHandler implements OMTraceHandler public void traced(Event event) { - stream.println("[" + event.getContext() + "] " + event.getMessage()); //$NON-NLS-1$ + stream.println(Thread.currentThread().getName() + + " [" + event.getContext() + "] " + event.getMessage()); //$NON-NLS-1$ if (event.getThrowable() != null) { IOUtil.print(event.getThrowable(), stream); diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java index 8b8c8084a7..4f7675003c 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/AbstractRegistry.java @@ -11,6 +11,7 @@ package org.eclipse.net4j.util.registry; import org.eclipse.net4j.util.om.trace.ContextTracer; +import org.eclipse.net4j.util.registry.IRegistryDelta.Kind; import org.eclipse.internal.net4j.bundle.Net4j; @@ -252,7 +253,7 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V> { K key = delta.getKey(); V value = delta.getValue(); - int kind = delta.getKind(); + Kind kind = delta.getKind(); TRACER.trace("Registry delta " + key + " = " + value + " (" + kind + ")"); } } @@ -344,12 +345,12 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V> protected void rememberRegistered(K key, V value) { - deltas.add(new RegistryDelta(key, value, IRegistryDelta.REGISTERED)); + deltas.add(new RegistryDelta(key, value, Kind.REGISTERED)); } protected void rememberDeregistering(Object key, V value) { - deltas.add(new RegistryDelta(key, value, IRegistryDelta.DEREGISTERING)); + deltas.add(new RegistryDelta(key, value, Kind.DEREGISTERING)); } } @@ -388,9 +389,9 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V> private V value; - private int kind; + private Kind kind; - public RegistryDelta(K key, V value, int kind) + public RegistryDelta(K key, V value, Kind kind) { this.key = key; this.value = value; @@ -412,7 +413,7 @@ public abstract class AbstractRegistry<K, V> implements IRegistry<K, V> throw new UnsupportedOperationException(); } - public int getKind() + public Kind getKind() { return kind; } diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistryDelta.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistryDelta.java index d0750c8b4d..7276619e79 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistryDelta.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/registry/IRegistryDelta.java @@ -17,9 +17,17 @@ import java.util.Map; */ public interface IRegistryDelta<K, V> extends Map.Entry<K, V> { - public static final int REGISTERED = 1; + // public static final int REGISTERED = 1; + // + // public static final int DEREGISTERING = 2; - public static final int DEREGISTERING = 2; + public Kind getKind(); - public int getKind(); + /** + * @author Eike Stepper + */ + public enum Kind + { + REGISTERED, DEREGISTERING + } } |