Author: trustin
Date: Thu Nov 4 07:31:32 2004
New Revision: 56598
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServiceEntry.java
incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
Log:
Added protocolProvider property (optional and writable) to InetServiceEntry.
Removed DefaultFrontend.register(ProtocolProvider) because
InetServiceEntry.setProtocolProvider() gives an immediate access to protocol
providers from EncoderManager and DecoderManager.
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
Thu Nov 4 07:31:32 2004
@@ -22,7 +22,6 @@
import org.apache.seda.decoder.DefaultDecoderManager;
import org.apache.seda.encoder.DefaultEncoderManager;
import org.apache.seda.encoder.EncoderManager;
-import org.apache.seda.event.AddProtocolEvent;
import org.apache.seda.event.EventRouter;
import org.apache.seda.input.InputManager;
import org.apache.seda.input.TCPInputManager;
@@ -34,7 +33,6 @@
import org.apache.seda.output.UDPOutputManager;
import org.apache.seda.protocol.DefaultRequestProcessor;
import org.apache.seda.protocol.InetServicesDatabase;
-import org.apache.seda.protocol.ProtocolProvider;
import org.apache.seda.protocol.RequestProcessor;
@@ -80,12 +78,6 @@
this.udpOutMan = udpOutMan;
this.reqProc = reqProc;
this.inetDb = inetDb;
- }
-
- public void register(ProtocolProvider provider)
- {
- AddProtocolEvent event = new AddProtocolEvent(provider);
- router.publish(event);
}
public void stop() throws Exception
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
Thu Nov 4 07:31:32 2004
@@ -68,20 +68,20 @@
// create dependent services in order
TCPListenerManager tcpListenerMan = createTCPListenerManager(router);
- UDPListenerManager udpListenerMan = createUDPListenerManager(router,
bp);
+ UDPListenerManager udpListenerMan =
+ createUDPListenerManager(router, bp);
TCPInputManager tcpInMan = createTCPInputManager(router, bp);
TCPOutputManager tcpOutMan = createTCPOutputManager(router);
UDPOutputManager udpOutMan = createUDPOutputManager(router);
-
+
DecoderManager decMan = createDecoderManager(router, inetDb);
EncoderManager encMan = createEncoderManager(router, inetDb);
RequestProcessor reqProc = createRequestProcessor(router, inetDb);
DefaultFrontend fe =
- new DefaultFrontend(
- bp, decMan, encMan, router, tcpInMan,
- tcpListenerMan,
udpListenerMan,
- tcpOutMan, udpOutMan, reqProc, inetDb);
+ new DefaultFrontend(bp, decMan, encMan, router, tcpInMan,
+ tcpListenerMan, udpListenerMan, tcpOutMan,
+ udpOutMan, reqProc, inetDb);
return fe;
}
@@ -109,8 +109,9 @@
private InetServicesDatabase createServicesDatabase()
{
InetServiceEntry[] entries =
- { new InetServiceEntry("echo", 7), new InetServiceEntry(
- "ldap",
389) };
+ { new InetServiceEntry("echo", 7, null), new
InetServiceEntry("ldap",
+ 389,
+
null) };
// @todo add a monitor interface for this service and logging impl
InetServicesDatabase inetDb = new DefaultInetServicesDatabase(entries);
@@ -121,10 +122,14 @@
private ThreadPool createThreadPool(int threads, boolean ordered)
{
AbstractThreadPool pool;
- if (ordered) {
- pool = new OrderedThreadPool();
- } else {
- pool = new SimpleThreadPool();
+
+ if (ordered)
+ {
+ pool = new OrderedThreadPool();
+ }
+ else
+ {
+ pool = new SimpleThreadPool();
}
pool.setThreadPoolSize(threads);
@@ -133,8 +138,7 @@
}
// deps on router, inetDb, and listener
- private DecoderManager createDecoderManager(
- EventRouter router,
+ private DecoderManager createDecoderManager(EventRouter router,
InetServicesDatabase inetDb)
{
DefaultStageConfig config =
@@ -148,11 +152,10 @@
}
// deps on router, inetDb, and listener
- private EncoderManager createEncoderManager(
- EventRouter router,
+ private EncoderManager createEncoderManager(EventRouter router,
InetServicesDatabase inetDb)
{
- // FIXME EncoderManager doesn't need to have an ordered thread pool.
+ // FIXME EncoderManager doesn't need to have an ordered thread pool.
DefaultStageConfig config =
new DefaultStageConfig("encoderManager", createThreadPool(3,
true));
DefaultEncoderManager encMan =
@@ -164,23 +167,25 @@
}
private TCPListenerManager createTCPListenerManager(EventRouter router)
- throws IOException
+ throws IOException
{
TCPListenerManager listMan = new TCPListenerManager(router);
listMan.start();
return listMan;
}
- private UDPListenerManager createUDPListenerManager(EventRouter router,
BufferPool bp)
- throws
IOException
- {
- UDPListenerManager listMan = new UDPListenerManager(router, bp);
- listMan.start();
- return listMan;
- }
+ private UDPListenerManager createUDPListenerManager(EventRouter router,
+ BufferPool bp)
+ throws IOException
+ {
+ UDPListenerManager listMan = new UDPListenerManager(router, bp);
+ listMan.start();
+ return listMan;
+ }
- private TCPInputManager createTCPInputManager(EventRouter router,
BufferPool bp)
- throws IOException
+ private TCPInputManager createTCPInputManager(EventRouter router,
+ BufferPool bp)
+ throws IOException
{
TCPInputManager inMan = new TCPInputManager(router, bp);
inMan.start();
@@ -190,7 +195,8 @@
private TCPOutputManager createTCPOutputManager(EventRouter router)
{
DefaultStageConfig config =
- new DefaultStageConfig("tcpOutputManager", createThreadPool(3,
true));
+ new DefaultStageConfig("tcpOutputManager",
+ createThreadPool(3, true));
TCPOutputManager outMan = new TCPOutputManager(router, config);
outMan.start();
return outMan;
@@ -199,19 +205,20 @@
private UDPOutputManager createUDPOutputManager(EventRouter router)
{
DefaultStageConfig config =
- new DefaultStageConfig("udpOutputManager", createThreadPool(3,
true));
+ new DefaultStageConfig("udpOutputManager",
+ createThreadPool(3, true));
UDPOutputManager outMan = new UDPOutputManager(router, config);
outMan.start();
return outMan;
}
- private RequestProcessor createRequestProcessor(
- EventRouter router,
+ private RequestProcessor createRequestProcessor(EventRouter router,
InetServicesDatabase
inetDb)
{
- // FIXME RequestProcessor doesn't need to have an ordered thread pool.
+ // FIXME RequestProcessor doesn't need to have an ordered thread pool.
DefaultStageConfig config =
- new DefaultStageConfig("requestProcessor", createThreadPool(3,
true));
+ new DefaultStageConfig("requestProcessor",
+ createThreadPool(3, true));
DefaultRequestProcessor reqProc =
new DefaultRequestProcessor(router, config, inetDb);
reqProc.start();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
Thu Nov 4 07:31:32 2004
@@ -98,7 +98,7 @@
if (
(ise != null)
- && (ise.getProtocol() == entry.getProtocol()))
+ && (ise.getTransport() == entry.getTransport()))
{
list.remove(ise);
}
@@ -123,7 +123,7 @@
if (
(ise != null)
- && (ise.getProtocol() == entry.getProtocol()))
+ && (ise.getTransport() == entry.getTransport()))
{
list.remove(ise);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServiceEntry.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServiceEntry.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServiceEntry.java
Thu Nov 4 07:31:32 2004
@@ -39,7 +39,10 @@
private final String[] aliases;
/** the transport protocol used by the service */
- private final TransportTypeEnum proto;
+ private final TransportTypeEnum transport;
+
+ /** the protocol provider of this service */
+ private ProtocolProvider protocolProvider;
/**
* Creates an internet service entry without any aliases using TCP as the
@@ -47,10 +50,12 @@
*
* @param name the authoritative name of the service
* @param port the port the service runs on
+ * @param protocolProvider the protocol provider of this service.
<code>null</code> if not available.
*/
- public InetServiceEntry(String name, int port)
+ public InetServiceEntry(String name, int port,
+ ProtocolProvider protocolProvider)
{
- this(name, port, TransportTypeEnum.TCP, null);
+ this(name, port, protocolProvider, TransportTypeEnum.TCP, null);
}
/**
@@ -58,11 +63,14 @@
*
* @param name the authoritative name of the service
* @param port the port the service runs on
- * @param proto the transport protocol used by the service
+ * @param protocolProvider the protocol provider of this service.
<code>null</code> if not available.
+ * @param transport the transport protocol used by the service
*/
- public InetServiceEntry(String name, int port, TransportTypeEnum proto)
+ public InetServiceEntry(String name, int port,
+ ProtocolProvider protocolProvider,
+ TransportTypeEnum transport)
{
- this(name, port, proto, null);
+ this(name, port, protocolProvider, transport, null);
}
/**
@@ -70,12 +78,13 @@
*
* @param name the authoritative name of the service
* @param port the port the service runs on
- * @param proto the transport protocol used by the service
+ * @param protocolProvider the protocol provider of this service.
<code>null</code> if not available.
+ * @param transport the transport protocol used by the service
* @param aliases alternative names for the service
*/
- public InetServiceEntry(
- String name, int port, TransportTypeEnum proto,
- String[] aliases)
+ public InetServiceEntry(String name, int port,
+ ProtocolProvider protocolProvider,
+ TransportTypeEnum transport, String[] aliases)
{
if (name == null)
{
@@ -84,9 +93,10 @@
this.name = name;
this.port = port;
- this.proto = proto;
+ this.protocolProvider = protocolProvider;
+ this.transport = transport;
- if (proto == null)
+ if (transport == null)
{
throw new NullPointerException("transport can't be null");
}
@@ -136,8 +146,25 @@
*
* @return the transport protocol used for this service
*/
- public TransportTypeEnum getProtocol()
+ public TransportTypeEnum getTransport()
{
- return proto;
+ return transport;
+ }
+
+ /**
+ * Returns the protocol provider of this service. <code>null</code> if not
available.
+ *
+ * @return <code>null</code> if no protocol provider is available
+ */
+ public ProtocolProvider getProtocolProvider()
+ {
+ return protocolProvider;
+ }
+
+ /**
+ * Sets the protocol provider of this service.
+ */
+ public void setProtocolProvider(ProtocolProvider protocolProvider) {
+ this.protocolProvider = protocolProvider;
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
Thu Nov 4 07:31:32 2004
@@ -93,9 +93,8 @@
int port = AvailablePortFinder.getNextAvailable();
ListenerConfig config = null;
config =
- new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry("ldap", port));
+ new TCPListenerConfig(InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port, null));
fe.getTCPListenerManager().bind(config);
fe.getTCPListenerManager().unbind(config);
}
@@ -103,15 +102,14 @@
public void testEcho() throws IOException
{
InetServiceEntry srvEntry =
- new InetServiceEntry(
- "echo",
- AvailablePortFinder.getNextAvailable(6666));
+ new InetServiceEntry("echo",
+ AvailablePortFinder.getNextAvailable(6666),
+ new EchoProtocolProvider());
((DefaultInetServicesDatabase)
fe.getInetServicesDatabase()).addEntry(srvEntry);
ListenerConfig config = null;
config = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry);
fe.getTCPListenerManager().bind(config);
- fe.register(new EchoProtocolProvider());
EchoTCPClient client = new EchoTCPClient();
client.connect(InetAddress.getLocalHost(), srvEntry.getPort());
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
Thu Nov 4 07:31:32 2004
@@ -81,12 +81,10 @@
this.port = AvailablePortFinder.getNextAvailable(6666);
InetServiceEntry srvEntry =
- new InetServiceEntry(proto.getName(), port);
+ new InetServiceEntry(proto.getName(), port, proto);
((DefaultInetServicesDatabase)
fe.getInetServicesDatabase()).addEntry(srvEntry);
config = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry);
fe.getTCPListenerManager().bind(config);
- fe.register(proto);
-
}
public static void assertEquals(byte[] expected, byte[] actual) {
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
Thu Nov 4 07:31:32 2004
@@ -77,9 +77,8 @@
{
int port = AvailablePortFinder.getNextAvailable();
ListenerConfig config =
- new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry("ldap", port));
+ new TCPListenerConfig(InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port, null));
listener.bind(config);
listener.unbind(config);
}
@@ -88,9 +87,8 @@
{
int port = AvailablePortFinder.getNextAvailable();
ListenerConfig config =
- new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry("ldap", port));
+ new TCPListenerConfig(InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port, null));
listener.bind(config);
listener.unbind(config);
}