Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-02-23 05:47:43 +0000
committerCaspar De Groot2011-02-23 05:47:43 +0000
commit40b806681aa48dcbcf5c94c3d01fee49a8b81315 (patch)
treee0204761d78411e36f1ab2cc3f01b76b0bccffb2 /plugins/org.eclipse.net4j.tcp
parentbaad70b607cd76bcbbd5dcb884eb697d6e37042f (diff)
downloadcdo-40b806681aa48dcbcf5c94c3d01fee49a8b81315.tar.gz
cdo-40b806681aa48dcbcf5c94c3d01fee49a8b81315.tar.xz
cdo-40b806681aa48dcbcf5c94c3d01fee49a8b81315.zip
[Bug 337095] Improve reusability of TCP classes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337095
Diffstat (limited to 'plugins/org.eclipse.net4j.tcp')
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java5
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java16
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java13
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java61
-rw-r--r--plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java22
5 files changed, 93 insertions, 24 deletions
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
index eadd284c5a..ee9f671167 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptor.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
*/
package org.eclipse.net4j.internal.tcp;
@@ -183,7 +184,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
// socketChannel.socket().setKeepAlive(true);
socketChannel.configureBlocking(false);
- TCPServerConnector connector = createConnector();
+ TCPConnector connector = createConnector();
prepareConnector(connector);
connector.setSocketChannel(socketChannel);
connector.setSelector(selector);
@@ -211,7 +212,7 @@ public class TCPAcceptor extends Acceptor implements ITCPAcceptor, ITCPPassiveSe
return MessageFormat.format("TCPAcceptor[{0}:{1}]", address, port); //$NON-NLS-1$
}
- protected TCPServerConnector createConnector()
+ protected TCPConnector createConnector()
{
return new TCPServerConnector(this);
}
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
index 5c96798d94..bd8d472b99 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPAcceptorFactory.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
*/
package org.eclipse.net4j.internal.tcp;
@@ -29,6 +30,14 @@ public class TCPAcceptorFactory extends AcceptorFactory
super(TYPE);
}
+ /**
+ * Allows derived classes to override the TYPE identifier
+ */
+ protected TCPAcceptorFactory(String type)
+ {
+ super(type);
+ }
+
public TCPAcceptor create(String description)
{
String address = ITCPAcceptor.DEFAULT_ADDRESS;
@@ -48,12 +57,17 @@ public class TCPAcceptorFactory extends AcceptorFactory
}
}
- TCPAcceptor acceptor = new TCPAcceptor();
+ TCPAcceptor acceptor = createAcceptor();
acceptor.setAddress(address);
acceptor.setPort(port);
return acceptor;
}
+ protected TCPAcceptor createAcceptor()
+ {
+ return new TCPAcceptor();
+ }
+
@Override
public String getDescriptionFor(Object object)
{
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
index 5fe6fff1be..7711c705af 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPClientConnector.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
*/
package org.eclipse.net4j.internal.tcp;
@@ -47,18 +48,6 @@ public class TCPClientConnector extends TCPConnector
}
@Override
- public void setHost(String host)
- {
- super.setHost(host);
- }
-
- @Override
- public void setPort(int port)
- {
- super.setPort(port);
- }
-
- @Override
public String toString()
{
if (getUserID() == null)
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
index 1e578f3dec..78dbbb4a56 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnector.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
*/
package org.eclipse.net4j.internal.tcp;
@@ -75,7 +76,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
return host;
}
- void setHost(String host)
+ public void setHost(String host)
{
this.host = host;
}
@@ -85,7 +86,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
return port;
}
- void setPort(int port)
+ public void setPort(int port)
{
this.port = port;
}
@@ -113,11 +114,51 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
this.socketChannel = socketChannel;
}
+ public SelectionKey getSelectionKey()
+ {
+ return selectionKey;
+ }
+
+ public void setSelectionKey(SelectionKey selectionKey)
+ {
+ this.selectionKey = selectionKey;
+ }
+
+ public BlockingQueue<InternalChannel> getWriteQueue()
+ {
+ return writeQueue;
+ }
+
+ public void setWriteQueue(BlockingQueue<InternalChannel> writeQueue)
+ {
+ this.writeQueue = writeQueue;
+ }
+
+ public IBuffer getInputBuffer()
+ {
+ return inputBuffer;
+ }
+
+ public void setInputBuffer(IBuffer inputBuffer)
+ {
+ this.inputBuffer = inputBuffer;
+ }
+
+ public ControlChannel getControlChannel()
+ {
+ return controlChannel;
+ }
+
+ public void setControlChannel(ControlChannel controlChannel)
+ {
+ this.controlChannel = controlChannel;
+ }
+
@Override
public String getURL()
{
StringBuilder builder = new StringBuilder();
- builder.append("tcp://");
+ builder.append(getProtocolString());
builder.append(host);
if (port != DEFAULT_PORT)
{
@@ -128,6 +169,11 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
return builder.toString();
}
+ public String getProtocolString()
+ {
+ return "tcp://";
+ }
+
public void handleRegistration(ITCPSelector selector, SocketChannel socketChannel)
{
try
@@ -242,7 +288,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
{
if (selectionKey != null)
{
- selector.orderWriteInterest(selectionKey, isClient(), true);
+ doOrderWriteInterest(true);
}
}
}
@@ -277,7 +323,7 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
{
if (selectionKey != null)
{
- selector.orderWriteInterest(selectionKey, isClient(), false);
+ doOrderWriteInterest(false);
}
}
}
@@ -304,6 +350,11 @@ public abstract class TCPConnector extends Connector implements ITCPConnector, I
}
}
+ protected void doOrderWriteInterest(boolean on)
+ {
+ selector.orderWriteInterest(selectionKey, isClient(), on);
+ }
+
@Override
protected void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol) throws ChannelException
{
diff --git a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
index 49b7870749..0f818ddbc9 100644
--- a/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
+++ b/plugins/org.eclipse.net4j.tcp/src/org/eclipse/net4j/internal/tcp/TCPConnectorFactory.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
*/
package org.eclipse.net4j.internal.tcp;
@@ -33,7 +34,15 @@ public class TCPConnectorFactory extends ConnectorFactory
super(TYPE);
}
- public TCPClientConnector create(String description)
+ /**
+ * Allows derived classes to override the TYPE identifier
+ */
+ protected TCPConnectorFactory(String type)
+ {
+ super(type);
+ }
+
+ public TCPConnector create(String description)
{
try
{
@@ -48,7 +57,7 @@ public class TCPConnectorFactory extends ConnectorFactory
port = ITCPConnector.DEFAULT_PORT;
}
- TCPClientConnector connector = new TCPClientConnector();
+ TCPConnector connector = createConnector();
connector.setUserID(userID);
connector.setHost(host);
connector.setPort(port);
@@ -60,12 +69,17 @@ public class TCPConnectorFactory extends ConnectorFactory
}
}
+ protected TCPConnector createConnector()
+ {
+ return new TCPClientConnector();
+ }
+
@Override
public String getDescriptionFor(Object object)
{
- if (object instanceof TCPClientConnector)
+ if (object instanceof TCPConnector)
{
- TCPClientConnector connector = (TCPClientConnector)object;
+ TCPConnector connector = (TCPConnector)object;
String description = connector.getHost();
String userID = connector.getUserID();
if (!StringUtil.isEmpty(userID))

Back to the top