Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j')
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/DescriptionUtil.java59
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java59
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java164
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jTransportInjector.java121
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/Acceptor.java222
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/AcceptorFactory.java26
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java322
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java60
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java241
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java69
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java43
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java137
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java61
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/Channel.java268
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/InternalChannel.java34
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java800
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/ConnectorFactory.java26
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ClientProtocolFactory.java26
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/Protocol.java92
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ServerProtocolFactory.java26
20 files changed, 0 insertions, 2856 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/DescriptionUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/DescriptionUtil.java
deleted file mode 100644
index 3e7381e0e9..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/DescriptionUtil.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j;
-
-/**
- * @author Eike Stepper
- */
-@Deprecated
-public final class DescriptionUtil
-{
- public static final String SEPARATOR = ":"; //$NON-NLS-1$
-
- public static final int TYPE_INDEX = 0;
-
- private DescriptionUtil()
- {
- }
-
- public static String getType(String description)
- {
- return getElement(description, TYPE_INDEX);
- }
-
- public static String getElement(String description, int index)
- {
- String[] elements = getElements(description);
- return elements[index];
- }
-
- public static String[] getElements(String description)
- {
- return description.split(SEPARATOR);
- }
-
- public static String getDescription(String type, Object[] elements)
- {
- StringBuilder builder = new StringBuilder();
- builder.append(type);
-
- for (Object element : elements)
- {
- builder.append(":");
- if (element != null)
- {
- builder.append(element);
- }
- }
-
- return builder.toString();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java
deleted file mode 100644
index bd04ee9824..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/ExecutorServiceFactory.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j;
-
-import org.eclipse.net4j.internal.util.factory.Factory;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-/**
- * @author Eike Stepper
- */
-public class ExecutorServiceFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.executorServices";
-
- public static final String TYPE = "default";
-
- public static final String DEFAULT_THREAD_GROUP_NAME = "net4j";
-
- public ExecutorServiceFactory()
- {
- super(PRODUCT_GROUP, TYPE);
- }
-
- public ExecutorService create(String threadGroupName)
- {
- if (threadGroupName == null)
- {
- threadGroupName = DEFAULT_THREAD_GROUP_NAME;
- }
-
- final ThreadGroup threadGroup = new ThreadGroup(threadGroupName);
- return Executors.newCachedThreadPool(new ThreadFactory()
- {
- public Thread newThread(Runnable r)
- {
- Thread thread = new Thread(threadGroup, r);
- thread.setDaemon(true);
- return thread;
- }
- });
- }
-
- public static ExecutorService get(IManagedContainer container)
- {
- return (ExecutorService)container.getElement(PRODUCT_GROUP, TYPE, null);
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java
deleted file mode 100644
index 5413a39dde..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jConfigurator.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.internal.util.security.NegotiatorFactory;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.acceptor.Acceptor;
-import org.eclipse.internal.net4j.acceptor.AcceptorFactory;
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.core.runtime.CoreException;
-
-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;
-
-/**
- * @author Eike Stepper
- */
-public class Net4jConfigurator
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, Net4jConfigurator.class);
-
- private IManagedContainer container;
-
- public Net4jConfigurator(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());
- }
-
- List<IAcceptor> acceptors = new ArrayList<IAcceptor>();
- Document document = getDocument(configFile);
- NodeList acceptorConfigs = document.getElementsByTagName("acceptor");
- 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");
- // TODO Make the following dependent on the "type" attribute value
- String listenAddr = acceptorConfig.getAttribute("listenAddr");
- String port = acceptorConfig.getAttribute("port");
- String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port);
- Acceptor acceptor = (Acceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description);
-
- NodeList negotiatorConfigs = acceptorConfig.getElementsByTagName("negotiator");
- if (negotiatorConfigs.getLength() > 1)
- {
- throw new IllegalStateException("A maximum of one negotiator can be configured for acceptor " + acceptor);
- }
-
- if (negotiatorConfigs.getLength() == 1)
- {
- Element negotiatorConfig = (Element)negotiatorConfigs.item(0);
- INegotiator negotiator = configureNegotiator(negotiatorConfig);
- acceptor.setNegotiator(negotiator);
- }
-
- return acceptor;
- }
-
- protected INegotiator configureNegotiator(Element negotiatorConfig)
- {
- String type = negotiatorConfig.getAttribute("type");
- String description = negotiatorConfig.getAttribute("description");
- INegotiator negotiator = (INegotiator)container.getElement(NegotiatorFactory.PRODUCT_GROUP, type, description);
- return negotiator;
- }
-
- 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");
- if (storeConfigs.getLength() != 1)
- {
- String repositoryName = repositoryConfig.getAttribute("name");
- throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName);
- }
-
- 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);
- return properties;
- }
-
- private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
- {
- if ("property".equals(element.getNodeName()))
- {
- String name = element.getAttribute("name");
- String value = element.getAttribute("value");
- properties.put(prefix + name, value);
- prefix += name + ".";
- }
-
- 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/internal/net4j/Net4jTransportInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jTransportInjector.java
deleted file mode 100644
index de0d2d36cc..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/Net4jTransportInjector.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j;
-
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.acceptor.Acceptor;
-import org.eclipse.internal.net4j.buffer.BufferProvider;
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-import org.eclipse.internal.net4j.connector.Connector;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public class Net4jTransportInjector implements IElementProcessor
-{
- public static INegotiator serverNegotiator;
-
- public static INegotiator clientNegotiator;
-
- public Net4jTransportInjector()
- {
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof Acceptor)
- {
- Acceptor acceptor = (Acceptor)element;
- processAcceptor(container, factoryType, description, acceptor);
- }
- else if (element instanceof Connector)
- {
- Connector connector = (Connector)element;
- processConnector(container, factoryType, description, connector);
- }
-
- return element;
- }
-
- protected void processAcceptor(IManagedContainer container, String factoryType, String description, Acceptor acceptor)
- {
- if (acceptor.getBufferProvider() == null)
- {
- acceptor.setBufferProvider(getBufferProvider(container));
- }
-
- if (acceptor.getReceiveExecutor() == null)
- {
- acceptor.setReceiveExecutor(getExecutorService(container));
- }
-
- if (acceptor.getProtocolFactoryRegistry() == null)
- {
- acceptor.setProtocolFactoryRegistry(container.getFactoryRegistry());
- }
-
- if (acceptor.getProtocolPostProcessors() == null)
- {
- acceptor.setProtocolPostProcessors(container.getPostProcessors());
- }
-
- if (serverNegotiator != null && acceptor.getNegotiator() == null)
- {
- acceptor.setNegotiator(serverNegotiator);
- }
- }
-
- protected void processConnector(IManagedContainer container, String factoryType, String description,
- Connector connector)
- {
- if (connector.getBufferProvider() == null)
- {
- connector.setBufferProvider(getBufferProvider(container));
- }
-
- if (connector.getReceiveExecutor() == null)
- {
- connector.setReceiveExecutor(getExecutorService(container));
- }
-
- if (connector.getProtocolFactoryRegistry() == null)
- {
- connector.setProtocolFactoryRegistry(container.getFactoryRegistry());
- }
-
- if (connector.getProtocolPostProcessors() == null)
- {
- connector.setProtocolPostProcessors(container.getPostProcessors());
- }
-
- if (clientNegotiator != null && connector.isClient() && connector.getNegotiator() == null)
- {
- connector.setNegotiator(clientNegotiator);
- }
- }
-
- protected BufferProvider getBufferProvider(IManagedContainer container)
- {
- return (BufferProvider)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/internal/net4j/acceptor/Acceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/Acceptor.java
deleted file mode 100644
index 088d7547af..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/Acceptor.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.acceptor;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.internal.util.container.Container;
-import org.eclipse.net4j.internal.util.container.LifecycleEventConverter;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IContainerDelta.Kind;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.factory.IFactoryKey;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.registry.IRegistry;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.bundle.OM;
-import org.eclipse.internal.net4j.connector.Connector;
-
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Acceptor extends Container<IConnector> implements IAcceptor
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class);
-
- private INegotiator negotiator;
-
- private IBufferProvider bufferProvider;
-
- private IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry;
-
- private List<IElementProcessor> protocolPostProcessors;
-
- private ExecutorService receiveExecutor;
-
- /**
- * Is registered with each {@link IConnector} of this {@link IAcceptor}.
- */
- private transient IListener lifecycleEventConverter = new LifecycleEventConverter<IConnector>(this)
- {
- @Override
- protected IContainerEvent<IConnector> createContainerEvent(IContainer<IConnector> container, IConnector element,
- Kind kind)
- {
- return newContainerEvent(element, kind);
- }
- };
-
- private Set<IConnector> acceptedConnectors = new HashSet<IConnector>(0);
-
- public Acceptor()
- {
- }
-
- public INegotiator getNegotiator()
- {
- return negotiator;
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- this.negotiator = negotiator;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- this.receiveExecutor = receiveExecutor;
- }
-
- public IRegistry<IFactoryKey, IFactory> getProtocolFactoryRegistry()
- {
- return protocolFactoryRegistry;
- }
-
- public void setProtocolFactoryRegistry(IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry)
- {
- this.protocolFactoryRegistry = protocolFactoryRegistry;
- }
-
- public List<IElementProcessor> getProtocolPostProcessors()
- {
- return protocolPostProcessors;
- }
-
- public void setProtocolPostProcessors(List<IElementProcessor> protocolPostProcessors)
- {
- this.protocolPostProcessors = protocolPostProcessors;
- }
-
- 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(Connector connector)
- {
- connector.setNegotiator(negotiator);
- connector.setBufferProvider(bufferProvider);
- connector.setReceiveExecutor(receiveExecutor);
- connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
- connector.setProtocolPostProcessors(protocolPostProcessors);
- }
-
- public void addConnector(Connector connector)
- {
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.add(connector);
- }
-
- connector.addListener(lifecycleEventConverter);
- if (TRACER.isEnabled())
- {
- TRACER.trace("Added connector " + connector); //$NON-NLS-1$
- }
-
- fireElementAddedEvent(connector);
- }
-
- public void removeConnector(IConnector connector)
- {
- connector.removeListener(lifecycleEventConverter);
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.remove(connector);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Removed connector " + connector); //$NON-NLS-1$
- }
-
- fireElementRemovedEvent(connector);
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- if (bufferProvider == null)
- {
- throw new IllegalStateException("bufferProvider == null"); //$NON-NLS-1$
- }
-
- if (protocolFactoryRegistry == null && TRACER.isEnabled())
- {
- // Just a reminder during development
- TRACER.trace("factoryRegistry == null"); //$NON-NLS-1$
- }
-
- if (protocolPostProcessors == null && TRACER.isEnabled())
- {
- // Just a reminder during development
- TRACER.trace("protocolPostProcessors == null"); //$NON-NLS-1$
- }
-
- if (receiveExecutor == null && TRACER.isEnabled())
- {
- // Just a reminder during development
- TRACER.trace("receiveExecutor == null"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- for (IConnector connector : getAcceptedConnectors())
- {
- LifecycleUtil.deactivate(connector);
- }
-
- super.doDeactivate();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/AcceptorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/AcceptorFactory.java
deleted file mode 100644
index 7d95c9c96d..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/acceptor/AcceptorFactory.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.acceptor;
-
-import org.eclipse.net4j.internal.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AcceptorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.acceptors";
-
- public AcceptorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
deleted file mode 100644
index 5732770a48..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
+++ /dev/null
@@ -1,322 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.BufferState;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.StringUtil;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public class Buffer implements IBuffer
-{
- public static final short HEADER_SIZE = 4;
-
- private static final int EOS_OFFSET = 1;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, Buffer.class);
-
- private IBufferProvider bufferProvider;
-
- private short channelIndex;
-
- private boolean eos;
-
- private BufferState state = BufferState.INITIAL;
-
- private ByteBuffer byteBuffer;
-
- public Buffer(IBufferProvider provider, short capacity)
- {
- this.bufferProvider = provider;
- byteBuffer = ByteBuffer.allocateDirect(capacity);
- }
-
- public boolean isEOS()
- {
- return eos;
- }
-
- public void setEOS(boolean eos)
- {
- this.eos = eos;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public short getChannelIndex()
- {
- if (state == BufferState.INITIAL || state == BufferState.READING_HEADER)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
-
- return channelIndex;
- }
-
- public short getCapacity()
- {
- return (short)byteBuffer.capacity();
- }
-
- public ByteBuffer getByteBuffer()
- {
- if (state != BufferState.GETTING && state != BufferState.PUTTING)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
-
- return byteBuffer;
- }
-
- public BufferState getState()
- {
- return state;
- }
-
- /**
- * TODO Check for multiply released buffers?
- */
- public void release()
- {
- if (bufferProvider != null)
- {
- bufferProvider.retainBuffer(this);
- }
- }
-
- public void clear()
- {
- byteBuffer.clear();
- state = BufferState.INITIAL;
- channelIndex = NO_CHANNEL;
- eos = false;
- }
-
- public void dispose()
- {
- bufferProvider = null;
- byteBuffer = null;
- }
-
- public ByteBuffer startGetting(SocketChannel socketChannel) throws IOException
- {
- if (state != BufferState.INITIAL && state != BufferState.READING_HEADER && state != BufferState.READING_BODY)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
-
- if (state == BufferState.INITIAL)
- {
- byteBuffer.limit(Buffer.HEADER_SIZE);
- state = BufferState.READING_HEADER;
- }
-
- if (state == BufferState.READING_HEADER)
- {
- int num = socketChannel.read(byteBuffer);
- if (num == -1)
- {
- throw new ClosedChannelException();
- }
-
- if (byteBuffer.hasRemaining())
- {
- return null;
- }
-
- byteBuffer.flip();
- channelIndex = byteBuffer.getShort();
- short payloadSize = byteBuffer.getShort();
- if (payloadSize < 0)
- {
- eos = true;
- payloadSize = (short)-payloadSize;
- }
-
- payloadSize -= EOS_OFFSET;
-
- byteBuffer.clear();
- byteBuffer.limit(payloadSize);
- state = BufferState.READING_BODY;
- }
-
- // state == State.READING_BODY
- if (socketChannel.read(byteBuffer) == -1)
- {
- throw new ClosedChannelException();
- }
-
- if (byteBuffer.hasRemaining())
- {
- return null;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read " + byteBuffer.limit() + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- byteBuffer.flip();
- state = BufferState.GETTING;
- return byteBuffer;
- }
-
- public ByteBuffer startPutting(short channelIndex)
- {
- if (state == BufferState.PUTTING)
- {
- if (channelIndex != this.channelIndex)
- {
- throw new IllegalArgumentException("channelIndex != this.channelIndex"); //$NON-NLS-1$
- }
- }
- else if (state != BufferState.INITIAL)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
- else
- {
- state = BufferState.PUTTING;
- this.channelIndex = channelIndex;
-
- byteBuffer.clear();
- byteBuffer.position(Buffer.HEADER_SIZE);
- }
-
- return byteBuffer;
- }
-
- /**
- * @return <code>true</code> if the buffer has been completely written, <code>false</code> otherwise.
- */
- public boolean write(SocketChannel socketChannel) throws IOException
- {
- if (state != BufferState.PUTTING && state != BufferState.WRITING)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
-
- if (state == BufferState.PUTTING)
- {
- if (channelIndex == NO_CHANNEL)
- {
- throw new IllegalStateException("channelIndex == NO_CHANNEL"); //$NON-NLS-1$
- }
-
- int payloadSize = byteBuffer.position() - Buffer.HEADER_SIZE + EOS_OFFSET;
- if (eos)
- {
- payloadSize = -payloadSize;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Writing " + (Math.abs(payloadSize) - 1) + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- byteBuffer.flip();
- byteBuffer.putShort(channelIndex);
- byteBuffer.putShort((short)payloadSize);
- byteBuffer.position(0);
- state = BufferState.WRITING;
- }
-
- int numBytes = socketChannel.write(byteBuffer);
- if (numBytes == -1)
- {
- throw new IOException("Channel closed"); //$NON-NLS-1$
- }
-
- if (byteBuffer.hasRemaining())
- {
- return false;
- }
-
- clear();
- return true;
- }
-
- public void flip()
- {
- if (state != BufferState.PUTTING)
- {
- throw new IllegalStateException("state == " + state); //$NON-NLS-1$
- }
-
- byteBuffer.flip();
- byteBuffer.position(HEADER_SIZE);
- state = BufferState.GETTING;
- }
-
- @Override
- public String toString()
- {
- return "Buffer@" + ReflectUtil.getID(this); //$NON-NLS-1$
- }
-
- @SuppressWarnings("deprecation")
- public String formatContent(boolean showHeader)
- {
- final int oldPosition = byteBuffer.position();
- final int oldLimit = byteBuffer.limit();
-
- try
- {
- if (state != BufferState.GETTING)
- {
- byteBuffer.flip();
- }
-
- if (state == BufferState.PUTTING && !showHeader)
- {
- byteBuffer.position(HEADER_SIZE);
- }
-
- StringBuilder builder = new StringBuilder();
- while (byteBuffer.hasRemaining())
- {
- byte b = byteBuffer.get();
- HexUtil.appendHex(builder, b < 0 ? ~b : b);
- builder.append(' ');
- }
-
- return builder.toString();
- }
- finally
- {
- byteBuffer.position(oldPosition);
- byteBuffer.limit(oldLimit);
- }
- }
-}
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
deleted file mode 100644
index f0844daf2c..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-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()
- {
- Buffer 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 Buffer)
- {
- ((Buffer)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/BufferPool.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java
deleted file mode 100644
index a8c2387647..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
-import java.text.MessageFormat;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/**
- * @author Eike Stepper
- */
-public class BufferPool extends BufferProvider implements IBufferPool, IBufferPool.Introspection
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferPool.class);
-
- private final IBufferProvider provider;
-
- private int pooledBuffers;
-
- @ExcludeFromDump
- private final Queue<BufferRef> buffers = new ConcurrentLinkedQueue<BufferRef>();
-
- @ExcludeFromDump
- private final ReferenceQueue<IBuffer> referenceQueue = new ReferenceQueue<IBuffer>();
-
- @ExcludeFromDump
- private Monitor monitor;
-
- public BufferPool(IBufferProvider provider)
- {
- super(provider.getBufferCapacity());
- this.provider = provider;
- }
-
- public IBufferProvider getProvider()
- {
- return provider;
- }
-
- public ReferenceQueue<IBuffer> getReferenceQueue()
- {
- return referenceQueue;
- }
-
- public int getPooledBuffers()
- {
- return pooledBuffers;
- }
-
- public boolean evictOne()
- {
- for (;;)
- {
- BufferRef bufferRef = buffers.poll();
- if (bufferRef == null)
- {
- return false;
- }
-
- IBuffer buffer = bufferRef.get();
- if (buffer != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Evicting " + buffer); //$NON-NLS-1$
- }
-
- provider.retainBuffer(buffer);
- --pooledBuffers;
- return true;
- }
- }
- }
-
- public int evict(int survivors)
- {
- int evictedBuffers = 0;
- while (pooledBuffers > survivors)
- {
- if (evictOne())
- {
- ++evictedBuffers;
- }
- else
- {
- break;
- }
- }
-
- return evictedBuffers;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("BufferPool[{0}]", getBufferCapacity()); //$NON-NLS-1$
- }
-
- protected BufferRef createBufferRef(IBuffer buffer)
- {
- return new BufferRef(buffer, referenceQueue);
- }
-
- @Override
- protected IBuffer doProvideBuffer()
- {
- IBuffer buffer = null;
- BufferRef bufferRef = buffers.poll();
- if (bufferRef != null)
- {
- buffer = bufferRef.get();
- }
-
- if (buffer == null)
- {
- buffer = provider.provideBuffer();
- ((Buffer)buffer).setBufferProvider(this);
- }
- else
- {
- --pooledBuffers;
- }
-
- buffer.clear();
- if (TRACER.isEnabled())
- {
- TRACER.trace("Obtained " + buffer); //$NON-NLS-1$
- }
-
- return buffer;
- }
-
- @Override
- protected void doRetainBuffer(IBuffer buffer)
- {
- if (buffer.getCapacity() != getBufferCapacity())
- {
- throw new IllegalArgumentException("buffer.getCapacity() != getBufferCapacity()"); //$NON-NLS-1$
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Retaining " + buffer); //$NON-NLS-1$
- }
-
- BufferRef bufferRef = createBufferRef(buffer);
- buffers.add(bufferRef);
- ++pooledBuffers;
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- monitor = new Monitor();
- monitor.start();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- monitor.interrupt();
- monitor = null;
- super.doDeactivate();
- }
-
- private static final class BufferRef extends SoftReference<IBuffer>
- {
- public BufferRef(IBuffer buffer, ReferenceQueue<IBuffer> queue)
- {
- super(buffer, queue);
- }
- }
-
- private final class Monitor extends Thread
- {
- public Monitor()
- {
- setName("BufferPoolMonitor");
- setDaemon(true);
- }
-
- @Override
- public void run()
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Start monitoring"); //$NON-NLS-1$
- }
-
- try
- {
- while (isActive() && !isInterrupted())
- {
- Reference<? extends IBuffer> bufferRef = referenceQueue.remove(200);
- if (bufferRef != null)
- {
- if (buffers.remove(bufferRef))
- {
- --pooledBuffers;
- if (TRACER.isEnabled())
- {
- TRACER.trace("Collected buffer"); //$NON-NLS-1$
- }
- }
- }
- }
- }
- catch (InterruptedException ex)
- {
- return;
- }
- finally
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Stop monitoring"); //$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
deleted file mode 100644
index 7a9f2c67fe..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
-
-/**
- * @author Eike Stepper
- */
-public abstract class BufferProvider extends Lifecycle implements IBufferProvider, 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
deleted file mode 100644
index f7b16d9f28..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.buffer;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.internal.util.factory.Factory;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-/**
- * @author Eike Stepper
- */
-public class BufferProviderFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.bufferProviders";
-
- public static final String TYPE = "default";
-
- 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
deleted file mode 100644
index 0f432ef75b..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.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
deleted file mode 100644
index 01fbec240b..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.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_SELECTOR = DEBUG.tracer("selector"); //$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);
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/Channel.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/Channel.java
deleted file mode 100644
index b3c9df0f1b..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/Channel.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.channel;
-
-import org.eclipse.net4j.buffer.BufferState;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.internal.util.concurrent.QueueWorkerWorkSerializer;
-import org.eclipse.net4j.internal.util.concurrent.SynchronousWorkSerializer;
-import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.concurrent.IWorkSerializer;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-import org.eclipse.internal.net4j.buffer.Buffer;
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.text.MessageFormat;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public class Channel extends Lifecycle implements InternalChannel
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CHANNEL, Channel.class);
-
- private int channelID;
-
- private IChannelMultiplexer channelMultiplexer;
-
- private short channelIndex = Buffer.NO_CHANNEL;
-
- private ExecutorService receiveExecutor;
-
- /**
- * The external handler for buffers passed from the {@link #connector}.
- */
- private IBufferHandler receiveHandler;
-
- private IWorkSerializer receiveSerializer;
-
- private Queue<IBuffer> sendQueue;
-
- public Channel()
- {
- }
-
- public int getChannelID()
- {
- return channelID;
- }
-
- public void setChannelID(int channelID)
- {
- this.channelID = channelID;
- }
-
- public IChannelMultiplexer getChannelMultiplexer()
- {
- return channelMultiplexer;
- }
-
- public void setChannelMultiplexer(IChannelMultiplexer channelMultiplexer)
- {
- this.channelMultiplexer = channelMultiplexer;
- }
-
- public short getChannelIndex()
- {
- return channelIndex;
- }
-
- public void setChannelIndex(short channelIndex)
- {
- if (channelIndex == Buffer.NO_CHANNEL)
- {
- throw new IllegalArgumentException("channelIndex == INVALID_CHANNEL_ID"); //$NON-NLS-1$
- }
-
- this.channelIndex = channelIndex;
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- this.receiveExecutor = receiveExecutor;
- }
-
- public IBufferHandler getReceiveHandler()
- {
- return receiveHandler;
- }
-
- public void setReceiveHandler(IBufferHandler receiveHandler)
- {
- this.receiveHandler = receiveHandler;
- }
-
- public Queue<IBuffer> getSendQueue()
- {
- return sendQueue;
- }
-
- public void close()
- {
- deactivate();
- }
-
- public void sendBuffer(IBuffer buffer)
- {
- handleBuffer(buffer);
- }
-
- public void handleBuffer(IBuffer buffer)
- {
- BufferState state = buffer.getState();
- if (state != BufferState.PUTTING)
- {
- OM.LOG.warn("Ignoring buffer in state == " + state + ": " + this); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Handling buffer from client: {0} --> {1}", buffer, this); //$NON-NLS-1$
- }
-
- if (sendQueue == null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Ignoring buffer because sendQueue == null: " + this); //$NON-NLS-1$
- }
-
- buffer.release();
- }
- else
- {
- sendQueue.add(buffer);
- channelMultiplexer.multiplexChannel(this);
- }
- }
-
- public void handleBufferFromMultiplexer(final IBuffer buffer)
- {
- if (receiveHandler != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Handling buffer from multiplexer: {0} --> {1}", buffer, this); //$NON-NLS-1$
- }
-
- receiveSerializer.addWork(new ReceiverWork(buffer));
- }
- else
- {
- // Shutting down
- buffer.release();
- }
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("Channel[{0}]", channelIndex); //$NON-NLS-1$
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(channelIndex != Buffer.NO_CHANNEL, "channelIndex == NO_CHANNEL"); //$NON-NLS-1$
- checkState(channelMultiplexer, "channelMultiplexer"); //$NON-NLS-1$
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- sendQueue = new ConcurrentLinkedQueue<IBuffer>();
- if (receiveExecutor == null)
- {
- receiveSerializer = new SynchronousWorkSerializer();
- }
- else
- {
- // CompletionWorkSerializer throws "One command already pending"
- // receiveSerializer = new CompletionWorkSerializer();
- // receiveSerializer = new AsynchronousWorkSerializer(receiveExecutor);
- // receiveSerializer = new SynchronousWorkSerializer();
-
- class ChannelReceiveSerializer extends QueueWorkerWorkSerializer
- {
- @Override
- protected String getThreadName()
- {
- return "ReceiveSerializer" + channelIndex;
- }
- }
-
- receiveSerializer = new ChannelReceiveSerializer();
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- LifecycleUtil.deactivate(receiveHandler);
- receiveHandler = null;
-
- channelMultiplexer.removeChannel(this);
- if (receiveSerializer != null)
- {
- receiveSerializer.dispose();
- receiveSerializer = null;
- }
-
- if (sendQueue != null)
- {
- sendQueue.clear();
- sendQueue = null;
- }
-
- super.doDeactivate();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class ReceiverWork implements Runnable
- {
- private final IBuffer buffer;
-
- private ReceiverWork(IBuffer buffer)
- {
- this.buffer = buffer;
- }
-
- public void run()
- {
- if (receiveHandler != null)
- {
- receiveHandler.handleBuffer(buffer);
- }
- else
- {
- // Shutting down
- buffer.release();
- }
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/InternalChannel.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/InternalChannel.java
deleted file mode 100644
index 192ecaf243..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/channel/InternalChannel.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.channel;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.Queue;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalChannel extends IChannel, ILifecycle.Introspection
-{
- public void setChannelID(int channelID);
-
- public void setChannelIndex(short channelIndex);
-
- public ExecutorService getReceiveExecutor();
-
- public Queue<IBuffer> getSendQueue();
-
- public void handleBufferFromMultiplexer(IBuffer buffer);
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java
deleted file mode 100644
index 7b211dce8c..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java
+++ /dev/null
@@ -1,800 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.connector;
-
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.connector.ConnectorLocation;
-import org.eclipse.net4j.connector.ConnectorState;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.connector.IConnectorStateEvent;
-import org.eclipse.net4j.internal.util.container.Container;
-import org.eclipse.net4j.internal.util.container.LifecycleEventConverter;
-import org.eclipse.net4j.internal.util.event.Event;
-import org.eclipse.net4j.internal.util.factory.FactoryKey;
-import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.concurrent.RWLock;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IContainerDelta.Kind;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.event.INotifier;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.factory.IFactoryKey;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.MonitorUtil;
-import org.eclipse.net4j.util.registry.IRegistry;
-import org.eclipse.net4j.util.security.INegotiationContext;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.bundle.OM;
-import org.eclipse.internal.net4j.channel.Channel;
-import org.eclipse.internal.net4j.channel.InternalChannel;
-import org.eclipse.internal.net4j.protocol.ClientProtocolFactory;
-import org.eclipse.internal.net4j.protocol.ServerProtocolFactory;
-
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Connector extends Container<IChannel> implements IConnector, IChannelMultiplexer
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONNECTOR, Connector.class);
-
- private String userID;
-
- private IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry;
-
- private List<IElementProcessor> protocolPostProcessors;
-
- private INegotiator negotiator;
-
- private INegotiationContext negotiationContext;
-
- 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 int nextChannelID;
-
- private List<InternalChannel> channels = new ArrayList<InternalChannel>(0);
-
- private RWLock channelsLock = new RWLock(2500);
-
- private ConnectorState connectorState = ConnectorState.DISCONNECTED;
-
- /**
- * Is registered with each {@link IChannel} of this {@link IConnector}.
- */
- private transient IListener channelListener = new LifecycleEventConverter<IChannel>(this)
- {
- @Override
- protected IContainerEvent<IChannel> createContainerEvent(IContainer<IChannel> container, IChannel element, Kind kind)
- {
- return newContainerEvent(element, kind);
- }
- };
-
- private transient CountDownLatch finishedConnecting;
-
- private transient CountDownLatch finishedNegotiating;
-
- public Connector()
- {
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- this.receiveExecutor = receiveExecutor;
- }
-
- public IRegistry<IFactoryKey, IFactory> getProtocolFactoryRegistry()
- {
- return protocolFactoryRegistry;
- }
-
- public void setProtocolFactoryRegistry(IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry)
- {
- this.protocolFactoryRegistry = protocolFactoryRegistry;
- }
-
- public List<IElementProcessor> getProtocolPostProcessors()
- {
- return protocolPostProcessors;
- }
-
- public void setProtocolPostProcessors(List<IElementProcessor> protocolPostProcessors)
- {
- this.protocolPostProcessors = protocolPostProcessors;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public INegotiator getNegotiator()
- {
- return negotiator;
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- this.negotiator = negotiator;
- }
-
- public INegotiationContext getNegotiationContext()
- {
- return negotiationContext;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public boolean isClient()
- {
- return getLocation() == ConnectorLocation.CLIENT;
- }
-
- public boolean isServer()
- {
- return getLocation() == ConnectorLocation.SERVER;
- }
-
- public String getUserID()
- {
- return userID;
- }
-
- public void setUserID(String userID)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting userID {0} for {1}", userID, this); //$NON-NLS-1$
- }
-
- this.userID = userID;
- }
-
- public ConnectorState getState()
- {
- return connectorState;
- }
-
- public void setState(ConnectorState newState) throws ConnectorException
- {
- ConnectorState oldState = getState();
- if (newState != oldState)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting state {0} (was {1}) for {2}", newState, oldState.toString().toLowerCase(), this); //$NON-NLS-1$
- }
-
- connectorState = newState;
- switch (newState)
- {
- case DISCONNECTED:
- if (finishedConnecting != null)
- {
- finishedConnecting.countDown();
- finishedConnecting = null;
- }
-
- if (finishedNegotiating != null)
- {
- finishedNegotiating.countDown();
- finishedNegotiating = null;
- }
- break;
-
- case CONNECTING:
- finishedConnecting = new CountDownLatch(1);
- finishedNegotiating = new CountDownLatch(1);
- // The concrete implementation must advance state to NEGOTIATING or CONNECTED
- break;
-
- case NEGOTIATING:
- finishedConnecting.countDown();
- negotiationContext = createNegotiationContext();
- negotiator.negotiate(negotiationContext);
- break;
-
- case CONNECTED:
- negotiationContext = null;
- deferredActivate();
- finishedConnecting.countDown();
- finishedNegotiating.countDown();
- break;
- }
-
- fireEvent(new ConnectorStateEvent(this, oldState, newState));
- }
- }
-
- public boolean isDisconnected()
- {
- return connectorState == ConnectorState.DISCONNECTED;
- }
-
- public boolean isConnecting()
- {
- return connectorState == ConnectorState.CONNECTING;
- }
-
- public boolean isNegotiating()
- {
- return connectorState == ConnectorState.NEGOTIATING;
- }
-
- public boolean isConnected()
- {
- return connectorState == ConnectorState.CONNECTED;
- }
-
- public void connectAsync() throws ConnectorException
- {
- try
- {
- activate();
- }
- catch (ConnectorException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
- }
-
- public boolean waitForConnection(long timeout) throws ConnectorException
- {
- try
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Waiting for connection..."); //$NON-NLS-1$
- }
-
- do
- {
- if (finishedNegotiating == null)
- {
- break;
- }
-
- if (finishedNegotiating.await(Math.min(100L, timeout), TimeUnit.MILLISECONDS))
- {
- break;
- }
-
- if (MonitorUtil.isCanceled())
- {
- break;
- }
-
- timeout -= 100L;
- } while (timeout > 0);
-
- return isConnected();
- }
- catch (InterruptedException ex)
- {
- return false;
- }
- }
-
- public boolean connect(long timeout) throws ConnectorException
- {
- connectAsync();
- return waitForConnection(timeout);
- }
-
- public ConnectorException disconnect()
- {
- Exception ex = deactivate();
- if (ex == null)
- {
- return null;
- }
-
- if (ex instanceof ConnectorException)
- {
- return (ConnectorException)ex;
- }
-
- return new ConnectorException(ex);
- }
-
- public IChannel[] getChannels()
- {
- final List<IChannel> result = new ArrayList<IChannel>(0);
- channelsLock.read(new Runnable()
- {
- public void run()
- {
- for (InternalChannel channel : channels)
- {
- if (channel != null)
- {
- result.add(channel);
- }
- }
- }
- });
-
- return result.toArray(new IChannel[result.size()]);
- }
-
- @Override
- public boolean isEmpty()
- {
- return getElements().length == 0;
- }
-
- public IChannel[] getElements()
- {
- return getChannels();
- }
-
- public IChannel openChannel() throws ConnectorException
- {
- return openChannel((IProtocol)null);
- }
-
- public IChannel openChannel(String protocolID, Object infraStructure) throws ConnectorException
- {
- IProtocol protocol = createProtocol(protocolID, infraStructure);
- if (protocol == null)
- {
- throw new IllegalArgumentException("Unknown protocolID: " + protocolID);
- }
-
- return openChannel(protocol);
- }
-
- public IChannel openChannel(IProtocol protocol) throws ConnectorException
- {
- if (!waitForConnection(Long.MAX_VALUE))
- {
- throw new ConnectorException("Connector not connected");
- }
-
- int channelID = getNextChannelID();
- InternalChannel channel = createChannel(channelID, protocol);
- registerChannelWithPeer(channelID, channel.getChannelIndex(), protocol);
-
- try
- {
- channel.activate();
- }
- catch (ConnectorException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
-
- return channel;
- }
-
- public InternalChannel createChannel(int channelID, short channelIndex, String protocolID)
- {
- IProtocol protocol = createProtocol(protocolID, null);
- return createAndAddChannel(channelID, channelIndex, protocol);
- }
-
- protected InternalChannel createChannelWithoutChannelIndex(int channelID, IProtocol protocol)
- {
- InternalChannel channel = createChannel();
- channel.setChannelID(channelID);
-
- if (protocol != null)
- {
- protocol.setChannel(channel);
- LifecycleUtil.activate(protocol);
- if (TRACER.isEnabled())
- {
- String protocolType = protocol == null ? null : protocol.getType();
- TRACER.format("Opening channel ID {0} with protocol {1}", channelID, protocolType); //$NON-NLS-1$
- }
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Opening channel ID {0} without protocol", channelID); //$NON-NLS-1$
- }
- }
- channel.setReceiveHandler(protocol);
- channel.addListener(channelListener);
- return channel;
- }
-
- public InternalChannel createAndAddChannel(int channelID, short channelIndex, IProtocol protocol)
- {
- InternalChannel channel = createChannelWithoutChannelIndex(channelID, protocol);
- channel.setChannelIndex(channelIndex);
- addChannelWithIndex(channel);
- return channel;
- }
-
- public InternalChannel createChannel(int channelID, IProtocol protocol)
- {
- InternalChannel channel = createChannelWithoutChannelIndex(channelID, protocol);
- addChannelWithoutIndex(channel);
- return channel;
- }
-
- protected InternalChannel createChannel()
- {
- Channel channel = new Channel();
- channel.setChannelMultiplexer(this);
- channel.setReceiveExecutor(receiveExecutor);
- return channel;
- }
-
- public InternalChannel getChannel(final short channelIndex)
- {
- return channelsLock.read(new Callable<InternalChannel>()
- {
- public InternalChannel call() throws Exception
- {
- return channels.get(channelIndex);
- }
- });
- }
-
- protected int getNextChannelID()
- {
- return nextChannelID++;
- }
-
- protected void addChannelWithIndex(final InternalChannel channel)
- {
- channelsLock.write(new Runnable()
- {
- public void run()
- {
- short channelIndex = channel.getChannelIndex();
- while (channelIndex >= channels.size())
- {
- channels.add(null);
- }
-
- channels.set(channelIndex, channel);
- }
- });
- }
-
- protected void addChannelWithoutIndex(final InternalChannel channel)
- {
- channelsLock.write(new Runnable()
- {
- public void run()
- {
- int size = channels.size();
- for (short i = 0; i < size; i++)
- {
- if (channels.get(i) == null)
- {
- channels.set(i, channel);
- channel.setChannelIndex(i);
- return;
- }
- }
-
- channel.setChannelIndex((short)size);
- channels.add(channel);
- }
- });
- }
-
- /**
- * @return <code>true</code> if the channel was removed, <code>false</code> otherwise.
- */
- public boolean removeChannel(final IChannel channel)
- {
- if (channel == null)
- {
- throw new IllegalArgumentException("channel == null");
- }
-
- if (!isConnected())
- {
- return false;
- }
-
- final int channelIndex = channel.getChannelIndex();
- boolean removed = false;
- try
- {
- removed = channelsLock.write(new Callable<Boolean>()
- {
- public Boolean call() throws Exception
- {
- if (channelIndex < channels.size() && channels.get(channelIndex) == channel)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Removing channel " + channelIndex); //$NON-NLS-1$
- }
-
- channels.set(channelIndex, null);
- return true;
- }
-
- return false;
- }
- });
-
- if (removed)
- {
- channel.close();
- }
- }
- catch (RuntimeException ex)
- {
- Exception unwrapped = WrappedException.unwrap(ex);
- if (unwrapped instanceof TimeoutException)
- {
- if (channelIndex < channels.size())
- {
- InternalChannel c = channels.get(channelIndex);
- if (c != null && c.isActive())
- {
- throw ex;
- }
- }
- }
- else
- {
- throw ex;
- }
- }
-
- return removed;
- }
-
- public void inverseRemoveChannel(int channelID, short channelIndex)
- {
- try
- {
- InternalChannel channel = getChannel(channelIndex);
- if (channel != null)
- {
- if (channel.getChannelID() != channelID)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Ignoring concurrent atempt to remove channel {0} (channelID={1}", channelIndex, channelID);
- }
- }
- else
- {
- removeChannel(channel);
- }
- }
- }
- catch (RuntimeException ex)
- {
- OM.LOG.warn(ex);
- }
- }
-
- protected void leaveConnecting()
- {
- if (getNegotiator() == null)
- {
- setState(ConnectorState.CONNECTED);
- }
- else
- {
- setState(ConnectorState.NEGOTIATING);
- }
- }
-
- protected abstract INegotiationContext createNegotiationContext();
-
- /**
- * TODO Use IProtocolProvider and make the protocols real container elements, so that the post processors can reach
- * them. The protocol description can be used to store unique protocol IDs so that always new protocols are created in
- * the container.
- */
- protected IProtocol createProtocol(String type, Object infraStructure)
- {
- IRegistry<IFactoryKey, IFactory> registry = getProtocolFactoryRegistry();
- if (StringUtil.isEmpty(type) || registry == null)
- {
- return null;
- }
-
- // Get protocol factory
- IFactoryKey key = createProtocolFactoryKey(type);
- IFactory factory = registry.get(key);
- if (factory == null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Unknown protocol " + type); //$NON-NLS-1$
- }
-
- return null;
- }
-
- // Create protocol
- String description = null;
- IProtocol protocol = (IProtocol)factory.create(description);
- protocol.setBufferProvider(bufferProvider);
- protocol.setExecutorService(receiveExecutor);
- if (infraStructure != null)
- {
- protocol.setInfraStructure(infraStructure);
- }
-
- // Post process protocol
- List<IElementProcessor> processors = getProtocolPostProcessors();
- if (processors != null)
- {
- for (IElementProcessor processor : processors)
- {
- protocol = (IProtocol)processor.process(null, key.getProductGroup(), key.getType(), description, protocol);
- }
- }
-
- return protocol;
- }
-
- protected IFactoryKey createProtocolFactoryKey(String type)
- {
- switch (getLocation())
- {
- case SERVER:
- return new FactoryKey(ServerProtocolFactory.PRODUCT_GROUP, type);
- case CLIENT:
- return new FactoryKey(ClientProtocolFactory.PRODUCT_GROUP, type);
- default:
- throw new IllegalStateException();
- }
- }
-
- @Override
- protected boolean isDeferredActivation()
- {
- return true;
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- if (bufferProvider == null)
- {
- throw new IllegalStateException("bufferProvider == null"); //$NON-NLS-1$
- }
-
- if (protocolFactoryRegistry == null && TRACER.isEnabled())
- {
- // Just a reminder during development
- TRACER.trace("No factoryRegistry!"); //$NON-NLS-1$
- }
-
- if (receiveExecutor == null && TRACER.isEnabled())
- {
- // Just a reminder during development
- TRACER.trace("No receiveExecutor!"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- setState(ConnectorState.CONNECTING);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- setState(ConnectorState.DISCONNECTED);
- channelsLock.write(new Runnable()
- {
- public void run()
- {
- for (short i = 0; i < channels.size(); i++)
- {
- InternalChannel channel = channels.get(i);
- if (channel != null)
- {
- LifecycleUtil.deactivate(channel);
- }
- }
-
- channels.clear();
- }
- });
-
- super.doDeactivate();
- }
-
- protected abstract void registerChannelWithPeer(int channelID, short channelIndex, IProtocol protocol)
- throws ConnectorException;
-
- /**
- * @author Eike Stepper
- */
- private static class ConnectorStateEvent extends Event implements IConnectorStateEvent
- {
- private static final long serialVersionUID = 1L;
-
- private ConnectorState oldState;
-
- private ConnectorState newState;
-
- public ConnectorStateEvent(INotifier notifier, ConnectorState oldState, ConnectorState newState)
- {
- super(notifier);
- this.oldState = oldState;
- this.newState = newState;
- }
-
- public IConnector getConnector()
- {
- return (IConnector)getSource();
- }
-
- public ConnectorState getOldState()
- {
- return oldState;
- }
-
- public ConnectorState getNewState()
- {
- return newState;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("ConnectorStateEvent[source={0}, oldState={1}, newState={2}]", getSource(),
- getOldState(), getNewState());
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/ConnectorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/ConnectorFactory.java
deleted file mode 100644
index 909099ab4a..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/ConnectorFactory.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.connector;
-
-import org.eclipse.net4j.internal.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ConnectorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.connectors";
-
- public ConnectorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ClientProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ClientProtocolFactory.java
deleted file mode 100644
index 792d4241ab..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ClientProtocolFactory.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.protocol;
-
-import org.eclipse.net4j.internal.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ClientProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.clientProtocols";
-
- public ClientProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/Protocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/Protocol.java
deleted file mode 100644
index f61e83893a..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/Protocol.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.protocol;
-
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.protocol.IProtocol;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Protocol extends Lifecycle implements IProtocol
-{
- private IChannel channel;
-
- private IBufferProvider bufferProvider;
-
- private ExecutorService executorService;
-
- private Object infraStructure;
-
- public Protocol()
- {
- }
-
- public IChannel getChannel()
- {
- return channel;
- }
-
- public void setChannel(IChannel channel)
- {
- this.channel = channel;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public ExecutorService getExecutorService()
- {
- return executorService;
- }
-
- public void setExecutorService(ExecutorService executorService)
- {
- this.executorService = executorService;
- }
-
- public Object getInfraStructure()
- {
- return infraStructure;
- }
-
- public void setInfraStructure(Object infraStructure)
- {
- this.infraStructure = infraStructure;
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(channel, "channel");
- checkState(bufferProvider, "bufferProvider");
- checkState(executorService, "executorService");
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- channel = null;
- super.doDeactivate();
- }
-}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ServerProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ServerProtocolFactory.java
deleted file mode 100644
index 575e35b116..0000000000
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/protocol/ServerProtocolFactory.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- **************************************************************************/
-package org.eclipse.internal.net4j.protocol;
-
-import org.eclipse.net4j.internal.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ServerProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.serverProtocols";
-
- public ServerProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}

Back to the top