diff options
author | Eike Stepper | 2012-07-19 08:22:04 +0000 |
---|---|---|
committer | Eike Stepper | 2012-07-19 08:22:04 +0000 |
commit | 1460904fd3c193ffaf809913b2983a400fce9d94 (patch) | |
tree | 72f3a17b75fedba3ae1060df1d32c9c7889be954 /plugins/org.eclipse.net4j/src/org | |
parent | 5f360965ae87478e0681899bf310a210cafc2c44 (diff) | |
download | cdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.gz cdo-1460904fd3c193ffaf809913b2983a400fce9d94.tar.xz cdo-1460904fd3c193ffaf809913b2983a400fce9d94.zip |
Fix line endings in master (dos2unix)
Diffstat (limited to 'plugins/org.eclipse.net4j/src/org')
54 files changed, 4150 insertions, 4150 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java index 43f63fd03c..238a3e323a 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java @@ -1,124 +1,124 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.ITransportConfig;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import java.text.MessageFormat;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public class TransportConfig implements ITransportConfig
-{
- private transient ILifecycle lifecycle;
-
- private IBufferProvider bufferProvider;
-
- /**
- * An optional executor to be used by the {@link IChannel}s to process their receive queues instead of the current
- * thread. If not <code>null</code> the sender and the receiver peers become decoupled.
- * <p>
- */
- private ExecutorService receiveExecutor;
-
- private IProtocolProvider protocolProvider;
-
- private INegotiator negotiator;
-
- public TransportConfig()
- {
- }
-
- public TransportConfig(ILifecycle lifecycle)
- {
- this.lifecycle = lifecycle;
- }
-
- public TransportConfig(ILifecycle lifecycle, ExecutorService receiveExecutor, IBufferProvider bufferProvider,
- IProtocolProvider protocolProvider, INegotiator negotiator)
- {
- this(lifecycle);
- this.receiveExecutor = receiveExecutor;
- this.bufferProvider = bufferProvider;
- this.protocolProvider = protocolProvider;
- this.negotiator = negotiator;
- }
-
- public ILifecycle getLifecycle()
- {
- return lifecycle;
- }
-
- public void setLifecycle(ILifecycle lifecycle)
- {
- this.lifecycle = lifecycle;
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.receiveExecutor = receiveExecutor;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.bufferProvider = bufferProvider;
- }
-
- public IProtocolProvider getProtocolProvider()
- {
- return protocolProvider;
- }
-
- public void setProtocolProvider(IProtocolProvider protocolProvider)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.protocolProvider = protocolProvider;
- }
-
- public INegotiator getNegotiator()
- {
- return negotiator;
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.negotiator = negotiator;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format(
- "TransportConfig[receiveExecutor={0}, bufferProvider={1}, protocolProvider={2}, negotiator={3}]", //$NON-NLS-1$
- receiveExecutor, bufferProvider, protocolProvider, negotiator);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.ITransportConfig; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.protocol.IProtocolProvider; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.security.INegotiator; + +import java.text.MessageFormat; +import java.util.concurrent.ExecutorService; + +/** + * @author Eike Stepper + */ +public class TransportConfig implements ITransportConfig +{ + private transient ILifecycle lifecycle; + + private IBufferProvider bufferProvider; + + /** + * An optional executor to be used by the {@link IChannel}s to process their receive queues instead of the current + * thread. If not <code>null</code> the sender and the receiver peers become decoupled. + * <p> + */ + private ExecutorService receiveExecutor; + + private IProtocolProvider protocolProvider; + + private INegotiator negotiator; + + public TransportConfig() + { + } + + public TransportConfig(ILifecycle lifecycle) + { + this.lifecycle = lifecycle; + } + + public TransportConfig(ILifecycle lifecycle, ExecutorService receiveExecutor, IBufferProvider bufferProvider, + IProtocolProvider protocolProvider, INegotiator negotiator) + { + this(lifecycle); + this.receiveExecutor = receiveExecutor; + this.bufferProvider = bufferProvider; + this.protocolProvider = protocolProvider; + this.negotiator = negotiator; + } + + public ILifecycle getLifecycle() + { + return lifecycle; + } + + public void setLifecycle(ILifecycle lifecycle) + { + this.lifecycle = lifecycle; + } + + public ExecutorService getReceiveExecutor() + { + return receiveExecutor; + } + + public void setReceiveExecutor(ExecutorService receiveExecutor) + { + LifecycleUtil.checkInactive(lifecycle); + this.receiveExecutor = receiveExecutor; + } + + public IBufferProvider getBufferProvider() + { + return bufferProvider; + } + + public void setBufferProvider(IBufferProvider bufferProvider) + { + LifecycleUtil.checkInactive(lifecycle); + this.bufferProvider = bufferProvider; + } + + public IProtocolProvider getProtocolProvider() + { + return protocolProvider; + } + + public void setProtocolProvider(IProtocolProvider protocolProvider) + { + LifecycleUtil.checkInactive(lifecycle); + this.protocolProvider = protocolProvider; + } + + public INegotiator getNegotiator() + { + return negotiator; + } + + public void setNegotiator(INegotiator negotiator) + { + LifecycleUtil.checkInactive(lifecycle); + this.negotiator = negotiator; + } + + @Override + public String toString() + { + return MessageFormat.format( + "TransportConfig[receiveExecutor={0}, bufferProvider={1}, protocolProvider={2}, negotiator={3}]", //$NON-NLS-1$ + receiveExecutor, bufferProvider, protocolProvider, negotiator); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java index 6d6ead780a..101e5e9192 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java @@ -1,62 +1,62 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.InternalBuffer;
-
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public class BufferFactory extends BufferProvider
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferFactory.class);
-
- public BufferFactory(short bufferCapacity)
- {
- super(bufferCapacity);
- }
-
- @Override
- protected IBuffer doProvideBuffer()
- {
- IBuffer buffer = new Buffer(this, getBufferCapacity());
- if (TRACER.isEnabled())
- {
- TRACER.trace("Created " + buffer); //$NON-NLS-1$
- }
-
- return buffer;
- }
-
- @Override
- protected void doRetainBuffer(IBuffer buffer)
- {
- if (buffer instanceof InternalBuffer)
- {
- ((InternalBuffer)buffer).dispose();
- }
-
- buffer = null;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("BufferFactory[{0}]", getBufferCapacity()); //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +import org.eclipse.spi.net4j.InternalBuffer; + +import java.text.MessageFormat; + +/** + * @author Eike Stepper + */ +public class BufferFactory extends BufferProvider +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferFactory.class); + + public BufferFactory(short bufferCapacity) + { + super(bufferCapacity); + } + + @Override + protected IBuffer doProvideBuffer() + { + IBuffer buffer = new Buffer(this, getBufferCapacity()); + if (TRACER.isEnabled()) + { + TRACER.trace("Created " + buffer); //$NON-NLS-1$ + } + + return buffer; + } + + @Override + protected void doRetainBuffer(IBuffer buffer) + { + if (buffer instanceof InternalBuffer) + { + ((InternalBuffer)buffer).dispose(); + } + + buffer = null; + } + + @Override + public String toString() + { + return MessageFormat.format("BufferFactory[{0}]", getBufferCapacity()); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java index 796b93f6d3..aff06bfafe 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java @@ -1,69 +1,69 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-/**
- * @author Eike Stepper
- */
-public abstract class BufferProvider extends Lifecycle implements IBufferProvider.Introspection
-{
- private short bufferCapacity;
-
- private long providedBuffers;
-
- private long retainedBuffers;
-
- public BufferProvider(short bufferCapacity)
- {
- this.bufferCapacity = bufferCapacity;
- }
-
- public final long getProvidedBuffers()
- {
- return providedBuffers;
- }
-
- public final long getRetainedBuffers()
- {
- return retainedBuffers;
- }
-
- public final short getBufferCapacity()
- {
- return bufferCapacity;
- }
-
- public final IBuffer provideBuffer()
- {
- ++providedBuffers;
- return doProvideBuffer();
- }
-
- public final void retainBuffer(IBuffer buffer)
- {
- ++retainedBuffers;
- doRetainBuffer(buffer);
- }
-
- @Override
- public String toString()
- {
- return "BufferProvider[capacity=" + bufferCapacity + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected abstract IBuffer doProvideBuffer();
-
- protected abstract void doRetainBuffer(IBuffer buffer);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.util.lifecycle.Lifecycle; + +/** + * @author Eike Stepper + */ +public abstract class BufferProvider extends Lifecycle implements IBufferProvider.Introspection +{ + private short bufferCapacity; + + private long providedBuffers; + + private long retainedBuffers; + + public BufferProvider(short bufferCapacity) + { + this.bufferCapacity = bufferCapacity; + } + + public final long getProvidedBuffers() + { + return providedBuffers; + } + + public final long getRetainedBuffers() + { + return retainedBuffers; + } + + public final short getBufferCapacity() + { + return bufferCapacity; + } + + public final IBuffer provideBuffer() + { + ++providedBuffers; + return doProvideBuffer(); + } + + public final void retainBuffer(IBuffer buffer) + { + ++retainedBuffers; + doRetainBuffer(buffer); + } + + @Override + public String toString() + { + return "BufferProvider[capacity=" + bufferCapacity + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } + + protected abstract IBuffer doProvideBuffer(); + + protected abstract void doRetainBuffer(IBuffer buffer); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java index 359daef646..d7d31395ed 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public class BufferProviderFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.bufferProviders"; //$NON-NLS-1$
-
- public static final String TYPE = "default"; //$NON-NLS-1$
-
- public static final short BUFFER_CAPACITY = 4096;
-
- public BufferProviderFactory()
- {
- super(PRODUCT_GROUP, TYPE);
- }
-
- public IBufferProvider create(String description)
- {
- return Net4jUtil.createBufferPool(BUFFER_CAPACITY);
- }
-
- public static IBufferProvider get(IManagedContainer container)
- {
- return (IBufferProvider)container.getElement(PRODUCT_GROUP, TYPE, null);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.factory.Factory; + +/** + * @author Eike Stepper + */ +public class BufferProviderFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.net4j.bufferProviders"; //$NON-NLS-1$ + + public static final String TYPE = "default"; //$NON-NLS-1$ + + public static final short BUFFER_CAPACITY = 4096; + + public BufferProviderFactory() + { + super(PRODUCT_GROUP, TYPE); + } + + public IBufferProvider create(String description) + { + return Net4jUtil.createBufferPool(BUFFER_CAPACITY); + } + + public static IBufferProvider get(IManagedContainer container) + { + return (IBufferProvider)container.getElement(PRODUCT_GROUP, TYPE, null); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java index 9d507aeed1..22a9de5035 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java @@ -1,137 +1,137 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-
-/**
- * @author Eike Stepper
- */
-public final class BufferUtil
-{
- private static final byte FALSE = (byte)0;
-
- private static final byte TRUE = (byte)1;
-
- public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$
-
- private BufferUtil()
- {
- }
-
- public static byte[] toUTF8(String str)
- {
- if (str == null)
- {
- return new byte[0];
- }
-
- try
- {
- byte[] bytes = str.getBytes(UTF8_CHAR_SET_NAME);
- String test = new String(bytes, UTF8_CHAR_SET_NAME);
- if (!str.equals(test))
- {
- throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$
- }
-
- return bytes;
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should really not happen
- throw new RuntimeException(ex);
- }
- }
-
- public static String fromUTF8(byte[] bytes)
- {
- try
- {
- return new String(bytes, UTF8_CHAR_SET_NAME);
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should really not happen
- throw new RuntimeException(ex);
- }
- }
-
- public static void putObject(ByteBuffer byteBuffer, Object object) throws IOException
- {
- if (object != null)
- {
- byteBuffer.put(TRUE);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream stream = new ObjectOutputStream(baos);
- stream.writeObject(object);
-
- byte[] array = baos.toByteArray();
- putByteArray(byteBuffer, array);
- }
- else
- {
- byteBuffer.put(FALSE);
- }
- }
-
- public static Object getObject(ByteBuffer byteBuffer) throws IOException, ClassNotFoundException
- {
- boolean nonNull = byteBuffer.get() == TRUE;
- if (nonNull)
- {
- byte[] array = getByteArray(byteBuffer);
- ByteArrayInputStream bais = new ByteArrayInputStream(array);
- ObjectInputStream stream = new ObjectInputStream(bais);
- return stream.readObject();
- }
-
- return null;
- }
-
- public static void putByteArray(ByteBuffer byteBuffer, byte[] array)
- {
- byteBuffer.putShort((short)array.length);
- if (array.length != 0)
- {
- byteBuffer.put(array);
- }
- }
-
- public static byte[] getByteArray(ByteBuffer byteBuffer)
- {
- short length = byteBuffer.getShort();
- byte[] array = new byte[length];
- if (length != 0)
- {
- byteBuffer.get(array);
- }
-
- return array;
- }
-
- public static void putUTF8(ByteBuffer byteBuffer, String str)
- {
- byte[] bytes = BufferUtil.toUTF8(str);
- if (bytes.length > byteBuffer.remaining())
- {
- throw new IllegalArgumentException("String too long: " + str); //$NON-NLS-1$
- }
-
- putByteArray(byteBuffer, bytes);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; + +/** + * @author Eike Stepper + */ +public final class BufferUtil +{ + private static final byte FALSE = (byte)0; + + private static final byte TRUE = (byte)1; + + public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$ + + private BufferUtil() + { + } + + public static byte[] toUTF8(String str) + { + if (str == null) + { + return new byte[0]; + } + + try + { + byte[] bytes = str.getBytes(UTF8_CHAR_SET_NAME); + String test = new String(bytes, UTF8_CHAR_SET_NAME); + if (!str.equals(test)) + { + throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$ + } + + return bytes; + } + catch (UnsupportedEncodingException ex) + { + // This should really not happen + throw new RuntimeException(ex); + } + } + + public static String fromUTF8(byte[] bytes) + { + try + { + return new String(bytes, UTF8_CHAR_SET_NAME); + } + catch (UnsupportedEncodingException ex) + { + // This should really not happen + throw new RuntimeException(ex); + } + } + + public static void putObject(ByteBuffer byteBuffer, Object object) throws IOException + { + if (object != null) + { + byteBuffer.put(TRUE); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream stream = new ObjectOutputStream(baos); + stream.writeObject(object); + + byte[] array = baos.toByteArray(); + putByteArray(byteBuffer, array); + } + else + { + byteBuffer.put(FALSE); + } + } + + public static Object getObject(ByteBuffer byteBuffer) throws IOException, ClassNotFoundException + { + boolean nonNull = byteBuffer.get() == TRUE; + if (nonNull) + { + byte[] array = getByteArray(byteBuffer); + ByteArrayInputStream bais = new ByteArrayInputStream(array); + ObjectInputStream stream = new ObjectInputStream(bais); + return stream.readObject(); + } + + return null; + } + + public static void putByteArray(ByteBuffer byteBuffer, byte[] array) + { + byteBuffer.putShort((short)array.length); + if (array.length != 0) + { + byteBuffer.put(array); + } + } + + public static byte[] getByteArray(ByteBuffer byteBuffer) + { + short length = byteBuffer.getShort(); + byte[] array = new byte[length]; + if (length != 0) + { + byteBuffer.get(array); + } + + return array; + } + + public static void putUTF8(ByteBuffer byteBuffer, String str) + { + byte[] bytes = BufferUtil.toUTF8(str); + if (bytes.length > byteBuffer.remaining()) + { + throw new IllegalArgumentException("String too long: " + str); //$NON-NLS-1$ + } + + putByteArray(byteBuffer, bytes); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java index e45ed99ae4..5398147069 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java @@ -1,65 +1,65 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.bundle;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.net4j"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_BUFFER = DEBUG.tracer("buffer"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_BUFFER_STREAM = DEBUG_BUFFER.tracer("stream"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_CHANNEL = DEBUG.tracer("channel"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_ACCEPTOR = DEBUG.tracer("acceptor"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_SIGNAL = DEBUG.tracer("signal"); //$NON-NLS-1$
-
- public static final boolean SET_SIGNAL_THREAD_NAME = BUNDLE.getDebugSupport().getDebugOption(
- "set.signal.thread.name", false); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
-
- @Override
- protected void doStart() throws Exception
- {
- new Net4jCommandProvider(bundleContext);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.bundle; + +import org.eclipse.net4j.util.om.OMBundle; +import org.eclipse.net4j.util.om.OMPlatform; +import org.eclipse.net4j.util.om.OSGiActivator; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.OMTracer; + +/** + * The <em>Operations & Maintenance</em> class of this bundle. + * + * @author Eike Stepper + */ +public abstract class OM +{ + public static final String BUNDLE_ID = "org.eclipse.net4j"; //$NON-NLS-1$ + + public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class); + + public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_BUFFER = DEBUG.tracer("buffer"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_BUFFER_STREAM = DEBUG_BUFFER.tracer("stream"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_CHANNEL = DEBUG.tracer("channel"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_ACCEPTOR = DEBUG.tracer("acceptor"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector"); //$NON-NLS-1$ + + public static final OMTracer DEBUG_SIGNAL = DEBUG.tracer("signal"); //$NON-NLS-1$ + + public static final boolean SET_SIGNAL_THREAD_NAME = BUNDLE.getDebugSupport().getDebugOption( + "set.signal.thread.name", false); //$NON-NLS-1$ + + public static final OMLogger LOG = BUNDLE.logger(); + + /** + * @author Eike Stepper + */ + public static final class Activator extends OSGiActivator + { + public Activator() + { + super(BUNDLE); + } + + @Override + protected void doStart() throws Exception + { + new Net4jCommandProvider(bundleContext); + } + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java index 21188d9489..1778692587 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java @@ -1,83 +1,83 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.concurrent.NonBlockingLongCounter;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import org.eclipse.spi.net4j.ClientProtocolFactory;
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-/**
- * Base class for container-based {@link IProtocolProvider protocol providers} like {@link Client} or {@link Server}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ContainerProtocolProvider implements IProtocolProvider
-{
- private static NonBlockingLongCounter counter = new NonBlockingLongCounter();
-
- private IManagedContainer container;
-
- private String productGroup;
-
- protected ContainerProtocolProvider(IManagedContainer container, String productGroup)
- {
- this.container = container;
- this.productGroup = productGroup;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public IProtocol<?> getProtocol(String type)
- {
- return (IProtocol<?>)container.getElement(productGroup, type, "protocol-" + counter.increment(), false); //$NON-NLS-1$
- }
-
- /**
- * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#CLIENT client}
- * protocols.
- *
- * @author Eike Stepper
- */
- public static class Client extends ContainerProtocolProvider
- {
- public Client(IManagedContainer container)
- {
- super(container, ClientProtocolFactory.PRODUCT_GROUP);
- }
- }
-
- /**
- * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#SERVER server}
- * protocols.
- *
- * @author Eike Stepper
- */
- public static class Server extends ContainerProtocolProvider
- {
- public Server(IManagedContainer container)
- {
- super(container, ServerProtocolFactory.PRODUCT_GROUP);
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.protocol.IProtocol; +import org.eclipse.net4j.protocol.IProtocolProvider; +import org.eclipse.net4j.util.concurrent.NonBlockingLongCounter; +import org.eclipse.net4j.util.container.IManagedContainer; + +import org.eclipse.spi.net4j.ClientProtocolFactory; +import org.eclipse.spi.net4j.ServerProtocolFactory; + +/** + * Base class for container-based {@link IProtocolProvider protocol providers} like {@link Client} or {@link Server}. + * + * @author Eike Stepper + * @since 2.0 + */ +public abstract class ContainerProtocolProvider implements IProtocolProvider +{ + private static NonBlockingLongCounter counter = new NonBlockingLongCounter(); + + private IManagedContainer container; + + private String productGroup; + + protected ContainerProtocolProvider(IManagedContainer container, String productGroup) + { + this.container = container; + this.productGroup = productGroup; + } + + public IManagedContainer getContainer() + { + return container; + } + + public String getProductGroup() + { + return productGroup; + } + + public IProtocol<?> getProtocol(String type) + { + return (IProtocol<?>)container.getElement(productGroup, type, "protocol-" + counter.increment(), false); //$NON-NLS-1$ + } + + /** + * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#CLIENT client} + * protocols. + * + * @author Eike Stepper + */ + public static class Client extends ContainerProtocolProvider + { + public Client(IManagedContainer container) + { + super(container, ClientProtocolFactory.PRODUCT_GROUP); + } + } + + /** + * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#SERVER server} + * protocols. + * + * @author Eike Stepper + */ + public static class Server extends ContainerProtocolProvider + { + public Server(IManagedContainer container) + { + super(container, ServerProtocolFactory.PRODUCT_GROUP); + } + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java index 7fd186597b..7de4e035a4 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java @@ -1,73 +1,73 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
-/**
- * Factory-based {@link IProtocolProvider protocol provider}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class FactoriesProtocolProvider implements IProtocolProvider
-{
- private IRegistry<String, IFactory> registry;
-
- public FactoriesProtocolProvider()
- {
- }
-
- public FactoriesProtocolProvider(IRegistry<String, IFactory> registry)
- {
- setRegistry(registry);
- }
-
- public FactoriesProtocolProvider(IFactory factory)
- {
- addFactory(factory);
- }
-
- public IRegistry<String, IFactory> getRegistry()
- {
- if (registry == null)
- {
- registry = new HashMapRegistry<String, IFactory>();
- }
-
- return registry;
- }
-
- public void setRegistry(IRegistry<String, IFactory> registry)
- {
- this.registry = registry;
- }
-
- public void addFactory(IFactory factory)
- {
- getRegistry().put(factory.getKey().getType(), factory);
- }
-
- public IProtocol<?> getProtocol(String type)
- {
- IFactory factory = registry.get(type);
- if (factory != null)
- {
- return (IProtocol<?>)factory.create(null);
- }
-
- return null;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.protocol.IProtocol; +import org.eclipse.net4j.protocol.IProtocolProvider; +import org.eclipse.net4j.util.factory.IFactory; +import org.eclipse.net4j.util.registry.HashMapRegistry; +import org.eclipse.net4j.util.registry.IRegistry; + +/** + * Factory-based {@link IProtocolProvider protocol provider}. + * + * @author Eike Stepper + * @since 2.0 + */ +public class FactoriesProtocolProvider implements IProtocolProvider +{ + private IRegistry<String, IFactory> registry; + + public FactoriesProtocolProvider() + { + } + + public FactoriesProtocolProvider(IRegistry<String, IFactory> registry) + { + setRegistry(registry); + } + + public FactoriesProtocolProvider(IFactory factory) + { + addFactory(factory); + } + + public IRegistry<String, IFactory> getRegistry() + { + if (registry == null) + { + registry = new HashMapRegistry<String, IFactory>(); + } + + return registry; + } + + public void setRegistry(IRegistry<String, IFactory> registry) + { + this.registry = registry; + } + + public void addFactory(IFactory factory) + { + getRegistry().put(factory.getKey().getType(), factory); + } + + public IProtocol<?> getProtocol(String type) + { + IFactory factory = registry.get(type); + if (factory != null) + { + return (IProtocol<?>)factory.create(null); + } + + return null; + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java index b4c521ab23..572654a4d4 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java @@ -1,47 +1,47 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-/**
- * A concept that has a {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server}
- * scenario.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public interface ILocationAware
-{
- /**
- * Returns the location of this object in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
- */
- public Location getLocation();
-
- /**
- * Same as <code>{@link #getLocation()} == {@link Location#CLIENT}</code>.
- */
- public boolean isClient();
-
- /**
- * Same as <code>{@link #getLocation()} == {@link Location#SERVER}</code>.
- */
- public boolean isServer();
-
- /**
- * A {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public enum Location
- {
- CLIENT, SERVER
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +/** + * A concept that has a {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server} + * scenario. + * + * @author Eike Stepper + * @since 2.0 + */ +public interface ILocationAware +{ + /** + * Returns the location of this object in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario. + */ + public Location getLocation(); + + /** + * Same as <code>{@link #getLocation()} == {@link Location#CLIENT}</code>. + */ + public boolean isClient(); + + /** + * Same as <code>{@link #getLocation()} == {@link Location#SERVER}</code>. + */ + public boolean isServer(); + + /** + * A {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario. + * + * @author Eike Stepper + * @since 2.0 + */ + public enum Location + { + CLIENT, SERVER + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java index cccd2fd9dc..45669cd3ee 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java @@ -1,57 +1,57 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * A common transport configuration that specifies basic dependencies for {@link IChannelMultiplexer channel
- * multiplexers}, {@link IConnector connectors} and {@link IAcceptor acceptors}.
- *
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface ITransportConfig extends INegotiatorAware
-{
- /**
- * Returns the lifecycle delegate used for inactivity checks in the setter implementations of this transport
- * configuration.
- */
- public ILifecycle getLifecycle();
-
- /**
- * Sets the lifecycle delegate to be used for inactivity checks in the setter implementations of this transport
- * configuration.
- */
- public void setLifecycle(ILifecycle lifecycle);
-
- public IBufferProvider getBufferProvider();
-
- public void setBufferProvider(IBufferProvider bufferProvider);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
-
- public IProtocolProvider getProtocolProvider();
-
- public void setProtocolProvider(IProtocolProvider protocolProvider);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.channel.IChannelMultiplexer; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.protocol.IProtocolProvider; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.security.INegotiatorAware; + +import java.util.concurrent.ExecutorService; + +/** + * A common transport configuration that specifies basic dependencies for {@link IChannelMultiplexer channel + * multiplexers}, {@link IConnector connectors} and {@link IAcceptor acceptors}. + * + * @author Eike Stepper + * @since 2.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface ITransportConfig extends INegotiatorAware +{ + /** + * Returns the lifecycle delegate used for inactivity checks in the setter implementations of this transport + * configuration. + */ + public ILifecycle getLifecycle(); + + /** + * Sets the lifecycle delegate to be used for inactivity checks in the setter implementations of this transport + * configuration. + */ + public void setLifecycle(ILifecycle lifecycle); + + public IBufferProvider getBufferProvider(); + + public void setBufferProvider(IBufferProvider bufferProvider); + + public ExecutorService getReceiveExecutor(); + + public void setReceiveExecutor(ExecutorService receiveExecutor); + + public IProtocolProvider getProtocolProvider(); + + public void setProtocolProvider(IProtocolProvider protocolProvider); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java index a8a92989aa..ba148de98d 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java @@ -1,35 +1,35 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.IConnector;
-
-/**
- * A concept that has a {@link ITransportConfig transport configuration}, typically a {@link IChannelMultiplexer channel
- * multiplexer}, {@link IConnector connector} or {@link IAcceptor acceptor}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public interface ITransportConfigAware
-{
- /**
- * Returns the current transport configuration if there is one, a new empty one otherwise.
- */
- public ITransportConfig getConfig();
-
- /**
- * Sets a new transport configuration by <b>copying</b> the given one.
- */
- public void setConfig(ITransportConfig config);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.channel.IChannelMultiplexer; +import org.eclipse.net4j.connector.IConnector; + +/** + * A concept that has a {@link ITransportConfig transport configuration}, typically a {@link IChannelMultiplexer channel + * multiplexer}, {@link IConnector connector} or {@link IAcceptor acceptor}. + * + * @author Eike Stepper + * @since 2.0 + */ +public interface ITransportConfigAware +{ + /** + * Returns the current transport configuration if there is one, a new empty one otherwise. + */ + public ITransportConfig getConfig(); + + /** + * Sets a new transport configuration by <b>copying</b> the given one. + */ + public void setConfig(ITransportConfig config); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java index e0d0b73508..23ed503f45 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java @@ -1,181 +1,181 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
-import org.eclipse.net4j.util.container.ContainerUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import org.eclipse.internal.net4j.TransportConfig;
-import org.eclipse.internal.net4j.buffer.BufferFactory;
-import org.eclipse.internal.net4j.buffer.BufferPool;
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-
-import org.eclipse.spi.net4j.AcceptorFactory;
-import org.eclipse.spi.net4j.ConnectorFactory;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * A utility class with various static factory and convenience methods.
- *
- * @author Eike Stepper
- */
-public final class Net4jUtil
-{
- public static final String SCHEME_SEPARATOR = "://"; //$NON-NLS-1$
-
- public static final short DEFAULT_BUFFER_CAPACITY = 4096;
-
- private Net4jUtil()
- {
- }
-
- public static void prepareContainer(IManagedContainer container)
- {
- ContainerUtil.prepareContainer(container);
- container.registerFactory(new BufferProviderFactory());
- container.addPostProcessor(new TransportInjector());
- container.registerFactory(new HeartBeatProtocol.Server.Factory());
- container.addPostProcessor(new HeartBeatProtocol.Server.TimerInjector());
- }
-
- public static ExecutorService getExecutorService(IManagedContainer container)
- {
- return ExecutorServiceFactory.get(container);
- }
-
- public static IBufferProvider getBufferProvider(IManagedContainer container)
- {
- return BufferProviderFactory.get(container);
- }
-
- public static IAcceptor getAcceptor(IManagedContainer container, String type, String description)
- {
- return (IAcceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description);
- }
-
- /**
- * @since 4.0
- */
- public static IConnector getConnector(IManagedContainer container, String type, String description, long timeout)
- {
- IConnector connector = (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description);
-
- try
- {
- connector.waitForConnection(timeout);
- }
- catch (ConnectorException ex)
- {
- container.removeElement(ConnectorFactory.PRODUCT_GROUP, type, description);
- throw ex;
- }
-
- return connector;
- }
-
- public static IConnector getConnector(IManagedContainer container, String type, String description)
- {
- return getConnector(container, type, description, 10000L);
- }
-
- public static IConnector getConnector(IManagedContainer container, String description)
- {
- int pos = description.indexOf(SCHEME_SEPARATOR);
- if (pos <= 0)
- {
- throw new IllegalArgumentException("Connector type (scheme) missing: " + description); //$NON-NLS-1$
- }
-
- String factoryType = description.substring(0, pos);
-
- String connectorDescription = description.substring(pos + SCHEME_SEPARATOR.length());
- if (StringUtil.isEmpty(connectorDescription))
- {
- throw new IllegalArgumentException("Illegal connector description: " + description); //$NON-NLS-1$
- }
-
- return getConnector(container, factoryType, connectorDescription);
- }
-
- public static IBufferProvider createBufferFactory(short bufferCapacity)
- {
- return new BufferFactory(bufferCapacity);
- }
-
- public static IBufferProvider createBufferFactory()
- {
- return createBufferFactory(DEFAULT_BUFFER_CAPACITY);
- }
-
- public static IBufferPool createBufferPool(IBufferProvider factory)
- {
- return new BufferPool(factory);
- }
-
- public static IBufferPool createBufferPool(short bufferCapacity)
- {
- return createBufferPool(createBufferFactory(bufferCapacity));
- }
-
- public static IBufferPool createBufferPool()
- {
- return createBufferPool(createBufferFactory());
- }
-
- public static long getProvidedBuffers(IBufferProvider bufferProvider)
- {
- if (bufferProvider instanceof IBufferProvider.Introspection)
- {
- return ((IBufferProvider.Introspection)bufferProvider).getProvidedBuffers();
- }
-
- return -1L;
- }
-
- public static long getRetainedBuffers(IBufferProvider bufferProvider)
- {
- if (bufferProvider instanceof IBufferProvider.Introspection)
- {
- return ((IBufferProvider.Introspection)bufferProvider).getRetainedBuffers();
- }
-
- return -1L;
- }
-
- public static int getPooledBuffers(IBufferPool bufferPool)
- {
- if (bufferPool instanceof IBufferPool.Introspection)
- {
- return ((IBufferPool.Introspection)bufferPool).getPooledBuffers();
- }
-
- return -1;
- }
-
- /**
- * @since 2.0
- */
- public static ITransportConfig copyTransportConfig(ILifecycle lifecycle, ITransportConfig source)
- {
- return new TransportConfig(lifecycle, source.getReceiveExecutor(), source.getBufferProvider(),
- source.getProtocolProvider(), source.getNegotiator());
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.buffer.IBufferPool; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.connector.ConnectorException; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol; +import org.eclipse.net4j.util.StringUtil; +import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory; +import org.eclipse.net4j.util.container.ContainerUtil; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +import org.eclipse.internal.net4j.TransportConfig; +import org.eclipse.internal.net4j.buffer.BufferFactory; +import org.eclipse.internal.net4j.buffer.BufferPool; +import org.eclipse.internal.net4j.buffer.BufferProviderFactory; + +import org.eclipse.spi.net4j.AcceptorFactory; +import org.eclipse.spi.net4j.ConnectorFactory; + +import java.util.concurrent.ExecutorService; + +/** + * A utility class with various static factory and convenience methods. + * + * @author Eike Stepper + */ +public final class Net4jUtil +{ + public static final String SCHEME_SEPARATOR = "://"; //$NON-NLS-1$ + + public static final short DEFAULT_BUFFER_CAPACITY = 4096; + + private Net4jUtil() + { + } + + public static void prepareContainer(IManagedContainer container) + { + ContainerUtil.prepareContainer(container); + container.registerFactory(new BufferProviderFactory()); + container.addPostProcessor(new TransportInjector()); + container.registerFactory(new HeartBeatProtocol.Server.Factory()); + container.addPostProcessor(new HeartBeatProtocol.Server.TimerInjector()); + } + + public static ExecutorService getExecutorService(IManagedContainer container) + { + return ExecutorServiceFactory.get(container); + } + + public static IBufferProvider getBufferProvider(IManagedContainer container) + { + return BufferProviderFactory.get(container); + } + + public static IAcceptor getAcceptor(IManagedContainer container, String type, String description) + { + return (IAcceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description); + } + + /** + * @since 4.0 + */ + public static IConnector getConnector(IManagedContainer container, String type, String description, long timeout) + { + IConnector connector = (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description); + + try + { + connector.waitForConnection(timeout); + } + catch (ConnectorException ex) + { + container.removeElement(ConnectorFactory.PRODUCT_GROUP, type, description); + throw ex; + } + + return connector; + } + + public static IConnector getConnector(IManagedContainer container, String type, String description) + { + return getConnector(container, type, description, 10000L); + } + + public static IConnector getConnector(IManagedContainer container, String description) + { + int pos = description.indexOf(SCHEME_SEPARATOR); + if (pos <= 0) + { + throw new IllegalArgumentException("Connector type (scheme) missing: " + description); //$NON-NLS-1$ + } + + String factoryType = description.substring(0, pos); + + String connectorDescription = description.substring(pos + SCHEME_SEPARATOR.length()); + if (StringUtil.isEmpty(connectorDescription)) + { + throw new IllegalArgumentException("Illegal connector description: " + description); //$NON-NLS-1$ + } + + return getConnector(container, factoryType, connectorDescription); + } + + public static IBufferProvider createBufferFactory(short bufferCapacity) + { + return new BufferFactory(bufferCapacity); + } + + public static IBufferProvider createBufferFactory() + { + return createBufferFactory(DEFAULT_BUFFER_CAPACITY); + } + + public static IBufferPool createBufferPool(IBufferProvider factory) + { + return new BufferPool(factory); + } + + public static IBufferPool createBufferPool(short bufferCapacity) + { + return createBufferPool(createBufferFactory(bufferCapacity)); + } + + public static IBufferPool createBufferPool() + { + return createBufferPool(createBufferFactory()); + } + + public static long getProvidedBuffers(IBufferProvider bufferProvider) + { + if (bufferProvider instanceof IBufferProvider.Introspection) + { + return ((IBufferProvider.Introspection)bufferProvider).getProvidedBuffers(); + } + + return -1L; + } + + public static long getRetainedBuffers(IBufferProvider bufferProvider) + { + if (bufferProvider instanceof IBufferProvider.Introspection) + { + return ((IBufferProvider.Introspection)bufferProvider).getRetainedBuffers(); + } + + return -1L; + } + + public static int getPooledBuffers(IBufferPool bufferPool) + { + if (bufferPool instanceof IBufferPool.Introspection) + { + return ((IBufferPool.Introspection)bufferPool).getPooledBuffers(); + } + + return -1; + } + + /** + * @since 2.0 + */ + public static ITransportConfig copyTransportConfig(ILifecycle lifecycle, ITransportConfig source) + { + return new TransportConfig(lifecycle, source.getReceiveExecutor(), source.getBufferProvider(), + source.getProtocolProvider(), source.getNegotiator()); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java index 0f23441710..f1acfc8d90 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java @@ -1,167 +1,167 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiator;
-import org.eclipse.net4j.util.security.NegotiatorFactory;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.spi.net4j.Acceptor;
-import org.eclipse.spi.net4j.AcceptorFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Reads an XML config file and creates, wires and starts the configured {@link IAcceptor acceptors}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class TransportConfigurator
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TransportConfigurator.class);
-
- private IManagedContainer container;
-
- public TransportConfigurator(IManagedContainer container)
- {
- this.container = container;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public IAcceptor[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException,
- CoreException
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Configuring Net4j server from " + configFile.getAbsolutePath()); //$NON-NLS-1$
- }
-
- List<IAcceptor> acceptors = new ArrayList<IAcceptor>();
- Document document = getDocument(configFile);
- NodeList acceptorConfigs = document.getElementsByTagName("acceptor"); //$NON-NLS-1$
- for (int i = 0; i < acceptorConfigs.getLength(); i++)
- {
- Element acceptorConfig = (Element)acceptorConfigs.item(i);
- IAcceptor acceptor = configureAcceptor(acceptorConfig);
- acceptors.add(acceptor);
- }
-
- return acceptors.toArray(new IAcceptor[acceptors.size()]);
- }
-
- protected IAcceptor configureAcceptor(Element acceptorConfig)
- {
- String type = acceptorConfig.getAttribute("type"); //$NON-NLS-1$
- // TODO Make the following dependent on the "type" attribute value
- String listenAddr = acceptorConfig.getAttribute("listenAddr"); //$NON-NLS-1$
- String port = acceptorConfig.getAttribute("port"); //$NON-NLS-1$
- String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Acceptor acceptor = (Acceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description, false);
-
- NodeList negotiatorConfigs = acceptorConfig.getElementsByTagName("negotiator"); //$NON-NLS-1$
- if (negotiatorConfigs.getLength() > 1)
- {
- throw new IllegalStateException("A maximum of one negotiator can be configured for acceptor " + acceptor); //$NON-NLS-1$
- }
-
- if (negotiatorConfigs.getLength() == 1)
- {
- Element negotiatorConfig = (Element)negotiatorConfigs.item(0);
- INegotiator negotiator = configureNegotiator(negotiatorConfig);
- acceptor.getConfig().setNegotiator(negotiator);
- }
-
- acceptor.activate();
- return acceptor;
- }
-
- protected INegotiator configureNegotiator(Element negotiatorConfig)
- {
- String type = negotiatorConfig.getAttribute("type"); //$NON-NLS-1$
- String description = negotiatorConfig.getAttribute("description"); //$NON-NLS-1$
- return (INegotiator)container.getElement(NegotiatorFactory.PRODUCT_GROUP, type, description);
- }
-
- protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(configFile);
- }
-
- protected Element getStoreConfig(Element repositoryConfig)
- {
- NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$
- if (storeConfigs.getLength() != 1)
- {
- String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
- throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName); //$NON-NLS-1$
- }
-
- return (Element)storeConfigs.item(0);
- }
-
- public static Map<String, String> getProperties(Element element, int levels)
- {
- Map<String, String> properties = new HashMap<String, String>();
- collectProperties(element, "", properties, levels); //$NON-NLS-1$
- return properties;
- }
-
- private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
- {
- if ("property".equals(element.getNodeName())) //$NON-NLS-1$
- {
- String name = element.getAttribute("name"); //$NON-NLS-1$
- String value = element.getAttribute("value"); //$NON-NLS-1$
- properties.put(prefix + name, value);
- prefix += name + "."; //$NON-NLS-1$
- }
-
- if (levels > 0)
- {
- NodeList childNodes = element.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++)
- {
- Node childNode = childNodes.item(i);
- if (childNode instanceof Element)
- {
- collectProperties((Element)childNode, prefix, properties, levels - 1);
- }
- }
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.util.container.IManagedContainer; +import org.eclipse.net4j.util.om.trace.ContextTracer; +import org.eclipse.net4j.util.security.INegotiator; +import org.eclipse.net4j.util.security.NegotiatorFactory; + +import org.eclipse.internal.net4j.bundle.OM; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.spi.net4j.Acceptor; +import org.eclipse.spi.net4j.AcceptorFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Reads an XML config file and creates, wires and starts the configured {@link IAcceptor acceptors}. + * + * @author Eike Stepper + * @since 2.0 + */ +public class TransportConfigurator +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TransportConfigurator.class); + + private IManagedContainer container; + + public TransportConfigurator(IManagedContainer container) + { + this.container = container; + } + + public IManagedContainer getContainer() + { + return container; + } + + public IAcceptor[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException, + CoreException + { + if (TRACER.isEnabled()) + { + TRACER.trace("Configuring Net4j server from " + configFile.getAbsolutePath()); //$NON-NLS-1$ + } + + List<IAcceptor> acceptors = new ArrayList<IAcceptor>(); + Document document = getDocument(configFile); + NodeList acceptorConfigs = document.getElementsByTagName("acceptor"); //$NON-NLS-1$ + for (int i = 0; i < acceptorConfigs.getLength(); i++) + { + Element acceptorConfig = (Element)acceptorConfigs.item(i); + IAcceptor acceptor = configureAcceptor(acceptorConfig); + acceptors.add(acceptor); + } + + return acceptors.toArray(new IAcceptor[acceptors.size()]); + } + + protected IAcceptor configureAcceptor(Element acceptorConfig) + { + String type = acceptorConfig.getAttribute("type"); //$NON-NLS-1$ + // TODO Make the following dependent on the "type" attribute value + String listenAddr = acceptorConfig.getAttribute("listenAddr"); //$NON-NLS-1$ + String port = acceptorConfig.getAttribute("port"); //$NON-NLS-1$ + String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + Acceptor acceptor = (Acceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description, false); + + NodeList negotiatorConfigs = acceptorConfig.getElementsByTagName("negotiator"); //$NON-NLS-1$ + if (negotiatorConfigs.getLength() > 1) + { + throw new IllegalStateException("A maximum of one negotiator can be configured for acceptor " + acceptor); //$NON-NLS-1$ + } + + if (negotiatorConfigs.getLength() == 1) + { + Element negotiatorConfig = (Element)negotiatorConfigs.item(0); + INegotiator negotiator = configureNegotiator(negotiatorConfig); + acceptor.getConfig().setNegotiator(negotiator); + } + + acceptor.activate(); + return acceptor; + } + + protected INegotiator configureNegotiator(Element negotiatorConfig) + { + String type = negotiatorConfig.getAttribute("type"); //$NON-NLS-1$ + String description = negotiatorConfig.getAttribute("description"); //$NON-NLS-1$ + return (INegotiator)container.getElement(NegotiatorFactory.PRODUCT_GROUP, type, description); + } + + protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException + { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + return builder.parse(configFile); + } + + protected Element getStoreConfig(Element repositoryConfig) + { + NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$ + if (storeConfigs.getLength() != 1) + { + String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$ + throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName); //$NON-NLS-1$ + } + + return (Element)storeConfigs.item(0); + } + + public static Map<String, String> getProperties(Element element, int levels) + { + Map<String, String> properties = new HashMap<String, String>(); + collectProperties(element, "", properties, levels); //$NON-NLS-1$ + return properties; + } + + private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels) + { + if ("property".equals(element.getNodeName())) //$NON-NLS-1$ + { + String name = element.getAttribute("name"); //$NON-NLS-1$ + String value = element.getAttribute("value"); //$NON-NLS-1$ + properties.put(prefix + name, value); + prefix += name + "."; //$NON-NLS-1$ + } + + if (levels > 0) + { + NodeList childNodes = element.getChildNodes(); + for (int i = 0; i < childNodes.getLength(); i++) + { + Node childNode = childNodes.item(i); + if (childNode instanceof Element) + { + collectProperties((Element)childNode, prefix, properties, levels - 1); + } + } + } + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java index c8807780d6..a8cb8ddae0 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java @@ -1,110 +1,110 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-
-import org.eclipse.spi.net4j.InternalAcceptor;
-import org.eclipse.spi.net4j.InternalConnector;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * An element post processor that injects a {@link ITransportConfig transport configuration} into the {@link IConnector
- * connectors} and {@link IAcceptor acceptors} of a {@link IManagedContainer managed container}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class TransportInjector implements IElementProcessor
-{
- public TransportInjector()
- {
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof InternalAcceptor)
- {
- InternalAcceptor acceptor = (InternalAcceptor)element;
- processAcceptor(container, factoryType, description, acceptor);
- }
- else if (element instanceof InternalConnector)
- {
- InternalConnector connector = (InternalConnector)element;
- processConnector(container, factoryType, description, connector);
- }
-
- return element;
- }
-
- protected void processAcceptor(IManagedContainer container, String factoryType, String description,
- InternalAcceptor acceptor)
- {
- ITransportConfig config = acceptor.getConfig();
- if (config.getBufferProvider() == null)
- {
- config.setBufferProvider(getBufferProvider(container));
- }
-
- if (config.getReceiveExecutor() == null)
- {
- config.setReceiveExecutor(getExecutorService(container));
- }
-
- if (config.getProtocolProvider() == null)
- {
- config.setProtocolProvider(new ContainerProtocolProvider.Server(container));
- }
- }
-
- protected void processConnector(IManagedContainer container, String factoryType, String description,
- InternalConnector connector)
- {
- ITransportConfig config = connector.getConfig();
- if (config.getBufferProvider() == null)
- {
- config.setBufferProvider(getBufferProvider(container));
- }
-
- if (config.getReceiveExecutor() == null)
- {
- config.setReceiveExecutor(getExecutorService(container));
- }
-
- if (config.getProtocolProvider() == null)
- {
- config.setProtocolProvider(new ContainerProtocolProvider.Client(container));
- }
- }
-
- /**
- * @since 2.0
- */
- protected IBufferProvider getBufferProvider(IManagedContainer container)
- {
- return (IBufferProvider)container.getElement(BufferProviderFactory.PRODUCT_GROUP, BufferProviderFactory.TYPE, null);
- }
-
- protected ExecutorService getExecutorService(IManagedContainer container)
- {
- return (ExecutorService)container.getElement(ExecutorServiceFactory.PRODUCT_GROUP, ExecutorServiceFactory.TYPE,
- null);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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; + +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory; +import org.eclipse.net4j.util.container.IElementProcessor; +import org.eclipse.net4j.util.container.IManagedContainer; + +import org.eclipse.internal.net4j.buffer.BufferProviderFactory; + +import org.eclipse.spi.net4j.InternalAcceptor; +import org.eclipse.spi.net4j.InternalConnector; + +import java.util.concurrent.ExecutorService; + +/** + * An element post processor that injects a {@link ITransportConfig transport configuration} into the {@link IConnector + * connectors} and {@link IAcceptor acceptors} of a {@link IManagedContainer managed container}. + * + * @author Eike Stepper + * @since 2.0 + */ +public class TransportInjector implements IElementProcessor +{ + public TransportInjector() + { + } + + public Object process(IManagedContainer container, String productGroup, String factoryType, String description, + Object element) + { + if (element instanceof InternalAcceptor) + { + InternalAcceptor acceptor = (InternalAcceptor)element; + processAcceptor(container, factoryType, description, acceptor); + } + else if (element instanceof InternalConnector) + { + InternalConnector connector = (InternalConnector)element; + processConnector(container, factoryType, description, connector); + } + + return element; + } + + protected void processAcceptor(IManagedContainer container, String factoryType, String description, + InternalAcceptor acceptor) + { + ITransportConfig config = acceptor.getConfig(); + if (config.getBufferProvider() == null) + { + config.setBufferProvider(getBufferProvider(container)); + } + + if (config.getReceiveExecutor() == null) + { + config.setReceiveExecutor(getExecutorService(container)); + } + + if (config.getProtocolProvider() == null) + { + config.setProtocolProvider(new ContainerProtocolProvider.Server(container)); + } + } + + protected void processConnector(IManagedContainer container, String factoryType, String description, + InternalConnector connector) + { + ITransportConfig config = connector.getConfig(); + if (config.getBufferProvider() == null) + { + config.setBufferProvider(getBufferProvider(container)); + } + + if (config.getReceiveExecutor() == null) + { + config.setReceiveExecutor(getExecutorService(container)); + } + + if (config.getProtocolProvider() == null) + { + config.setProtocolProvider(new ContainerProtocolProvider.Client(container)); + } + } + + /** + * @since 2.0 + */ + protected IBufferProvider getBufferProvider(IManagedContainer container) + { + return (IBufferProvider)container.getElement(BufferProviderFactory.PRODUCT_GROUP, BufferProviderFactory.TYPE, null); + } + + protected ExecutorService getExecutorService(IManagedContainer container) + { + return (ExecutorService)container.getElement(ExecutorServiceFactory.PRODUCT_GROUP, ExecutorServiceFactory.TYPE, + null); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java index a4b9d7d01f..fb62b2d86d 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java @@ -1,53 +1,53 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.acceptor;
-
-import org.eclipse.net4j.ILocationAware.Location;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.container.IContainer;
-
-import org.eclipse.spi.net4j.Acceptor;
-
-/**
- * Accepts incoming connection requests from {@link Location#CLIENT client} {@link IConnector connectors} and creates
- * the appropriate {@link Location#SERVER server} connectors.
- * <p>
- * Since the process of accepting connection requests is heavily dependent on the implementation of the respective
- * connectors the only public API is introspection and notification.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients. Service providers <b>must</b> extend the abstract
- * {@link Acceptor} class.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IAcceptor-1.gif" title="Diagram Acceptors" border="0" usemap="#IAcceptor-1.gif"/></dd>
- * <p>
- * <MAP NAME="IAcceptor-1.gif"> <AREA SHAPE="RECT" COORDS="10,8,99,58" HREF="IAcceptor.html"> <AREA SHAPE="RECT"
- * COORDS="289,8,378,58" HREF="../connector/IConnector.html"> </MAP>
- * <p>
- * <dt><b>Sequence Diagram:</b></dt>
- * <dd><img src="doc-files/IAcceptor-2.gif" title="Connection Process" border="0" usemap="#IAcceptor-2.gif"/></dd>
- * <p>
- * <MAP NAME="IAcceptor-2.gif"> <AREA SHAPE="RECT" COORDS="146,136,265,165" HREF="IConnector.html"> <AREA SHAPE="RECT"
- * COORDS="485,75,564,105" HREF="IAcceptor.html"> <AREA SHAPE="RECT" COORDS="296,325,414,355" HREF="IConnector.html">
- * <AREA SHAPE="RECT" COORDS="64,426,444,506" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
- * COORDS="64,516,444,596" HREF="ConnectorState.html#NEGOTIATING"> </MAP>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IAcceptor extends IContainer<IConnector>, Closeable
-{
- /**
- * Returns an array of the connectors that have been accepted by this acceptor and not been closed since.
- */
- public IConnector[] getAcceptedConnectors();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.acceptor; + +import org.eclipse.net4j.ILocationAware.Location; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.collection.Closeable; +import org.eclipse.net4j.util.container.IContainer; + +import org.eclipse.spi.net4j.Acceptor; + +/** + * Accepts incoming connection requests from {@link Location#CLIENT client} {@link IConnector connectors} and creates + * the appropriate {@link Location#SERVER server} connectors. + * <p> + * Since the process of accepting connection requests is heavily dependent on the implementation of the respective + * connectors the only public API is introspection and notification. + * <p> + * This interface is <b>not</b> intended to be implemented by clients. Service providers <b>must</b> extend the abstract + * {@link Acceptor} class. + * <p> + * <dt><b>Class Diagram:</b></dt> + * <dd><img src="doc-files/IAcceptor-1.gif" title="Diagram Acceptors" border="0" usemap="#IAcceptor-1.gif"/></dd> + * <p> + * <MAP NAME="IAcceptor-1.gif"> <AREA SHAPE="RECT" COORDS="10,8,99,58" HREF="IAcceptor.html"> <AREA SHAPE="RECT" + * COORDS="289,8,378,58" HREF="../connector/IConnector.html"> </MAP> + * <p> + * <dt><b>Sequence Diagram:</b></dt> + * <dd><img src="doc-files/IAcceptor-2.gif" title="Connection Process" border="0" usemap="#IAcceptor-2.gif"/></dd> + * <p> + * <MAP NAME="IAcceptor-2.gif"> <AREA SHAPE="RECT" COORDS="146,136,265,165" HREF="IConnector.html"> <AREA SHAPE="RECT" + * COORDS="485,75,564,105" HREF="IAcceptor.html"> <AREA SHAPE="RECT" COORDS="296,325,414,355" HREF="IConnector.html"> + * <AREA SHAPE="RECT" COORDS="64,426,444,506" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT" + * COORDS="64,516,444,596" HREF="ConnectorState.html#NEGOTIATING"> </MAP> + * + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IAcceptor extends IContainer<IConnector>, Closeable +{ + /** + * Returns an array of the connectors that have been accepted by this acceptor and not been closed since. + */ + public IConnector[] getAcceptedConnectors(); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java index e806d3930b..61e81f7c9a 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java @@ -1,229 +1,229 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import org.eclipse.net4j.signal.RemoteException;
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.IOTimeoutException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A {@link IBufferHandler buffer handler} that defragments the passed {@link IBuffer buffers} into a continuous byte
- * sequence which is exposed as an {@link InputStream input stream}.
- *
- * @author Eike Stepper
- */
-public class BufferInputStream extends InputStream implements IBufferHandler
-{
- public static final long NO_TIMEOUT = -1;
-
- public static final long DEFAULT_MILLIS_BEFORE_TIMEOUT = NO_TIMEOUT;
-
- public static final long DEFAULT_MILLIS_INTERRUPT_CHECK = 100;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferInputStream.class);
-
- private final boolean tracerEnabled;
-
- private BlockingQueue<IBuffer> buffers = new LinkedBlockingQueue<IBuffer>();
-
- private IBuffer currentBuffer;
-
- private boolean eos;
-
- private RemoteException exception;
-
- private long stopTimeMillis;
-
- public BufferInputStream()
- {
- tracerEnabled = TRACER.isEnabled();
- }
-
- public long getMillisBeforeTimeout()
- {
- return DEFAULT_MILLIS_BEFORE_TIMEOUT;
- }
-
- public long getMillisInterruptCheck()
- {
- return DEFAULT_MILLIS_INTERRUPT_CHECK;
- }
-
- /**
- * @since 2.0
- */
- public void restartTimeout()
- {
- synchronized (this)
- {
- stopTimeMillis = System.currentTimeMillis() + getMillisBeforeTimeout();
- }
- }
-
- /**
- * @since 2.0
- */
- public RuntimeException getException()
- {
- return exception;
- }
-
- /**
- * @since 4.0
- */
- public void setException(RemoteException exception)
- {
- this.exception = exception;
- }
-
- public void handleBuffer(IBuffer buffer)
- {
- buffers.add(buffer);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public int read() throws IOException
- {
- if (currentBuffer == null)
- {
- if (eos)
- {
- // End of stream
- return IOUtil.EOF;
- }
-
- if (!ensureBuffer())
- {
- // Timeout or interrupt
- return IOUtil.EOF;
- }
- }
-
- ByteBuffer byteBuffer = currentBuffer.getByteBuffer();
- if (!byteBuffer.hasRemaining())
- {
- // End of stream
- return IOUtil.EOF;
- }
-
- final int result = byteBuffer.get() & 0xFF;
- if (tracerEnabled)
- {
- TRACER.trace("<-- " + HexUtil.formatByte(result) //$NON-NLS-1$
- + (result >= 32 ? " " + Character.toString((char)result) : "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (!byteBuffer.hasRemaining())
- {
- currentBuffer.release();
- currentBuffer = null;
- }
-
- return result;
- }
-
- @Override
- public void close() throws IOException
- {
- buffers = null;
- currentBuffer = null;
- super.close();
- }
-
- @Override
- public String toString()
- {
- return "BufferInputStream"; //$NON-NLS-1$
- }
-
- protected boolean ensureBuffer() throws IOException
- {
- final long check = getMillisInterruptCheck();
-
- try
- {
- if (getMillisBeforeTimeout() == NO_TIMEOUT)
- {
- while (currentBuffer == null)
- {
- throwRemoteExceptionIfExists();
-
- if (buffers == null)
- {
- // Stream has been closed - shutting down
- return false;
- }
-
- currentBuffer = buffers.poll(check, TimeUnit.MILLISECONDS);
- }
- }
- else
- {
- restartTimeout();
- while (currentBuffer == null)
- {
- throwRemoteExceptionIfExists();
-
- if (buffers == null)
- {
- // Stream has been closed - shutting down
- return false;
- }
-
- long remaining;
- synchronized (this)
- {
- remaining = stopTimeMillis;
- }
-
- remaining -= System.currentTimeMillis();
- if (remaining <= 0)
- {
- // Throw an exception so that caller can distinguish between end-of-stream and a timeout
- throw new IOTimeoutException();
- }
-
- currentBuffer = buffers.poll(Math.min(remaining, check), TimeUnit.MILLISECONDS);
- }
- }
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- eos = currentBuffer.isEOS();
- return true;
- }
-
- private void throwRemoteExceptionIfExists()
- {
- if (exception != null)
- {
- StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- exception.setLocalStacktrace(stackTrace);
- throw exception;
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import org.eclipse.net4j.signal.RemoteException; +import org.eclipse.net4j.util.HexUtil; +import org.eclipse.net4j.util.WrappedException; +import org.eclipse.net4j.util.io.IOTimeoutException; +import org.eclipse.net4j.util.io.IOUtil; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +/** + * A {@link IBufferHandler buffer handler} that defragments the passed {@link IBuffer buffers} into a continuous byte + * sequence which is exposed as an {@link InputStream input stream}. + * + * @author Eike Stepper + */ +public class BufferInputStream extends InputStream implements IBufferHandler +{ + public static final long NO_TIMEOUT = -1; + + public static final long DEFAULT_MILLIS_BEFORE_TIMEOUT = NO_TIMEOUT; + + public static final long DEFAULT_MILLIS_INTERRUPT_CHECK = 100; + + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferInputStream.class); + + private final boolean tracerEnabled; + + private BlockingQueue<IBuffer> buffers = new LinkedBlockingQueue<IBuffer>(); + + private IBuffer currentBuffer; + + private boolean eos; + + private RemoteException exception; + + private long stopTimeMillis; + + public BufferInputStream() + { + tracerEnabled = TRACER.isEnabled(); + } + + public long getMillisBeforeTimeout() + { + return DEFAULT_MILLIS_BEFORE_TIMEOUT; + } + + public long getMillisInterruptCheck() + { + return DEFAULT_MILLIS_INTERRUPT_CHECK; + } + + /** + * @since 2.0 + */ + public void restartTimeout() + { + synchronized (this) + { + stopTimeMillis = System.currentTimeMillis() + getMillisBeforeTimeout(); + } + } + + /** + * @since 2.0 + */ + public RuntimeException getException() + { + return exception; + } + + /** + * @since 4.0 + */ + public void setException(RemoteException exception) + { + this.exception = exception; + } + + public void handleBuffer(IBuffer buffer) + { + buffers.add(buffer); + } + + @SuppressWarnings("deprecation") + @Override + public int read() throws IOException + { + if (currentBuffer == null) + { + if (eos) + { + // End of stream + return IOUtil.EOF; + } + + if (!ensureBuffer()) + { + // Timeout or interrupt + return IOUtil.EOF; + } + } + + ByteBuffer byteBuffer = currentBuffer.getByteBuffer(); + if (!byteBuffer.hasRemaining()) + { + // End of stream + return IOUtil.EOF; + } + + final int result = byteBuffer.get() & 0xFF; + if (tracerEnabled) + { + TRACER.trace("<-- " + HexUtil.formatByte(result) //$NON-NLS-1$ + + (result >= 32 ? " " + Character.toString((char)result) : "")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + if (!byteBuffer.hasRemaining()) + { + currentBuffer.release(); + currentBuffer = null; + } + + return result; + } + + @Override + public void close() throws IOException + { + buffers = null; + currentBuffer = null; + super.close(); + } + + @Override + public String toString() + { + return "BufferInputStream"; //$NON-NLS-1$ + } + + protected boolean ensureBuffer() throws IOException + { + final long check = getMillisInterruptCheck(); + + try + { + if (getMillisBeforeTimeout() == NO_TIMEOUT) + { + while (currentBuffer == null) + { + throwRemoteExceptionIfExists(); + + if (buffers == null) + { + // Stream has been closed - shutting down + return false; + } + + currentBuffer = buffers.poll(check, TimeUnit.MILLISECONDS); + } + } + else + { + restartTimeout(); + while (currentBuffer == null) + { + throwRemoteExceptionIfExists(); + + if (buffers == null) + { + // Stream has been closed - shutting down + return false; + } + + long remaining; + synchronized (this) + { + remaining = stopTimeMillis; + } + + remaining -= System.currentTimeMillis(); + if (remaining <= 0) + { + // Throw an exception so that caller can distinguish between end-of-stream and a timeout + throw new IOTimeoutException(); + } + + currentBuffer = buffers.poll(Math.min(remaining, check), TimeUnit.MILLISECONDS); + } + } + } + catch (InterruptedException ex) + { + throw WrappedException.wrap(ex); + } + + eos = currentBuffer.isEOS(); + return true; + } + + private void throwRemoteExceptionIfExists() + { + if (exception != null) + { + StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); + exception.setLocalStacktrace(stackTrace); + throw exception; + } + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java index 276f25cf23..ac2cfa15ba 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java @@ -1,254 +1,254 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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
- * Andre Dietisheim - Bug 262875: java.nio.BufferUnderFlowException https://bugs.eclipse.org/bugs/show_bug.cgi?id=262875
- */
-package org.eclipse.net4j.buffer;
-
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.IErrorHandler;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-
-/**
- * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
- * buffers} and passes them to configured {@link IBufferHandler buffer handler}.
- *
- * @author Eike Stepper
- */
-public class BufferOutputStream extends OutputStream
-{
- public static final boolean DEFAULT_PROPAGATE_CLOSE = false;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferOutputStream.class);
-
- private final boolean tracerEnabled;
-
- private IBufferProvider bufferProvider;
-
- private IBufferHandler bufferHandler;
-
- private IBuffer currentBuffer;
-
- private short channelID;
-
- private Throwable error;
-
- @ExcludeFromDump
- private transient IErrorHandler errorHandler = new IErrorHandler()
- {
- public void handleError(Throwable t)
- {
- setError(t);
- }
- };
-
- public BufferOutputStream(IBufferHandler bufferHandler, IBufferProvider bufferProvider, short channelID)
- {
- if (bufferHandler == null)
- {
- throw new IllegalArgumentException("bufferHandler == null"); //$NON-NLS-1$
- }
-
- if (bufferProvider == null)
- {
- throw new IllegalArgumentException("bufferProvider == null"); //$NON-NLS-1$
- }
-
- this.bufferHandler = bufferHandler;
- this.bufferProvider = bufferProvider;
- this.channelID = channelID;
- tracerEnabled = TRACER.isEnabled();
- }
-
- public BufferOutputStream(IBufferHandler bufferHandler, short channelID)
- {
- this(bufferHandler, extractBufferProvider(bufferHandler), channelID);
- }
-
- /**
- * @since 2.0
- */
- public Throwable getError()
- {
- return error;
- }
-
- /**
- * @since 2.0
- */
- public void setError(Throwable error)
- {
- this.error = error;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void write(int b) throws IOException
- {
- throwExceptionOnError();
- flushIfFilled();
- ensureBufferPrivate();
-
- // If this was called with a primitive byte with a negative value,
- // the implicit conversion prepended 24 leading 1's. We'll undo those.
- b = b & 0xFF;
-
- if (tracerEnabled)
- {
- TRACER.trace("--> " + HexUtil.formatByte(b) //$NON-NLS-1$
- + (b >= 32 ? " " + Character.toString((char)b) : "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- ByteBuffer buffer = currentBuffer.getByteBuffer();
- buffer.put((byte)b);
- }
-
- /**
- * Flushes the current buffer, it's handled over to the buffer handler.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #currentBuffer
- * @see IBufferHandler#handleBuffer(IBuffer)
- */
- @Override
- public void flush() throws IOException
- {
- flushPrivate();
- }
-
- /**
- * Flushes the current buffer if it has no remaining space.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- private void flushIfFilled() throws IOException
- {
- if (currentBuffer != null && !currentBuffer.getByteBuffer().hasRemaining())
- {
- flushPrivate();
- }
- }
-
- private void flushPrivate()
- {
- if (currentBuffer != null)
- {
- bufferHandler.handleBuffer(currentBuffer);
- currentBuffer = null;
- }
- }
-
- public void flushWithEOS() throws IOException
- {
- throwExceptionOnError();
- ensureBufferPrivate();
- currentBuffer.setEOS(true);
- flushPrivate();
- }
-
- @Override
- public void close() throws IOException
- {
- try
- {
- if (isPropagateClose())
- {
- LifecycleUtil.deactivate(bufferHandler);
- }
- }
- finally
- {
- bufferHandler = null;
- bufferProvider = null;
- currentBuffer = null;
- super.close();
- }
- }
-
- @Override
- public String toString()
- {
- return "BufferOutputStream"; //$NON-NLS-1$
- }
-
- /**
- * Ensures that this BufferOutputStream has a buffer. If the current buffer was flushed a new one is fetched from the
- * buffer provider.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #flush()
- * @see IBufferProvider#provideBuffer()
- */
- protected void ensureBuffer() throws IOException
- {
- ensureBufferPrivate();
- }
-
- private void ensureBufferPrivate()
- {
- if (currentBuffer == null)
- {
- currentBuffer = bufferProvider.provideBuffer();
- currentBuffer.setErrorHandler(errorHandler);
- currentBuffer.startPutting(channelID);
- }
- }
-
- /**
- * Throws an exception if there's an error.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #error
- */
- private void throwExceptionOnError() throws IOException
- {
- if (error != null)
- {
- if (error instanceof IOException)
- {
- throw (IOException)error;
- }
-
- if (error instanceof RuntimeException)
- {
- throw (RuntimeException)error;
- }
-
- throw new IORuntimeException(error);
- }
- }
-
- protected boolean isPropagateClose()
- {
- return DEFAULT_PROPAGATE_CLOSE;
- }
-
- private static IBufferProvider extractBufferProvider(IBufferHandler bufferHandler)
- {
- if (bufferHandler instanceof IBufferProvider)
- {
- return (IBufferProvider)bufferHandler;
- }
-
- throw new IllegalArgumentException("Buffer handler unable to provide buffers"); //$NON-NLS-1$
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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 + * Andre Dietisheim - Bug 262875: java.nio.BufferUnderFlowException https://bugs.eclipse.org/bugs/show_bug.cgi?id=262875 + */ +package org.eclipse.net4j.buffer; + +import org.eclipse.net4j.util.HexUtil; +import org.eclipse.net4j.util.IErrorHandler; +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.io.IORuntimeException; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +/** + * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer + * buffers} and passes them to configured {@link IBufferHandler buffer handler}. + * + * @author Eike Stepper + */ +public class BufferOutputStream extends OutputStream +{ + public static final boolean DEFAULT_PROPAGATE_CLOSE = false; + + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferOutputStream.class); + + private final boolean tracerEnabled; + + private IBufferProvider bufferProvider; + + private IBufferHandler bufferHandler; + + private IBuffer currentBuffer; + + private short channelID; + + private Throwable error; + + @ExcludeFromDump + private transient IErrorHandler errorHandler = new IErrorHandler() + { + public void handleError(Throwable t) + { + setError(t); + } + }; + + public BufferOutputStream(IBufferHandler bufferHandler, IBufferProvider bufferProvider, short channelID) + { + if (bufferHandler == null) + { + throw new IllegalArgumentException("bufferHandler == null"); //$NON-NLS-1$ + } + + if (bufferProvider == null) + { + throw new IllegalArgumentException("bufferProvider == null"); //$NON-NLS-1$ + } + + this.bufferHandler = bufferHandler; + this.bufferProvider = bufferProvider; + this.channelID = channelID; + tracerEnabled = TRACER.isEnabled(); + } + + public BufferOutputStream(IBufferHandler bufferHandler, short channelID) + { + this(bufferHandler, extractBufferProvider(bufferHandler), channelID); + } + + /** + * @since 2.0 + */ + public Throwable getError() + { + return error; + } + + /** + * @since 2.0 + */ + public void setError(Throwable error) + { + this.error = error; + } + + @SuppressWarnings("deprecation") + @Override + public void write(int b) throws IOException + { + throwExceptionOnError(); + flushIfFilled(); + ensureBufferPrivate(); + + // If this was called with a primitive byte with a negative value, + // the implicit conversion prepended 24 leading 1's. We'll undo those. + b = b & 0xFF; + + if (tracerEnabled) + { + TRACER.trace("--> " + HexUtil.formatByte(b) //$NON-NLS-1$ + + (b >= 32 ? " " + Character.toString((char)b) : "")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + ByteBuffer buffer = currentBuffer.getByteBuffer(); + buffer.put((byte)b); + } + + /** + * Flushes the current buffer, it's handled over to the buffer handler. + * + * @throws IOException + * Signals that an I/O exception has occurred. + * @see #currentBuffer + * @see IBufferHandler#handleBuffer(IBuffer) + */ + @Override + public void flush() throws IOException + { + flushPrivate(); + } + + /** + * Flushes the current buffer if it has no remaining space. + * + * @throws IOException + * Signals that an I/O exception has occurred. + */ + private void flushIfFilled() throws IOException + { + if (currentBuffer != null && !currentBuffer.getByteBuffer().hasRemaining()) + { + flushPrivate(); + } + } + + private void flushPrivate() + { + if (currentBuffer != null) + { + bufferHandler.handleBuffer(currentBuffer); + currentBuffer = null; + } + } + + public void flushWithEOS() throws IOException + { + throwExceptionOnError(); + ensureBufferPrivate(); + currentBuffer.setEOS(true); + flushPrivate(); + } + + @Override + public void close() throws IOException + { + try + { + if (isPropagateClose()) + { + LifecycleUtil.deactivate(bufferHandler); + } + } + finally + { + bufferHandler = null; + bufferProvider = null; + currentBuffer = null; + super.close(); + } + } + + @Override + public String toString() + { + return "BufferOutputStream"; //$NON-NLS-1$ + } + + /** + * Ensures that this BufferOutputStream has a buffer. If the current buffer was flushed a new one is fetched from the + * buffer provider. + * + * @throws IOException + * Signals that an I/O exception has occurred. + * @see #flush() + * @see IBufferProvider#provideBuffer() + */ + protected void ensureBuffer() throws IOException + { + ensureBufferPrivate(); + } + + private void ensureBufferPrivate() + { + if (currentBuffer == null) + { + currentBuffer = bufferProvider.provideBuffer(); + currentBuffer.setErrorHandler(errorHandler); + currentBuffer.startPutting(channelID); + } + } + + /** + * Throws an exception if there's an error. + * + * @throws IOException + * Signals that an I/O exception has occurred. + * @see #error + */ + private void throwExceptionOnError() throws IOException + { + if (error != null) + { + if (error instanceof IOException) + { + throw (IOException)error; + } + + if (error instanceof RuntimeException) + { + throw (RuntimeException)error; + } + + throw new IORuntimeException(error); + } + } + + protected boolean isPropagateClose() + { + return DEFAULT_PROPAGATE_CLOSE; + } + + private static IBufferProvider extractBufferProvider(IBufferHandler bufferHandler) + { + if (bufferHandler instanceof IBufferProvider) + { + return (IBufferProvider)bufferHandler; + } + + throw new IllegalArgumentException("Buffer handler unable to provide buffers"); //$NON-NLS-1$ + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java index 3e04f5aa26..b826ced11b 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java @@ -1,110 +1,110 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-/**
- * Enumerates the internal states of an {@link IBuffer}.
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
- * <p>
- * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
- * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
- * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
- * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
- * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- */
-public enum BufferState
-{
- /**
- * Indicates that the {@link IBuffer} has just been provided by its {@link IBufferProvider} or that is has been used
- * and subsequently {@link IBuffer#clear() cleared}.
- * <p>
- * A transition to {@link #PUTTING} can be triggered by calling {@link IBuffer#startPutting(short)} once. If the
- * buffer is intended to be passed to an {@link org.eclipse.net4j.channel.IChannel IChannel} later the
- * {@link org.eclipse.net4j.channel.IChannel#getID() channel index} of that Channel has to be passed because it is
- * part of the buffer's header. A {@link ByteBuffer} is returned that can be used for putting data.
- * <p>
- * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#startGetting(SocketChannel)} repeatedly
- * until it finally returns a {@link ByteBuffer} that can be used for getting data.
- */
- INITIAL,
-
- /**
- * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for putting data.
- * <p>
- * A transition to {@link #WRITING} can be triggered by calling {@link IBuffer#write(SocketChannel)}.
- * <p>
- * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#flip()}.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- PUTTING,
-
- /**
- * Indicates that the {@link IBuffer} is currently writing its data to a {@link SocketChannel}.
- * <p>
- * Self transitions to {@link #WRITING} can be triggered by repeatedly calling {@link IBuffer#write(SocketChannel)}
- * until it returns <code>true</code>.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- WRITING,
-
- /**
- * Indicates that the {@link IBuffer} is currently reading its header from a {@link SocketChannel}.
- * <p>
- * Transitions to {@link #READING_HEADER}, {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly
- * calling {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for
- * getting data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- READING_HEADER,
-
- /**
- * Indicates that the {@link IBuffer} is currently reading its body from a {@link SocketChannel}.
- * <p>
- * Transitions to {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly calling
- * {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for getting
- * data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- READING_BODY,
-
- /**
- * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for getting data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- GETTING,
-
- /**
- * Indicates that the {@link IBuffer} is owned by its {@link IBufferProvider}.
- *
- * @since 3.0
- */
- RELEASED,
-
- /**
- * Indicates that the {@link IBuffer} can not be used anymore.
- *
- * @since 3.0
- */
- DISPOSED
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +/** + * Enumerates the internal states of an {@link IBuffer}. + * <p> + * <dt><b>State Machine Diagram:</b></dt> + * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd> + * <p> + * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA + * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295" + * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER"> + * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT" + * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP> + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + */ +public enum BufferState +{ + /** + * Indicates that the {@link IBuffer} has just been provided by its {@link IBufferProvider} or that is has been used + * and subsequently {@link IBuffer#clear() cleared}. + * <p> + * A transition to {@link #PUTTING} can be triggered by calling {@link IBuffer#startPutting(short)} once. If the + * buffer is intended to be passed to an {@link org.eclipse.net4j.channel.IChannel IChannel} later the + * {@link org.eclipse.net4j.channel.IChannel#getID() channel index} of that Channel has to be passed because it is + * part of the buffer's header. A {@link ByteBuffer} is returned that can be used for putting data. + * <p> + * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#startGetting(SocketChannel)} repeatedly + * until it finally returns a {@link ByteBuffer} that can be used for getting data. + */ + INITIAL, + + /** + * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for putting data. + * <p> + * A transition to {@link #WRITING} can be triggered by calling {@link IBuffer#write(SocketChannel)}. + * <p> + * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#flip()}. + * <p> + * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}. + */ + PUTTING, + + /** + * Indicates that the {@link IBuffer} is currently writing its data to a {@link SocketChannel}. + * <p> + * Self transitions to {@link #WRITING} can be triggered by repeatedly calling {@link IBuffer#write(SocketChannel)} + * until it returns <code>true</code>. + * <p> + * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}. + */ + WRITING, + + /** + * Indicates that the {@link IBuffer} is currently reading its header from a {@link SocketChannel}. + * <p> + * Transitions to {@link #READING_HEADER}, {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly + * calling {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for + * getting data. + * <p> + * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}. + */ + READING_HEADER, + + /** + * Indicates that the {@link IBuffer} is currently reading its body from a {@link SocketChannel}. + * <p> + * Transitions to {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly calling + * {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for getting + * data. + * <p> + * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}. + */ + READING_BODY, + + /** + * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for getting data. + * <p> + * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}. + */ + GETTING, + + /** + * Indicates that the {@link IBuffer} is owned by its {@link IBufferProvider}. + * + * @since 3.0 + */ + RELEASED, + + /** + * Indicates that the {@link IBuffer} can not be used anymore. + * + * @since 3.0 + */ + DISPOSED +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java index 5814f3ba54..3f59cc079b 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java @@ -1,286 +1,286 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.util.IErrorHandler;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-/**
- * Basic <b>unit of transport</b> in Net4j.
- * <p>
- * A buffer is well prepared for the usage with asynchronous {@link IChannel}s but can also be used with pure
- * {@link SocketChannel}s. All methods of <code>IBuffer</code> are non-blocking.
- * <p>
- * Usually buffers are obtained from a {@link IBufferProvider}. Buffers can be accessed, passed around and finally
- * {@link #release() released} to their original provider. The capacity of a buffer is determined by its provider.
- * <p>
- * In addition to its payload data each buffer contains an internal header of four bytes, two of them representing a
- * channel identifier the other two of them denoting the length of the payload data. The payload data may be accessed
- * through a {@link #getByteBuffer() ByteBuffer}.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IBuffer-1.gif" title="Diagram Buffers" border="0" usemap="#IBuffer-1.gif"/></dd>
- * <p>
- * <MAP NAME="IBuffer-1.gif"> <AREA SHAPE="RECT" COORDS="303,12,403,72" HREF="IBufferHandler.html"> <AREA SHAPE="RECT"
- * COORDS="533,199,619,249" HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html"> <AREA SHAPE="RECT"
- * COORDS="283,126,422,322" HREF="IBuffer.html"> <AREA SHAPE="RECT" COORDS="9,180,155,268" HREF="IBufferProvider.html">
- * <AREA SHAPE="RECT" COORDS="33,321,132,399" HREF="IBufferPool.html"></MAP>
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
- * <p>
- * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
- * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
- * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
- * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
- * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
- * <p>
- * An example for <b>putting</b> values into a buffer and writing it to a {@link SocketChannel}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Obtain a fresh buffer
- * Buffer buffer = bufferProvider.getBuffer(); // Start filling the buffer for channelID 4711 ByteBuffer byteBuffer =
- * buffer.startPutting(4711); byteBuffer.putDouble(15.47); // Write the contents of the Buffer to a // SocketChannel
- * without blocking while (!buffer.write(socketChannel)) { // Do something else }
- * </pre>
- *
- * An example for reading a buffer from a {@link SocketChannel} and <b>getting</b> values from it:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Obtain a fresh buffer
- * Buffer buffer = bufferProvider.getBuffer();
- *
- * // Read the contents of the Buffer from a SocketChannel without blocking
- * ByteBuffer byteBuffer;
- * while ((byteBuffer = buffer.startGetting(socketChannel)) == null)
- * {
- * // Do something else
- * }
- *
- * // Access the contents of the buffer and release it to its provider
- * double value = byteBuffer.getDouble();
- * buffer.release();
- * </pre>
- *
- * @see IBufferProvider
- * @see IChannel#sendBuffer(IBuffer)
- * @see IChannel#setReceiveHandler(IBufferHandler)
- * @see IBufferHandler#handleBuffer(IBuffer)
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IBuffer
-{
- /**
- * Possible argument value of {@link #startPutting(short)} and possible return value of {@link #getChannelID()} that
- * indicates that this buffer is not intended to be passed to a {@link SocketChannel}.
- */
- public static final short NO_CHANNEL = Short.MIN_VALUE;
-
- /**
- * @since 2.0
- */
- public static final short MIN_CHANNEL = 1;
-
- /**
- * @since 2.0
- */
- public static final short MAX_CHANNEL = Short.MAX_VALUE;
-
- public static final short HEADER_SIZE = 4;
-
- /**
- * Returns the {@link IBufferProvider} that has provided this buffer and that this buffer will be returned to when its
- * {@link #release()} method is called.
- */
- public IBufferProvider getBufferProvider();
-
- /**
- * Returns the channel index value stored in the header of this buffer.
- *
- * @since 2.0
- */
- public short getChannelID();
-
- /**
- * Returns the capacity of this buffer.
- * <p>
- * The capacity of this buffer is equal to the {@link IBufferProvider#getBufferCapacity() capacity} of the
- * {@link IBufferProvider} that has provided this buffer.
- */
- public short getCapacity();
-
- /**
- * Returns the internal state of this buffer.
- */
- public BufferState getState();
-
- /**
- * Tries to read a {@link ByteBuffer} from a {@link SocketChannel} that can be used for getting data.
- * <p>
- * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to read a
- * complete header from the <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
- * {@link BufferState#READING_HEADER READING_HEADER}. If it was not possible to read a complete body from the
- * <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
- * {@link BufferState#READING_BODY READING_BODY}.
- * <p>
- * If a <code>ByteBuffer</code> is returned it <b>may only</b> be used for getting data. It is left to the
- * responsibility of the caller that only the following methods of that <code>ByteBuffer</code> are used:
- * <ul>
- * <li> {@link ByteBuffer#get()}
- * <li> {@link ByteBuffer#get(byte[])}
- * <li> {@link ByteBuffer#get(int)}
- * <li> {@link ByteBuffer#get(byte[], int, int)}
- * <li> {@link ByteBuffer#getChar()}
- * <li> {@link ByteBuffer#getChar(int)}
- * <li> {@link ByteBuffer#getDouble()}
- * <li> {@link ByteBuffer#getDouble(int)}
- * <li> {@link ByteBuffer#getFloat()}
- * <li> {@link ByteBuffer#getFloat(int)}
- * <li> {@link ByteBuffer#getInt()}
- * <li> {@link ByteBuffer#getInt(int)}
- * <li> {@link ByteBuffer#getLong()}
- * <li> {@link ByteBuffer#getLong(int)}
- * <li> {@link ByteBuffer#getShort()}
- * <li> {@link ByteBuffer#getShort(int)}
- * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
- * {@link ByteBuffer#capacity()}
- * </ul>
- *
- * @param socketChannel
- * The <code>socketChannel</code> to read the {@link ByteBuffer} from.
- * @return A {@link ByteBuffer} that can be used for getting data if it was possible to completely read the data from
- * the given <code>SocketChannel</code>, <code>null</code> otherwise.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#INITIAL INITIAL},
- * {@link BufferState#READING_HEADER READING_HEADER} or {@link BufferState#READING_BODY READING_BODY}.
- * @throws IOException
- * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
- */
- public ByteBuffer startGetting(SocketChannel socketChannel) throws IllegalStateException, IOException;
-
- /**
- * Returns a {@link ByteBuffer} that can be used for putting data.
- * <p>
- * Turns the {@link #getState() state} of this buffer into {@link BufferState#PUTTING PUTTING}.
- * <p>
- * The returned <code>ByteBuffer</code> <b>may only</b> be used for putting data. It is left to the responsibility of
- * the caller that only the following methods of that <code>ByteBuffer</code> are used:
- * <ul>
- * <li> {@link ByteBuffer#put(byte)}
- * <li> {@link ByteBuffer#put(byte[])}
- * <li> {@link ByteBuffer#put(ByteBuffer)}
- * <li> {@link ByteBuffer#put(int, byte)}
- * <li> {@link ByteBuffer#put(byte[], int, int)}
- * <li> {@link ByteBuffer#putChar(char)}
- * <li> {@link ByteBuffer#putChar(int, char)}
- * <li> {@link ByteBuffer#putDouble(double)}
- * <li> {@link ByteBuffer#putDouble(int, double)}
- * <li> {@link ByteBuffer#putFloat(float)}
- * <li> {@link ByteBuffer#putFloat(int, float)}
- * <li> {@link ByteBuffer#putInt(int)}
- * <li> {@link ByteBuffer#putInt(int, int)}
- * <li> {@link ByteBuffer#putLong(long)}
- * <li> {@link ByteBuffer#putLong(int, long)}
- * <li> {@link ByteBuffer#putShort(short)}
- * <li> {@link ByteBuffer#putShort(int, short)}
- * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
- * {@link ByteBuffer#capacity()}
- * </ul>
- *
- * @param channelID
- * The index of an {@link IChannel} that this buffer is intended to be passed to later or {@link #NO_CHANNEL}
- * .
- * @return A {@link ByteBuffer} that can be used for putting data.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#INITIAL INITIAL} ({@link BufferState#PUTTING
- * PUTTING} is allowed but meaningless if and only if the given <code>channelID</code> is equal to the
- * existing <code>channelID</code> of this buffer).
- */
- public ByteBuffer startPutting(short channelID) throws IllegalStateException;
-
- /**
- * Tries to write the data of this buffer to a {@link SocketChannel}.
- * <p>
- * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to completely
- * write the data to the <code>SocketChannel</code> <code>false</code> is returned and the state of this buffer
- * remains {@link BufferState#WRITING WRITING}.
- *
- * @param socketChannel
- * The <code>socketChannel</code> to write the data to.
- * @return <code>true</code> if it was possible to completely write the data to the <code>SocketChannel</code>,
- * <code>false</code> otherwise.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#WRITING
- * WRITING}.
- * @throws IOException
- * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
- */
- public boolean write(SocketChannel socketChannel) throws IllegalStateException, IOException;
-
- /**
- * Turns the state of this buffer from {@link BufferState#PUTTING PUTTING} into {@link BufferState#GETTING GETTING}.
- *
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING}.
- */
- public void flip() throws IllegalStateException;
-
- /**
- * Returns the <code>ByteBuffer</code> that can be used for putting or getting data.
- *
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#GETTING
- * GETTING}.
- */
- public ByteBuffer getByteBuffer() throws IllegalStateException;
-
- /**
- * Returns the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
- */
- public boolean isEOS();
-
- /**
- * Sets the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
- */
- public void setEOS(boolean eos);
-
- /**
- * Releases this buffer to its original {@link IBufferProvider}.
- */
- public void release();
-
- /**
- * Turns the state of this buffer from any state into {@link BufferState#INITIAL INITIAL}.
- */
- public void clear();
-
- public String formatContent(boolean showHeader);
-
- /**
- * @since 2.0
- */
- public IErrorHandler getErrorHandler();
-
- /**
- * @since 2.0
- */
- public void setErrorHandler(IErrorHandler errorHandler);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.util.IErrorHandler; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; + +/** + * Basic <b>unit of transport</b> in Net4j. + * <p> + * A buffer is well prepared for the usage with asynchronous {@link IChannel}s but can also be used with pure + * {@link SocketChannel}s. All methods of <code>IBuffer</code> are non-blocking. + * <p> + * Usually buffers are obtained from a {@link IBufferProvider}. Buffers can be accessed, passed around and finally + * {@link #release() released} to their original provider. The capacity of a buffer is determined by its provider. + * <p> + * In addition to its payload data each buffer contains an internal header of four bytes, two of them representing a + * channel identifier the other two of them denoting the length of the payload data. The payload data may be accessed + * through a {@link #getByteBuffer() ByteBuffer}. + * <p> + * This interface is <b>not</b> intended to be implemented by clients. + * <p> + * <dt><b>Class Diagram:</b></dt> + * <dd><img src="doc-files/IBuffer-1.gif" title="Diagram Buffers" border="0" usemap="#IBuffer-1.gif"/></dd> + * <p> + * <MAP NAME="IBuffer-1.gif"> <AREA SHAPE="RECT" COORDS="303,12,403,72" HREF="IBufferHandler.html"> <AREA SHAPE="RECT" + * COORDS="533,199,619,249" HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html"> <AREA SHAPE="RECT" + * COORDS="283,126,422,322" HREF="IBuffer.html"> <AREA SHAPE="RECT" COORDS="9,180,155,268" HREF="IBufferProvider.html"> + * <AREA SHAPE="RECT" COORDS="33,321,132,399" HREF="IBufferPool.html"></MAP> + * <p> + * <dt><b>State Machine Diagram:</b></dt> + * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd> + * <p> + * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA + * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295" + * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER"> + * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT" + * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP> + * <p> + * An example for <b>putting</b> values into a buffer and writing it to a {@link SocketChannel}: + * <p> + * + * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;"> + * // Obtain a fresh buffer + * Buffer buffer = bufferProvider.getBuffer(); // Start filling the buffer for channelID 4711 ByteBuffer byteBuffer = + * buffer.startPutting(4711); byteBuffer.putDouble(15.47); // Write the contents of the Buffer to a // SocketChannel + * without blocking while (!buffer.write(socketChannel)) { // Do something else } + * </pre> + * + * An example for reading a buffer from a {@link SocketChannel} and <b>getting</b> values from it: + * <p> + * + * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;"> + * // Obtain a fresh buffer + * Buffer buffer = bufferProvider.getBuffer(); + * + * // Read the contents of the Buffer from a SocketChannel without blocking + * ByteBuffer byteBuffer; + * while ((byteBuffer = buffer.startGetting(socketChannel)) == null) + * { + * // Do something else + * } + * + * // Access the contents of the buffer and release it to its provider + * double value = byteBuffer.getDouble(); + * buffer.release(); + * </pre> + * + * @see IBufferProvider + * @see IChannel#sendBuffer(IBuffer) + * @see IChannel#setReceiveHandler(IBufferHandler) + * @see IBufferHandler#handleBuffer(IBuffer) + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IBuffer +{ + /** + * Possible argument value of {@link #startPutting(short)} and possible return value of {@link #getChannelID()} that + * indicates that this buffer is not intended to be passed to a {@link SocketChannel}. + */ + public static final short NO_CHANNEL = Short.MIN_VALUE; + + /** + * @since 2.0 + */ + public static final short MIN_CHANNEL = 1; + + /** + * @since 2.0 + */ + public static final short MAX_CHANNEL = Short.MAX_VALUE; + + public static final short HEADER_SIZE = 4; + + /** + * Returns the {@link IBufferProvider} that has provided this buffer and that this buffer will be returned to when its + * {@link #release()} method is called. + */ + public IBufferProvider getBufferProvider(); + + /** + * Returns the channel index value stored in the header of this buffer. + * + * @since 2.0 + */ + public short getChannelID(); + + /** + * Returns the capacity of this buffer. + * <p> + * The capacity of this buffer is equal to the {@link IBufferProvider#getBufferCapacity() capacity} of the + * {@link IBufferProvider} that has provided this buffer. + */ + public short getCapacity(); + + /** + * Returns the internal state of this buffer. + */ + public BufferState getState(); + + /** + * Tries to read a {@link ByteBuffer} from a {@link SocketChannel} that can be used for getting data. + * <p> + * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to read a + * complete header from the <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is + * {@link BufferState#READING_HEADER READING_HEADER}. If it was not possible to read a complete body from the + * <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is + * {@link BufferState#READING_BODY READING_BODY}. + * <p> + * If a <code>ByteBuffer</code> is returned it <b>may only</b> be used for getting data. It is left to the + * responsibility of the caller that only the following methods of that <code>ByteBuffer</code> are used: + * <ul> + * <li> {@link ByteBuffer#get()} + * <li> {@link ByteBuffer#get(byte[])} + * <li> {@link ByteBuffer#get(int)} + * <li> {@link ByteBuffer#get(byte[], int, int)} + * <li> {@link ByteBuffer#getChar()} + * <li> {@link ByteBuffer#getChar(int)} + * <li> {@link ByteBuffer#getDouble()} + * <li> {@link ByteBuffer#getDouble(int)} + * <li> {@link ByteBuffer#getFloat()} + * <li> {@link ByteBuffer#getFloat(int)} + * <li> {@link ByteBuffer#getInt()} + * <li> {@link ByteBuffer#getInt(int)} + * <li> {@link ByteBuffer#getLong()} + * <li> {@link ByteBuffer#getLong(int)} + * <li> {@link ByteBuffer#getShort()} + * <li> {@link ByteBuffer#getShort(int)} + * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and + * {@link ByteBuffer#capacity()} + * </ul> + * + * @param socketChannel + * The <code>socketChannel</code> to read the {@link ByteBuffer} from. + * @return A {@link ByteBuffer} that can be used for getting data if it was possible to completely read the data from + * the given <code>SocketChannel</code>, <code>null</code> otherwise. + * @throws IllegalStateException + * If the state of this buffer is not {@link BufferState#INITIAL INITIAL}, + * {@link BufferState#READING_HEADER READING_HEADER} or {@link BufferState#READING_BODY READING_BODY}. + * @throws IOException + * If the <code>SocketChannel</code> has been closed or discovers other I/O problems. + */ + public ByteBuffer startGetting(SocketChannel socketChannel) throws IllegalStateException, IOException; + + /** + * Returns a {@link ByteBuffer} that can be used for putting data. + * <p> + * Turns the {@link #getState() state} of this buffer into {@link BufferState#PUTTING PUTTING}. + * <p> + * The returned <code>ByteBuffer</code> <b>may only</b> be used for putting data. It is left to the responsibility of + * the caller that only the following methods of that <code>ByteBuffer</code> are used: + * <ul> + * <li> {@link ByteBuffer#put(byte)} + * <li> {@link ByteBuffer#put(byte[])} + * <li> {@link ByteBuffer#put(ByteBuffer)} + * <li> {@link ByteBuffer#put(int, byte)} + * <li> {@link ByteBuffer#put(byte[], int, int)} + * <li> {@link ByteBuffer#putChar(char)} + * <li> {@link ByteBuffer#putChar(int, char)} + * <li> {@link ByteBuffer#putDouble(double)} + * <li> {@link ByteBuffer#putDouble(int, double)} + * <li> {@link ByteBuffer#putFloat(float)} + * <li> {@link ByteBuffer#putFloat(int, float)} + * <li> {@link ByteBuffer#putInt(int)} + * <li> {@link ByteBuffer#putInt(int, int)} + * <li> {@link ByteBuffer#putLong(long)} + * <li> {@link ByteBuffer#putLong(int, long)} + * <li> {@link ByteBuffer#putShort(short)} + * <li> {@link ByteBuffer#putShort(int, short)} + * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and + * {@link ByteBuffer#capacity()} + * </ul> + * + * @param channelID + * The index of an {@link IChannel} that this buffer is intended to be passed to later or {@link #NO_CHANNEL} + * . + * @return A {@link ByteBuffer} that can be used for putting data. + * @throws IllegalStateException + * If the state of this buffer is not {@link BufferState#INITIAL INITIAL} ({@link BufferState#PUTTING + * PUTTING} is allowed but meaningless if and only if the given <code>channelID</code> is equal to the + * existing <code>channelID</code> of this buffer). + */ + public ByteBuffer startPutting(short channelID) throws IllegalStateException; + + /** + * Tries to write the data of this buffer to a {@link SocketChannel}. + * <p> + * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to completely + * write the data to the <code>SocketChannel</code> <code>false</code> is returned and the state of this buffer + * remains {@link BufferState#WRITING WRITING}. + * + * @param socketChannel + * The <code>socketChannel</code> to write the data to. + * @return <code>true</code> if it was possible to completely write the data to the <code>SocketChannel</code>, + * <code>false</code> otherwise. + * @throws IllegalStateException + * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#WRITING + * WRITING}. + * @throws IOException + * If the <code>SocketChannel</code> has been closed or discovers other I/O problems. + */ + public boolean write(SocketChannel socketChannel) throws IllegalStateException, IOException; + + /** + * Turns the state of this buffer from {@link BufferState#PUTTING PUTTING} into {@link BufferState#GETTING GETTING}. + * + * @throws IllegalStateException + * If the state of this buffer is not {@link BufferState#PUTTING PUTTING}. + */ + public void flip() throws IllegalStateException; + + /** + * Returns the <code>ByteBuffer</code> that can be used for putting or getting data. + * + * @throws IllegalStateException + * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#GETTING + * GETTING}. + */ + public ByteBuffer getByteBuffer() throws IllegalStateException; + + /** + * Returns the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers. + */ + public boolean isEOS(); + + /** + * Sets the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers. + */ + public void setEOS(boolean eos); + + /** + * Releases this buffer to its original {@link IBufferProvider}. + */ + public void release(); + + /** + * Turns the state of this buffer from any state into {@link BufferState#INITIAL INITIAL}. + */ + public void clear(); + + public String formatContent(boolean showHeader); + + /** + * @since 2.0 + */ + public IErrorHandler getErrorHandler(); + + /** + * @since 2.0 + */ + public void setErrorHandler(IErrorHandler errorHandler); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java index 500d24ae70..02bf0c9923 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java @@ -1,29 +1,29 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-/**
- * Provides clients with the ability to pass {@link IBuffer}s in for further buffer handling.
- *
- * @author Eike Stepper
- */
-public interface IBufferHandler
-{
- /**
- * Handles an {@link IBuffer} and optionally releases it. The implementor of this method takes over the ownership of
- * the buffer. Care must be taken to properly {@link IBuffer#release() release} the buffer if the ownership is not
- * explicitely passed to some further party.
- *
- * @param buffer
- * The buffer to be handled and otionally released.
- */
- public void handleBuffer(IBuffer buffer);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +/** + * Provides clients with the ability to pass {@link IBuffer}s in for further buffer handling. + * + * @author Eike Stepper + */ +public interface IBufferHandler +{ + /** + * Handles an {@link IBuffer} and optionally releases it. The implementor of this method takes over the ownership of + * the buffer. Care must be taken to properly {@link IBuffer#release() release} the buffer if the ownership is not + * explicitely passed to some further party. + * + * @param buffer + * The buffer to be handled and otionally released. + */ + public void handleBuffer(IBuffer buffer); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java index beaca3144b..7c71bee06d 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java @@ -1,47 +1,47 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-/**
- * Provides clients with the ability to obtain and retain pooled {@link IBuffer}s.
- *
- * @author Eike Stepper
- */
-public interface IBufferPool extends IBufferProvider
-{
- /**
- * Tries to remove a single buffer from this <code>BufferPool</code> and {@link IBuffer#release() release} it.
- *
- * @return <code>true</code> if a buffer could be evicted, <code>false</code> otherwise.
- */
- public boolean evictOne();
-
- /**
- * Tries to remove as many buffers from this <code>BufferPool</code> and {@link IBuffer#release() release} them as are
- * needed to let a given maximum number of buffers survive in the pool.
- *
- * @return The number of buffers that could be evicted.
- */
- public int evict(int survivors);
-
- /**
- * Offers additional introspection features for {@link IBufferPool}s.
- *
- * @author Eike Stepper
- */
- public interface Introspection extends IBufferPool, IBufferProvider.Introspection
- {
- /**
- * Returns the number of buffers that are currently pooled in this <code>BufferPool</code>.
- */
- public int getPooledBuffers();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +/** + * Provides clients with the ability to obtain and retain pooled {@link IBuffer}s. + * + * @author Eike Stepper + */ +public interface IBufferPool extends IBufferProvider +{ + /** + * Tries to remove a single buffer from this <code>BufferPool</code> and {@link IBuffer#release() release} it. + * + * @return <code>true</code> if a buffer could be evicted, <code>false</code> otherwise. + */ + public boolean evictOne(); + + /** + * Tries to remove as many buffers from this <code>BufferPool</code> and {@link IBuffer#release() release} them as are + * needed to let a given maximum number of buffers survive in the pool. + * + * @return The number of buffers that could be evicted. + */ + public int evict(int survivors); + + /** + * Offers additional introspection features for {@link IBufferPool}s. + * + * @author Eike Stepper + */ + public interface Introspection extends IBufferPool, IBufferProvider.Introspection + { + /** + * Returns the number of buffers that are currently pooled in this <code>BufferPool</code>. + */ + public int getPooledBuffers(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java index 3f3eed8bdb..045ee75a94 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java @@ -1,52 +1,52 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.buffer;
-
-/**
- * Provides clients with the ability to obtain and retain {@link IBuffer}s.
- *
- * @author Eike Stepper
- */
-public interface IBufferProvider
-{
- /**
- * Returns the capacity of the buffers provided by {@link #provideBuffer()} .
- */
- public short getBufferCapacity();
-
- /**
- * Provides a buffer from this <code>BufferProvider</code>.
- */
- public IBuffer provideBuffer();
-
- /**
- * Retains a buffer to this <code>BufferProvider</code>.
- */
- public void retainBuffer(IBuffer buffer);
-
- /**
- * Offers additional introspection features for {@link IBufferProvider}s.
- *
- * @author Eike Stepper
- */
- public interface Introspection extends IBufferProvider
- {
- /**
- * Returns the number of buffers that have already been provided by this <code>BufferProvider</code>.
- */
- public long getProvidedBuffers();
-
- /**
- * Returns the number of buffers that have already been retained to this <code>BufferProvider</code>.
- */
- public long getRetainedBuffers();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.buffer; + +/** + * Provides clients with the ability to obtain and retain {@link IBuffer}s. + * + * @author Eike Stepper + */ +public interface IBufferProvider +{ + /** + * Returns the capacity of the buffers provided by {@link #provideBuffer()} . + */ + public short getBufferCapacity(); + + /** + * Provides a buffer from this <code>BufferProvider</code>. + */ + public IBuffer provideBuffer(); + + /** + * Retains a buffer to this <code>BufferProvider</code>. + */ + public void retainBuffer(IBuffer buffer); + + /** + * Offers additional introspection features for {@link IBufferProvider}s. + * + * @author Eike Stepper + */ + public interface Introspection extends IBufferProvider + { + /** + * Returns the number of buffers that have already been provided by this <code>BufferProvider</code>. + */ + public long getProvidedBuffers(); + + /** + * Returns the number of buffers that have already been retained to this <code>BufferProvider</code>. + */ + public long getRetainedBuffers(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java index df43fed9e8..41cdc01d34 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.channel;
-
-/**
- * Thrown by an {@link IChannel} to indicate channel management problems.
- *
- * @see IChannelMultiplexer
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- */
-public class ChannelException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- public ChannelException()
- {
- }
-
- public ChannelException(String message)
- {
- super(message);
- }
-
- public ChannelException(Throwable cause)
- {
- super(cause);
- }
-
- public ChannelException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.channel; + +/** + * Thrown by an {@link IChannel} to indicate channel management problems. + * + * @see IChannelMultiplexer + * @author Eike Stepper + * @since 2.0 + * @noextend This interface is not intended to be extended by clients. + */ +public class ChannelException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public ChannelException() + { + } + + public ChannelException(String message) + { + super(message); + } + + public ChannelException(Throwable cause) + { + super(cause); + } + + public ChannelException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java index 6fff240199..3cf6af1573 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java @@ -1,77 +1,77 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.channel;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.IBuffer;
-
-import java.io.InputStream;
-
-/**
- * An {@link InputStream input stream} that provides the {@link IBuffer buffers} which arrive at a {@link IChannel
- * channel} as a continuous byte sequence.
- *
- * @author Eike Stepper
- */
-public class ChannelInputStream extends BufferInputStream
-{
- private IChannel channel;
-
- private long millisBeforeTimeout = DEFAULT_MILLIS_BEFORE_TIMEOUT;
-
- private long millisInterruptCheck = DEFAULT_MILLIS_INTERRUPT_CHECK;
-
- public ChannelInputStream(IChannel channel)
- {
- this(channel, DEFAULT_MILLIS_BEFORE_TIMEOUT);
- }
-
- public ChannelInputStream(IChannel channel, long millisBeforeTimeout)
- {
- this.channel = channel;
- this.millisBeforeTimeout = millisBeforeTimeout;
-
- channel.setReceiveHandler(this);
- }
-
- public IChannel getChannel()
- {
- return channel;
- }
-
- @Override
- public long getMillisBeforeTimeout()
- {
- return millisBeforeTimeout;
- }
-
- public void setMillisBeforeTimeout(long millisBeforeTimeout)
- {
- this.millisBeforeTimeout = millisBeforeTimeout;
- }
-
- @Override
- public long getMillisInterruptCheck()
- {
- return millisInterruptCheck;
- }
-
- public void setMillisInterruptCheck(long millisInterruptCheck)
- {
- this.millisInterruptCheck = millisInterruptCheck;
- }
-
- @Override
- public String toString()
- {
- return "ChannelInputStream[" + channel + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.channel; + +import org.eclipse.net4j.buffer.BufferInputStream; +import org.eclipse.net4j.buffer.IBuffer; + +import java.io.InputStream; + +/** + * An {@link InputStream input stream} that provides the {@link IBuffer buffers} which arrive at a {@link IChannel + * channel} as a continuous byte sequence. + * + * @author Eike Stepper + */ +public class ChannelInputStream extends BufferInputStream +{ + private IChannel channel; + + private long millisBeforeTimeout = DEFAULT_MILLIS_BEFORE_TIMEOUT; + + private long millisInterruptCheck = DEFAULT_MILLIS_INTERRUPT_CHECK; + + public ChannelInputStream(IChannel channel) + { + this(channel, DEFAULT_MILLIS_BEFORE_TIMEOUT); + } + + public ChannelInputStream(IChannel channel, long millisBeforeTimeout) + { + this.channel = channel; + this.millisBeforeTimeout = millisBeforeTimeout; + + channel.setReceiveHandler(this); + } + + public IChannel getChannel() + { + return channel; + } + + @Override + public long getMillisBeforeTimeout() + { + return millisBeforeTimeout; + } + + public void setMillisBeforeTimeout(long millisBeforeTimeout) + { + this.millisBeforeTimeout = millisBeforeTimeout; + } + + @Override + public long getMillisInterruptCheck() + { + return millisInterruptCheck; + } + + public void setMillisInterruptCheck(long millisInterruptCheck) + { + this.millisInterruptCheck = millisInterruptCheck; + } + + @Override + public String toString() + { + return "ChannelInputStream[" + channel + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java index 0ca4b3dd4f..124aa87c87 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java @@ -1,36 +1,36 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.channel;
-
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-
-import java.io.OutputStream;
-
-/**
- * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
- * buffers} and passes them to configured {@link IChannel channel}.
- *
- * @author Eike Stepper
- */
-public class ChannelOutputStream extends BufferOutputStream
-{
- public ChannelOutputStream(IChannel channel)
- {
- super(channel, channel.getID());
- }
-
- public ChannelOutputStream(IChannel channel, IBufferProvider bufferProvider)
- {
- super(channel, bufferProvider, channel == null ? IBuffer.NO_CHANNEL : channel.getID());
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.channel; + +import org.eclipse.net4j.buffer.BufferOutputStream; +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.buffer.IBufferProvider; + +import java.io.OutputStream; + +/** + * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer + * buffers} and passes them to configured {@link IChannel channel}. + * + * @author Eike Stepper + */ +public class ChannelOutputStream extends BufferOutputStream +{ + public ChannelOutputStream(IChannel channel) + { + super(channel, channel.getID()); + } + + public ChannelOutputStream(IChannel channel, IBufferProvider bufferProvider) + { + super(channel, bufferProvider, channel == null ? IBuffer.NO_CHANNEL : channel.getID()); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java index cd34aee1d9..4fc54ae25a 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java @@ -1,114 +1,114 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.channel;
-
-import org.eclipse.net4j.ILocationAware;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.event.INotifier;
-import org.eclipse.net4j.util.security.IUserAware;
-
-/**
- * A bidirectional communications channel for the asynchronous exchange of {@link IBuffer buffers}. A channel is
- * lightweight and virtual in the sense that it does not necessarily represent a single physical connection like a TCP
- * socket connection. The underlying physical connection is represented by a {@link IChannelMultiplexer channel
- * multiplexer}.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IChannel-1.gif" title="Diagram Buffers" border="0" usemap="#IChannel-1.gif"/></dd>
- * <p>
- * <MAP NAME="IChannel-1.gif"> <AREA SHAPE="RECT" COORDS="301,8,451,68" HREF="IChannelID.html"> <AREA SHAPE="RECT"
- * COORDS="301,141,451,211" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="599,151,696,201"
- * HREF="../buffer/IBufferHandler.html"> <AREA SHAPE="RECT" COORDS="7,151,96,201" HREF="../connector/IConnector.html">
- * </MAP>
- * <p>
- * An example for opening a channel on an {@link IConnector} and sending an {@link IBuffer}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Open a channel
- * IChannel channel = connector.openChannel();
- * short channelID = channel.getIndex();
- *
- * // Fill a buffer
- * Buffer buffer = bufferProvider.getBuffer();
- * ByteBuffer byteBuffer = buffer.startPutting(channelID);
- * byteBuffer.putDouble(15.47);
- *
- * // Let the channel send the buffer without blocking
- * channel.sendBuffer(buffer);
- * </pre>
- * <p>
- * An example for receiving {@link IBuffer}s from channels on an {@link IConnector}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Create a receive handler
- * final IBufferHandler receiveHandler = new IBufferHandler()
- * {
- * public void handleBuffer(IBuffer buffer)
- * {
- * ByteBuffer byteBuffer = buffer.getByteBuffer();
- * IOUtil.OUT().println("Received " + byteBuffer.getDouble());
- * buffer.release();
- * }
- * };
- *
- * // Set the receive handler to all new channels
- * connector.addListener(new ContainerEventAdapter()
- * {
- * protected void onAdded(IContainer container, Object element)
- * {
- * IChannel channel = (IChannel)element;
- * channel.setReceiveHandler(receiveHandler);
- * }
- * });
- * </pre>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This interface is not intended to be extended by clients.
- */
-public interface IChannel extends ILocationAware, IUserAware, IBufferHandler, INotifier, Closeable
-{
- /**
- * Returns the ID of this channel. The ID is unique at any time among all channels of the associated
- * {@link IChannelMultiplexer multiplexer}.
- *
- * @since 2.0
- */
- public short getID();
-
- /**
- * Returns the multiplexer this channel is associated with. This channel multiplexer can be used, for example, to open
- * additional channels that will be multiplexed through the same transport medium.
- *
- * @since 2.0
- */
- public IChannelMultiplexer getMultiplexer();
-
- /**
- * Asynchronously sends the given buffer to the receive handler of the peer channel.
- */
- public void sendBuffer(IBuffer buffer);
-
- /**
- * Returns the <code>IBufferHandler</code> that handles buffers received from the peer channel.
- */
- public IBufferHandler getReceiveHandler();
-
- /**
- * Sets the <code>IBufferHandler</code> to handle buffers received from the peer channel.
- */
- public void setReceiveHandler(IBufferHandler receiveHandler);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.channel; + +import org.eclipse.net4j.ILocationAware; +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.buffer.IBufferHandler; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.collection.Closeable; +import org.eclipse.net4j.util.event.INotifier; +import org.eclipse.net4j.util.security.IUserAware; + +/** + * A bidirectional communications channel for the asynchronous exchange of {@link IBuffer buffers}. A channel is + * lightweight and virtual in the sense that it does not necessarily represent a single physical connection like a TCP + * socket connection. The underlying physical connection is represented by a {@link IChannelMultiplexer channel + * multiplexer}. + * <p> + * <dt><b>Class Diagram:</b></dt> + * <dd><img src="doc-files/IChannel-1.gif" title="Diagram Buffers" border="0" usemap="#IChannel-1.gif"/></dd> + * <p> + * <MAP NAME="IChannel-1.gif"> <AREA SHAPE="RECT" COORDS="301,8,451,68" HREF="IChannelID.html"> <AREA SHAPE="RECT" + * COORDS="301,141,451,211" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="599,151,696,201" + * HREF="../buffer/IBufferHandler.html"> <AREA SHAPE="RECT" COORDS="7,151,96,201" HREF="../connector/IConnector.html"> + * </MAP> + * <p> + * An example for opening a channel on an {@link IConnector} and sending an {@link IBuffer}: + * <p> + * + * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;"> + * // Open a channel + * IChannel channel = connector.openChannel(); + * short channelID = channel.getIndex(); + * + * // Fill a buffer + * Buffer buffer = bufferProvider.getBuffer(); + * ByteBuffer byteBuffer = buffer.startPutting(channelID); + * byteBuffer.putDouble(15.47); + * + * // Let the channel send the buffer without blocking + * channel.sendBuffer(buffer); + * </pre> + * <p> + * An example for receiving {@link IBuffer}s from channels on an {@link IConnector}: + * <p> + * + * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;"> + * // Create a receive handler + * final IBufferHandler receiveHandler = new IBufferHandler() + * { + * public void handleBuffer(IBuffer buffer) + * { + * ByteBuffer byteBuffer = buffer.getByteBuffer(); + * IOUtil.OUT().println("Received " + byteBuffer.getDouble()); + * buffer.release(); + * } + * }; + * + * // Set the receive handler to all new channels + * connector.addListener(new ContainerEventAdapter() + * { + * protected void onAdded(IContainer container, Object element) + * { + * IChannel channel = (IChannel)element; + * channel.setReceiveHandler(receiveHandler); + * } + * }); + * </pre> + * + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + */ +public interface IChannel extends ILocationAware, IUserAware, IBufferHandler, INotifier, Closeable +{ + /** + * Returns the ID of this channel. The ID is unique at any time among all channels of the associated + * {@link IChannelMultiplexer multiplexer}. + * + * @since 2.0 + */ + public short getID(); + + /** + * Returns the multiplexer this channel is associated with. This channel multiplexer can be used, for example, to open + * additional channels that will be multiplexed through the same transport medium. + * + * @since 2.0 + */ + public IChannelMultiplexer getMultiplexer(); + + /** + * Asynchronously sends the given buffer to the receive handler of the peer channel. + */ + public void sendBuffer(IBuffer buffer); + + /** + * Returns the <code>IBufferHandler</code> that handles buffers received from the peer channel. + */ + public IBufferHandler getReceiveHandler(); + + /** + * Sets the <code>IBufferHandler</code> to handle buffers received from the peer channel. + */ + public void setReceiveHandler(IBufferHandler receiveHandler); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java index e0414a2565..d2b2c426d1 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java @@ -1,98 +1,98 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.channel;
-
-import org.eclipse.net4j.ILocationAware;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.Collection;
-
-/**
- * Manages and multiplexes virtual data {@link IChannel channels} over a shared physical connection.
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This interface is not intended to be extended by clients.
- */
-public interface IChannelMultiplexer extends ILocationAware, IContainer<IChannel>
-{
- /**
- * @since 2.0
- */
- public static final long NO_CHANNEL_TIMEOUT = Long.MAX_VALUE;
-
- /**
- * Indicates to use the timeout that is configured via debug property <code>open.channel.timeout</code> (see .options
- * file) which has a default of 10 seconds.
- *
- * @since 2.0
- */
- public static final long DEFAULT_OPEN_CHANNEL_TIMEOUT = -1;
-
- /**
- * Synchronous request to open a new {@link IChannel} with an undefined channel protocol. Since the peer connector
- * can't lookup a protocol {@link IFactory factory} without a protocol identifier the {@link IBufferHandler} of the
- * peer {@link IChannel} can only be provided by externally provided channel {@link ILifecycle lifecycle}
- * {@link IListener listeners}.
- * <p>
- *
- * @see #openChannel(String, Object)
- * @see #openChannel(IProtocol)
- * @since 2.0
- */
- public IChannel openChannel() throws ChannelException;
-
- /**
- * Synchronous request to open a new {@link IChannel} with a channel protocol defined by a given protocol identifier.
- * The peer connector will lookup a protocol {@link IFactory factory} with the protocol identifier, create a
- * {@link IBufferHandler} and inject it into the peer {@link IChannel}.
- * <p>
- *
- * @see #openChannel()
- * @see #openChannel(IProtocol)
- * @since 2.0
- */
- public IChannel openChannel(String protocolID, Object infraStructure) throws ChannelException;
-
- /**
- * Synchronous request to open a new {@link IChannel} with the given channel protocol . The peer connector will lookup
- * a protocol {@link IFactory factory} with the protocol identifier, create a {@link IBufferHandler} and inject it
- * into the peer channel.
- * <p>
- *
- * @see #openChannel()
- * @see #openChannel(String, Object)
- * @since 2.0
- */
- public IChannel openChannel(IProtocol<?> protocol) throws ChannelException;
-
- /**
- * Returns a collection of currently open channels.
- *
- * @since 2.0
- */
- public Collection<IChannel> getChannels();
-
- /**
- * @since 2.0
- */
- public long getOpenChannelTimeout();
-
- /**
- * @since 2.0
- */
- public void setOpenChannelTimeout(long openChannelTimeout);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.channel; + +import org.eclipse.net4j.ILocationAware; +import org.eclipse.net4j.buffer.IBufferHandler; +import org.eclipse.net4j.protocol.IProtocol; +import org.eclipse.net4j.util.container.IContainer; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.factory.IFactory; +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +import java.util.Collection; + +/** + * Manages and multiplexes virtual data {@link IChannel channels} over a shared physical connection. + * + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + * @noextend This interface is not intended to be extended by clients. + */ +public interface IChannelMultiplexer extends ILocationAware, IContainer<IChannel> +{ + /** + * @since 2.0 + */ + public static final long NO_CHANNEL_TIMEOUT = Long.MAX_VALUE; + + /** + * Indicates to use the timeout that is configured via debug property <code>open.channel.timeout</code> (see .options + * file) which has a default of 10 seconds. + * + * @since 2.0 + */ + public static final long DEFAULT_OPEN_CHANNEL_TIMEOUT = -1; + + /** + * Synchronous request to open a new {@link IChannel} with an undefined channel protocol. Since the peer connector + * can't lookup a protocol {@link IFactory factory} without a protocol identifier the {@link IBufferHandler} of the + * peer {@link IChannel} can only be provided by externally provided channel {@link ILifecycle lifecycle} + * {@link IListener listeners}. + * <p> + * + * @see #openChannel(String, Object) + * @see #openChannel(IProtocol) + * @since 2.0 + */ + public IChannel openChannel() throws ChannelException; + + /** + * Synchronous request to open a new {@link IChannel} with a channel protocol defined by a given protocol identifier. + * The peer connector will lookup a protocol {@link IFactory factory} with the protocol identifier, create a + * {@link IBufferHandler} and inject it into the peer {@link IChannel}. + * <p> + * + * @see #openChannel() + * @see #openChannel(IProtocol) + * @since 2.0 + */ + public IChannel openChannel(String protocolID, Object infraStructure) throws ChannelException; + + /** + * Synchronous request to open a new {@link IChannel} with the given channel protocol . The peer connector will lookup + * a protocol {@link IFactory factory} with the protocol identifier, create a {@link IBufferHandler} and inject it + * into the peer channel. + * <p> + * + * @see #openChannel() + * @see #openChannel(String, Object) + * @since 2.0 + */ + public IChannel openChannel(IProtocol<?> protocol) throws ChannelException; + + /** + * Returns a collection of currently open channels. + * + * @since 2.0 + */ + public Collection<IChannel> getChannels(); + + /** + * @since 2.0 + */ + public long getOpenChannelTimeout(); + + /** + * @since 2.0 + */ + public void setOpenChannelTimeout(long openChannelTimeout); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java index c12c78cee7..89ac240711 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java @@ -1,103 +1,103 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-import org.eclipse.net4j.util.security.INegotiatorAware;
-import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.ResponseNegotiator;
-import org.eclipse.net4j.util.security.ResponseNegotiatorInjector;
-import org.eclipse.net4j.util.security.SecurityUtil;
-
-/**
- * Injects a configurable response negotiator into selected client connectors.
- * <p>
- * An example:
- *
- * <pre>
- * IManagedContainer container = IPluginContainer.INSTANCE;
- *
- * String connectorDescription = "localhost:2036";
- * String userID = "name";
- * String password = "secret";
- *
- * IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(userID, password);
- *
- * container.addPostProcessor(new ConnectorCredentialsInjector(connectorDescription, credentialsProvider));
- * IConnector connector = (IConnector)container.getElement("org.eclipse.net4j.connectors", "tcp", connectorDescription);
- *
- * IChannel channel = connector.openChannel();
- * // ...
- * </pre>
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class ConnectorCredentialsInjector extends ResponseNegotiatorInjector
-{
- private String connectorDescription;
-
- /**
- * @param connectorDescription
- * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
- * bypass the description check.
- */
- public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider,
- String algorithmName)
- {
- super(createNegotiator(credentialsProvider, algorithmName));
- this.connectorDescription = connectorDescription;
- }
-
- /**
- * @param connectorDescription
- * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
- * bypass the description check.
- */
- public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider)
- {
- this(connectorDescription, credentialsProvider, SecurityUtil.PBE_WITH_MD5_AND_DES);
- }
-
- @Override
- protected boolean filterElement(String productGroup, String factoryType, String description,
- INegotiatorAware negotiatorAware)
- {
- if (negotiatorAware instanceof IConnector)
- {
- IConnector connector = (IConnector)negotiatorAware;
- if (connector.isClient())
- {
- return filterConnectorDescription(description);
- }
- }
-
- return false;
- }
-
- protected boolean filterConnectorDescription(String description)
- {
- if (connectorDescription == null)
- {
- return true;
- }
-
- return connectorDescription.equals(description);
- }
-
- private static ResponseNegotiator createNegotiator(IPasswordCredentialsProvider credentialsProvider,
- String algorithmName)
- {
- ResponseNegotiator negotiator = new ResponseNegotiator();
- negotiator.setCredentialsProvider(credentialsProvider);
- negotiator.setEncryptionAlgorithmName(algorithmName);
- return negotiator;
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +import org.eclipse.net4j.util.security.INegotiatorAware; +import org.eclipse.net4j.util.security.IPasswordCredentialsProvider; +import org.eclipse.net4j.util.security.ResponseNegotiator; +import org.eclipse.net4j.util.security.ResponseNegotiatorInjector; +import org.eclipse.net4j.util.security.SecurityUtil; + +/** + * Injects a configurable response negotiator into selected client connectors. + * <p> + * An example: + * + * <pre> + * IManagedContainer container = IPluginContainer.INSTANCE; + * + * String connectorDescription = "localhost:2036"; + * String userID = "name"; + * String password = "secret"; + * + * IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(userID, password); + * + * container.addPostProcessor(new ConnectorCredentialsInjector(connectorDescription, credentialsProvider)); + * IConnector connector = (IConnector)container.getElement("org.eclipse.net4j.connectors", "tcp", connectorDescription); + * + * IChannel channel = connector.openChannel(); + * // ... + * </pre> + * + * @author Eike Stepper + * @since 2.0 + */ +public class ConnectorCredentialsInjector extends ResponseNegotiatorInjector +{ + private String connectorDescription; + + /** + * @param connectorDescription + * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to + * bypass the description check. + */ + public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider, + String algorithmName) + { + super(createNegotiator(credentialsProvider, algorithmName)); + this.connectorDescription = connectorDescription; + } + + /** + * @param connectorDescription + * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to + * bypass the description check. + */ + public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider) + { + this(connectorDescription, credentialsProvider, SecurityUtil.PBE_WITH_MD5_AND_DES); + } + + @Override + protected boolean filterElement(String productGroup, String factoryType, String description, + INegotiatorAware negotiatorAware) + { + if (negotiatorAware instanceof IConnector) + { + IConnector connector = (IConnector)negotiatorAware; + if (connector.isClient()) + { + return filterConnectorDescription(description); + } + } + + return false; + } + + protected boolean filterConnectorDescription(String description) + { + if (connectorDescription == null) + { + return true; + } + + return connectorDescription.equals(description); + } + + private static ResponseNegotiator createNegotiator(IPasswordCredentialsProvider credentialsProvider, + String algorithmName) + { + ResponseNegotiator negotiator = new ResponseNegotiator(); + negotiator.setCredentialsProvider(credentialsProvider); + negotiator.setEncryptionAlgorithmName(algorithmName); + return negotiator; + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java index 042fb2bbf3..dfc92074e6 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java @@ -1,40 +1,40 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-/**
- * Thrown by an {@link IConnector} to indicate connection problems.
- *
- * @author Eike Stepper
- */
-public class ConnectorException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- public ConnectorException()
- {
- }
-
- public ConnectorException(String message)
- {
- super(message);
- }
-
- public ConnectorException(Throwable cause)
- {
- super(cause);
- }
-
- public ConnectorException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +/** + * Thrown by an {@link IConnector} to indicate connection problems. + * + * @author Eike Stepper + */ +public class ConnectorException extends RuntimeException +{ + private static final long serialVersionUID = 1L; + + public ConnectorException() + { + } + + public ConnectorException(String message) + { + super(message); + } + + public ConnectorException(Throwable cause) + { + super(cause); + } + + public ConnectorException(String message, Throwable cause) + { + super(message, cause); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java index 86231c1a5f..06de3d4904 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java @@ -1,92 +1,92 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-import org.eclipse.net4j.util.security.INegotiator;
-
-/**
- * Enumerates the lifecycle states of an {@link IConnector}.
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/ConnectorState-1.gif" title="Diagram Connector States" border="0"
- * usemap="#ConnectorState-1.gif"/></dd>
- * <p>
- * <MAP NAME="ConnectorState-1.gif"> <AREA SHAPE="RECT" COORDS="26,135,143,159" HREF="ConnectorState.html#DISCONNECTED">
- * <AREA SHAPE="RECT" COORDS="449,50,547,73" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
- * COORDS="449,133,549,159" HREF="ConnectorState.html#NEGOTIATING"> <AREA SHAPE="RECT" COORDS="451,216,545,240"
- * HREF="ConnectorState.html#CONNECTED"> <AREA SHAPE="POLYGON" COORDS="10,89,11,183,164,183,163,109,77,109,77,89,11,88"
- * HREF="../util/lifecycle/ILifecycle.html#isActive()"> <AREA SHAPE="POLYGON"
- * COORDS="429,10,428,262,597,263,597,30,483,29,483,10,428,11" HREF="../util/lifecycle/ILifecycle.html#isActive()">
- * </MAP>
- *
- * @see IConnector#getState()
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- */
-public enum ConnectorState
-{
- /**
- * Indicates that the {@link IConnector} has not been connected yet or has been disconnected after being connected
- * previously.
- * <p>
- * A connector is <code>DISCONNECTED</code> if and only if it is not
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to {@link #CONNECTING}
- * can be triggered by calling {@link IConnector#connect(long)} or {@link IConnector#connectAsync()}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- DISCONNECTED,
-
- /**
- * Indicates that the {@link IConnector} is currently trying to establish an underlying physical connection like a TCP
- * socket connection.
- * <p>
- * A connector can only be <code>CONNECTING</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. As soon as the underlying physical
- * connection is successfully established the state of the connector automatically transitions to {@link #NEGOTIATING}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- CONNECTING,
-
- /**
- * Indicates that the {@link IConnector} has successfully managed to establish the underlying physical connection and
- * has currently delegated control over this connection to an {@link INegotiator}.
- * <p>
- * A connector can only be <code>NEGOTIATING</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active} and a negotiator has been supplied.
- * As soon as the negotiator has successfully negotiated both peers (or a negotiator has not been supplied) the state
- * of the connector automatically transitions to {@link #CONNECTED}.
- * <p>
- * Negotiators can implement arbitrary handshake protocols, challenge-response sequences or other authentication
- * procedures. They can also be used to initially setup connection encryption if the connector implementation is not
- * able to do so.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- NEGOTIATING,
-
- /**
- * Indicates that the {@link IConnector} has successfully managed to establish and negotiate the underlying physical
- * connection and is ready now to perform actual communications.
- * <p>
- * A connector can only be <code>CONNECTED</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to
- * {@link #DISCONNECTED} can be triggered by calling {@link IConnector#close()}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- CONNECTED
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +import org.eclipse.net4j.util.security.INegotiator; + +/** + * Enumerates the lifecycle states of an {@link IConnector}. + * <p> + * <dt><b>State Machine Diagram:</b></dt> + * <dd><img src="doc-files/ConnectorState-1.gif" title="Diagram Connector States" border="0" + * usemap="#ConnectorState-1.gif"/></dd> + * <p> + * <MAP NAME="ConnectorState-1.gif"> <AREA SHAPE="RECT" COORDS="26,135,143,159" HREF="ConnectorState.html#DISCONNECTED"> + * <AREA SHAPE="RECT" COORDS="449,50,547,73" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT" + * COORDS="449,133,549,159" HREF="ConnectorState.html#NEGOTIATING"> <AREA SHAPE="RECT" COORDS="451,216,545,240" + * HREF="ConnectorState.html#CONNECTED"> <AREA SHAPE="POLYGON" COORDS="10,89,11,183,164,183,163,109,77,109,77,89,11,88" + * HREF="../util/lifecycle/ILifecycle.html#isActive()"> <AREA SHAPE="POLYGON" + * COORDS="429,10,428,262,597,263,597,30,483,29,483,10,428,11" HREF="../util/lifecycle/ILifecycle.html#isActive()"> + * </MAP> + * + * @see IConnector#getState() + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + */ +public enum ConnectorState +{ + /** + * Indicates that the {@link IConnector} has not been connected yet or has been disconnected after being connected + * previously. + * <p> + * A connector is <code>DISCONNECTED</code> if and only if it is not + * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to {@link #CONNECTING} + * can be triggered by calling {@link IConnector#connect(long)} or {@link IConnector#connectAsync()}. + * + * @see IConnector#getState() + * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive() + */ + DISCONNECTED, + + /** + * Indicates that the {@link IConnector} is currently trying to establish an underlying physical connection like a TCP + * socket connection. + * <p> + * A connector can only be <code>CONNECTING</code> if it is + * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. As soon as the underlying physical + * connection is successfully established the state of the connector automatically transitions to {@link #NEGOTIATING}. + * + * @see IConnector#getState() + * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive() + */ + CONNECTING, + + /** + * Indicates that the {@link IConnector} has successfully managed to establish the underlying physical connection and + * has currently delegated control over this connection to an {@link INegotiator}. + * <p> + * A connector can only be <code>NEGOTIATING</code> if it is + * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active} and a negotiator has been supplied. + * As soon as the negotiator has successfully negotiated both peers (or a negotiator has not been supplied) the state + * of the connector automatically transitions to {@link #CONNECTED}. + * <p> + * Negotiators can implement arbitrary handshake protocols, challenge-response sequences or other authentication + * procedures. They can also be used to initially setup connection encryption if the connector implementation is not + * able to do so. + * + * @see IConnector#getState() + * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive() + */ + NEGOTIATING, + + /** + * Indicates that the {@link IConnector} has successfully managed to establish and negotiate the underlying physical + * connection and is ready now to perform actual communications. + * <p> + * A connector can only be <code>CONNECTED</code> if it is + * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to + * {@link #DISCONNECTED} can be triggered by calling {@link IConnector#close()}. + * + * @see IConnector#getState() + * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive() + */ + CONNECTED +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java index 123aaa2c8b..cf06eb171d 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java @@ -1,108 +1,108 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.security.IUserAware;
-
-/**
- * One endpoint of a physical connection of arbitrary nature between two communicating parties. A {@link IConnector}
- * encapsulates the process of establishing and closing such connections and has a
- * {@link org.eclipse.net4j.ILocationAware.Location location} of
- * {@link org.eclipse.net4j.ILocationAware.Location#CLIENT CLIENT} or
- * {@link org.eclipse.net4j.ILocationAware.Location#SERVER SERVER} with respect to this process. Once a connection is
- * established either party can use its connector to open multiple {@link IChannel}s to asynchronously exchange
- * {@link IBuffer}s.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients. Providers of connectors for new physical
- * connection types have to implement org.eclipse.internal.net4j.connector.InternalConnector.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IConnector-1.gif" title="Diagram Connectors" border="0" usemap="IConnector-1.gif"/></dd>
- * <p>
- * <MAP NAME="IConnector-1.gif"> <AREA SHAPE="RECT" COORDS="259,15,400,75" HREF="IConnectorCredentials.html"> <AREA
- * SHAPE="RECT" COORDS="12,174,138,245" HREF="ConnectorLocation.html"> <AREA SHAPE="RECT" COORDS="258,139,401,281"
- * HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="518,156,642,263" HREF="ConnectorState.html"> <AREA SHAPE="RECT"
- * COORDS="280,360,380,410" HREF="IChannel.html"> </MAP>
- * <p>
- * <dt><b>Sequence Diagram: Communication Process</b></dt>
- * <dd><img src="doc-files/IConnector-2.gif" title="Communication Process" border="0" usemap="#IConnector-2.gif"/></dd>
- * <p>
- * <MAP NAME="IConnector-2.gif"> <AREA SHAPE="RECT" COORDS="128,94,247,123" HREF="IConnector.html"> <AREA SHAPE="RECT"
- * COORDS="648,95,767,123" HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="509,254,608,283" HREF="IChannel.html">
- * <AREA SHAPE="RECT" COORDS="287,355,387,383" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="818,195,897,222"
- * HREF="IProtocol.html"> </MAP>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnector extends IChannelMultiplexer, IUserAware, Closeable
-{
- /**
- * @since 2.0
- */
- public static final long NO_TIMEOUT = -1;
-
- public String getURL();
-
- /**
- * Returns the current state of this connector.
- */
- public ConnectorState getState();
-
- /**
- * Same as <code>{@link #getState()} == {@link ConnectorState#CONNECTED}</code>.
- */
- public boolean isConnected();
-
- /**
- * Synchronous connect with infinite timeout value. Same as {@link #connect() connect(NO_TIMEOUT)}.
- *
- * @throws ConnectorException
- * @since 4.0
- */
- public void connect() throws ConnectorException;
-
- /**
- * Synchronous connect. Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- *
- * @param timeout
- * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
- * connection occurs.
- * @throws ConnectorException
- * @since 4.0
- */
- public void connect(long timeout) throws ConnectorException;
-
- /**
- * Asynchronous connect. May leave this {@link IConnector} in a state where <code>{@link #isConnected()} == false
- * </code>.
- *
- * @throws ConnectorException
- * @see #waitForConnection(long)
- * @see #connect(long)
- */
- public void connectAsync() throws ConnectorException;
-
- /**
- * Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- *
- * @param timeout
- * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
- * connection occurs.
- * @throws ConnectorException
- * @since 4.0
- */
- public void waitForConnection(long timeout) throws ConnectorException;
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.channel.IChannelMultiplexer; +import org.eclipse.net4j.util.collection.Closeable; +import org.eclipse.net4j.util.security.IUserAware; + +/** + * One endpoint of a physical connection of arbitrary nature between two communicating parties. A {@link IConnector} + * encapsulates the process of establishing and closing such connections and has a + * {@link org.eclipse.net4j.ILocationAware.Location location} of + * {@link org.eclipse.net4j.ILocationAware.Location#CLIENT CLIENT} or + * {@link org.eclipse.net4j.ILocationAware.Location#SERVER SERVER} with respect to this process. Once a connection is + * established either party can use its connector to open multiple {@link IChannel}s to asynchronously exchange + * {@link IBuffer}s. + * <p> + * This interface is <b>not</b> intended to be implemented by clients. Providers of connectors for new physical + * connection types have to implement org.eclipse.internal.net4j.connector.InternalConnector. + * <p> + * <dt><b>Class Diagram:</b></dt> + * <dd><img src="doc-files/IConnector-1.gif" title="Diagram Connectors" border="0" usemap="IConnector-1.gif"/></dd> + * <p> + * <MAP NAME="IConnector-1.gif"> <AREA SHAPE="RECT" COORDS="259,15,400,75" HREF="IConnectorCredentials.html"> <AREA + * SHAPE="RECT" COORDS="12,174,138,245" HREF="ConnectorLocation.html"> <AREA SHAPE="RECT" COORDS="258,139,401,281" + * HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="518,156,642,263" HREF="ConnectorState.html"> <AREA SHAPE="RECT" + * COORDS="280,360,380,410" HREF="IChannel.html"> </MAP> + * <p> + * <dt><b>Sequence Diagram: Communication Process</b></dt> + * <dd><img src="doc-files/IConnector-2.gif" title="Communication Process" border="0" usemap="#IConnector-2.gif"/></dd> + * <p> + * <MAP NAME="IConnector-2.gif"> <AREA SHAPE="RECT" COORDS="128,94,247,123" HREF="IConnector.html"> <AREA SHAPE="RECT" + * COORDS="648,95,767,123" HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="509,254,608,283" HREF="IChannel.html"> + * <AREA SHAPE="RECT" COORDS="287,355,387,383" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="818,195,897,222" + * HREF="IProtocol.html"> </MAP> + * + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IConnector extends IChannelMultiplexer, IUserAware, Closeable +{ + /** + * @since 2.0 + */ + public static final long NO_TIMEOUT = -1; + + public String getURL(); + + /** + * Returns the current state of this connector. + */ + public ConnectorState getState(); + + /** + * Same as <code>{@link #getState()} == {@link ConnectorState#CONNECTED}</code>. + */ + public boolean isConnected(); + + /** + * Synchronous connect with infinite timeout value. Same as {@link #connect() connect(NO_TIMEOUT)}. + * + * @throws ConnectorException + * @since 4.0 + */ + public void connect() throws ConnectorException; + + /** + * Synchronous connect. Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired. + * + * @param timeout + * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no + * connection occurs. + * @throws ConnectorException + * @since 4.0 + */ + public void connect(long timeout) throws ConnectorException; + + /** + * Asynchronous connect. May leave this {@link IConnector} in a state where <code>{@link #isConnected()} == false + * </code>. + * + * @throws ConnectorException + * @see #waitForConnection(long) + * @see #connect(long) + */ + public void connectAsync() throws ConnectorException; + + /** + * Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired. + * + * @param timeout + * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no + * connection occurs. + * @throws ConnectorException + * @since 4.0 + */ + public void waitForConnection(long timeout) throws ConnectorException; +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java index 14220aa95e..cccbcd4dc5 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java @@ -1,32 +1,32 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.event.IEvent;
-
-/**
- * A generic {@link IEvent event} fired from a {@link IConnector connector}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnectorEvent extends IEvent
-{
- /**
- * The {@link IConnector} that sent this event.
- *
- * @see IContainerEvent#getSource()
- * @since 3.0
- */
- public IConnector getSource();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +import org.eclipse.net4j.util.container.IContainerEvent; +import org.eclipse.net4j.util.event.IEvent; + +/** + * A generic {@link IEvent event} fired from a {@link IConnector connector}. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IConnectorEvent extends IEvent +{ + /** + * The {@link IConnector} that sent this event. + * + * @see IContainerEvent#getSource() + * @since 3.0 + */ + public IConnector getSource(); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java index 9e32994f9c..1f3f4cc4e2 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java @@ -1,31 +1,31 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.connector;
-
-/**
- * An event that is fired by an {@link IConnector} to indicate that its state has changed.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnectorStateEvent extends IConnectorEvent
-{
- /**
- * The old state of the {@link IConnector} that sent this event.
- */
- public ConnectorState getOldState();
-
- /**
- * The new state of the {@link IConnector} that sent this event.
- */
- public ConnectorState getNewState();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.connector; + +/** + * An event that is fired by an {@link IConnector} to indicate that its state has changed. + * + * @author Eike Stepper + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface IConnectorStateEvent extends IConnectorEvent +{ + /** + * The old state of the {@link IConnector} that sent this event. + */ + public ConnectorState getOldState(); + + /** + * The new state of the {@link IConnector} that sent this event. + */ + public ConnectorState getNewState(); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java index 074b459c8f..8bd9e355db 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java @@ -1,41 +1,41 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorCanceledIndication extends Indication
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledIndication.class);
-
- public MonitorCanceledIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- int correlationID = in.readInt();
- if (TRACER.isEnabled())
- {
- TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
- }
-
- getProtocol().handleMonitorCanceled(correlationID);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class MonitorCanceledIndication extends Indication +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledIndication.class); + + public MonitorCanceledIndication(SignalProtocol<?> protocol) + { + super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED); + } + + @Override + protected void indicating(ExtendedDataInputStream in) throws Exception + { + int correlationID = in.readInt(); + if (TRACER.isEnabled()) + { + TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$ + } + + getProtocol().handleMonitorCanceled(correlationID); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java index e884c75720..8cd401db95 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorCanceledRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledRequest.class);
-
- private int correlationID;
-
- public MonitorCanceledRequest(SignalProtocol<?> protocol, int correlationID)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
- this.correlationID = correlationID;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class MonitorCanceledRequest extends Request +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledRequest.class); + + private int correlationID; + + public MonitorCanceledRequest(SignalProtocol<?> protocol, int correlationID) + { + super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED); + this.correlationID = correlationID; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + if (TRACER.isEnabled()) + { + TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$ + } + + out.writeInt(correlationID); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java index 8a5ebff093..783eef4e00 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java @@ -1,43 +1,43 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorProgressIndication extends Indication
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressIndication.class);
-
- public MonitorProgressIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- int correlationID = in.readInt();
- double totalWork = in.readDouble();
- double work = in.readDouble();
- if (TRACER.isEnabled())
- {
- TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
- }
-
- getProtocol().handleMonitorProgress(correlationID, totalWork, work);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class MonitorProgressIndication extends Indication +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressIndication.class); + + public MonitorProgressIndication(SignalProtocol<?> protocol) + { + super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS); + } + + @Override + protected void indicating(ExtendedDataInputStream in) throws Exception + { + int correlationID = in.readInt(); + double totalWork = in.readDouble(); + double work = in.readDouble(); + if (TRACER.isEnabled()) + { + TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$ + } + + getProtocol().handleMonitorProgress(correlationID, totalWork, work); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java index e80399c24a..147a8b21c3 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java @@ -1,51 +1,51 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorProgressRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressRequest.class);
-
- private int correlationID;
-
- private double totalWork;
-
- private double work;
-
- public MonitorProgressRequest(SignalProtocol<?> protocol, int correlationID, double totalWork, double work)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
- this.correlationID = correlationID;
- this.totalWork = totalWork;
- this.work = work;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- out.writeDouble(totalWork);
- out.writeDouble(work);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class MonitorProgressRequest extends Request +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressRequest.class); + + private int correlationID; + + private double totalWork; + + private double work; + + public MonitorProgressRequest(SignalProtocol<?> protocol, int correlationID, double totalWork, double work) + { + super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS); + this.correlationID = correlationID; + this.totalWork = totalWork; + this.work = work; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + if (TRACER.isEnabled()) + { + TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$ + } + + out.writeInt(correlationID); + out.writeDouble(totalWork); + out.writeDouble(work); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java index bd20af662c..40a8cf45cb 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java @@ -1,97 +1,97 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.io.ExtendedIOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-class RemoteExceptionRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionRequest.class);
-
- private int correlationID;
-
- private boolean responding;
-
- private String message;
-
- private Throwable t;
-
- public RemoteExceptionRequest(SignalProtocol<?> protocol, int correlationID, boolean responding, String message,
- Throwable t)
- {
- super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION);
- this.correlationID = correlationID;
- this.message = message;
- this.t = t;
- this.responding = responding;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- String msg = getFirstLine(message);
- TRACER.format("Writing remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- out.writeBoolean(responding);
- out.writeString(message);
- out.writeByteArray(serializeThrowable(t));
- }
-
- public static byte[] serializeThrowable(Throwable t)
- {
- try
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- ExtendedIOUtil.writeObject(dos, t);
- return baos.toByteArray();
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
- public static String getFirstLine(String message)
- {
- if (message == null)
- {
- return null;
- }
-
- int nl = message.indexOf('\n');
- if (nl == -1)
- {
- nl = message.length();
- }
-
- if (nl > 100)
- {
- nl = 100;
- }
-
- return message.substring(0, nl);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.io.ExtendedIOUtil; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; + +/** + * @author Eike Stepper + */ +class RemoteExceptionRequest extends Request +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionRequest.class); + + private int correlationID; + + private boolean responding; + + private String message; + + private Throwable t; + + public RemoteExceptionRequest(SignalProtocol<?> protocol, int correlationID, boolean responding, String message, + Throwable t) + { + super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION); + this.correlationID = correlationID; + this.message = message; + this.t = t; + this.responding = responding; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + if (TRACER.isEnabled()) + { + String msg = getFirstLine(message); + TRACER.format("Writing remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$ + } + + out.writeInt(correlationID); + out.writeBoolean(responding); + out.writeString(message); + out.writeByteArray(serializeThrowable(t)); + } + + public static byte[] serializeThrowable(Throwable t) + { + try + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + ExtendedIOUtil.writeObject(dos, t); + return baos.toByteArray(); + } + catch (Exception ex) + { + return null; + } + } + + public static String getFirstLine(String message) + { + if (message == null) + { + return null; + } + + int nl = message.indexOf('\n'); + if (nl == -1) + { + nl = message.length(); + } + + if (nl > 100) + { + nl = 100; + } + + return message.substring(0, nl); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java index e85603d896..bf6cdf6d73 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java @@ -1,48 +1,48 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class SetTimeoutIndication extends IndicationWithResponse
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutIndication.class);
-
- public SetTimeoutIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- long timeout = in.readLong();
- if (TRACER.isEnabled())
- {
- TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
- }
-
- getProtocol().handleSetTimeOut(timeout);
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- out.writeBoolean(true);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class SetTimeoutIndication extends IndicationWithResponse +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutIndication.class); + + public SetTimeoutIndication(SignalProtocol<?> protocol) + { + super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT); + } + + @Override + protected void indicating(ExtendedDataInputStream in) throws Exception + { + long timeout = in.readLong(); + if (TRACER.isEnabled()) + { + TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$ + } + + getProtocol().handleSetTimeOut(timeout); + } + + @Override + protected void responding(ExtendedDataOutputStream out) throws Exception + { + out.writeBoolean(true); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java index 8b9c3ecf74..e0ed97cd70 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java @@ -1,50 +1,50 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class SetTimeoutRequest extends RequestWithConfirmation<Boolean>
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutRequest.class);
-
- private long timeout;
-
- public SetTimeoutRequest(SignalProtocol<?> protocol, long timeout)
- {
- super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
- this.timeout = timeout;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
- }
-
- out.writeLong(timeout);
- }
-
- @Override
- protected Boolean confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readBoolean();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.signal; + +import org.eclipse.net4j.util.io.ExtendedDataInputStream; +import org.eclipse.net4j.util.io.ExtendedDataOutputStream; +import org.eclipse.net4j.util.om.trace.ContextTracer; + +import org.eclipse.internal.net4j.bundle.OM; + +/** + * @author Eike Stepper + */ +class SetTimeoutRequest extends RequestWithConfirmation<Boolean> +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutRequest.class); + + private long timeout; + + public SetTimeoutRequest(SignalProtocol<?> protocol, long timeout) + { + super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT); + this.timeout = timeout; + } + + @Override + protected void requesting(ExtendedDataOutputStream out) throws Exception + { + if (TRACER.isEnabled()) + { + TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$ + } + + out.writeLong(timeout); + } + + @Override + protected Boolean confirming(ExtendedDataInputStream in) throws Exception + { + return in.readBoolean(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java index 317b3d6efc..affdfd292b 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java @@ -1,15 +1,15 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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
- */
-
-/**
- * A signal protocol implementation that realizes a configurable heart beat protocol.
- */
-package org.eclipse.net4j.signal.heartbeat;
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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 + */ + +/** + * A signal protocol implementation that realizes a configurable heart beat protocol. + */ +package org.eclipse.net4j.signal.heartbeat; diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java index 4f7ce78c8b..592a363dfb 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java @@ -1,15 +1,15 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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
- */
-
-/**
- * Some container injectors for use with signal protocols.
- */
-package org.eclipse.net4j.signal.wrapping;
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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 + */ + +/** + * Some container injectors for use with signal protocols. + */ +package org.eclipse.net4j.signal.wrapping; diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java index ee667662a7..31cf56d34d 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java @@ -1,167 +1,167 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfig;
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.TransportConfig;
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Acceptor extends Container<IConnector> implements InternalAcceptor
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class);
-
- private ITransportConfig config;
-
- private transient IListener connectorListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- removeConnector((IConnector)lifecycle);
- }
- };
-
- private Set<IConnector> acceptedConnectors = new HashSet<IConnector>(0);
-
- public Acceptor()
- {
- }
-
- public synchronized ITransportConfig getConfig()
- {
- if (config == null)
- {
- config = new TransportConfig(this);
- }
-
- return config;
- }
-
- public synchronized void setConfig(ITransportConfig config)
- {
- this.config = Net4jUtil.copyTransportConfig(this, config);
- }
-
- public INegotiator getNegotiator()
- {
- return getConfig().getNegotiator();
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- getConfig().setNegotiator(negotiator);
- }
-
- public IConnector[] getAcceptedConnectors()
- {
- synchronized (acceptedConnectors)
- {
- return acceptedConnectors.toArray(new IConnector[acceptedConnectors.size()]);
- }
- }
-
- @Override
- public boolean isEmpty()
- {
- return acceptedConnectors.isEmpty();
- }
-
- public IConnector[] getElements()
- {
- return getAcceptedConnectors();
- }
-
- public void prepareConnector(InternalConnector connector)
- {
- connector.setConfig(getConfig());
- }
-
- public void addConnector(InternalConnector connector)
- {
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.add(connector);
- }
-
- connector.addListener(connectorListener);
- if (TRACER.isEnabled())
- {
- TRACER.trace("Added connector " + connector); //$NON-NLS-1$
- }
-
- fireElementAddedEvent(connector);
- }
-
- public void removeConnector(IConnector connector)
- {
- connector.removeListener(connectorListener);
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.remove(connector);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Removed connector " + connector); //$NON-NLS-1$
- }
-
- fireElementRemovedEvent(connector);
- }
-
- public void close()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- public boolean isClosed()
- {
- return !isActive();
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- if (getConfig().getBufferProvider() == null)
- {
- throw new IllegalStateException("getConfig().getBufferProvider() == null"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- for (IConnector connector : getAcceptedConnectors())
- {
- connector.close();
- }
-
- super.doDeactivate();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.ITransportConfig; +import org.eclipse.net4j.Net4jUtil; +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.container.Container; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.log.OMLogger; +import org.eclipse.net4j.util.om.trace.ContextTracer; +import org.eclipse.net4j.util.security.INegotiator; + +import org.eclipse.internal.net4j.TransportConfig; +import org.eclipse.internal.net4j.bundle.OM; + +import java.util.HashSet; +import java.util.Set; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class Acceptor extends Container<IConnector> implements InternalAcceptor +{ + private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class); + + private ITransportConfig config; + + private transient IListener connectorListener = new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + removeConnector((IConnector)lifecycle); + } + }; + + private Set<IConnector> acceptedConnectors = new HashSet<IConnector>(0); + + public Acceptor() + { + } + + public synchronized ITransportConfig getConfig() + { + if (config == null) + { + config = new TransportConfig(this); + } + + return config; + } + + public synchronized void setConfig(ITransportConfig config) + { + this.config = Net4jUtil.copyTransportConfig(this, config); + } + + public INegotiator getNegotiator() + { + return getConfig().getNegotiator(); + } + + public void setNegotiator(INegotiator negotiator) + { + getConfig().setNegotiator(negotiator); + } + + public IConnector[] getAcceptedConnectors() + { + synchronized (acceptedConnectors) + { + return acceptedConnectors.toArray(new IConnector[acceptedConnectors.size()]); + } + } + + @Override + public boolean isEmpty() + { + return acceptedConnectors.isEmpty(); + } + + public IConnector[] getElements() + { + return getAcceptedConnectors(); + } + + public void prepareConnector(InternalConnector connector) + { + connector.setConfig(getConfig()); + } + + public void addConnector(InternalConnector connector) + { + synchronized (acceptedConnectors) + { + acceptedConnectors.add(connector); + } + + connector.addListener(connectorListener); + if (TRACER.isEnabled()) + { + TRACER.trace("Added connector " + connector); //$NON-NLS-1$ + } + + fireElementAddedEvent(connector); + } + + public void removeConnector(IConnector connector) + { + connector.removeListener(connectorListener); + synchronized (acceptedConnectors) + { + acceptedConnectors.remove(connector); + } + + if (TRACER.isEnabled()) + { + TRACER.trace("Removed connector " + connector); //$NON-NLS-1$ + } + + fireElementRemovedEvent(connector); + } + + public void close() + { + LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG); + } + + public boolean isClosed() + { + return !isActive(); + } + + @Override + protected void doBeforeActivate() throws Exception + { + super.doBeforeActivate(); + if (getConfig().getBufferProvider() == null) + { + throw new IllegalStateException("getConfig().getBufferProvider() == null"); //$NON-NLS-1$ + } + } + + @Override + protected void doDeactivate() throws Exception + { + for (IConnector connector : getAcceptedConnectors()) + { + connector.close(); + } + + super.doDeactivate(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java index 69db39c22e..6233ada1d2 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java @@ -1,26 +1,26 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AcceptorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.acceptors"; //$NON-NLS-1$
-
- public AcceptorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.util.factory.Factory; + +/** + * @author Eike Stepper + */ +public abstract class AcceptorFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.net4j.acceptors"; //$NON-NLS-1$ + + public AcceptorFactory(String type) + { + super(PRODUCT_GROUP, type); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java index 0111ab0cb0..18a314c862 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java @@ -1,27 +1,27 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ClientProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.clientProtocols"; //$NON-NLS-1$
-
- public ClientProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.util.factory.Factory; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class ClientProtocolFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.net4j.clientProtocols"; //$NON-NLS-1$ + + public ClientProtocolFactory(String type) + { + super(PRODUCT_GROUP, type); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java index ae16c8861e..0efca2a96b 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java @@ -1,26 +1,26 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ConnectorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.connectors"; //$NON-NLS-1$
-
- public ConnectorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.util.factory.Factory; + +/** + * @author Eike Stepper + */ +public abstract class ConnectorFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.net4j.connectors"; //$NON-NLS-1$ + + public ConnectorFactory(String type) + { + super(PRODUCT_GROUP, type); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java index 7fec99ef66..5459baff65 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java @@ -1,22 +1,22 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfigAware;
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalAcceptor extends IAcceptor, ITransportConfigAware, INegotiatorAware
-{
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.ITransportConfigAware; +import org.eclipse.net4j.acceptor.IAcceptor; +import org.eclipse.net4j.util.security.INegotiatorAware; + +/** + * @author Eike Stepper + */ +public interface InternalAcceptor extends IAcceptor, ITransportConfigAware, INegotiatorAware +{ +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java index d73b527592..020c3d6218 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java @@ -1,25 +1,25 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-
-/**
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalBuffer extends IBuffer
-{
- public void setBufferProvider(IBufferProvider bufferProvider);
-
- public void dispose();
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.buffer.IBufferProvider; + +/** + * @author Eike Stepper + * @noimplement This interface is not intended to be implemented by clients. + */ +public interface InternalBuffer extends IBuffer +{ + public void setBufferProvider(IBufferProvider bufferProvider); + + public void dispose(); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java index 3ab8890941..da1e3248f3 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java @@ -1,88 +1,88 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.Queue;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalChannel extends IChannel, IBufferProvider, ILifecycle
-{
- /**
- * @since 2.0
- */
- public void setID(short id);
-
- /**
- * @since 2.0
- */
- public void setUserID(String userID);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
-
- /**
- * @since 2.0
- */
- public void setMultiplexer(IChannelMultiplexer channelMultiplexer);
-
- public void handleBufferFromMultiplexer(IBuffer buffer);
-
- /**
- * @since 3.0
- */
- public long getReceivedBuffers();
-
- /**
- * @since 3.0
- */
- public long getSentBuffers();
-
- public Queue<IBuffer> getSendQueue();
-
- /**
- * An {@link IEvent event} fired from a {@link InternalChannel channel} when a {@link IBuffer buffer} is enqueued or
- * dequeued.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
- public interface SendQueueEvent extends IEvent
- {
- public InternalChannel getSource();
-
- public Type getType();
-
- public int getQueueSize();
-
- /**
- * Enumerates the possible {@link InternalChannel#getSendQueue() send queue} {@link SendQueueEvent event} types.
- *
- * @author Eike Stepper
- */
- public enum Type
- {
- ENQUEUED, DEQUEUED
- }
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.buffer.IBuffer; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.channel.IChannelMultiplexer; +import org.eclipse.net4j.util.event.IEvent; +import org.eclipse.net4j.util.lifecycle.ILifecycle; + +import java.util.Queue; +import java.util.concurrent.ExecutorService; + +/** + * @author Eike Stepper + */ +public interface InternalChannel extends IChannel, IBufferProvider, ILifecycle +{ + /** + * @since 2.0 + */ + public void setID(short id); + + /** + * @since 2.0 + */ + public void setUserID(String userID); + + public ExecutorService getReceiveExecutor(); + + public void setReceiveExecutor(ExecutorService receiveExecutor); + + /** + * @since 2.0 + */ + public void setMultiplexer(IChannelMultiplexer channelMultiplexer); + + public void handleBufferFromMultiplexer(IBuffer buffer); + + /** + * @since 3.0 + */ + public long getReceivedBuffers(); + + /** + * @since 3.0 + */ + public long getSentBuffers(); + + public Queue<IBuffer> getSendQueue(); + + /** + * An {@link IEvent event} fired from a {@link InternalChannel channel} when a {@link IBuffer buffer} is enqueued or + * dequeued. + * + * @author Eike Stepper + * @since 3.0 + * @noextend This interface is not intended to be extended by clients. + * @noimplement This interface is not intended to be implemented by clients. + */ + public interface SendQueueEvent extends IEvent + { + public InternalChannel getSource(); + + public Type getType(); + + public int getQueueSize(); + + /** + * Enumerates the possible {@link InternalChannel#getSendQueue() send queue} {@link SendQueueEvent event} types. + * + * @author Eike Stepper + */ + public enum Type + { + ENQUEUED, DEQUEUED + } + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java index 1dfd554a3c..7385dbbc30 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java @@ -1,39 +1,39 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfigAware;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public interface InternalChannelMultiplexer extends IChannelMultiplexer, IBufferProvider, ITransportConfigAware
-{
- /**
- * @since 4.0
- */
- public static final short RESERVED_CHANNEL = 0;
-
- /**
- * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be
- * dequeued from the outputQueue of the {@link IChannel}.
- */
- public void multiplexChannel(InternalChannel channel);
-
- /**
- * @since 2.0
- */
- public void closeChannel(InternalChannel channel);
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.ITransportConfigAware; +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.channel.IChannelMultiplexer; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public interface InternalChannelMultiplexer extends IChannelMultiplexer, IBufferProvider, ITransportConfigAware +{ + /** + * @since 4.0 + */ + public static final short RESERVED_CHANNEL = 0; + + /** + * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be + * dequeued from the outputQueue of the {@link IChannel}. + */ + public void multiplexChannel(InternalChannel channel); + + /** + * @since 2.0 + */ + public void closeChannel(InternalChannel channel); +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java index ec6ac8b6d5..1fb8dc4295 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java @@ -1,21 +1,21 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalConnector extends IConnector, INegotiatorAware, InternalChannelMultiplexer
-{
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.connector.IConnector; +import org.eclipse.net4j.util.security.INegotiatorAware; + +/** + * @author Eike Stepper + */ +public interface InternalConnector extends IConnector, INegotiatorAware, InternalChannelMultiplexer +{ +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java index a7a5afaf9b..46fde5dd08 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java @@ -1,177 +1,177 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE>
-{
- private String type;
-
- private ExecutorService executorService;
-
- private IBufferProvider bufferProvider;
-
- private INFRA_STRUCTURE infraStructure;
-
- private IChannel channel;
-
- @ExcludeFromDump
- private transient IListener channelListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- handleChannelDeactivation();
- }
- };
-
- private String userID;
-
- public Protocol(String type)
- {
- this.type = type;
- }
-
- public final String getType()
- {
- return type;
- }
-
- public ExecutorService getExecutorService()
- {
- return executorService;
- }
-
- public void setExecutorService(ExecutorService executorService)
- {
- this.executorService = executorService;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public INFRA_STRUCTURE getInfraStructure()
- {
- return infraStructure;
- }
-
- public void setInfraStructure(INFRA_STRUCTURE infraStructure)
- {
- this.infraStructure = infraStructure;
- }
-
- /**
- * @since 2.0
- */
- public Location getLocation()
- {
- return channel.getLocation();
- }
-
- /**
- * @since 2.0
- */
- public boolean isClient()
- {
- return channel.isClient();
- }
-
- /**
- * @since 2.0
- */
- public boolean isServer()
- {
- return channel.isServer();
- }
-
- public IChannel getChannel()
- {
- return channel;
- }
-
- public void setChannel(IChannel newChannel)
- {
- if (channel != newChannel)
- {
- executorService = null;
- bufferProvider = null;
- if (channel != null)
- {
- channel.removeListener(channelListener);
- }
-
- channel = newChannel;
- if (channel != null)
- {
- channel.addListener(channelListener);
- executorService = ((InternalChannel)channel).getReceiveExecutor();
- bufferProvider = (InternalChannel)channel;
- }
- }
- }
-
- public String getUserID()
- {
- if (userID == null && channel != null)
- {
- return channel.getUserID();
- }
-
- return userID;
- }
-
- protected void setUserID(String userID)
- {
- this.userID = userID;
- }
-
- /**
- * @since 2.0
- */
- protected void handleChannelDeactivation()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(channel, "channel"); //$NON-NLS-1$
- checkState(bufferProvider, "bufferProvider"); //$NON-NLS-1$
- checkState(executorService, "executorService"); //$NON-NLS-1$
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- setChannel(null);
- super.doDeactivate();
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.buffer.IBufferProvider; +import org.eclipse.net4j.channel.IChannel; +import org.eclipse.net4j.protocol.IProtocol; +import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump; +import org.eclipse.net4j.util.event.IListener; +import org.eclipse.net4j.util.lifecycle.ILifecycle; +import org.eclipse.net4j.util.lifecycle.Lifecycle; +import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter; +import org.eclipse.net4j.util.lifecycle.LifecycleUtil; +import org.eclipse.net4j.util.om.log.OMLogger; + +import java.util.concurrent.ExecutorService; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE> +{ + private String type; + + private ExecutorService executorService; + + private IBufferProvider bufferProvider; + + private INFRA_STRUCTURE infraStructure; + + private IChannel channel; + + @ExcludeFromDump + private transient IListener channelListener = new LifecycleEventAdapter() + { + @Override + protected void onDeactivated(ILifecycle lifecycle) + { + handleChannelDeactivation(); + } + }; + + private String userID; + + public Protocol(String type) + { + this.type = type; + } + + public final String getType() + { + return type; + } + + public ExecutorService getExecutorService() + { + return executorService; + } + + public void setExecutorService(ExecutorService executorService) + { + this.executorService = executorService; + } + + public IBufferProvider getBufferProvider() + { + return bufferProvider; + } + + public INFRA_STRUCTURE getInfraStructure() + { + return infraStructure; + } + + public void setInfraStructure(INFRA_STRUCTURE infraStructure) + { + this.infraStructure = infraStructure; + } + + /** + * @since 2.0 + */ + public Location getLocation() + { + return channel.getLocation(); + } + + /** + * @since 2.0 + */ + public boolean isClient() + { + return channel.isClient(); + } + + /** + * @since 2.0 + */ + public boolean isServer() + { + return channel.isServer(); + } + + public IChannel getChannel() + { + return channel; + } + + public void setChannel(IChannel newChannel) + { + if (channel != newChannel) + { + executorService = null; + bufferProvider = null; + if (channel != null) + { + channel.removeListener(channelListener); + } + + channel = newChannel; + if (channel != null) + { + channel.addListener(channelListener); + executorService = ((InternalChannel)channel).getReceiveExecutor(); + bufferProvider = (InternalChannel)channel; + } + } + } + + public String getUserID() + { + if (userID == null && channel != null) + { + return channel.getUserID(); + } + + return userID; + } + + protected void setUserID(String userID) + { + this.userID = userID; + } + + /** + * @since 2.0 + */ + protected void handleChannelDeactivation() + { + LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG); + } + + @Override + protected void doBeforeActivate() throws Exception + { + super.doBeforeActivate(); + checkState(channel, "channel"); //$NON-NLS-1$ + checkState(bufferProvider, "bufferProvider"); //$NON-NLS-1$ + checkState(executorService, "executorService"); //$NON-NLS-1$ + } + + @Override + protected void doDeactivate() throws Exception + { + setChannel(null); + super.doDeactivate(); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java index a721e9d776..245d02fca5 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java @@ -1,27 +1,27 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ServerProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.serverProtocols"; //$NON-NLS-1$
-
- public ServerProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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.spi.net4j; + +import org.eclipse.net4j.util.factory.Factory; + +/** + * @author Eike Stepper + * @since 2.0 + */ +public abstract class ServerProtocolFactory extends Factory +{ + public static final String PRODUCT_GROUP = "org.eclipse.net4j.serverProtocols"; //$NON-NLS-1$ + + public ServerProtocolFactory(String type) + { + super(PRODUCT_GROUP, type); + } +} diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java index 15a3a41f9e..e697088561 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java @@ -1,15 +1,15 @@ -/*
- * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
- * 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
- */
-
-/**
- * Server service provider interfaces and useful base implementations for the Net4j transport layer.
- */
-package org.eclipse.spi.net4j;
+/* + * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. + * 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 + */ + +/** + * Server service provider interfaces and useful base implementations for the Net4j transport layer. + */ +package org.eclipse.spi.net4j; |