summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-10-26 13:57:00 (EDT)
committerEike Stepper2006-10-26 13:57:00 (EDT)
commit93f050d755621f380f6a5ba2b4bfe527b842efb6 (patch)
tree24344e1b2bf4421b286d03d3088bc69bd29477c8
parent35d15ecd3ecbaa6f5215745e006f39f6cd5a62aa (diff)
downloadcdo-93f050d755621f380f6a5ba2b4bfe527b842efb6.zip
cdo-93f050d755621f380f6a5ba2b4bfe527b842efb6.tar.gz
cdo-93f050d755621f380f6a5ba2b4bfe527b842efb6.tar.bz2
Operations & Maintenance
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java9
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java6
-rw-r--r--plugins/org.eclipse.net4j/.options8
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java33
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java12
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java21
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferFactoryImpl.java12
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferPoolImpl.java24
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java19
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/AbstractTCPConnector.java19
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java7
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java33
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPSelectorImpl.java46
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java14
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java31
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/lifecycle/AbstractLifecycle.java35
17 files changed, 253 insertions, 100 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
index 64d9e64..a06840e 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
@@ -19,15 +19,13 @@ import org.eclipse.net4j.transport.Channel;
import org.eclipse.net4j.transport.ProtocolFactory;
import org.eclipse.net4j.transport.util.BufferInputStream;
import org.eclipse.net4j.transport.util.BufferOutputStream;
-import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiLoggingBridge;
+import org.eclipse.net4j.util.om.PrintStreamLogHandler;
import org.eclipse.net4j.util.om.PrintStreamTraceHandler;
import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
-import org.eclipse.internal.net4j.transport.BufferImpl;
import org.eclipse.internal.net4j.transport.tcp.AbstractTCPConnector;
import org.eclipse.internal.net4j.transport.tcp.TCPAcceptorImpl;
import org.eclipse.internal.net4j.transport.tcp.TCPSelectorImpl;
@@ -55,12 +53,9 @@ public class SignalTest extends TestCase
protected void setUp() throws Exception
{
super.setUp();
- // OMPlatform.INSTANCE.addLogHandler(EclipseLoggingBridge.INSTANCE);
- OMPlatform.INSTANCE.addLogHandler(OSGiLoggingBridge.INSTANCE);
+ OMPlatform.INSTANCE.addLogHandler(PrintStreamLogHandler.CONSOLE);
OMPlatform.INSTANCE.addTraceHandler(PrintStreamTraceHandler.CONSOLE);
- AbstractLifecycle.DUMP_ON_ACTIVATE = true;
- BufferImpl.TRACE = true;
BufferInputStream.TRACE = true;
BufferOutputStream.TRACE = true;
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
index 446d233..1688830 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPTransportTest.java
@@ -22,6 +22,9 @@ import org.eclipse.net4j.transport.tcp.TCPConnector;
import org.eclipse.net4j.transport.util.ChannelInputStream;
import org.eclipse.net4j.transport.util.ChannelOutputStream;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.PrintStreamLogHandler;
+import org.eclipse.net4j.util.om.PrintStreamTraceHandler;
import org.eclipse.net4j.util.registry.HashCacheRegistry;
import org.eclipse.net4j.util.registry.HashMapRegistry;
import org.eclipse.net4j.util.registry.IRegistry;
@@ -61,6 +64,9 @@ public class TCPTransportTest extends TestCase
protected void setUp() throws Exception
{
super.setUp();
+ OMPlatform.INSTANCE.addLogHandler(PrintStreamLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintStreamTraceHandler.CONSOLE);
+
System.out.print("================================= ");
System.out.print(getName());
System.out.println(" =================================");
diff --git a/plugins/org.eclipse.net4j/.options b/plugins/org.eclipse.net4j/.options
index ab9973e..918a378 100644
--- a/plugins/org.eclipse.net4j/.options
+++ b/plugins/org.eclipse.net4j/.options
@@ -1,4 +1,10 @@
-org.eclipse.net4j/debug = true
+org.eclipse.net4j/debug = false
+org.eclipse.net4j/debug.lifecycle = true
+org.eclipse.net4j/debug.lifecycle.dump = true
+org.eclipse.net4j/debug.buffer = true
+org.eclipse.net4j/debug.channel = true
+org.eclipse.net4j/debug.selector = true
+org.eclipse.net4j/debug.acceptor = true
org.eclipse.net4j/debug.connector = true
org.eclipse.net4j/perf = false
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java
index 1d19658..36b3ac8 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/AbstractOMBundle.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.internal.net4j.bundle;
+import org.eclipse.net4j.util.IOUtil;
+import org.eclipse.net4j.util.ReflectUtil;
import org.eclipse.net4j.util.om.OMBundle;
import org.eclipse.net4j.util.om.OMLogger;
import org.eclipse.net4j.util.om.OMPlatform;
@@ -197,12 +199,7 @@ public abstract class AbstractOMBundle implements OMBundle
ResourceBundle bundle = translate ? resourceBundle : untranslatedResourceBundle;
if (bundle == null)
{
- String packageName = getClass().getName();
- int index = packageName.lastIndexOf(".");
- if (index != -1)
- {
- packageName = packageName.substring(0, index);
- }
+ String packageName = ReflectUtil.getPackageName(accessor);
if (translate)
{
try
@@ -214,17 +211,21 @@ public abstract class AbstractOMBundle implements OMBundle
// If the bundle can't be found the normal way, try to find it as
// the base URL. If that also doesn't work, rethrow the original
// exception.
+ InputStream inputStream = null;
try
{
- InputStream inputStream = new URL(getBaseURL().toString() + "plugin.properties")
- .openStream();
- bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(
- inputStream);
+ inputStream = getInputStream("plugin.properties");
+ bundle = new PropertyResourceBundle(inputStream);
+ untranslatedResourceBundle = resourceBundle = bundle;
inputStream.close();
}
catch (IOException ioException)
{
}
+ finally
+ {
+ IOUtil.closeSilent(inputStream);
+ }
if (resourceBundle == null)
{
@@ -234,17 +235,21 @@ public abstract class AbstractOMBundle implements OMBundle
}
else
{
- String resourceName = getBaseURL().toString() + "plugin.properties";
+ InputStream inputStream = null;
try
{
- InputStream inputStream = new URL(resourceName).openStream();
+ inputStream = getInputStream("plugin.properties");
bundle = untranslatedResourceBundle = new PropertyResourceBundle(inputStream);
inputStream.close();
}
catch (IOException ioException)
{
- throw new MissingResourceException("Missing properties: " + resourceName, getClass()
- .getName(), "plugin.properties");
+ throw new MissingResourceException("Missing resource: plugin.properties", accessor
+ .getName(), key);
+ }
+ finally
+ {
+ IOUtil.closeSilent(inputStream);
}
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java
index d9ce3db..cc37b56 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4j.java
@@ -25,6 +25,18 @@ public final class Net4j
public static final OMTracer DEBUG = BUNDLE.tracer("debug");
+ public static final OMTracer DEBUG_LIFECYCLE = DEBUG.tracer("lifecycle");
+
+ public static final OMTracer DEBUG_LIFECYCLE_DUMP = DEBUG_LIFECYCLE.tracer("dump");
+
+ public static final OMTracer DEBUG_BUFFER = DEBUG.tracer("buffer");
+
+ public static final OMTracer DEBUG_CHANNEL = DEBUG.tracer("channel");
+
+ public static final OMTracer DEBUG_SELECTOR = DEBUG.tracer("selector");
+
+ public static final OMTracer DEBUG_ACCEPTOR = DEBUG.tracer("acceptor");
+
public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector");
public static final OMTracer PERF = BUNDLE.tracer("perf");
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 ecbf7c2..726d537 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
@@ -197,7 +197,8 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
if (TRACER.isEnabled())
{
- TRACER.trace("Setting state " + newState + " (was " + oldState.toString().toLowerCase() //$NON-NLS-1$ //$NON-NLS-2$
+ TRACER.trace(toString()
+ + ": Setting state " + newState + " (was " + oldState.toString().toLowerCase() //$NON-NLS-1$ //$NON-NLS-2$
+ ")"); //$NON-NLS-1$
}
@@ -276,7 +277,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
if (TRACER.isEnabled())
{
- TRACER.trace("Waiting for connection..."); //$NON-NLS-1$
+ TRACER.trace(toString() + ": Waiting for connection..."); //$NON-NLS-1$
}
return finishedNegotiating.await(timeout, TimeUnit.MILLISECONDS);
@@ -359,7 +360,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
Protocol protocol = createProtocol(protocolID, channel);
if (TRACER.isEnabled())
{
- TRACER.trace("Opening channel " + channelID //$NON-NLS-1$
+ TRACER.trace(toString() + ": Opening channel " + channelID //$NON-NLS-1$
+ (protocol == null ? " without protocol" : " with protocol " + protocolID)); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -387,7 +388,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
if (TRACER.isEnabled())
{
- TRACER.trace("Invalid channelID " + channelID); //$NON-NLS-1$
+ TRACER.trace(toString() + ": Invalid channelID " + channelID); //$NON-NLS-1$
}
return null;
@@ -446,7 +447,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
int channelID = channel.getChannelID();
if (TRACER.isEnabled())
{
- TRACER.trace("Removing channel " + channelID); //$NON-NLS-1$
+ TRACER.trace(toString() + ": Removing channel " + channelID); //$NON-NLS-1$
}
channels.set(channelID, NULL_CHANNEL);
@@ -470,7 +471,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
{
if (TRACER.isEnabled())
{
- TRACER.trace("Unknown protocol " + protocolID); //$NON-NLS-1$
+ TRACER.trace(toString() + ": Unknown protocol " + protocolID); //$NON-NLS-1$
}
return null;
@@ -489,7 +490,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
}
@@ -504,7 +505,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
}
@@ -519,7 +520,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
}
@@ -534,7 +535,7 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferFactoryImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferFactoryImpl.java
index 2fbd2da..beac29a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferFactoryImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferFactoryImpl.java
@@ -11,12 +11,18 @@
package org.eclipse.internal.net4j.transport;
import org.eclipse.net4j.transport.Buffer;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
/**
* @author Eike Stepper
*/
public class BufferFactoryImpl extends BufferProviderImpl
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_BUFFER,
+ BufferFactoryImpl.class);
+
public BufferFactoryImpl(short bufferCapacity)
{
super(bufferCapacity);
@@ -26,7 +32,11 @@ public class BufferFactoryImpl extends BufferProviderImpl
protected Buffer doProvideBuffer()
{
BufferImpl buffer = new BufferImpl(this, getBufferCapacity());
- System.out.println(toString() + ": Created " + buffer); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Created " + buffer); //$NON-NLS-1$
+ }
+
return buffer;
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java
index 765d8db..3570ed0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java
@@ -14,6 +14,9 @@ import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.BufferProvider;
import org.eclipse.net4j.util.HexUtil;
import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
import java.io.IOException;
import java.nio.ByteBuffer;
@@ -29,10 +32,13 @@ public class BufferImpl implements Buffer
public static final short NO_CHANNEL = Short.MIN_VALUE;
- public static boolean TRACE = false;
-
private static final int EOS_OFFSET = 1;
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_BUFFER,
+ BufferImpl.class);
+
+ private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
private BufferProvider bufferProvider;
private short channelID;
@@ -177,11 +183,10 @@ public class BufferImpl implements Buffer
return null;
}
- if (TRACE)
+ if (TRACER.isEnabled())
{
- System.out.println(toString() + ": Read " + byteBuffer.limit() + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "")); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println(formatContent());
+ TRACER.trace(toString() + ": Read " + byteBuffer.limit() + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
+ + (eos ? " (EOS)" : "") + NL + formatContent()); //$NON-NLS-1$ //$NON-NLS-2$
}
byteBuffer.flip();
@@ -234,11 +239,10 @@ public class BufferImpl implements Buffer
payloadSize = -payloadSize;
}
- if (TRACE)
+ if (TRACER.isEnabled())
{
- System.out.println(toString() + ": Writing " + (payloadSize - 1) + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "")); //$NON-NLS-1$ //$NON-NLS-2$
- System.out.println(formatContent());
+ TRACER.trace(toString() + ": Writing " + (payloadSize - 1) + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
+ + (eos ? " (EOS)" : "") + NL + formatContent()); //$NON-NLS-1$ //$NON-NLS-2$
}
byteBuffer.flip();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferPoolImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferPoolImpl.java
index 07d4a79..e7021bd 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferPoolImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferPoolImpl.java
@@ -13,6 +13,9 @@ package org.eclipse.internal.net4j.transport;
import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.transport.BufferPool;
import org.eclipse.net4j.transport.BufferProvider;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -23,6 +26,9 @@ import java.util.concurrent.ConcurrentLinkedQueue;
public class BufferPoolImpl extends BufferProviderImpl implements BufferPool,
BufferPool.Introspection
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_BUFFER,
+ BufferPoolImpl.class);
+
private final BufferProvider factory;
private final Queue<Buffer> queue = new ConcurrentLinkedQueue<Buffer>();
@@ -48,7 +54,11 @@ public class BufferPoolImpl extends BufferProviderImpl implements BufferPool,
return false;
}
- System.out.println(toString() + ": Evicting " + buffer); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Evicting " + buffer); //$NON-NLS-1$
+ }
+
factory.retainBuffer(buffer);
--pooledBuffers;
return true;
@@ -83,7 +93,11 @@ public class BufferPoolImpl extends BufferProviderImpl implements BufferPool,
}
buffer.clear();
- System.out.println(toString() + ": Obtained " + buffer); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Obtained " + buffer); //$NON-NLS-1$
+ }
+
return buffer;
}
@@ -95,7 +109,11 @@ public class BufferPoolImpl extends BufferProviderImpl implements BufferPool,
throw new IllegalArgumentException("buffer.getCapacity() != getBufferCapacity()"); //$NON-NLS-1$
}
- System.out.println(toString() + ": Retaining " + buffer); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Retaining " + buffer); //$NON-NLS-1$
+ }
+
queue.add(buffer);
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
index c820c00..5aa0842 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/ChannelImpl.java
@@ -19,7 +19,9 @@ import org.eclipse.net4j.util.concurrent.AsynchronousWorkSerializer;
import org.eclipse.net4j.util.concurrent.SynchronousWorkSerializer;
import org.eclipse.net4j.util.concurrent.WorkSerializer;
import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+import org.eclipse.net4j.util.om.ContextTracer;
+import org.eclipse.internal.net4j.bundle.Net4j;
import org.eclipse.internal.net4j.transport.BufferImpl.State;
import java.util.Queue;
@@ -31,6 +33,9 @@ import java.util.concurrent.ExecutorService;
*/
public class ChannelImpl extends AbstractLifecycle implements Channel, BufferProvider
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CHANNEL,
+ ChannelImpl.class);
+
private short channelID = BufferImpl.NO_CHANNEL;
private AbstractConnector connector;
@@ -127,10 +132,15 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
State state = ((BufferImpl)buffer).getState();
if (state != State.PUTTING)
{
- System.out.println(toString() + ": Ignoring buffer in state == " + state); //$NON-NLS-1$
+ Net4j.LOG.warn("Ignoring buffer in state == " + state + ": " + this); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Handling buffer from client: " + buffer); //$NON-NLS-1$
+ }
+
sendQueue.add(buffer);
connector.multiplexBuffer(this);
}
@@ -139,11 +149,16 @@ public class ChannelImpl extends AbstractLifecycle implements Channel, BufferPro
{
if (receiveHandler == null)
{
- System.out.println(toString() + ": Ignoring buffer because receiveHandler == null"); //$NON-NLS-1$
+ Net4j.LOG.warn("Ignoring buffer because receiveHandler == null: " + this); //$NON-NLS-1$
buffer.release();
return;
}
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Handling buffer from multiplexer: " + buffer); //$NON-NLS-1$
+ }
+
receiveSerializer.addWork(new Runnable()
{
public void run()
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 c37308b..8974e39 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
@@ -18,7 +18,9 @@ import org.eclipse.net4j.transport.tcp.TCPConnector;
import org.eclipse.net4j.transport.tcp.TCPSelector;
import org.eclipse.net4j.transport.tcp.TCPSelectorListener;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.ContextTracer;
+import org.eclipse.internal.net4j.bundle.Net4j;
import org.eclipse.internal.net4j.transport.AbstractConnector;
import org.eclipse.internal.net4j.transport.ChannelImpl;
@@ -36,6 +38,9 @@ import java.util.Queue;
public abstract class AbstractTCPConnector extends AbstractConnector implements TCPConnector,
TCPSelectorListener.Active
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_CONNECTOR,
+ AbstractTCPConnector.class);
+
private SocketChannel socketChannel;
private TCPSelector selector;
@@ -55,7 +60,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
catch (IOException ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
@@ -119,7 +124,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
deactivate();
}
}
@@ -152,7 +157,11 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
else
{
- System.out.println(toString() + ": Discarding buffer from unknown channel"); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Discarding buffer from unknown channel"); //$NON-NLS-1$
+ }
+
inputBuffer.release();
}
@@ -165,7 +174,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
deactivate();
}
}
@@ -216,7 +225,7 @@ public abstract class AbstractTCPConnector extends AbstractConnector implements
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
deactivate();
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
index d0e298c..0deb676 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/ControlChannelImpl.java
@@ -4,6 +4,7 @@ import org.eclipse.net4j.transport.Buffer;
import org.eclipse.net4j.util.concurrent.Synchronizer;
import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator;
+import org.eclipse.internal.net4j.bundle.Net4j;
import org.eclipse.internal.net4j.transport.BufferUtil;
import org.eclipse.internal.net4j.transport.ChannelImpl;
@@ -77,7 +78,6 @@ public final class ControlChannelImpl extends ChannelImpl
{
ByteBuffer byteBuffer = buffer.getByteBuffer();
byte opcode = byteBuffer.get();
- System.out.println("CONTROL: " + opcode); //$NON-NLS-1$
switch (opcode)
{
case OPCODE_REGISTRATION:
@@ -103,7 +103,7 @@ public final class ControlChannelImpl extends ChannelImpl
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
success = false;
}
@@ -123,9 +123,8 @@ public final class ControlChannelImpl extends ChannelImpl
throw new UnsupportedOperationException();
default:
- System.out.println("Invalid opcode: " + opcode); //$NON-NLS-1$
+ Net4j.LOG.error("Invalid opcode: " + opcode); //$NON-NLS-1$
((AbstractTCPConnector)getConnector()).deactivate();
- break;
}
}
finally
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
index fe0f4f0..ed11bff 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPAcceptorImpl.java
@@ -23,8 +23,10 @@ import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleListener;
import org.eclipse.net4j.util.lifecycle.LifecycleNotifier;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.ContextTracer;
import org.eclipse.net4j.util.registry.IRegistry;
+import org.eclipse.internal.net4j.bundle.Net4j;
import org.eclipse.internal.net4j.transport.ChannelImpl;
import java.io.IOException;
@@ -48,6 +50,9 @@ import java.util.concurrent.ExecutorService;
public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, BufferProvider,
TCPSelectorListener.Passive, LifecycleListener
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_ACCEPTOR,
+ TCPAcceptorImpl.class);
+
private IRegistry<String, ProtocolFactory> protocolFactoryRegistry;
private BufferProvider bufferProvider;
@@ -216,7 +221,7 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
{
if (isActive())
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
deactivate();
@@ -242,19 +247,24 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
acceptedConnectors.add(connector);
}
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Accepted connector " + connector);
+ }
+
fireConnectorAccepted(connector);
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
try
{
socketChannel.close();
}
- catch (IOException ioex)
+ catch (IOException ignore)
{
- ioex.printStackTrace();
+ ;
}
}
}
@@ -275,7 +285,7 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
}
}
}
@@ -291,12 +301,12 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
if (protocolFactoryRegistry == null)
{
- System.out.println(toString() + ": (INFO) protocolFactoryRegistry == null"); //$NON-NLS-1$
+ Net4j.LOG.info("No protocol factory registry in " + this); //$NON-NLS-1$
}
if (receiveExecutor == null)
{
- System.out.println(toString() + ": (INFO) receiveExecutor == null"); //$NON-NLS-1$
+ Net4j.LOG.info("No receive executor in " + this); //$NON-NLS-1$
}
if (selector == null)
@@ -325,14 +335,7 @@ public class TCPAcceptorImpl extends AbstractLifecycle implements TCPAcceptor, B
{
for (TCPConnector connector : getAcceptedConnectors())
{
- try
- {
- LifecycleUtil.deactivate(connector);
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
+ LifecycleUtil.deactivate(connector);
}
Exception exception = 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 c1d5237..568083d 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
@@ -13,6 +13,9 @@ package org.eclipse.internal.net4j.transport.tcp;
import org.eclipse.net4j.transport.tcp.TCPSelector;
import org.eclipse.net4j.transport.tcp.TCPSelectorListener;
import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
import java.io.IOException;
import java.nio.channels.CancelledKeyException;
@@ -30,6 +33,9 @@ import java.util.Iterator;
*/
public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, Runnable
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_SELECTOR,
+ TCPSelectorImpl.class);
+
private static final long SELECT_TIMEOUT = 100;
private Selector selector;
@@ -48,7 +54,11 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
throw new IllegalArgumentException("listener == null"); //$NON-NLS-1$
}
- System.out.println(toString() + ": Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
+ }
+
return channel.register(selector, SelectionKey.OP_ACCEPT, listener);
}
@@ -60,7 +70,11 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
throw new IllegalArgumentException("listener == null"); //$NON-NLS-1$
}
- System.out.println(toString() + ": Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Registering " + TCPUtil.toString(channel)); //$NON-NLS-1$
+ }
+
return channel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ, listener);
}
@@ -94,7 +108,7 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
selKey.cancel();
}
}
@@ -106,7 +120,7 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
}
catch (Exception ex)
{
- ex.printStackTrace();
+ Net4j.LOG.error(ex);
deactivate();
break;
}
@@ -129,7 +143,11 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
if (selKey.isAcceptable())
{
- System.out.println(toString() + ": Accepting " + TCPUtil.toString(ssChannel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Accepting " + TCPUtil.toString(ssChannel)); //$NON-NLS-1$
+ }
+
listener.handleAccept(this, ssChannel);
}
}
@@ -140,19 +158,31 @@ public class TCPSelectorImpl extends AbstractLifecycle implements TCPSelector, R
if (selKey.isConnectable())
{
- System.out.println(toString() + ": Connecting " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Connecting " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ }
+
listener.handleConnect(this, sChannel);
}
if (selKey.isReadable())
{
- System.out.println(toString() + ": Reading " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Reading " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ }
+
listener.handleRead(this, sChannel);
}
if (selKey.isWritable())
{
- System.out.println(toString() + ": Writing " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Writing " + TCPUtil.toString(sChannel)); //$NON-NLS-1$
+ }
+
listener.handleWrite(this, sChannel);
}
}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java
index 38f918b..74ec0be 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/tcp/TCPUtil.java
@@ -10,6 +10,10 @@
**************************************************************************/
package org.eclipse.internal.net4j.transport.tcp;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
+
import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
@@ -19,6 +23,8 @@ import java.nio.channels.SocketChannel;
*/
public final class TCPUtil
{
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_SELECTOR, TCPUtil.class);
+
private TCPUtil()
{
}
@@ -74,8 +80,12 @@ public final class TCPUtil
if (oldOps != newOps)
{
- System.out.println(selectionKey.channel().toString() + ": Setting interest " //$NON-NLS-1$
- + formatInterestOps(newOps) + " (was " + formatInterestOps(oldOps).toLowerCase() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(selectionKey.channel().toString() + ": Setting interest " //$NON-NLS-1$
+ + formatInterestOps(newOps) + " (was " + formatInterestOps(oldOps).toLowerCase() + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
selectionKey.interestOps(newOps);
}
}
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 7b06500..56834bf 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/ReflectUtil.java
@@ -10,6 +10,8 @@
**************************************************************************/
package org.eclipse.net4j.util;
+import org.eclipse.net4j.util.lifecycle.AbstractLifecycle;
+
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
@@ -30,7 +32,7 @@ public final class ReflectUtil
private static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
- private static final Method hashCodeMethod = getHashCodeMethod();
+ private static final Method HASH_CODE_METHOD = lookupHashCodeMethod();
private static final Map<Object, Long> ids = new WeakHashMap();
@@ -46,7 +48,7 @@ public final class ReflectUtil
{
try
{
- return (Integer)hashCodeMethod.invoke(object, NO_ARGUMENTS);
+ return (Integer)HASH_CODE_METHOD.invoke(object, NO_ARGUMENTS);
}
catch (Exception ex)
{
@@ -122,22 +124,35 @@ public final class ReflectUtil
public static void dump(Object object, String prefix, PrintStream out)
{
+ out.print(toString(object, prefix));
+ }
+
+ public static String toString(Object object)
+ {
+ return toString(object, ""); //$NON-NLS-1$
+ }
+
+ public static String toString(Object object, String prefix)
+ {
StringBuilder builder = new StringBuilder();
builder.append(prefix);
builder.append(getLabel(object));
builder.append(NL);
- dumpSegment(object.getClass(), object, prefix + " ", builder); //$NON-NLS-1$
- out.print(builder.toString());
+ toString(object.getClass(), object, prefix, builder);
+ return builder.toString();
}
- private static void dumpSegment(Class<? extends Object> segment, Object object, String prefix,
+ private static void toString(Class<? extends Object> segment, Object object, String prefix,
StringBuilder builder)
{
- if (segment != ROOT_CLASS)
+ if (segment == ROOT_CLASS || segment == AbstractLifecycle.class)
{
- dumpSegment(segment.getSuperclass(), object, prefix, builder);
+ return;
}
+ // Recurse
+ toString(segment.getSuperclass(), object, prefix, builder);
+
String segmentPrefix = segment == object.getClass() ? "" : getSimpleName(segment) + "."; //$NON-NLS-1$ //$NON-NLS-2$
Field[] fields = segment.getDeclaredFields();
for (Field field : fields)
@@ -181,7 +196,7 @@ public final class ReflectUtil
}
}
- private static Method getHashCodeMethod()
+ private static Method lookupHashCodeMethod()
{
Method method;
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 8ae147b..4587a40 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
@@ -1,6 +1,9 @@
package org.eclipse.net4j.util.lifecycle;
import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.om.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.Net4j;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -10,10 +13,14 @@ import java.util.concurrent.ConcurrentLinkedQueue;
*/
public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
{
- public static boolean DUMP_ON_ACTIVATE = false;
-
public static boolean USE_LABEL = true;
+ private static final ContextTracer TRACER = new ContextTracer(Net4j.DEBUG_LIFECYCLE,
+ AbstractLifecycle.class);
+
+ private static final ContextTracer DUMPER = new ContextTracer(Net4j.DEBUG_LIFECYCLE_DUMP,
+ AbstractLifecycle.class);
+
private boolean active;
/**
@@ -39,18 +46,22 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
{
if (!active)
{
- System.out.println(toString() + ": Activating"); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Activating");//$NON-NLS-1$
+ }
+
onAboutToActivate();
fireLifecycleAboutToActivate();
+ if (DUMPER.isEnabled())
+ {
+ DUMPER.trace("DUMP " + ReflectUtil.toString(this)); //$NON-NLS-1$
+ }
- active = true;
onActivate();
- fireLifecycleActivated();
+ active = true;
- if (DUMP_ON_ACTIVATE)
- {
- ReflectUtil.dump(this, toString() + ": DUMP "); //$NON-NLS-1$
- }
+ fireLifecycleActivated();
}
}
@@ -58,7 +69,11 @@ public abstract class AbstractLifecycle implements Lifecycle, LifecycleNotifier
{
if (active)
{
- System.out.println(toString() + ": Deactivating"); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(toString() + ": Deactivating");//$NON-NLS-1$
+ }
+
fireLifecycleDeactivating();
try