Author: trustin
Date: Sat Oct 30 04:31:52 2004
New Revision: 56039
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/DiscardProtocolProvider.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoProtocolProvider.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullDecoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullEncoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruDecoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruEncoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontend.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/DefaultFrontendFactory.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/Frontend.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/ResourceException.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPool.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPool.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/ClientDecoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecodeStageHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/ClientEncoder.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncodeStageHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AbstractSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AddProtocolEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ClientEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Filter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RoutingAdvice.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationSubscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionEvent.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionListener.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscriber.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SubscriberMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/event/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/Enum.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/EnumUtils.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/ValuedEnum.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/input/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ClientKey.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/KeyExpiryException.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPClientKey.java
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPClientKey.java
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/LoggingOutputMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
incubator/directory/seda/trunk/src/java/org/apache/seda/output/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServiceEntry.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServicesDatabase.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ManyReplyHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/NoReplyHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ProtocolProvider.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/SingleReplyHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/TransportTypeEnum.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/package.html
(props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/session/ClientSession.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStage.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStageConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/EnqueuePredicate.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/LoggingStageMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/Stage.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageConfig.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageHandler.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitor.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitorAdapter.java
(contents, props changed)
incubator/directory/seda/trunk/src/java/org/apache/seda/thread/ThreadPool.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/ProtocolTestCase.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/event/AbstractSubscriberTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/event/DefaultStageTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
(contents, props changed)
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
(contents, props changed)
Log:
* Reformatted using Jalopy
* Set keyword substitution properties
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/DiscardProtocolProvider.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/DiscardProtocolProvider.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/DiscardProtocolProvider.java
Sat Oct 30 04:31:52 2004
@@ -14,18 +14,17 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
-
-import org.apache.seda.protocol.RequestHandler;
-import org.apache.seda.protocol.ProtocolProvider;
-import org.apache.seda.protocol.NoReplyHandler;
-import org.apache.seda.protocol.HandlerTypeEnum;
+package org.apache.seda.examples;
import org.apache.commons.codec.stateful.DecoderFactory;
import org.apache.commons.codec.stateful.EncoderFactory;
import org.apache.commons.codec.stateful.StatefulDecoder;
import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.seda.protocol.HandlerTypeEnum;
+import org.apache.seda.protocol.NoReplyHandler;
+import org.apache.seda.protocol.ProtocolProvider;
+import org.apache.seda.protocol.RequestHandler;
/**
@@ -36,66 +35,47 @@
* @version $Rev$
*/
public class DiscardProtocolProvider implements ProtocolProvider,
- DecoderFactory, EncoderFactory
-{
+ DecoderFactory, EncoderFactory
{
/** a null do nothing decoder that swallows all input */
public static final StatefulDecoder NULL_DECODER = new NullDecoder();
+
/** a null do nothing encoder that swallows all input */
public static final StatefulEncoder NULL_ENCODER = new NullEncoder();
-
// ------------------------------------------------------------------------
// ProtocolProvider Methods
// ------------------------------------------------------------------------
-
-
- public String getName()
- {
+ public String getName() {
return "discard";
}
-
- public DecoderFactory getDecoderFactory()
- {
+ public DecoderFactory getDecoderFactory() {
return this;
}
-
- public EncoderFactory getEncoderFactory()
- {
+ public EncoderFactory getEncoderFactory() {
return this;
}
-
- public RequestHandler getHandler( Object request )
- {
- return new NoReplyHandler()
- {
- public void handle( Object request )
- {
- }
-
- public HandlerTypeEnum getHandlerType()
- {
- return HandlerTypeEnum.NOREPLY;
- }
- };
+ public RequestHandler getHandler(Object request) {
+ return new NoReplyHandler() {
+ public void handle(Object request) {
+ }
+
+ public HandlerTypeEnum getHandlerType() {
+ return HandlerTypeEnum.NOREPLY;
+ }
+ };
}
-
// ------------------------------------------------------------------------
// Factory Methods
// ------------------------------------------------------------------------
-
-
- public StatefulDecoder createDecoder()
- {
+ public StatefulDecoder createDecoder() {
return NULL_DECODER;
}
-
- public StatefulEncoder createEncoder()
- {
+ public StatefulEncoder createEncoder() {
return NULL_ENCODER;
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoProtocolProvider.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoProtocolProvider.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoProtocolProvider.java
Sat Oct 30 04:31:52 2004
@@ -14,15 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
-import org.apache.seda.protocol.RequestHandler;
+import org.apache.commons.codec.stateful.*;
import org.apache.seda.protocol.ProtocolProvider;
+import org.apache.seda.protocol.RequestHandler;
import org.apache.seda.protocol.SingleReplyHandler;
-import org.apache.commons.codec.stateful.*;
-
/**
* An echo protocol service provider for the SEDA framework. The provider
along
@@ -31,24 +30,28 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public final class EchoProtocolProvider implements ProtocolProvider
-{
+public final class EchoProtocolProvider implements ProtocolProvider {
/** the authoritative service name of this internet protocol: 'echo' */
public static final String NAME = "echo";
+
/** a null decoder that triggers a callback returning the substrate as is
*/
- public static final StatefulDecoder PASSTHRU_DECODER = new
PassThruDecoder();
+ public static final StatefulDecoder PASSTHRU_DECODER =
+ new PassThruDecoder();
+
/** a null encoder that triggers a callback returning the substrate as is
*/
- public static final StatefulEncoder PASSTHRU_ENCODER = new
PassThruEncoder();
+ public static final StatefulEncoder PASSTHRU_ENCODER =
+ new PassThruEncoder();
+
/** echo handler where request is return back as a response */
- public static final SingleReplyHandler PASSTHRU_HANDLER = new
PassThruHandler();
+ public static final SingleReplyHandler PASSTHRU_HANDLER =
+ new PassThruHandler();
/**
* Gets the authoritative name for the service of this provider.
*
* @return the authoritative service name
*/
- public final String getName()
- {
+ public final String getName() {
return NAME;
}
@@ -58,23 +61,20 @@
*
* @return a new StatefulDecoder for this service's protocol
*/
- public final DecoderFactory getDecoderFactory()
- {
- return new DecoderFactory()
- {
- /**
- * Creates a really simple factory for decoders that return back
- * thir request in the same decode call; 1:1 decode to callback.
- * The same decoder will be returned evertime since no state is
- * ever stored by these decoders.
- *
- * @return a chunking state based decoder
- */
- public StatefulDecoder createDecoder()
- {
- return PASSTHRU_DECODER;
- }
- };
+ public final DecoderFactory getDecoderFactory() {
+ return new DecoderFactory() {
+ /**
+ * Creates a really simple factory for decoders that return
back
+ * thir request in the same decode call; 1:1 decode to
callback.
+ * The same decoder will be returned evertime since no state is
+ * ever stored by these decoders.
+ *
+ * @return a chunking state based decoder
+ */
+ public StatefulDecoder createDecoder() {
+ return PASSTHRU_DECODER;
+ }
+ };
}
/**
@@ -83,22 +83,19 @@
*
* @return a new StatefulEncoder for this service's protocol
*/
- public EncoderFactory getEncoderFactory()
- {
- return new EncoderFactory()
- {
- /**
- * Creates a factory that always returns the same encoder which
- * never really maintains any state. This encoder simply returns
- * the object to encode as is without affecting it in any way.
- *
- * @return a new chunking state based encoder
- */
- public StatefulEncoder createEncoder()
- {
- return PASSTHRU_ENCODER;
- }
- };
+ public EncoderFactory getEncoderFactory() {
+ return new EncoderFactory() {
+ /**
+ * Creates a factory that always returns the same encoder which
+ * never really maintains any state. This encoder simply
returns
+ * the object to encode as is without affecting it in any way.
+ *
+ * @return a new chunking state based encoder
+ */
+ public StatefulEncoder createEncoder() {
+ return PASSTHRU_ENCODER;
+ }
+ };
}
/**
@@ -112,8 +109,7 @@
* @param request the ByteBuffer containing the data to echo
* @return the same ByteBuffer without any changes
*/
- public RequestHandler getHandler( Object request )
- {
+ public RequestHandler getHandler(Object request) {
return PASSTHRU_HANDLER;
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/EchoTest.java
Sat Oct 30 04:31:52 2004
@@ -1,41 +1,53 @@
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.seda.examples;
import org.apache.commons.net.EchoTCPClient;
-public class EchoTest
-{
- public static void main(String[]args)
- {
+public class EchoTest {
+ public static void main(String[] args) {
byte[] recieved = null;
- try
- {
+ try {
EchoTCPClient client = new EchoTCPClient();
- client.connect( args[0], 7 );
+ client.connect(args[0], 7);
+
byte[] toSend = args[1].getBytes();
recieved = new byte[toSend.length];
- client.getOutputStream().write( toSend );
- client.getInputStream().read( recieved );
+ client.getOutputStream().write(toSend);
+ client.getInputStream().read(recieved);
client.disconnect();
- }
- catch( Exception e )
- {
+ } catch (Exception e) {
e.printStackTrace();
- System.out.println( "echo of '" + args[1] +
- "' to " + args[0] + " failed!" );
- System.exit( 1 );
+ System.out.println("echo of '" + args[1] + "' to " + args[0]
+ + " failed!");
+ System.exit(1);
}
- if ( args[1].equals( new String( recieved ) ) )
- {
- System.out.println( "Successfully echo'd '" + args[1] +
- "' to " + args[0] ) ;
- System.exit( 0 );
+ if (args[1].equals(new String(recieved))) {
+ System.out.println("Successfully echo'd '" + args[1] + "' to "
+ + args[0]);
+ System.exit(0);
}
- System.out.println( "echo of '" + args[1] + "' to "
- + args[0] + " failed!" );
- System.exit( 2 );
- }
+ System.out.println("echo of '" + args[1] + "' to " + args[0]
+ + " failed!");
+ System.exit(2);
+ }
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullDecoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullDecoder.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullDecoder.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
import org.apache.commons.codec.stateful.AbstractStatefulDecoder;
@@ -26,14 +26,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class NullDecoder extends AbstractStatefulDecoder
-{
+public class NullDecoder extends AbstractStatefulDecoder {
/**
- * Does nothing at all.
+ * Does nothing at all.
*
* @param encoded the object
*/
- public void decode( Object encoded )
- {
+ public void decode(Object encoded) {
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullEncoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullEncoder.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/NullEncoder.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
@@ -26,14 +26,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class NullEncoder extends AbstractStatefulEncoder
-{
+public class NullEncoder extends AbstractStatefulEncoder {
/**
- * Does nothing at all.
+ * Does nothing at all.
*
* @param substrate the object to encode which is just ignored
*/
- public void encode( Object substrate )
- {
+ public void encode(Object substrate) {
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruDecoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruDecoder.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruDecoder.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
import org.apache.commons.codec.stateful.AbstractStatefulDecoder;
@@ -27,8 +27,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class PassThruDecoder extends AbstractStatefulDecoder
-{
+public class PassThruDecoder extends AbstractStatefulDecoder {
/**
* Simply returns back the encoded data as is. The codec is an identity
* operation. Each decode call triggers a callback since we're presuming
@@ -36,8 +35,7 @@
*
* @param encoded the object to return which is a buffer
*/
- public void decode( Object encoded )
- {
- super.decodeOccurred( encoded );
+ public void decode(Object encoded) {
+ super.decodeOccurred(encoded);
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruEncoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruEncoder.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruEncoder.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
import org.apache.commons.codec.stateful.AbstractStatefulEncoder;
@@ -27,8 +27,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class PassThruEncoder extends AbstractStatefulEncoder
-{
+public class PassThruEncoder extends AbstractStatefulEncoder {
/**
* Simply returns back the decoded data as is. The codec is an identity
* operation. Each encode call triggers a callback since we're presuming
@@ -37,8 +36,7 @@
*
* @param substrate the object to return which is a buffer
*/
- public void encode( Object substrate )
- {
- super.encodeOccurred( substrate );
+ public void encode(Object substrate) {
+ super.encodeOccurred(substrate);
}
}
Modified:
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruHandler.java
(original)
+++
incubator/directory/seda/trunk/src/examples/org/apache/seda/examples/PassThruHandler.java
Sat Oct 30 04:31:52 2004
@@ -14,11 +14,11 @@
* limitations under the License.
*
*/
-package org.apache.seda.examples;
+package org.apache.seda.examples;
-import org.apache.seda.protocol.SingleReplyHandler;
import org.apache.seda.protocol.HandlerTypeEnum;
+import org.apache.seda.protocol.SingleReplyHandler;
/**
@@ -28,27 +28,23 @@
* Project</a>
* @version $Rev$
*/
-public class PassThruHandler implements SingleReplyHandler
-{
+public class PassThruHandler implements SingleReplyHandler {
/**
* Returns the request back without any changes as a response.
*
* @param request the buffer of data to be echo'd.
* @return the response to the request but resp = req here.
*/
- public Object handle( Object request )
- {
+ public Object handle(Object request) {
return request;
}
-
/**
* Gets the handler type.
*
* @return a HandlerTypeEnum constant.
*/
- public HandlerTypeEnum getHandlerType()
- {
+ public HandlerTypeEnum getHandlerType() {
return HandlerTypeEnum.SINGLEREPLY;
}
}
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
Sat Oct 30 04:31:52 2004
@@ -14,39 +14,38 @@
* limitations under the License.
*
*/
-package org.apache.seda;
+package org.apache.seda;
import org.apache.seda.buffer.BufferPool;
-import org.apache.seda.event.EventRouter;
-import org.apache.seda.event.AddProtocolEvent;
import org.apache.seda.decoder.DecoderManager;
import org.apache.seda.decoder.DefaultDecoderManager;
-import org.apache.seda.encoder.EncoderManager;
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;
import org.apache.seda.listener.ListenerManager;
import org.apache.seda.listener.TCPListenerManager;
import org.apache.seda.output.OutputManager;
import org.apache.seda.output.TCPOutputManager;
-import org.apache.seda.protocol.RequestProcessor;
-import org.apache.seda.protocol.InetServicesDatabase;
import org.apache.seda.protocol.DefaultRequestProcessor;
+import org.apache.seda.protocol.InetServicesDatabase;
import org.apache.seda.protocol.ProtocolProvider;
+import org.apache.seda.protocol.RequestProcessor;
/**
- * A container neutral implementation of the Eve frontend. There really is
- * nothing here but this will evolve as we determine the use cases for
- * applications embedding the frontend and accessing it outside of the
+ * A container neutral implementation of the Eve frontend. There really is
+ * nothing here but this will evolve as we determine the use cases for
+ * applications embedding the frontend and accessing it outside of the
* container.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultFrontend implements Frontend
-{
+public class DefaultFrontend implements Frontend {
private final BufferPool bp;
private final DecoderManager decMan;
private final EncoderManager encMan;
@@ -57,12 +56,11 @@
private final RequestProcessor reqProc;
private final InetServicesDatabase inetDb;
- DefaultFrontend( BufferPool bp, DecoderManager decMan,
- EncoderManager encMan, EventRouter router,
- InputManager inMan, ListenerManager srvMan,
- OutputManager outMan, RequestProcessor reqProc,
- InetServicesDatabase inetDb )
- {
+ DefaultFrontend(
+ BufferPool bp, DecoderManager decMan, EncoderManager
encMan,
+ EventRouter router, InputManager inMan,
+ ListenerManager srvMan, OutputManager outMan,
+ RequestProcessor reqProc, InetServicesDatabase inetDb) {
this.bp = bp;
this.decMan = decMan;
this.encMan = encMan;
@@ -74,67 +72,53 @@
this.inetDb = inetDb;
}
-
- public void register( ProtocolProvider provider )
- {
- AddProtocolEvent event = new AddProtocolEvent( provider );
- router.publish( event );
+ public void register(ProtocolProvider provider) {
+ AddProtocolEvent event = new AddProtocolEvent(provider);
+ router.publish(event);
}
-
- public void stop() throws Exception
- {
- ( ( TCPListenerManager ) srvMan ).stop();
- ( ( TCPInputManager ) inMan ).stop();
- ( ( TCPOutputManager ) outMan ).stop();
- ( ( DefaultRequestProcessor ) reqProc ).stop();
- ( ( DefaultDecoderManager ) decMan ).stop();
- ( ( DefaultEncoderManager ) encMan ).stop();
+ public void stop() throws Exception {
+ ((TCPListenerManager) srvMan).stop();
+ ((TCPInputManager) inMan).stop();
+ ((TCPOutputManager) outMan).stop();
+ ((DefaultRequestProcessor) reqProc).stop();
+ ((DefaultDecoderManager) decMan).stop();
+ ((DefaultEncoderManager) encMan).stop();
}
-
- public BufferPool getBufferPool()
- {
+ public BufferPool getBufferPool() {
return bp;
}
- public DecoderManager getDecoderManager()
- {
+ public DecoderManager getDecoderManager() {
return decMan;
}
- public EncoderManager getEncoderManager()
- {
+ public EncoderManager getEncoderManager() {
return encMan;
}
- public EventRouter getEventRouter()
- {
+ public EventRouter getEventRouter() {
return router;
}
- public InputManager getInputManager()
- {
+ public InputManager getInputManager() {
return inMan;
}
- public ListenerManager getListenerManager()
- {
+ public ListenerManager getListenerManager() {
return srvMan;
}
- public OutputManager getOutputManager()
- {
+ public OutputManager getOutputManager() {
return outMan;
}
- public RequestProcessor getRequestProcessor()
- {
+ public RequestProcessor getRequestProcessor() {
return reqProc;
}
- public InetServicesDatabase getInetServicesDatabase()
- {
+ public InetServicesDatabase getInetServicesDatabase() {
return inetDb;
}
}
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
Sat Oct 30 04:31:52 2004
@@ -14,35 +14,35 @@
* limitations under the License.
*
*/
+
package org.apache.seda;
+import java.io.IOException;
+import org.apache.commons.threadpool.CommonsLoggingThreadPoolMonitor;
+import org.apache.commons.threadpool.DefaultThreadPool;
import org.apache.seda.buffer.BufferPool;
import org.apache.seda.buffer.DefaultBufferPool;
import org.apache.seda.buffer.DefaultBufferPoolConfig;
import org.apache.seda.buffer.LoggingBufferMonitor;
-import org.apache.seda.event.EventRouter;
-import org.apache.seda.event.DefaultEventRouter;
-import org.apache.seda.event.EventRouterMonitorAdapter;
-import org.apache.seda.protocol.*;
+import org.apache.seda.decoder.DecodeStageHandler;
import org.apache.seda.decoder.DecoderManager;
import org.apache.seda.decoder.DefaultDecoderManager;
-import org.apache.seda.decoder.DecodeStageHandler;
-import org.apache.seda.stage.DefaultStageConfig;
-import org.apache.seda.thread.ThreadPool;
-import org.apache.seda.encoder.EncoderManager;
import org.apache.seda.encoder.DefaultEncoderManager;
import org.apache.seda.encoder.EncodeStageHandler;
-import org.apache.seda.listener.ListenerManager;
-import org.apache.seda.listener.TCPListenerManager;
+import org.apache.seda.encoder.EncoderManager;
+import org.apache.seda.event.DefaultEventRouter;
+import org.apache.seda.event.EventRouter;
+import org.apache.seda.event.EventRouterMonitorAdapter;
import org.apache.seda.input.InputManager;
import org.apache.seda.input.TCPInputManager;
+import org.apache.seda.listener.ListenerManager;
+import org.apache.seda.listener.TCPListenerManager;
import org.apache.seda.output.OutputManager;
import org.apache.seda.output.TCPOutputManager;
-import org.apache.commons.threadpool.DefaultThreadPool;
-import org.apache.commons.threadpool.CommonsLoggingThreadPoolMonitor;
-
-import java.io.IOException;
+import org.apache.seda.protocol.*;
+import org.apache.seda.stage.DefaultStageConfig;
+import org.apache.seda.thread.ThreadPool;
/**
@@ -53,148 +53,129 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultFrontendFactory implements FrontendFactory
-{
- public Frontend create() throws Exception
- {
+public class DefaultFrontendFactory implements FrontendFactory {
+ public Frontend create() throws Exception {
// create all services that do not have any deps on other services
BufferPool bp = createBufferPool();
EventRouter router = createEventRouter();
InetServicesDatabase inetDb = createServicesDatabase();
// create dependent services in order
- ListenerManager listMan = createListenerManager( router );
- InputManager inMan = createInputManager( router, bp );
- OutputManager outMan = createOutputManager( router );
- DecoderManager decMan = createDecoderManager( router, inetDb );
- EncoderManager encMan = createEncoderManager( router, inetDb );
- RequestProcessor reqProc = createRequestProcessor( router, inetDb );
-
- DefaultFrontend fe = new DefaultFrontend( bp, decMan, encMan, router,
- inMan, listMan, outMan, reqProc, inetDb );
+ ListenerManager listMan = createListenerManager(router);
+ InputManager inMan = createInputManager(router, bp);
+ OutputManager outMan = createOutputManager(router);
+ DecoderManager decMan = createDecoderManager(router, inetDb);
+ EncoderManager encMan = createEncoderManager(router, inetDb);
+ RequestProcessor reqProc = createRequestProcessor(router, inetDb);
+
+ DefaultFrontend fe =
+ new DefaultFrontend(
+ bp, decMan, encMan, router, inMan, listMan,
+ outMan, reqProc, inetDb);
return fe;
}
-
// no deps
- private BufferPool createBufferPool()
- {
- DefaultBufferPoolConfig config = new DefaultBufferPoolConfig(
- "", 10, 100, 20, 20 );
- DefaultBufferPool bp = new DefaultBufferPool( config ) ;
- bp.setMonitor( new LoggingBufferMonitor( "bufferPool" ) );
+ private BufferPool createBufferPool() {
+ DefaultBufferPoolConfig config =
+ new DefaultBufferPoolConfig("", 10, 100, 20, 20);
+ DefaultBufferPool bp = new DefaultBufferPool(config);
+ bp.setMonitor(new LoggingBufferMonitor("bufferPool"));
return bp;
}
-
// no deps
- private EventRouter createEventRouter()
- {
+ private EventRouter createEventRouter() {
DefaultEventRouter router = new DefaultEventRouter();
// @todo start using a logging monitor for event router
- router.setMonitor( new EventRouterMonitorAdapter() );
+ router.setMonitor(new EventRouterMonitorAdapter());
return router;
}
-
// no deps
- private InetServicesDatabase createServicesDatabase()
- {
- InetServiceEntry[] entries = {
- new InetServiceEntry( "echo", 7 ),
- new InetServiceEntry( "ldap", 389 )
- };
+ private InetServicesDatabase createServicesDatabase() {
+ InetServiceEntry[] entries =
+ { new InetServiceEntry("echo", 7), new InetServiceEntry(
+ "ldap",
389) };
// @todo add a monitor interface for this service and logging impl
- InetServicesDatabase inetDb =
- new DefaultInetServicesDatabase( entries );
+ InetServicesDatabase inetDb = new DefaultInetServicesDatabase(entries);
return inetDb;
}
-
// no deps
- private ThreadPool createThreadPool( int threads )
- {
+ private ThreadPool createThreadPool(int threads) {
CommonsLoggingThreadPoolMonitor monitor =
new CommonsLoggingThreadPoolMonitor();
- final DefaultThreadPool ctp = new DefaultThreadPool( monitor, threads
);
- ThreadPool pool = new ThreadPool()
- {
- public void execute( Runnable runnable )
- {
- ctp.invokeLater( runnable );
- }
- };
+ final DefaultThreadPool ctp = new DefaultThreadPool(monitor, threads);
+ ThreadPool pool =
+ new ThreadPool() {
+ public void execute(Runnable runnable) {
+ ctp.invokeLater(runnable);
+ }
+ };
+
return pool;
}
-
// deps on router, inetDb, and listener
- private DecoderManager createDecoderManager( EventRouter router,
- InetServicesDatabase inetDb )
- {
- DefaultStageConfig config = new DefaultStageConfig( "decoderManager",
- createThreadPool( 3 ) );
- DefaultDecoderManager decMan = new DefaultDecoderManager( router,
- config, inetDb );
- DecodeStageHandler handler = new DecodeStageHandler( decMan );
- config.setHandler( handler );
+ private DecoderManager createDecoderManager(
+ EventRouter router,
+ InetServicesDatabase inetDb) {
+ DefaultStageConfig config =
+ new DefaultStageConfig("decoderManager", createThreadPool(3));
+ DefaultDecoderManager decMan =
+ new DefaultDecoderManager(router, config, inetDb);
+ DecodeStageHandler handler = new DecodeStageHandler(decMan);
+ config.setHandler(handler);
decMan.start();
return decMan;
}
-
// deps on router, inetDb, and listener
- private EncoderManager createEncoderManager( EventRouter router,
- InetServicesDatabase inetDb )
- {
- DefaultStageConfig config = new DefaultStageConfig( "encoderManager",
- createThreadPool( 3 ) );
- DefaultEncoderManager encMan = new DefaultEncoderManager( router,
- config, inetDb );
- EncodeStageHandler handler = new EncodeStageHandler( encMan );
- config.setHandler( handler );
+ private EncoderManager createEncoderManager(
+ EventRouter router,
+ InetServicesDatabase inetDb) {
+ DefaultStageConfig config =
+ new DefaultStageConfig("encoderManager", createThreadPool(3));
+ DefaultEncoderManager encMan =
+ new DefaultEncoderManager(router, config, inetDb);
+ EncodeStageHandler handler = new EncodeStageHandler(encMan);
+ config.setHandler(handler);
encMan.start();
return encMan;
}
-
- private ListenerManager createListenerManager( EventRouter router )
- throws IOException
- {
- TCPListenerManager listMan = new TCPListenerManager( router );
+ private ListenerManager createListenerManager(EventRouter router)
+ throws IOException {
+ TCPListenerManager listMan = new TCPListenerManager(router);
listMan.start();
return listMan;
}
-
- private InputManager createInputManager( EventRouter router, BufferPool bp
)
- throws IOException
- {
- TCPInputManager inMan = new TCPInputManager( router, bp );
+ private InputManager createInputManager(EventRouter router, BufferPool bp)
+ throws IOException {
+ TCPInputManager inMan = new TCPInputManager(router, bp);
inMan.start();
return inMan;
}
-
- private OutputManager createOutputManager( EventRouter router )
- {
- DefaultStageConfig config = new DefaultStageConfig( "outputManager",
- createThreadPool( 3 ) );
- TCPOutputManager outMan = new TCPOutputManager( router, config );
+ private OutputManager createOutputManager(EventRouter router) {
+ DefaultStageConfig config =
+ new DefaultStageConfig("outputManager", createThreadPool(3));
+ TCPOutputManager outMan = new TCPOutputManager(router, config);
outMan.start();
return outMan;
}
-
- private RequestProcessor createRequestProcessor( EventRouter router,
- InetServicesDatabase
inetDb )
- {
- DefaultStageConfig config = new DefaultStageConfig( "requestProcessor",
- createThreadPool( 3 ) );
+ private RequestProcessor createRequestProcessor(
+ EventRouter router,
+ InetServicesDatabase
inetDb) {
+ DefaultStageConfig config =
+ new DefaultStageConfig("requestProcessor", createThreadPool(3));
DefaultRequestProcessor reqProc =
- new DefaultRequestProcessor( router, config, inetDb );
+ new DefaultRequestProcessor(router, config, inetDb);
reqProc.start();
return reqProc;
}
Modified: incubator/directory/seda/trunk/src/java/org/apache/seda/Frontend.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/Frontend.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/Frontend.java
Sat Oct 30 04:31:52 2004
@@ -1,30 +1,30 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda;
-
-
-/**
- * SEDA frontend service interface. There really is nothing here but this
- * service will evolve as we determine the use cases for applications embedding
- * the frontend and accessing it outside of the container.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface Frontend
-{
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda;
+
+
+/**
+ * SEDA frontend service interface. There really is nothing here but this
+ * service will evolve as we determine the use cases for applications embedding
+ * the frontend and accessing it outside of the container.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface Frontend {
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/FrontendFactory.java
Sat Oct 30 04:31:52 2004
@@ -14,15 +14,16 @@
* limitations under the License.
*
*/
+
package org.apache.seda;
+
/**
* Document me.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface FrontendFactory
-{
+public interface FrontendFactory {
Frontend create() throws Exception;
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/ResourceException.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/ResourceException.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/ResourceException.java
Sat Oct 30 04:31:52 2004
@@ -14,33 +14,30 @@
* limitations under the License.
*
*/
+
package org.apache.seda;
/**
- * Exception thrown when a resource was needed and could not be acquired.
+ * Exception thrown when a resource was needed and could not be acquired.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class ResourceException extends Exception
-{
+public class ResourceException extends Exception {
/**
- * Creates a simple ResourceException without any details.
+ * Creates a simple ResourceException without any details.
*/
- public ResourceException()
- {
+ public ResourceException() {
super();
}
-
/**
* Creates a simple ResourceException with a message.
- *
+ *
* @param message a detailed message
*/
- public ResourceException( String message )
- {
- super( message );
+ public ResourceException(String message) {
+ super(message);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPool.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPool.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPool.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -28,82 +28,81 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface BufferPool
-{
+public interface BufferPool {
/**
* Acquires a dedicated buffer from the buffer pool and claims interest
with
* the buffer using an object representing the interested party.
- *
+ *
* @param party the object interested in the buffer
* @return a claimed direct memory buffer
*/
- ByteBuffer getBuffer( Object party ) throws ResourceException;
-
+ ByteBuffer getBuffer(Object party) throws ResourceException;
+
/**
* Allows a party to claim interest on a buffer pooled by this buffer. The
* buffer cannot be reclaimed until all the interested parties release
their
* interest claim on the buffer.
- *
+ *
* @param party the object interested in the buffer
* @param buffer a claimed direct memory buffer pooled by this BufferPool
- * @throws IllegalArgumentException if the buffer is not direct or has not
- * been recognized as a pooled resource of this pool.
+ * @throws IllegalArgumentException if the buffer is not direct or has not
+ * been recognized as a pooled resource of this pool.
*/
- void claimInterest( ByteBuffer buffer, Object party );
-
+ void claimInterest(ByteBuffer buffer, Object party);
+
/**
- * Allows a party that claimed interest on a buffer to release the buffer.
- * The buffer cannot be reclaimed until all the interested parties release
+ * Allows a party that claimed interest on a buffer to release the buffer.
+ * The buffer cannot be reclaimed until all the interested parties release
* their interest claim on the buffer.
- *
+ *
* @param buffer the buffer to release
* @param party the party claiming interest in the buffer
- * @throws IllegalArgumentException if the buffer is not direct or has not
- * been recognized as a pooled resource of this pool.
+ * @throws IllegalArgumentException if the buffer is not direct or has not
+ * been recognized as a pooled resource of this pool.
*/
- void releaseClaim( ByteBuffer buffer, Object party );
-
+ void releaseClaim(ByteBuffer buffer, Object party);
+
/**
* Gets the configuration for this BufferPool.
- *
+ *
* @return the configuration for this BufferPool
*/
BufferPoolConfig getConfig();
-
+
/**
* Gets the number of interested parties that have claimed interest on a
* pooled buffer. This number is like the link count.
- *
+ *
* @param buffer the buffer to get a interest count for
* @return count of parties claiming interest on the buffer
*/
- int getInterestedCount( ByteBuffer buffer );
-
+ int getInterestedCount(ByteBuffer buffer);
+
/**
* Gets a count of the number of free buffers in this BufferPool.
- *
+ *
* @return count of free buffers in this BufferPool
*/
int getFreeCount();
-
+
/**
- * Gets a count of the number of buffers currently being used in this
+ * Gets a count of the number of buffers currently being used in this
* BufferPool.
- *
+ *
* @return count of buffers currently being used in this BufferPool
*/
int getInUseCount();
-
+
/**
* Gets the current size of this BufferPool.
- *
+ *
* @return the number of buffers total (free and in use) in this BufferPool
*/
int size();
/**
* Gets the name of this BufferPool
- *
+ *
* @return the name of this BufferPool
*/
String getName();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,50 +14,51 @@
* limitations under the License.
*
*/
+
package org.apache.seda.buffer;
+
/**
* BufferPool configuration parameters used regardless of implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface BufferPoolConfig
-{
+public interface BufferPoolConfig {
/**
* Gets the name of this BufferPool configuration.
- *
- * @return the name
+ *
+ * @return the name
*/
String getName();
-
+
/**
* The increment by which the BufferPool should grow.
- *
+ *
* @return the increment amount for the BufferPool
*/
int getIncrement();
-
+
/**
- * The size of the buffers that are pooled. Recommended settings are of
+ * The size of the buffers that are pooled. Recommended settings are of
* multiples of 1024: 1k, 2k, 4k and 8k.
- *
+ *
* @return the size of the pooled buffers
*/
int getBufferSize();
-
+
/**
- * Gets the initial size of the pool. This should be a multiple of the
+ * Gets the initial size of the pool. This should be a multiple of the
* pool's growth increment.
- *
+ *
* @return the initial pool size.
*/
int getInitialSize();
-
+
/**
* The maximum size a BufferPool can grow to. This should be a multiple of
* the pool's growth increment.
- *
+ *
* @return the maximum pool size.
*/
int getMaximumSize();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -26,86 +26,85 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface BufferPoolMonitor
-{
+public interface BufferPoolMonitor {
/**
* Monitors the augmentation of a BufferPool.
- *
+ *
* @param bp the BufferPool that grew
*/
- void augmented( BufferPool bp );
-
+ void augmented(BufferPool bp);
+
/**
* Monitors the release of an unclaimed buffer which cannot be released if
* there is no claim and it is on the free list.
- *
+ *
* @param bp the BufferPool the buffer is released back to
* @param buffer the buffer that is released
* @param releaser the object doing the releasing
*/
- void releaseOfUnclaimed( BufferPool bp, ByteBuffer buffer, Object releaser
);
-
+ void releaseOfUnclaimed(BufferPool bp, ByteBuffer buffer, Object releaser);
+
/**
* Monitors the giving of a buffer to a client.
- *
+ *
* @param bp the BufferPool the buffer is taken from
* @param buffer the buffer that is taken
* @param taker the object doing the taking
*/
- void bufferTaken( BufferPool bp, ByteBuffer buffer, Object taker );
-
+ void bufferTaken(BufferPool bp, ByteBuffer buffer, Object taker);
+
/**
* Monitors the release of a buffer to be reclaimed onto the free list.
- *
+ *
* @param bp the BufferPool the buffer is released back to
* @param buffer the buffer that is released
* @param releaser the object doing the releasing
*/
- void bufferReleased( BufferPool bp, ByteBuffer buffer, Object releaser );
-
+ void bufferReleased(BufferPool bp, ByteBuffer buffer, Object releaser);
+
/**
* Monitors the claim of interest in a buffer.
- *
+ *
* @param bp the BufferPool the buffer of interest is from
* @param buffer the buffer that is the interest
* @param claimer the object doing the interest claiming
*/
- void interestClaimed( BufferPool bp, ByteBuffer buffer, Object claimer );
-
+ void interestClaimed(BufferPool bp, ByteBuffer buffer, Object claimer);
+
/**
* Monitors the release of a claim on a buffer.
- *
+ *
* @param bp the BufferPool the buffer of interest is from
* @param buffer the buffer that has an interest claim released
* @param releaser the object doing the interest claim releasing
*/
- void interestReleased( BufferPool bp, ByteBuffer buffer, Object releaser
);
+ void interestReleased(BufferPool bp, ByteBuffer buffer, Object releaser);
/**
- * Monitors situations where the BufferPool is in full use at its maximum
+ * Monitors situations where the BufferPool is in full use at its maximum
* capacity and a request for a Buffer cannot be satisfied.
- *
+ *
* @param bp the BufferPool the where the buffer is unavailable
* @param party the party trying to acquire the buffer resource
*/
- void resourceUnavailable( BufferPool bp, Object party );
-
+ void resourceUnavailable(BufferPool bp, Object party);
+
/**
- * A party that never registered interest in a buffer is attempting to
+ * A party that never registered interest in a buffer is attempting to
* remove its interest on a buffer.
- *
+ *
* @param bp the buffer pool this fault is occuring in
* @param buffer the buffer the party is trying to claim interest on
* @param party the party trying to claim interest
*/
- void unregisteredParty( BufferPool bp, ByteBuffer buffer, Object party );
-
+ void unregisteredParty(BufferPool bp, ByteBuffer buffer, Object party);
+
/**
* Monitors attempts to deal with a buffer that is not a pooled resource.
- *
+ *
* @param bp the BufferPool that does not contain the buffer
* @param buffer the buffer that is not pooled in the BufferPool
* @param party the party that attempted the operation causing the fault
*/
- void nonPooledBuffer( BufferPool bp, ByteBuffer buffer, Object party );
+ void nonPooledBuffer(BufferPool bp, ByteBuffer buffer, Object party);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -27,55 +27,46 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class BufferPoolMonitorAdapter implements BufferPoolMonitor
-{
-
+public class BufferPoolMonitorAdapter implements BufferPoolMonitor {
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#augmented(
* org.apache.seda.buffer.BufferPool)
*/
- public void augmented( BufferPool bp )
- {
+ public void augmented(BufferPool bp) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#bufferTaken(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void bufferTaken( BufferPool bp, ByteBuffer buffer,
- Object taker )
- {
+ public void bufferTaken(BufferPool bp, ByteBuffer buffer, Object taker) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#bufferReleased(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void bufferReleased( BufferPool bp, ByteBuffer buffer,
- Object releaser )
- {
+ public void bufferReleased(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#interestClaimed(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void interestClaimed( BufferPool bp, ByteBuffer buffer,
- Object claimer )
- {
+ public void interestClaimed(
+ BufferPool bp, ByteBuffer buffer,
+ Object claimer) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#interestReleased(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void interestReleased( BufferPool bp, ByteBuffer buffer,
- Object releaser )
- {
+ public void interestReleased(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
}
/*
@@ -83,8 +74,7 @@
* @see org.apache.seda.buffer.BufferPoolMonitor#resourceUnavailable(
* org.apache.seda.buffer.BufferPool, java.lang.Object)
*/
- public void resourceUnavailable( BufferPool bp, Object party )
- {
+ public void resourceUnavailable(BufferPool bp, Object party) {
}
/*
@@ -92,28 +82,26 @@
* @see org.apache.seda.buffer.BufferPoolMonitor#unregisteredParty(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void unregisteredParty( BufferPool bp, ByteBuffer buffer,
- Object party )
- {
+ public void unregisteredParty(
+ BufferPool bp, ByteBuffer buffer,
+ Object party) {
}
-
+
/*
* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#nonPooledBuffer(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void nonPooledBuffer( BufferPool bp, ByteBuffer buffer,
- Object party )
- {
+ public void nonPooledBuffer(
+ BufferPool bp, ByteBuffer buffer, Object
party) {
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#releaseOfUnclaimed(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void releaseOfUnclaimed( BufferPool bp, ByteBuffer buffer,
- Object
releaser )
- {
+ public void releaseOfUnclaimed(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPool.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPool.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPool.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -26,328 +26,269 @@
/**
* The default BufferPool implementation.
- *
+ *
* @see <a
href="http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=DIR-12">JIRA
Issue</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultBufferPool implements BufferPool
-{
+public class DefaultBufferPool implements BufferPool {
/** a configuration bean */
private final BufferPoolConfig config;
+
/** list of all buffers */
private final ArrayList allList;
+
/** list of currently free buffers */
private final ArrayList freeList;
+
/** list of currently in use buffers */
private final ArrayList inUseList;
+
/** the monitor for this DefaultBufferPool */
private BufferPoolMonitor monitor = new BufferPoolMonitorAdapter();
-
-
+
/**
* Creates a BufferPool using a pool configuration bean.
- *
+ *
* @param config the pool configuration bean
*/
- public DefaultBufferPool( BufferPoolConfig config )
- {
+ public DefaultBufferPool(BufferPoolConfig config) {
super();
-
+
this.config = config;
- this.freeList = new ArrayList( config.getMaximumSize() );
- this.inUseList = new ArrayList( config.getMaximumSize() );
- this.allList = new ArrayList( config.getMaximumSize() );
+ this.freeList = new ArrayList(config.getMaximumSize());
+ this.inUseList = new ArrayList(config.getMaximumSize());
+ this.allList = new ArrayList(config.getMaximumSize());
- for( int ii = 0; ii < this.config.getInitialSize(); ii++ )
- {
+ for (int ii = 0; ii < this.config.getInitialSize(); ii++) {
BufferListPair list = new BufferListPair();
- this.freeList.add( list );
- this.allList.add( list );
+ this.freeList.add(list);
+ this.allList.add(list);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getBuffer(java.lang.Object)
*/
- public synchronized ByteBuffer getBuffer( Object party )
- throws ResourceException
- {
+ public synchronized ByteBuffer getBuffer(Object party)
+ throws ResourceException {
BufferListPair list = null;
-
- if ( freeList.size() == 0 )
- {
- if ( config.getIncrement() <= config.getMaximumSize() )
- {
- for ( int ii = 0; ii < config.getIncrement(); ii++ )
- {
+
+ if (freeList.size() == 0) {
+ if (config.getIncrement() <= config.getMaximumSize()) {
+ for (int ii = 0; ii < config.getIncrement(); ii++) {
list = new BufferListPair();
- freeList.add( list );
- allList.add( list );
+ freeList.add(list);
+ allList.add(list);
}
- }
- else
- {
- monitor.resourceUnavailable( this, party );
- throw new ResourceException( "Free Buffers unavailable" );
+ } else {
+ monitor.resourceUnavailable(this, party);
+ throw new ResourceException("Free Buffers unavailable");
}
}
-
+
// remove from free list and add to in use list then report to monitir
- list = ( BufferListPair ) freeList.remove( 0 );
- inUseList.add( list );
- monitor.bufferTaken( this, list.getBuffer(), party );
+ list = (BufferListPair) freeList.remove(0);
+ inUseList.add(list);
+ monitor.bufferTaken(this, list.getBuffer(), party);
// claim interest on the buffer automatically then report to monitor
- list.add( party );
- monitor.interestClaimed( this, list.getBuffer(), party );
+ list.add(party);
+ monitor.interestClaimed(this, list.getBuffer(), party);
return list.getBuffer();
}
-
/* (non-Javadoc)
* @see
org.apache.seda.buffer.BufferPool#claimInterest(java.nio.ByteBuffer,
* java.lang.Object)
*/
- public synchronized void claimInterest( ByteBuffer buffer,
- Object party )
- {
- BufferListPair list = getBufferListPair( buffer );
-
- if ( null == list )
- {
- monitor.nonPooledBuffer( this, buffer, party );
- throw new IllegalStateException( "Not a BufferPool resource" );
- }
-
- list.add( party );
- monitor.interestClaimed( this, buffer, party );
+ public synchronized void claimInterest(ByteBuffer buffer, Object party) {
+ BufferListPair list = getBufferListPair(buffer);
+
+ if (null == list) {
+ monitor.nonPooledBuffer(this, buffer, party);
+ throw new IllegalStateException("Not a BufferPool resource");
+ }
+
+ list.add(party);
+ monitor.interestClaimed(this, buffer, party);
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#releaseClaim(java.nio.ByteBuffer,
* java.lang.Object)
*/
- public synchronized void releaseClaim( ByteBuffer buffer, Object party )
- {
- BufferListPair list = getBufferListPair( buffer );
-
- if ( null == list )
- {
- monitor.releaseOfUnclaimed( this, buffer, party );
- throw new IllegalArgumentException( "Not a pooled resource" );
- }
-
- if ( ! list.contains( party ) )
- {
- monitor.unregisteredParty( this, buffer, party );
- throw new IllegalStateException(
- "Party nsedar registered interest with buffer" );
- }
-
- list.remove( party );
- monitor.interestReleased( this, buffer, party );
-
+ public synchronized void releaseClaim(ByteBuffer buffer, Object party) {
+ BufferListPair list = getBufferListPair(buffer);
+
+ if (null == list) {
+ monitor.releaseOfUnclaimed(this, buffer, party);
+ throw new IllegalArgumentException("Not a pooled resource");
+ }
+
+ if (!list.contains(party)) {
+ monitor.unregisteredParty(this, buffer, party);
+ throw new IllegalStateException("Party nsedar registered interest
with buffer");
+ }
+
+ list.remove(party);
+ monitor.interestReleased(this, buffer, party);
+
// if the list of interested parties hits zero then we release buf
- if ( list.size() == 0 )
- {
- inUseList.remove( list );
- freeList.add( list );
- monitor.bufferReleased( this, buffer, party );
+ if (list.size() == 0) {
+ inUseList.remove(list);
+ freeList.add(list);
+ monitor.bufferReleased(this, buffer, party);
}
}
-
/*
* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getConfig()
*/
- public BufferPoolConfig getConfig()
- {
+ public BufferPoolConfig getConfig() {
return config;
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#size()
*/
- public synchronized int size()
- {
+ public synchronized int size() {
return allList.size();
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getName()
*/
- public String getName()
- {
+ public String getName() {
return config.getName();
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getFreeCount()
*/
- public synchronized int getFreeCount()
- {
+ public synchronized int getFreeCount() {
return freeList.size();
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getInUseCount()
*/
- public synchronized int getInUseCount()
- {
+ public synchronized int getInUseCount() {
return inUseList.size();
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPool#getInterestedCount(
* java.nio.ByteBuffer)
*/
- public int getInterestedCount( ByteBuffer buffer )
- {
- BufferListPair list = getBufferListPair( buffer );
-
- if ( list == null )
- {
- throw new IllegalArgumentException( "not a buffer from this pool"
);
+ public int getInterestedCount(ByteBuffer buffer) {
+ BufferListPair list = getBufferListPair(buffer);
+
+ if (list == null) {
+ throw new IllegalArgumentException("not a buffer from this pool");
}
return list.size();
}
-
-
+
/**
* Gets the monitor.
- *
+ *
* @return returns the monitor
*/
- public BufferPoolMonitor getMonitor()
- {
+ public BufferPoolMonitor getMonitor() {
return monitor;
}
-
/**
* Sets the monitor.
- *
+ *
* @param monitor the monitor to set
*/
- public void setMonitor( BufferPoolMonitor monitor )
- {
+ public void setMonitor(BufferPoolMonitor monitor) {
this.monitor = monitor;
}
-
-
+
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
- public String toString()
- {
- StringBuffer buf = new StringBuffer( config.getName() );
- buf.append( " buffer pool" );
+ public String toString() {
+ StringBuffer buf = new StringBuffer(config.getName());
+ buf.append(" buffer pool");
return buf.toString();
}
-
-
+
// ------------------------------------------------------------------------
// code dealing with pairs of buffers and an interested party list
// ------------------------------------------------------------------------
-
-
+
/**
- * Finds and returns a BufferListPair by scanning the complete list of
+ * Finds and returns a BufferListPair by scanning the complete list of
* pairs looking for the pair that contains the same buffer.
- *
+ *
* @param buffer the buffer to search for in the list of pairs
* @return null if the buffer does not exist or the pair containing it
*/
- BufferListPair getBufferListPair( ByteBuffer buffer )
- {
+ BufferListPair getBufferListPair(ByteBuffer buffer) {
BufferListPair list = null;
-
- for ( int ii = 0; ii < allList.size(); ii++ )
- {
- list = ( BufferListPair ) allList.get( ii );
- if ( buffer == list.getBuffer() )
- {
+
+ for (int ii = 0; ii < allList.size(); ii++) {
+ list = (BufferListPair) allList.get(ii);
+
+ if (buffer == list.getBuffer()) {
return list;
}
}
-
+
return null;
}
-
-
+
/**
- * Class used to pair up a buffer with a list to track the parties
- * interested in the buffer.
+ * Class used to pair up a buffer with a list to track the parties
+ * interested in the buffer.
*/
- class BufferListPair
- {
+ class BufferListPair {
final ArrayList list;
final ByteBuffer buffer;
-
-
- BufferListPair()
- {
- this( new ArrayList( 3 ),
- ByteBuffer.allocateDirect( config.getBufferSize() ) );
- }
-
-
- BufferListPair( ByteBuffer buffer )
- {
- this( new ArrayList( 3 ), buffer );
- }
-
-
- BufferListPair( ArrayList list, ByteBuffer buffer )
- {
+
+ BufferListPair() {
+ this(
+ new ArrayList(3),
+ ByteBuffer.allocateDirect(config.getBufferSize()));
+ }
+
+ BufferListPair(ByteBuffer buffer) {
+ this(new ArrayList(3), buffer);
+ }
+
+ BufferListPair(ArrayList list, ByteBuffer buffer) {
this.list = list;
this.buffer = buffer;
}
-
-
- ByteBuffer getBuffer()
- {
+
+ ByteBuffer getBuffer() {
return buffer;
}
-
-
- ArrayList getList()
- {
+
+ ArrayList getList() {
return list;
}
-
-
- void add( Object party )
- {
- list.add( party );
- }
-
-
- boolean contains( Object party )
- {
- return list.contains( party );
- }
-
-
- boolean remove( Object party )
- {
- return list.remove( party );
- }
-
-
- int size()
- {
+
+ void add(Object party) {
+ list.add(party);
+ }
+
+ boolean contains(Object party) {
+ return list.contains(party);
+ }
+
+ boolean remove(Object party) {
+ return list.remove(party);
+ }
+
+ int size() {
return list.size();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.buffer;
@@ -24,81 +25,73 @@
* Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultBufferPoolConfig implements BufferPoolConfig
-{
+public class DefaultBufferPoolConfig implements BufferPoolConfig {
/** the name */
private final String name;
+
/** the growth increment */
private int inc = 0;
+
/** the maximum pool size */
private int max = 0;
+
/** the initial pool size */
private int ini = 0;
+
/** the size of the buffers pooled */
private int size = 0;
-
-
+
/**
* Creates a BufferPool configuration bean using the supplied values.
- *
+ *
* @param name the name
* @param inc the growth increment
* @param max the maximum pool size
- * @param ini the initial pool size
+ * @param ini the initial pool size
* @param size the size of the buffers pooled
*/
- public DefaultBufferPoolConfig( String name, int inc, int max,
- int ini, int size )
- {
+ public DefaultBufferPoolConfig(
+ String name, int inc, int max, int ini,
+ int size) {
this.name = name;
this.inc = inc;
this.max = max;
this.ini = ini;
this.size = size;
}
-
-
+
/* (non-Javadoc)
* @see org.apache.stage.buffer.BufferPoolConfig#getIncrement()
*/
- public int getIncrement()
- {
+ public int getIncrement() {
return inc;
}
-
/* (non-Javadoc)
* @see org.apache.stage.buffer.BufferPoolConfig#getBufferSize()
*/
- public int getBufferSize()
- {
+ public int getBufferSize() {
return size;
}
-
/* (non-Javadoc)
* @see org.apache.stage.buffer.BufferPoolConfig#getInitialSize()
*/
- public int getInitialSize()
- {
+ public int getInitialSize() {
return ini;
}
-
/* (non-Javadoc)
* @see org.apache.stage.buffer.BufferPoolConfig#getMaximumSize()
*/
- public int getMaximumSize()
- {
+ public int getMaximumSize() {
return max;
}
-
-
+
/* (non-Javadoc)
* @see org.apache.stage.buffer.BufferPoolConfig#getName()
*/
- public String getName()
- {
+ public String getName() {
return name;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -29,165 +29,136 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class LoggingBufferMonitor implements BufferPoolMonitor
-{
+public class LoggingBufferMonitor implements BufferPoolMonitor {
/** the default name for the logging channel */
private final String DEFAULT = "BufferPool";
+
/** the log - can be any implementation */
private final Log log;
-
-
+
/**
* Creates a buffer pool logging monitor.
*/
- public LoggingBufferMonitor()
- {
- log = LogFactory.getLog( DEFAULT );
+ public LoggingBufferMonitor() {
+ log = LogFactory.getLog(DEFAULT);
}
-
-
+
/**
* Creates a buffer pool logging monitor.
- *
+ *
* @param name the logging channel name
*/
- public LoggingBufferMonitor( String name )
- {
- log = LogFactory.getLog( name );
+ public LoggingBufferMonitor(String name) {
+ log = LogFactory.getLog(name);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#
* augmented(org.apache.seda.buffer.BufferPool)
*/
- public void augmented( BufferPool bp )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Just augmented the buffer pool" );
+ public void augmented(BufferPool bp) {
+ if (log.isDebugEnabled()) {
+ log.debug("Just augmented the buffer pool");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#bufferReleased(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void bufferReleased( BufferPool bp, ByteBuffer buffer,
- Object releaser)
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( releaser + " released " + buffer
- + " from pool " + bp );
+ public void bufferReleased(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
+ if (log.isDebugEnabled()) {
+ log.debug(releaser + " released " + buffer + " from pool " + bp);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#bufferTaken(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void bufferTaken( BufferPool bp, ByteBuffer buffer,
- Object taker )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( taker + " took " + buffer + " from pool " + bp );
+ public void bufferTaken(BufferPool bp, ByteBuffer buffer, Object taker) {
+ if (log.isDebugEnabled()) {
+ log.debug(taker + " took " + buffer + " from pool " + bp);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#interestClaimed(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void interestClaimed( BufferPool bp, ByteBuffer buffer,
- Object claimer )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( claimer + " claimed interest in " + buffer
- + " from pool " + bp );
+ public void interestClaimed(
+ BufferPool bp, ByteBuffer buffer,
+ Object claimer) {
+ if (log.isDebugEnabled()) {
+ log.debug(claimer + " claimed interest in " + buffer
+ + " from pool " + bp);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#interestReleased(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void interestReleased( BufferPool bp, ByteBuffer buffer,
- Object
releaser )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( releaser + " released interest in " + buffer
- + " from pool " + bp );
+ public void interestReleased(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
+ if (log.isDebugEnabled()) {
+ log.debug(releaser + " released interest in " + buffer
+ + " from pool " + bp);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#nonPooledBuffer(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void nonPooledBuffer( BufferPool bp, ByteBuffer buffer,
- Object party )
- {
- if ( log.isErrorEnabled() )
- {
- log.error( party + " tried to release interest in "
- + buffer + " from pool " + bp
- + " but resouce was not from this pool.");
+ public void nonPooledBuffer(
+ BufferPool bp, ByteBuffer buffer, Object
party) {
+ if (log.isErrorEnabled()) {
+ log.error(party + " tried to release interest in " + buffer
+ + " from pool " + bp
+ + " but resouce was not from this pool.");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#resourceUnavailable(
* org.apache.seda.buffer.BufferPool, java.lang.Object)
*/
- public void resourceUnavailable( BufferPool bp, Object party )
- {
- if ( log.isErrorEnabled() )
- {
- log.error( "BufferPool " + bp
- + " is at capacity - cannot allocate buffer resouce to "
- + party );
+ public void resourceUnavailable(BufferPool bp, Object party) {
+ if (log.isErrorEnabled()) {
+ log.error("BufferPool " + bp
+ + " is at capacity - cannot allocate buffer resouce to "
+ + party);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#unregisteredParty(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void unregisteredParty( BufferPool bp, ByteBuffer buffer,
- Object party )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( party
- + " has not registered as claiming interest on " + buffer
- + " from pool " + bp );
+ public void unregisteredParty(
+ BufferPool bp, ByteBuffer buffer,
+ Object party) {
+ if (log.isDebugEnabled()) {
+ log.debug(party + " has not registered as claiming interest on "
+ + buffer + " from pool " + bp);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.buffer.BufferPoolMonitor#releaseOfUnclaimed(
* org.apache.seda.buffer.BufferPool, java.nio.ByteBuffer,
java.lang.Object)
*/
- public void releaseOfUnclaimed( BufferPool bp, ByteBuffer buffer,
- Object
releaser )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( releaser + " attempted to release interest in "
- + buffer + " from pool "
- + bp + " when the buffer was not claimed." );
+ public void releaseOfUnclaimed(
+ BufferPool bp, ByteBuffer buffer,
+ Object releaser) {
+ if (log.isDebugEnabled()) {
+ log.debug(releaser + " attempted to release interest in " + buffer
+ + " from pool " + bp
+ + " when the buffer was not claimed.");
}
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/ClientDecoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/ClientDecoder.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/ClientDecoder.java
Sat Oct 30 04:31:52 2004
@@ -1,107 +1,95 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.decoder;
-
-
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.stateful.DecoderMonitor;
-import org.apache.commons.codec.stateful.StatefulDecoder;
-import org.apache.commons.codec.stateful.DecoderCallback;
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * A stateful decoder dedicated to a specific client.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ClientDecoder implements StatefulDecoder, DecoderCallback
-{
- /** the key of the client this decoder is associated with */
- private final ClientKey key;
- /** the actual decoder doing the work for us */
- private final StatefulDecoder decoder;
- /** the callback used by this decoder */
- private DecoderCallback cb;
-
-
- /**
- * Creates a client dedicated stateful decoder.
- *
- * @param key the key of the client this decoder is for
- * @param decoder the underlying decoder doing the work
- */
- public ClientDecoder( ClientKey key, StatefulDecoder decoder )
- {
- this.key = key;
- this.decoder = decoder;
- this.decoder.setCallback( this );
- }
-
-
- /* (non-Javadoc)
- * @see
org.apache.commons.codec.stateful.StatefulDecoder#decodeNonBlocking(
- * java.lang.Object)
- */
- public void decode( Object encoded ) throws DecoderException
- {
- decoder.decode( encoded );
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.commons.codec.stateful.StatefulDecoder#setCallback(
- * org.apache.commons.codec.stateful.DecoderCallback)
- */
- public void setCallback( DecoderCallback cb )
- {
- this.cb = cb;
- }
-
-
- /* (non-Javadoc)
- * @see
org.apache.commons.codec.stateful.StatefulDecoder#setDecoderMonitor(
- * org.apache.commons.codec.stateful.DecoderMonitor)
- */
- public void setDecoderMonitor( DecoderMonitor monitor )
- {
- decoder.setDecoderMonitor( monitor );
- }
-
-
- /**
- * Gets the key of the client this stateful decoder is dedicated to.
- *
- * @return the key of the client for this stateful decoder
- */
- public ClientKey getClientKey()
- {
- return key;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.commons.codec.stateful.DecoderCallback#decodeOccurred(
- * org.apache.commons.codec.stateful.StatefulDecoder, java.lang.Object)
- */
- public void decodeOccurred( StatefulDecoder decoder, Object decoded )
- {
- cb.decodeOccurred( this, decoded );
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.decoder;
+
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.stateful.DecoderCallback;
+import org.apache.commons.codec.stateful.DecoderMonitor;
+import org.apache.commons.codec.stateful.StatefulDecoder;
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * A stateful decoder dedicated to a specific client.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ClientDecoder implements StatefulDecoder, DecoderCallback {
+ /** the key of the client this decoder is associated with */
+ private final ClientKey key;
+
+ /** the actual decoder doing the work for us */
+ private final StatefulDecoder decoder;
+
+ /** the callback used by this decoder */
+ private DecoderCallback cb;
+
+ /**
+ * Creates a client dedicated stateful decoder.
+ *
+ * @param key the key of the client this decoder is for
+ * @param decoder the underlying decoder doing the work
+ */
+ public ClientDecoder(ClientKey key, StatefulDecoder decoder) {
+ this.key = key;
+ this.decoder = decoder;
+ this.decoder.setCallback(this);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.commons.codec.stateful.StatefulDecoder#decodeNonBlocking(
+ * java.lang.Object)
+ */
+ public void decode(Object encoded) throws DecoderException {
+ decoder.decode(encoded);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.codec.stateful.StatefulDecoder#setCallback(
+ * org.apache.commons.codec.stateful.DecoderCallback)
+ */
+ public void setCallback(DecoderCallback cb) {
+ this.cb = cb;
+ }
+
+ /* (non-Javadoc)
+ * @see
org.apache.commons.codec.stateful.StatefulDecoder#setDecoderMonitor(
+ * org.apache.commons.codec.stateful.DecoderMonitor)
+ */
+ public void setDecoderMonitor(DecoderMonitor monitor) {
+ decoder.setDecoderMonitor(monitor);
+ }
+
+ /**
+ * Gets the key of the client this stateful decoder is dedicated to.
+ *
+ * @return the key of the client for this stateful decoder
+ */
+ public ClientKey getClientKey() {
+ return key;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.commons.codec.stateful.DecoderCallback#decodeOccurred(
+ * org.apache.commons.codec.stateful.StatefulDecoder, java.lang.Object)
+ */
+ public void decodeOccurred(StatefulDecoder decoder, Object decoded) {
+ cb.decodeOccurred(this, decoded);
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecodeStageHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecodeStageHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecodeStageHandler.java
Sat Oct 30 04:31:52 2004
@@ -14,18 +14,18 @@
* limitations under the License.
*
*/
-package org.apache.seda.decoder;
+package org.apache.seda.decoder;
import java.nio.ByteBuffer;
+
import java.util.EventObject;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.stateful.StatefulDecoder;
-
import org.apache.seda.event.InputEvent;
-import org.apache.seda.stage.StageHandler;
import org.apache.seda.listener.ClientKey;
+import org.apache.seda.stage.StageHandler;
/**
@@ -35,50 +35,42 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DecodeStageHandler implements StageHandler
-{
+public class DecodeStageHandler implements StageHandler {
/** reference to the decoder manager this handler is used by */
private final DefaultDecoderManager manager;
-
/**
* Creates the decoder manager's decodeNonBlocking stage handler.
- *
+ *
* @param manager the decoder manager this handler is for
*/
- public DecodeStageHandler( DefaultDecoderManager manager )
- {
+ public DecodeStageHandler(DefaultDecoderManager manager) {
this.manager = manager;
}
-
/**
- * Uses the client key to have the decoder manager lookup the client's
+ * Uses the client key to have the decoder manager lookup the client's
* stateful decoder. The decoder's decodeNonBlocking method is called and
* control is returned. Error handling is left upto the decoder's monitor.
- *
+ *
* @see
org.apache.seda.stage.StageHandler#handleEvent(java.util.EventObject)
*/
- public void handleEvent( EventObject event )
- {
- InputEvent e = ( InputEvent ) event;
+ public void handleEvent(EventObject event) {
+ InputEvent e = (InputEvent) event;
ClientKey key = e.getClientKey();
- ByteBuffer buf = e.claimInterest( this );
- StatefulDecoder decoder = manager.getDecoder( key );
-
- try
- {
- decoder.decode( buf );
- }
- catch( DecoderException ex )
- {
+ ByteBuffer buf = e.claimInterest(this);
+ StatefulDecoder decoder = manager.getDecoder(key);
+
+ try {
+ decoder.decode(buf);
+ } catch (DecoderException ex) {
/*
* monitor should be handling errors already for us and rethrowing
* so we shouldn't have to do anything here but return control
*/
}
-
- e.releaseInterest( this );
- e.releaseInterest( manager );
+
+ e.releaseInterest(this);
+ e.releaseInterest(manager);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManager.java
Sat Oct 30 04:31:52 2004
@@ -1,60 +1,58 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.decoder;
-
-
-import java.nio.ByteBuffer;
-
-import org.apache.seda.listener.ClientKey;
-
-import org.apache.commons.codec.DecoderException;
-
-
-/**
- * The DecoderManager creates, maintains and destroys StatefulDecoder
instances,
- * one dedicated per client. The StatefulDecoder implementation decodes BER
- * encoded LDAPv3 messages into Message instances.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface DecoderManager
-{
- /**
- * Decodes a chunk buffer of encoded data without blocking. The chunk may
- * contain one or more fragments of a message without necessarily
containing
- * an entire message.
- *
- * @param key the unique key associated with the client
- * @param buffer the buffer of encoded data
- * @throws DecoderException if there is a failure while decoding
- */
- void decodeNonBlocking( ClientKey key, ByteBuffer buffer )
- throws DecoderException;
-
- /**
- * One shot blocking operation requiring a single complete unit of encoded
- * data to return the decoded request object immediately.
- *
- * @param buffer the buffer containing a single encoded message
- * @return the decoded object representing the message
- * @throws DecoderException if there is a failure while decoding
- */
- Object decodeBlocking( ClientKey key, ByteBuffer buffer )
- throws DecoderException;
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.decoder;
+
+import java.nio.ByteBuffer;
+
+import org.apache.commons.codec.DecoderException;
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * The DecoderManager creates, maintains and destroys StatefulDecoder
instances,
+ * one dedicated per client. The StatefulDecoder implementation decodes BER
+ * encoded LDAPv3 messages into Message instances.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface DecoderManager {
+ /**
+ * Decodes a chunk buffer of encoded data without blocking. The chunk may
+ * contain one or more fragments of a message without necessarily
containing
+ * an entire message.
+ *
+ * @param key the unique key associated with the client
+ * @param buffer the buffer of encoded data
+ * @throws DecoderException if there is a failure while decoding
+ */
+ void decodeNonBlocking(ClientKey key, ByteBuffer buffer)
+ throws DecoderException;
+
+ /**
+ * One shot blocking operation requiring a single complete unit of encoded
+ * data to return the decoded request object immediately.
+ *
+ * @param buffer the buffer containing a single encoded message
+ * @return the decoded object representing the message
+ * @throws DecoderException if there is a failure while decoding
+ */
+ Object decodeBlocking(ClientKey key, ByteBuffer buffer)
+ throws DecoderException;
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
Sat Oct 30 04:31:52 2004
@@ -1,42 +1,41 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.decoder;
-
-
-import java.util.EventObject;
-
-import org.apache.seda.event.Subscriber;
-
-/**
- * Monitors DecoderManagers.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface DecoderManagerMonitor
-{
- /**
- * Monitors failures while processing inform methods if any.
- *
- * @param subscriber the subscriber
- * @param event the event being delievered
- * @param t the throwable that prevented delivery
- */
- void failedOnInform( Subscriber subscriber, EventObject event,
- Throwable t );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.decoder;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.Subscriber;
+
+
+/**
+ * Monitors DecoderManagers.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface DecoderManagerMonitor {
+ /**
+ * Monitors failures while processing inform methods if any.
+ *
+ * @param subscriber the subscriber
+ * @param event the event being delievered
+ * @param t the throwable that prevented delivery
+ */
+ void failedOnInform(Subscriber subscriber, EventObject event, Throwable t);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.decoder;
+package org.apache.seda.decoder;
import java.util.EventObject;
@@ -29,18 +29,16 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DecoderManagerMonitorAdapter implements DecoderManagerMonitor
-{
+public class DecoderManagerMonitorAdapter implements DecoderManagerMonitor {
/* (non-Javadoc)
* @see org.apache.seda.event.SubscriberMonitor#failedOnInform(
- * org.apache.seda.event.Subscriber,
+ * org.apache.seda.event.Subscriber,
* java.util.EventObject, java.lang.Throwable)
*/
- public void failedOnInform( Subscriber subscriber, EventObject event,
- Throwable t )
- {
- if ( t != null )
- {
+ public void failedOnInform(
+ Subscriber subscriber, EventObject event,
+ Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/decoder/DefaultDecoderManager.java
Sat Oct 30 04:31:52 2004
@@ -14,28 +14,26 @@
* limitations under the License.
*
*/
-package org.apache.seda.decoder;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.EventObject;
+package org.apache.seda.decoder;
import java.nio.ByteBuffer;
-import org.apache.seda.stage.StageConfig;
-import org.apache.seda.stage.DefaultStage;
-import org.apache.seda.stage.LoggingStageMonitor;
-
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-import org.apache.seda.event.*;
-import org.apache.seda.protocol.InetServicesDatabase;
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.Map;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.stateful.DecoderCallback;
-import org.apache.commons.codec.stateful.StatefulDecoder;
import org.apache.commons.codec.stateful.DecoderFactory;
+import org.apache.commons.codec.stateful.StatefulDecoder;
+import org.apache.seda.event.*;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
+import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.stage.DefaultStage;
+import org.apache.seda.stage.LoggingStageMonitor;
+import org.apache.seda.stage.StageConfig;
/**
@@ -45,73 +43,64 @@
* @version $Rev$
*/
public class DefaultDecoderManager extends DefaultStage
- implements
- DecoderManager,
- InputSubscriber,
- ConnectSubscriber,
- ProtocolSubscriber,
- DisconnectSubscriber
-{
+ implements DecoderManager, InputSubscriber, ConnectSubscriber,
+ ProtocolSubscriber, DisconnectSubscriber {
/** event router or bus this component subscribes and publishes events on
*/
private final EventRouter router;
+
/** the internet service database */
private final InetServicesDatabase inetdb;
+
/** map of decoders for client keys */
private final Map decoders = new HashMap();
+
/** map of DecoderFactory for different protos using proto name as key */
private final Map factories = new HashMap(2);
+
/** the monitor used for this decoder manager */
private DecoderManagerMonitor monitor;
-
/**
* Creates a instance of the default decoder manager implementation.
- *
+ *
* @param router the event bus or router component depended upon
* @param config the stage configuration
*/
- public DefaultDecoderManager( EventRouter router, StageConfig config,
- InetServicesDatabase inetdb )
- {
- super( config );
-
+ public DefaultDecoderManager(
+ EventRouter router, StageConfig config,
+ InetServicesDatabase inetdb) {
+ super(config);
+
this.router = router;
this.inetdb = inetdb;
this.monitor = new DecoderManagerMonitorAdapter();
- super.setMonitor( new LoggingStageMonitor( getClass() ) );
+ super.setMonitor(new LoggingStageMonitor(getClass()));
- router.subscribe( InputEvent.class, this );
- router.subscribe( ConnectEvent.class, this );
- router.subscribe( ProtocolEvent.class, this );
- router.subscribe( DisconnectEvent.class, this );
+ router.subscribe(InputEvent.class, this);
+ router.subscribe(ConnectEvent.class, this);
+ router.subscribe(ProtocolEvent.class, this);
+ router.subscribe(DisconnectEvent.class, this);
}
-
-
+
// ------------------------------------------------------------------------
// Subscriber Methods
// ------------------------------------------------------------------------
-
/**
* Routes the event to the appropriate typed <code>inform()</code> method.
- *
+ *
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
* @see org.apache.seda.event.AbstractSubscriber#inform(
* org.apache.seda.event.Subscriber, java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch ( Throwable t )
- {
- monitor.failedOnInform( this, event, t );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Throwable t) {
+ monitor.failedOnInform(this, event, t);
}
}
-
/**
* For now this method just adds the DecoderFactory associated with the
* protocol to a map for use when setting up new clients. Later as other
@@ -120,42 +109,36 @@
*
* @param event the protocol event to be informed of
*/
- public void inform( ProtocolEvent event )
- {
- if ( event instanceof AddProtocolEvent )
- {
- factories.put( event.getProtocolProvider().getName(),
- event.getProtocolProvider().getDecoderFactory() );
+ public void inform(ProtocolEvent event) {
+ if (event instanceof AddProtocolEvent) {
+ factories.put(
+ event.getProtocolProvider().getName(),
+ event.getProtocolProvider().getDecoderFactory());
}
}
-
/**
* Enqueues the event onto this Stages event queue for processing.
- *
+ *
* @see org.apache.seda.event.InputSubscriber#inform(
* org.apache.seda.event.InputEvent)
*/
- public void inform( InputEvent event )
- {
+ public void inform(InputEvent event) {
// claim interest and release after asynchronous processing of event
- event.claimInterest( this );
- enqueue( event );
+ event.claimInterest(this);
+ enqueue(event);
}
-
/**
* Removes the clients decoder from the map of decoders.
- *
+ *
* @see org.apache.seda.event.DisconnectSubscriber#inform(
* org.apache.seda.event.DisconnectEvent)
*/
- public void inform( DisconnectEvent event )
- {
- decoders.remove( event.getClientKey() );
+ public void inform(DisconnectEvent event) {
+ decoders.remove(event.getClientKey());
}
-
/**
* Temporary place holder for functionality that looks up a protocol
* specific StatefulDecoder.
@@ -163,34 +146,28 @@
* @param key the client key used to determine associated protocol
* @return the new stateful nonblocking protocol specific decoder
*/
- private StatefulDecoder createDecoder( ClientKey key )
- throws KeyExpiryException
- {
- String proto = inetdb.getProtoByPort( key.getLocalAddress().getPort()
);
- DecoderFactory factory = ( DecoderFactory ) factories.get( proto );
+ private StatefulDecoder createDecoder(ClientKey key)
+ throws KeyExpiryException {
+ String proto = inetdb.getProtoByPort(key.getLocalAddress().getPort());
+ DecoderFactory factory = (DecoderFactory) factories.get(proto);
return factory.createDecoder();
}
-
/**
* We basically create a new client decoder and put it into a map for
* use later when we are processing input events from the client.
- *
+ *
* @see org.apache.seda.event.ConnectSubscriber#inform(
* org.apache.seda.event.ConnectEvent)
*/
- public void inform( ConnectEvent event )
- {
+ public void inform(ConnectEvent event) {
StatefulDecoder decoder = null;
ClientKey key = event.getClientKey();
- try
- {
- decoder = new ClientDecoder( key, createDecoder( key ) );
- }
- catch ( KeyExpiryException e )
- {
- monitor.failedOnInform( this, event, e );
+ try {
+ decoder = new ClientDecoder(key, createDecoder(key));
+ } catch (KeyExpiryException e) {
+ monitor.failedOnInform(this, event, e);
return;
}
@@ -200,16 +177,15 @@
* for a request. We use this request to create a RequestEvent and
* publish the event on the queue.
*/
- decoder.setCallback( new DecoderCallback()
- {
- public void decodeOccurred( StatefulDecoder decoder,
- Object decoded )
- {
- ClientKey key = ( ( ClientDecoder ) decoder ).getClientKey();
- RequestEvent event = new RequestEvent( this, key, decoded );
- router.publish( event );
- }
- });
+ decoder.setCallback(new DecoderCallback() {
+ public void decodeOccurred(
+ StatefulDecoder decoder,
+ Object decoded) {
+ ClientKey key = ((ClientDecoder) decoder).getClientKey();
+ RequestEvent event = new RequestEvent(this, key, decoded);
+ router.publish(event);
+ }
+ });
/*
* For potential race conditions between ConnectEvent processing and
@@ -218,107 +194,90 @@
* for a client decoder in the decoders map will wait on the map until
* awoken.
*/
- synchronized( decoders )
- {
- decoders.put( key, decoder );
+ synchronized (decoders) {
+ decoders.put(key, decoder);
decoders.notifyAll();
}
}
-
// ------------------------------------------------------------------------
// Service Interface Methods
// ------------------------------------------------------------------------
-
/* (non-Javadoc)
* @see org.apache.seda.decoder.DecoderManager#decodeNonBlocking(
* org.apache.seda.listener.ClientKey, java.nio.ByteBuffer)
*/
- public void decodeNonBlocking( ClientKey key, ByteBuffer buffer )
- throws DecoderException
- {
- StatefulDecoder decoder = ( StatefulDecoder ) decoders.get( key );
- decoder.decode( buffer );
+ public void decodeNonBlocking(ClientKey key, ByteBuffer buffer)
+ throws DecoderException {
+ StatefulDecoder decoder = (StatefulDecoder) decoders.get(key);
+ decoder.decode(buffer);
}
-
/* (non-Javadoc)
* @see org.apache.seda.decoder.DecoderManager#
* decodeNonBlocking(java.nio.ByteBuffer)
*/
- public Object decodeBlocking( ClientKey key, ByteBuffer buffer )
- throws DecoderException
- {
+ public Object decodeBlocking(ClientKey key, ByteBuffer buffer)
+ throws DecoderException {
// replace this decoder with a real one later
StatefulDecoder decoder = null;
- try
- {
- decoder = createDecoder( key );
- }
- catch ( KeyExpiryException e )
- {
- throw new DecoderException( "client key has expired" );
+
+ try {
+ decoder = createDecoder(key);
+ } catch (KeyExpiryException e) {
+ throw new DecoderException("client key has expired");
}
// used array to set a value on final variable and get by compiler
final Object[] decoded = new Object[1];
-
- decoder.setCallback( new DecoderCallback()
- {
- public void decodeOccurred( StatefulDecoder decoder, Object obj )
- {
- decoded[0] = obj;
- }
- });
-
+
+ decoder.setCallback(new DecoderCallback() {
+ public void decodeOccurred(
+ StatefulDecoder decoder, Object
obj) {
+ decoded[0] = obj;
+ }
+ });
+
// force synchronous callback
- decoder.decode( buffer );
-
+ decoder.decode(buffer);
+
// the decoded value should be set
- if ( decoded[0] == null )
- {
- throw new DecoderException( "Expected a complete encoded unit of "
- + "data but got a partial encoding in buffer arg" );
+ if (decoded[0] == null) {
+ throw new DecoderException("Expected a complete encoded unit of "
+ + "data but got a partial encoding in
buffer arg");
}
-
+
return decoded[0];
}
-
// ------------------------------------------------------------------------
// Additional Methods
// ------------------------------------------------------------------------
-
/**
* Gets the monitor for this DecoderManager.
- *
+ *
* @return the monitor
*/
- public DecoderManagerMonitor getMonitor()
- {
+ public DecoderManagerMonitor getMonitor() {
return monitor;
}
-
/**
* @param monitor the monitor to set
*/
- public void setMonitor( DecoderManagerMonitor monitor )
- {
+ public void setMonitor(DecoderManagerMonitor monitor) {
this.monitor = monitor;
}
-
/**
* Gets a stateful decoder for a particular client.
- *
+ *
* @param key the client's key
* @return the stateful decoder for the client
*/
- StatefulDecoder getDecoder( ClientKey key )
- {
+ StatefulDecoder getDecoder(ClientKey key) {
StatefulDecoder decoder = null;
/*
@@ -328,22 +287,17 @@
* has not been created yet. When processing of the ConnectEvent is
* complete we are awoken via a notifyAll in the inform() method.
*/
- synchronized( decoders )
- {
- decoder = ( StatefulDecoder ) decoders.get( key );
-
- while ( decoder == null )
- {
- try
- {
+ synchronized (decoders) {
+ decoder = (StatefulDecoder) decoders.get(key);
+
+ while (decoder == null) {
+ try {
decoders.wait();
- }
- catch ( InterruptedException e )
- {
+ } catch (InterruptedException e) {
e.printStackTrace();
}
- decoder = ( StatefulDecoder ) decoders.get( key );
+ decoder = (StatefulDecoder) decoders.get(key);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/ClientEncoder.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/ClientEncoder.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/ClientEncoder.java
Sat Oct 30 04:31:52 2004
@@ -1,92 +1,80 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.encoder;
-
-
-import org.apache.commons.codec.EncoderException;
-import org.apache.commons.codec.stateful.EncoderMonitor;
-import org.apache.commons.codec.stateful.StatefulEncoder;
-import org.apache.commons.codec.stateful.EncoderCallback;
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * A stateful encoder dedicated to a specific client.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev: 43377 $
- */
-public class ClientEncoder implements StatefulEncoder, EncoderCallback
-{
- /** the key of the client this encoder is associated with */
- private final ClientKey key;
- /** the actual encoder doing the work for us */
- private final StatefulEncoder encoder;
- /** the callback used by this encoder */
- private EncoderCallback cb;
-
-
- /**
- * Creates a client dedicated stateful encoder.
- *
- * @param key the key of the client this encoder is for
- * @param encoder the underlying encoder doing the work
- */
- public ClientEncoder( ClientKey key, StatefulEncoder encoder )
- {
- this.key = key;
- this.encoder = encoder;
- this.encoder.setCallback( this );
- }
-
-
- public void encode( Object encoded ) throws EncoderException
- {
- encoder.encode( encoded );
- }
-
-
- public void setCallback( EncoderCallback cb )
- {
- this.cb = cb;
- }
-
-
- public void setEncoderMonitor( EncoderMonitor monitor )
- {
- encoder.setEncoderMonitor( monitor );
- }
-
-
- /**
- * Gets the key of the client this stateful encoder is dedicated to.
- *
- * @return the key of the client for this stateful encoder
- */
- public ClientKey getClientKey()
- {
- return key;
- }
-
-
- public void encodeOccurred( StatefulEncoder encoder, Object encoded )
- {
- cb.encodeOccurred( this, encoded );
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.encoder;
+
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.EncoderCallback;
+import org.apache.commons.codec.stateful.EncoderMonitor;
+import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * A stateful encoder dedicated to a specific client.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ClientEncoder implements StatefulEncoder, EncoderCallback {
+ /** the key of the client this encoder is associated with */
+ private final ClientKey key;
+
+ /** the actual encoder doing the work for us */
+ private final StatefulEncoder encoder;
+
+ /** the callback used by this encoder */
+ private EncoderCallback cb;
+
+ /**
+ * Creates a client dedicated stateful encoder.
+ *
+ * @param key the key of the client this encoder is for
+ * @param encoder the underlying encoder doing the work
+ */
+ public ClientEncoder(ClientKey key, StatefulEncoder encoder) {
+ this.key = key;
+ this.encoder = encoder;
+ this.encoder.setCallback(this);
+ }
+
+ public void encode(Object encoded) throws EncoderException {
+ encoder.encode(encoded);
+ }
+
+ public void setCallback(EncoderCallback cb) {
+ this.cb = cb;
+ }
+
+ public void setEncoderMonitor(EncoderMonitor monitor) {
+ encoder.setEncoderMonitor(monitor);
+ }
+
+ /**
+ * Gets the key of the client this stateful encoder is dedicated to.
+ *
+ * @return the key of the client for this stateful encoder
+ */
+ public ClientKey getClientKey() {
+ return key;
+ }
+
+ public void encodeOccurred(StatefulEncoder encoder, Object encoded) {
+ cb.encodeOccurred(this, encoded);
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
Sat Oct 30 04:31:52 2004
@@ -14,24 +14,23 @@
* limitations under the License.
*
*/
-package org.apache.seda.encoder;
+package org.apache.seda.encoder;
import java.nio.ByteBuffer;
+
import java.util.EventObject;
import java.util.HashMap;
import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.EncoderCallback;
import org.apache.commons.codec.stateful.EncoderFactory;
import org.apache.commons.codec.stateful.StatefulEncoder;
-import org.apache.commons.codec.stateful.EncoderCallback;
-
-import org.apache.seda.stage.*;
-
import org.apache.seda.event.*;
import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.stage.*;
/**
@@ -43,93 +42,78 @@
* @version $Rev$
*/
public class DefaultEncoderManager extends DefaultStage
- implements
- EncoderManager,
- ConnectSubscriber,
- ResponseSubscriber,
- ProtocolSubscriber,
- DisconnectSubscriber
-{
+ implements EncoderManager, ConnectSubscriber, ResponseSubscriber,
+ ProtocolSubscriber, DisconnectSubscriber {
/** the event router used to publish and subscribe to events on */
private final EventRouter router;
+
/** the internet service database used to lookup protocols by port */
private final InetServicesDatabase inetdb;
+
/** a map of protocol names to EncoderFactorys */
- private final HashMap factories = new HashMap( 2 );
+ private final HashMap factories = new HashMap(2);
+
/** map of client keys to client encoders */
private final HashMap encoders = new HashMap();
+
/** the monitor used by this encoder manager */
private EncoderManagerMonitor monitor;
-
-
+
/**
* Creates the default EncoderManager.
- *
+ *
* @param router the event router used to publish and subscribe to events
on
*/
- public DefaultEncoderManager( EventRouter router,
- StageConfig config,
- InetServicesDatabase inetdb )
- {
- super( config );
- super.setMonitor( new LoggingStageMonitor( this.getClass() ) );
+ public DefaultEncoderManager(
+ EventRouter router, StageConfig config,
+ InetServicesDatabase inetdb) {
+ super(config);
+ super.setMonitor(new LoggingStageMonitor(this.getClass()));
monitor = new EncoderManagerMonitorAdapter();
this.inetdb = inetdb;
this.router = router;
- this.router.subscribe( ConnectEvent.class, this );
- this.router.subscribe( ProtocolEvent.class, this );
- this.router.subscribe( ResponseEvent.class, this );
+ this.router.subscribe(ConnectEvent.class, this);
+ this.router.subscribe(ProtocolEvent.class, this);
+ this.router.subscribe(ResponseEvent.class, this);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch( Throwable t )
- {
- monitor.failedOnInform( this, event, t );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Throwable t) {
+ monitor.failedOnInform(this, event, t);
}
}
-
/**
* Removes the clients encoder from the map of encoders.
*
* @see org.apache.seda.event.DisconnectSubscriber#inform(
* org.apache.seda.event.DisconnectEvent)
*/
- public void inform( DisconnectEvent event )
- {
- encoders.remove( event.getClientKey() );
+ public void inform(DisconnectEvent event) {
+ encoders.remove(event.getClientKey());
}
-
/* (non-Javadoc)
* @see org.apache.seda.event.ResponseSubscriber#inform(
* org.apache.seda.event.ResponseEvent)
*/
- public void inform( ResponseEvent event )
- {
- super.enqueue( event );
+ public void inform(ResponseEvent event) {
+ super.enqueue(event);
}
-
- public void inform( ProtocolEvent event )
- {
- if ( event instanceof AddProtocolEvent )
- {
- factories.put( event.getProtocolProvider().getName(),
- event.getProtocolProvider().getEncoderFactory() );
+ public void inform(ProtocolEvent event) {
+ if (event instanceof AddProtocolEvent) {
+ factories.put(
+ event.getProtocolProvider().getName(),
+ event.getProtocolProvider().getEncoderFactory());
}
}
-
/**
* Temporary place holder for functionality that looks up a protocol
* specific StatefulEncoder.
@@ -137,15 +121,13 @@
* @param key the client key used to determine associated protocol
* @return the new stateful nonblocking protocol specific encoder
*/
- private StatefulEncoder createEncoder( ClientKey key )
- throws KeyExpiryException
- {
- String proto = inetdb.getProtoByPort( key.getLocalAddress().getPort()
);
- EncoderFactory factory = ( EncoderFactory ) factories.get( proto );
+ private StatefulEncoder createEncoder(ClientKey key)
+ throws KeyExpiryException {
+ String proto = inetdb.getProtoByPort(key.getLocalAddress().getPort());
+ EncoderFactory factory = (EncoderFactory) factories.get(proto);
return factory.createEncoder();
}
-
/**
* We basically create a new client encoder and put it into a map for
* use later when we are processing response events from the client.
@@ -153,97 +135,79 @@
* @see org.apache.seda.event.ConnectSubscriber#inform(
* org.apache.seda.event.ConnectEvent)
*/
- public void inform( ConnectEvent event )
- {
+ public void inform(ConnectEvent event) {
StatefulEncoder encoder = null;
ClientKey key = event.getClientKey();
- try
- {
- encoder = new ClientEncoder( key, createEncoder( key ) );
- }
- catch ( KeyExpiryException e )
- {
- monitor.failedOnInform( this, event, e );
+ try {
+ encoder = new ClientEncoder(key, createEncoder(key));
+ } catch (KeyExpiryException e) {
+ monitor.failedOnInform(this, event, e);
return;
}
/*
* Here the encoder informs us that a response encoded.
*/
- encoder.setCallback( new EncoderCallback()
- {
- public void encodeOccurred( StatefulEncoder encoder,
- Object encoded )
- {
- ClientKey key = ( ( ClientEncoder ) encoder ).getClientKey();
- OutputEvent event = new OutputEvent( this, key,
- ( ByteBuffer ) encoded );
- router.publish( event );
- }
- });
- encoders.put( key, encoder );
+ encoder.setCallback(new EncoderCallback() {
+ public void encodeOccurred(
+ StatefulEncoder encoder,
+ Object encoded) {
+ ClientKey key = ((ClientEncoder) encoder).getClientKey();
+ OutputEvent event =
+ new OutputEvent(this, key, (ByteBuffer) encoded);
+ router.publish(event);
+ }
+ });
+ encoders.put(key, encoder);
}
-
- public ByteBuffer encodeBlocking( ClientKey key, Object response )
- throws EncoderException
- {
+ public ByteBuffer encodeBlocking(ClientKey key, Object response)
+ throws EncoderException {
int port = -1;
- try
- {
+ try {
port = key.getLocalAddress().getPort();
- }
- catch ( KeyExpiryException e )
- {
- monitor.failedOnEncode( this, key, response, e );
+ } catch (KeyExpiryException e) {
+ monitor.failedOnEncode(this, key, response, e);
}
- EncoderFactory factory = ( EncoderFactory )
- factories.get( inetdb.getProtoByPort( port ) );
+ EncoderFactory factory =
+ (EncoderFactory) factories.get(inetdb.getProtoByPort(port));
StatefulEncoder encoder =
- new ClientEncoder( key, factory.createEncoder() );
+ new ClientEncoder(key, factory.createEncoder());
// used array to set a value on final variable and get by compiler
final Object[] encoded = new Object[1];
- encoder.setCallback( new EncoderCallback()
- {
- public void encodeOccurred( StatefulEncoder encoder, Object obj )
- {
- encoded[0] = obj;
- }
- });
+ encoder.setCallback(new EncoderCallback() {
+ public void encodeOccurred(
+ StatefulEncoder encoder, Object
obj) {
+ encoded[0] = obj;
+ }
+ });
- encoder.encode( response );
+ encoder.encode(response);
// the encoded value should be set
- if ( encoded[0] == null )
- {
- throw new EncoderException( "Expected a complete encoded object" +
- " but encoder did not produce one" );
+ if (encoded[0] == null) {
+ throw new EncoderException("Expected a complete encoded object"
+ + " but encoder did not produce one");
}
- return ( ByteBuffer ) encoded[0];
+ return (ByteBuffer) encoded[0];
}
-
- public void encodeNonBlocking( ClientKey key, Object response )
- throws EncoderException
- {
- StatefulEncoder encoder = ( StatefulEncoder ) encoders.get( key );
- encoder.encode( response );
+ public void encodeNonBlocking(ClientKey key, Object response)
+ throws EncoderException {
+ StatefulEncoder encoder = (StatefulEncoder) encoders.get(key);
+ encoder.encode(response);
}
-
- EncoderManagerMonitor getMonitor()
- {
+ EncoderManagerMonitor getMonitor() {
return monitor;
}
-
- StatefulEncoder getEncoder( ClientKey key )
- {
- return ( StatefulEncoder ) encoders.get( key ) ;
+ StatefulEncoder getEncoder(ClientKey key) {
+ return (StatefulEncoder) encoders.get(key);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncodeStageHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncodeStageHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncodeStageHandler.java
Sat Oct 30 04:31:52 2004
@@ -14,16 +14,16 @@
* limitations under the License.
*
*/
+
package org.apache.seda.encoder;
+import java.util.EventObject;
-import org.apache.seda.stage.StageHandler;
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.StatefulEncoder;
import org.apache.seda.event.ResponseEvent;
import org.apache.seda.listener.ClientKey;
-import org.apache.commons.codec.stateful.StatefulEncoder;
-import org.apache.commons.codec.EncoderException;
-
-import java.util.EventObject;
+import org.apache.seda.stage.StageHandler;
/**
@@ -32,35 +32,27 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class EncodeStageHandler implements StageHandler
-{
+public class EncodeStageHandler implements StageHandler {
private final DefaultEncoderManager encMan;
-
- public EncodeStageHandler( DefaultEncoderManager encMan )
- {
+ public EncodeStageHandler(DefaultEncoderManager encMan) {
this.encMan = encMan;
}
-
/**
* Handles an event for the Stage.
*
* @param event the event to process or handle.
*/
- public void handleEvent( EventObject event )
- {
- ResponseEvent re = ( ResponseEvent ) event;
+ public void handleEvent(EventObject event) {
+ ResponseEvent re = (ResponseEvent) event;
ClientKey key = re.getClientKey();
- StatefulEncoder encoder = encMan.getEncoder( key );
+ StatefulEncoder encoder = encMan.getEncoder(key);
- try
- {
- encoder.encode( re.getResponse() );
- }
- catch ( EncoderException e )
- {
- encMan.getMonitor().failedOnEncode( encMan, event, e );
+ try {
+ encoder.encode(re.getResponse());
+ } catch (EncoderException e) {
+ encMan.getMonitor().failedOnEncode(encMan, event, e);
}
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManager.java
Sat Oct 30 04:31:52 2004
@@ -1,55 +1,52 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.encoder ;
-
-
-import org.apache.commons.codec.EncoderException ;
-
-import org.apache.seda.listener.ClientKey;
-
-import java.nio.ByteBuffer;
-
-
-/**
- * An encoder manager used to encode a protocol specific response message into
- * a byte buffer. No requirement is enforced on the protocol or the type of
- * encoding applied.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface EncoderManager
-{
- /**
- * Encodes a protocol response without blocking.
- *
- * @param key the client's key
- * @param response the protocol response message to be encoded.
- */
- public void encodeNonBlocking( ClientKey key, Object response )
- throws EncoderException;
-
-
- /**
- * Encodes a protocol response into a byte buffer while blocking.
- *
- * @param key the client's key
- * @param response the protocol response message to be encoded.
- */
- public ByteBuffer encodeBlocking( ClientKey key, Object response )
- throws EncoderException;
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.encoder;
+
+import java.nio.ByteBuffer;
+
+import org.apache.commons.codec.EncoderException;
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * An encoder manager used to encode a protocol specific response message into
+ * a byte buffer. No requirement is enforced on the protocol or the type of
+ * encoding applied.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface EncoderManager {
+ /**
+ * Encodes a protocol response without blocking.
+ *
+ * @param key the client's key
+ * @param response the protocol response message to be encoded.
+ */
+ public void encodeNonBlocking(ClientKey key, Object response)
+ throws EncoderException;
+
+ /**
+ * Encodes a protocol response into a byte buffer while blocking.
+ *
+ * @param key the client's key
+ * @param response the protocol response message to be encoded.
+ */
+ public ByteBuffer encodeBlocking(ClientKey key, Object response)
+ throws EncoderException;
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
Sat Oct 30 04:31:52 2004
@@ -1,40 +1,42 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.encoder;
-
-
-import org.apache.seda.listener.ClientKey;
-
-import java.util.EventObject;
-
-
-/**
- * Monitor for the EncoderManager.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface EncoderManagerMonitor
-{
- void failedOnInform( EncoderManager manager, EventObject event,
- Throwable t );
- void failedOnEncode( EncoderManager manager, EventObject event,
- Throwable t );
- void failedOnEncode( EncoderManager manager, ClientKey key, Object
response,
- Throwable t );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.encoder;
+
+import java.util.EventObject;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * Monitor for the EncoderManager.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface EncoderManagerMonitor {
+ void failedOnInform(
+ EncoderManager manager, EventObject event, Throwable
t);
+
+ void failedOnEncode(
+ EncoderManager manager, EventObject event, Throwable
t);
+
+ void failedOnEncode(
+ EncoderManager manager, ClientKey key, Object response,
+ Throwable t);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,13 +14,13 @@
* limitations under the License.
*
*/
+
package org.apache.seda.encoder;
+import java.util.EventObject;
import org.apache.seda.listener.ClientKey;
-import java.util.EventObject;
-
/**
* A minimalistic monitor adapter for the EncoderManager.
@@ -28,31 +28,27 @@
* @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory Project</a>
* @version $Rev$
*/
-public class EncoderManagerMonitorAdapter implements EncoderManagerMonitor
-{
- public void failedOnInform( EncoderManager manager, EventObject event,
- Throwable t )
- {
- if ( t != null )
- {
+public class EncoderManagerMonitorAdapter implements EncoderManagerMonitor {
+ public void failedOnInform(
+ EncoderManager manager, EventObject event,
+ Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
- public void failedOnEncode( EncoderManager manager, EventObject event,
- Throwable t )
- {
- if ( t != null )
- {
+ public void failedOnEncode(
+ EncoderManager manager, EventObject event,
+ Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
- public void failedOnEncode( EncoderManager manager, ClientKey key,
- Object response, Throwable t )
- {
- if ( t != null )
- {
+ public void failedOnEncode(
+ EncoderManager manager, ClientKey key,
+ Object response, Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AbstractSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AbstractSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AbstractSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,187 +14,165 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
-import java.util.List;
-import java.util.HashMap;
-import java.util.EventObject;
import java.util.ArrayList;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
+import java.util.EventObject;
+import java.util.HashMap;
+import java.util.List;
/**
* An abstract Subscriber that calls the provided type-specific inform method
- * of Subscriber sub-interface. This way their is no need to downcast the
- * event. Reflection is used by the abstract subscriber's inform method to
+ * of Subscriber sub-interface. This way their is no need to downcast the
+ * event. Reflection is used by the abstract subscriber's inform method to
* determine at run time which inform method of a concrete subscriber to
invoke.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class AbstractSubscriber implements Subscriber
-{
+public class AbstractSubscriber implements Subscriber {
/** cached inform methods for subscribers */
private static final HashMap methods = new HashMap();
/** monitor for this Subscriber */
private final SubscriberMonitor monitor;
-
-
+
/**
* Creates a Subscriber that does not monitor failures to inform.
*/
- public AbstractSubscriber()
- {
+ public AbstractSubscriber() {
monitor = null;
}
-
-
+
/**
* Creates a Subscriber that does monitor failures on inform.
- *
+ *
* @param monitor the monitor to use on failures
*/
- public AbstractSubscriber( SubscriberMonitor monitor )
- {
+ public AbstractSubscriber(SubscriberMonitor monitor) {
this.monitor = monitor;
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- inform( this, event );
- }
- catch ( Throwable t )
- {
- if ( monitor != null )
- {
- monitor.failedOnInform( this, event, t );
- }
- else
- {
- System.err.println( "Failed to inform this Subscriber " +
- this + " about event " + event );
- System.err.println( "To prevent the above println use a non "
- + "null SubscriberMonitor" );
+ public void inform(EventObject event) {
+ try {
+ inform(this, event);
+ } catch (Throwable t) {
+ if (monitor != null) {
+ monitor.failedOnInform(this, event, t);
+ } else {
+ System.err.println("Failed to inform this Subscriber " + this
+ + " about event " + event);
+ System.err.println("To prevent the above println use a non "
+ + "null SubscriberMonitor");
}
}
}
-
-
+
/**
- * Searches for the most event type specific inform method on the target
- * subscriber to call and invokes that method. The class of the event
+ * Searches for the most event type specific inform method on the target
+ * subscriber to call and invokes that method. The class of the event
* and all its superclasses are used in succession to find a specific
inform
- * method. If a more specific inform method other than
- * <code>inform(EventObject)</code> cannot be found then a
+ * method. If a more specific inform method other than
+ * <code>inform(EventObject)</code> cannot be found then a
* NoSuchMethodException is raised.
- *
+ *
* @param subscriber the subscriber to inform
* @param event the event that is the argument to inform
*/
- public static void inform( Subscriber subscriber, EventObject event )
throws
- NoSuchMethodException, IllegalAccessException,
InvocationTargetException
- {
- if ( subscriber == null )
- {
- throw new IllegalArgumentException( "subscriber arg can't be null"
);
- }
-
- if ( event == null )
- {
- throw new IllegalArgumentException( "event arg cannot be null" );
- }
-
- Method method = getSpecificInformMethod( subscriber, event );
- Object params[] = { event };
- method.invoke( subscriber, params );
+ public static void inform(Subscriber subscriber, EventObject event)
+ throws NoSuchMethodException, IllegalAccessException,
+ InvocationTargetException {
+ if (subscriber == null) {
+ throw new IllegalArgumentException("subscriber arg can't be null");
+ }
+
+ if (event == null) {
+ throw new IllegalArgumentException("event arg cannot be null");
+ }
+
+ Method method = getSpecificInformMethod(subscriber, event);
+ Object[] params = { event };
+ method.invoke(subscriber, params);
}
-
-
+
/**
* Gets the specific inform method of a subscriber class that takes the
- * event class as its sole argument.
- *
+ * event class as its sole argument.
+ *
* @param subscr the subscriber
* @param event the event
* @return the specific inform Method to invoke
* @throws NoSuchMethodException if an inform method other than <code>
- * inform(EventObject)</code> cannot be found
+ * inform(EventObject)</code> cannot be found
*/
- public static Method getSpecificInformMethod( Subscriber subscr,
- EventObject event )
- throws NoSuchMethodException
- {
+ public static Method getSpecificInformMethod(
+ Subscriber subscr,
+ EventObject event)
+ throws NoSuchMethodException {
Method method = null;
-
+
/*
* attempt a lookup into the signature cache to see if we can find
- * the method there if not then we need to search for the method
+ * the method there if not then we need to search for the method
*/
StringBuffer signature = new StringBuffer();
- signature.append( subscr.getClass().getName() );
- signature.append( '.' );
- signature.append( "inform(" );
- signature.append( event.getClass().getName() );
- signature.append( ')' );
-
+ signature.append(subscr.getClass().getName());
+ signature.append('.');
+ signature.append("inform(");
+ signature.append(event.getClass().getName());
+ signature.append(')');
+
String key = signature.toString();
- if ( methods.containsKey( key ) )
- {
- return ( Method ) methods.get( key );
+
+ if (methods.containsKey(key)) {
+ return (Method) methods.get(key);
}
-
+
/*
* we could not find the method in the cache so we need to find it
- * and add it to the cache if it exists at all
+ * and add it to the cache if it exists at all
*/
- List list = getAllSuperclasses( event.getClass() );
- list.removeAll( getAllSuperclasses( EventObject.class ) );
- list.add( 0, event.getClass() );
-
+ List list = getAllSuperclasses(event.getClass());
+ list.removeAll(getAllSuperclasses(EventObject.class));
+ list.add(0, event.getClass());
+
// there may be two EventObject class references in the list
- while( list.contains( EventObject.class ) )
- {
- list.remove( EventObject.class );
+ while (list.contains(EventObject.class)) {
+ list.remove(EventObject.class);
}
Method[] all = subscr.getClass().getMethods();
- for ( int ii = 0; ii < all.length; ii++ )
- {
+
+ for (int ii = 0; ii < all.length; ii++) {
method = all[ii];
-
- if ( method.getName().equals( "inform" ) )
- {
+
+ if (method.getName().equals("inform")) {
Class[] paramTypes = method.getParameterTypes();
-
- if ( paramTypes.length == 1 )
- {
- for ( int jj = 0; jj < list.size(); jj++ )
- {
- if ( paramTypes[0] == list.get( jj ) )
- {
- methods.put( key, method );
+
+ if (paramTypes.length == 1) {
+ for (int jj = 0; jj < list.size(); jj++) {
+ if (paramTypes[0] == list.get(jj)) {
+ methods.put(key, method);
return method;
}
}
}
}
}
-
- throw new NoSuchMethodException( "Could not find a more specific "
- + "inform method other than " + subscr.getClass().getName()
- + ".inform(EventObject)" );
- }
+ throw new NoSuchMethodException("Could not find a more specific "
+ + "inform method other than "
+ + subscr.getClass().getName()
+ + ".inform(EventObject)");
+ }
/**
* <p>Gets a <code>List</code> of superclasses for the given class.</p>
@@ -205,18 +183,18 @@
* this one <code>null</code> if null input
*/
public static List getAllSuperclasses(Class cls) {
- if (cls == null)
- {
+ if (cls == null) {
return null;
}
-
+
List classes = new ArrayList();
Class superclass = cls.getSuperclass();
- while ( superclass != null )
- {
- classes.add( superclass );
+
+ while (superclass != null) {
+ classes.add(superclass);
superclass = superclass.getSuperclass();
}
+
return classes;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AddProtocolEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AddProtocolEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/AddProtocolEvent.java
Sat Oct 30 04:31:52 2004
@@ -1,41 +1,39 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import org.apache.seda.protocol.ProtocolProvider;
-
-
-/**
- * An event indicating the addition of a new protocol.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class AddProtocolEvent extends ProtocolEvent
-{
- /**
- * Creates a protocol addition event denoting the addition of a new
- * protocol.
- *
- * @param proto the newly added protocol
- */
- public AddProtocolEvent( ProtocolProvider proto )
- {
- super( proto );
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import org.apache.seda.protocol.ProtocolProvider;
+
+
+/**
+ * An event indicating the addition of a new protocol.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class AddProtocolEvent extends ProtocolEvent {
+ /**
+ * Creates a protocol addition event denoting the addition of a new
+ * protocol.
+ *
+ * @param proto the newly added protocol
+ */
+ public AddProtocolEvent(ProtocolProvider proto) {
+ super(proto);
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ClientEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ClientEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ClientEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
@@ -23,38 +23,33 @@
/**
- * An event associated with a specific client.
- *
+ * An event associated with a specific client.
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">
* Apache Directory Project</a>
* @version $Rev$
*/
-public abstract class ClientEvent extends EventObject
-{
+public abstract class ClientEvent extends EventObject {
/** the unique client identifier */
private final ClientKey clientKey;
-
-
+
/**
* Creates a client based event using a unique client key.
- *
+ *
* @param source the source that generated this event
* @param clientKey the client's read client key
*/
- public ClientEvent( Object source, ClientKey clientKey )
- {
- super( source );
+ public ClientEvent(Object source, ClientKey clientKey) {
+ super(source);
this.clientKey = clientKey;
}
-
/**
* Gets the unique identifier for the client associated with this event.
- *
+ *
* @return the client's unique key
*/
- public final ClientKey getClientKey()
- {
+ public final ClientKey getClientKey() {
return clientKey;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,30 +14,27 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import org.apache.seda.listener.ClientKey;
/**
* Represents the acceptance by the server of a new client socket connection.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class ConnectEvent
- extends ClientEvent
-{
+public class ConnectEvent extends ClientEvent {
/**
- * Creates a connect event which represents a client socket connection
+ * Creates a connect event which represents a client socket connection
* being established.
- *
+ *
* @param source the source that creates this event
* @param clientKey the unique client key
*/
- public ConnectEvent( Object source, ClientKey clientKey )
- {
- super( source, clientKey );
+ public ConnectEvent(Object source, ClientKey clientKey) {
+ super(source, clientKey);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ConnectSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,23 +14,22 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
/**
- * Type specific Subscriber interface for ConnectEvents which represent the
+ * Type specific Subscriber interface for ConnectEvents which represent the
* acceptance of client socket connections by a server.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface ConnectSubscriber extends Subscriber
-{
+public interface ConnectSubscriber extends Subscriber {
/**
* ConnectionEvent specific inform handler.
- *
+ *
* @param event the ConnectEvent to handle
*/
- void inform( ConnectEvent event );
+ void inform(ConnectEvent event);
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DefaultEventRouter.java
Sat Oct 30 04:31:52 2004
@@ -14,13 +14,13 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
-import java.util.List;
-import java.util.Iterator;
import java.util.ArrayList;
import java.util.EventObject;
+import java.util.Iterator;
+import java.util.List;
/**
@@ -29,251 +29,206 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultEventRouter implements EventRouter
-{
+public class DefaultEventRouter implements EventRouter {
/** a list of applied routing advice */
- private List adviceList = new ArrayList( 2 );
+ private List adviceList = new ArrayList(2);
+
/** the list of subscriptions made with this router */
- private List subscriptions = new ArrayList( 15 );
+ private List subscriptions = new ArrayList(15);
+
/** the monitor - initially set to the null monitor */
private EventRouterMonitor monitor = new EventRouterMonitorAdapter();
-
-
+
/* (non-Javadoc)
- * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
+ * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
* org.apache.seda.event.Subscriber)
*/
- public void subscribe( Class type, Subscriber subscriber )
- {
- subscribe( type, null, subscriber );
+ public void subscribe(Class type, Subscriber subscriber) {
+ subscribe(type, null, subscriber);
}
-
/*
- * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
+ * @see org.apache.seda.event.EventRouter#subscribe(java.lang.Class,
* org.apache.seda.event.Filter, org.apache.eve.event.Subscriber)
*/
- public void subscribe( Class type, Filter filter, Subscriber subscriber )
- {
- if ( ! EventObject.class.isAssignableFrom( type ) )
- {
- throw new IllegalArgumentException( "Invalid event class: "
- + type.getName() );
- }
-
- Subscription l_subscription =
- new Subscription( type, filter, subscriber );
-
- if ( ! subscriptions.contains( l_subscription ) )
- {
- synchronized ( subscriptions )
- {
- subscriptions.add( l_subscription );
+ public void subscribe(Class type, Filter filter, Subscriber subscriber) {
+ if (!EventObject.class.isAssignableFrom(type)) {
+ throw new IllegalArgumentException("Invalid event class: "
+ + type.getName());
+ }
+
+ Subscription l_subscription =
+ new Subscription(type, filter, subscriber);
+
+ if (!subscriptions.contains(l_subscription)) {
+ synchronized (subscriptions) {
+ subscriptions.add(l_subscription);
}
-
- monitor.addedSubscription( l_subscription );
+
+ monitor.addedSubscription(l_subscription);
}
}
-
/**
* @see org.apache.seda.event.EventRouter#unsubscribe(
* org.apache.seda.event.Subscriber)
*/
- public void unsubscribe( Subscriber subscriber )
- {
+ public void unsubscribe(Subscriber subscriber) {
Iterator l_list = subscriptions.iterator();
-
- synchronized ( subscriptions )
- {
- while ( l_list.hasNext() )
- {
- Subscription l_subscription = ( Subscription ) l_list.next();
- if ( subscriber == l_subscription.getSubscriber() )
- {
+
+ synchronized (subscriptions) {
+ while (l_list.hasNext()) {
+ Subscription l_subscription = (Subscription) l_list.next();
+
+ if (subscriber == l_subscription.getSubscriber()) {
l_list.remove();
- monitor.removedSubscription( l_subscription );
+ monitor.removedSubscription(l_subscription);
}
}
}
}
-
/**
* (non-Javadoc)
* @see org.apache.seda.event.EventRouter#unsubscribe(java.lang.Class,
* org.apache.seda.event.Subscriber)
*/
- public void unsubscribe( Class type, Subscriber subscriber )
- {
+ public void unsubscribe(Class type, Subscriber subscriber) {
Iterator l_list = subscriptions.iterator();
-
- synchronized ( subscriptions )
- {
- while ( l_list.hasNext() )
- {
- Subscription l_subscription = ( Subscription ) l_list.next();
- if ( subscriber == l_subscription.getSubscriber()
- && type.equals( l_subscription.getType() ) )
- {
+
+ synchronized (subscriptions) {
+ while (l_list.hasNext()) {
+ Subscription l_subscription = (Subscription) l_list.next();
+
+ if (
+ (subscriber == l_subscription.getSubscriber())
+ && type.equals(l_subscription.getType())) {
l_list.remove();
- monitor.removedSubscription( l_subscription );
+ monitor.removedSubscription(l_subscription);
}
}
}
}
-
/**
* (non-Javadoc)
* @see org.apache.seda.event.EventRouter#unsubscribe(java.lang.Class,
* org.apache.seda.event.Subscriber)
*/
- public void unsubscribe( Class type, Filter filter,
- Subscriber subscriber )
- {
- if ( ! EventObject.class.isAssignableFrom( type ) )
- {
- throw new IllegalArgumentException( "Invalid event class: "
- + type.getName() );
- }
-
- final Subscription l_subscription = new Subscription( type, filter,
- subscriber );
-
- synchronized ( subscriptions )
- {
- subscriptions.remove( l_subscription );
+ public void unsubscribe(Class type, Filter filter, Subscriber subscriber) {
+ if (!EventObject.class.isAssignableFrom(type)) {
+ throw new IllegalArgumentException("Invalid event class: "
+ + type.getName());
}
- }
+ final Subscription l_subscription =
+ new Subscription(type, filter, subscriber);
+
+ synchronized (subscriptions) {
+ subscriptions.remove(l_subscription);
+ }
+ }
/**
* (non-Javadoc)
* @see org.apache.seda.event.EventRouter#publish(java.util.EventObject)
*/
- public void publish( EventObject event )
- {
+ public void publish(EventObject event) {
final ArrayList applicableAdvice = new ArrayList();
// --------------------------------------------------------------------
// Try and see what advice we can apply
// --------------------------------------------------------------------
+ synchronized (adviceList) {
+ for (int ii = 0; ii < adviceList.size(); ii++) {
+ RoutingAdvice advice = (RoutingAdvice) adviceList.get(ii);
- synchronized( adviceList )
- {
- for ( int ii = 0; ii < adviceList.size(); ii++ )
- {
- RoutingAdvice advice = ( RoutingAdvice ) adviceList.get( ii ) ;
-
- if ( advice.isApplicable( event ) )
- {
- applicableAdvice.add( advice );
+ if (advice.isApplicable(event)) {
+ applicableAdvice.add(advice);
}
}
}
-
Subscription[] subscrArray;
- synchronized ( subscriptions )
- {
- subscrArray = ( Subscription [] ) subscriptions
- .toArray( new Subscription [ subscriptions.size() ] );
- }
- if ( applicableAdvice.isEmpty() )
- {
+ synchronized (subscriptions) {
+ subscrArray =
+ (Subscription[]) subscriptions.toArray(new
Subscription[subscriptions
+
.size()]);
+ }
- publish( event, subscrArray );
+ if (applicableAdvice.isEmpty()) {
+ publish(event, subscrArray);
return;
}
-
- if ( applicableAdvice.size() == 1 )
- {
- RoutingAdvice advice = ( RoutingAdvice ) adviceList.get( 0 ) ;
- publish( advice.getEvent( event ),
- advice.getSubscriptions( event, subscrArray ) );
+ if (applicableAdvice.size() == 1) {
+ RoutingAdvice advice = (RoutingAdvice) adviceList.get(0);
+ publish(
+ advice.getEvent(event),
+ advice.getSubscriptions(event, subscrArray));
return;
}
- throw new UnsupportedOperationException( "only one advice supported" );
+ throw new UnsupportedOperationException("only one advice supported");
/*
* you know I'm still not sure what sematics are best here whether to
* keep resubsituting events and the subscriptions or what.
*
+ EventObject newEvent = null;
+ for ( int ii = 0; ii < applicableAdvice.size(); ii++ )
+ {
+ RoutingAdvice advice = ( RoutingAdvice ) adviceList.get( ii ) ;
+ if ( ii >= applicableAdvice.size() - 1 )
+ {
+ newEvent = advice.getEvent( event );
+ }
+ }
+ */
+ }
+
+ private void publish(EventObject ev, Subscription[] subscriptions) {
+ for (int ii = 0; ii < subscriptions.length; ii++) {
+ boolean isAssignable =
+ subscriptions[ii].getType().isAssignableFrom(ev.getClass());
- EventObject newEvent = null;
- for ( int ii = 0; ii < applicableAdvice.size(); ii++ )
- {
- RoutingAdvice advice = ( RoutingAdvice ) adviceList.get( ii ) ;
-
- if ( ii >= applicableAdvice.size() - 1 )
- {
- newEvent = advice.getEvent( event );
-
- }
- }
- */
-
- }
-
-
-
- private void publish( EventObject ev, Subscription[] subscriptions )
- {
- for ( int ii = 0; ii < subscriptions.length; ii++ )
- {
- boolean isAssignable = subscriptions[ii].getType()
- .isAssignableFrom( ev.getClass() );
-
- if ( ! isAssignable )
- {
+ if (!isAssignable) {
continue;
}
- if ( subscriptions[ii].getFilter() == null )
- {
- subscriptions[ii].getSubscriber().inform( ev );
- }
- else if ( subscriptions[ii].getFilter().accept( ev ) )
- {
- subscriptions[ii].getSubscriber().inform( ev );
+ if (subscriptions[ii].getFilter() == null) {
+ subscriptions[ii].getSubscriber().inform(ev);
+ } else if (subscriptions[ii].getFilter().accept(ev)) {
+ subscriptions[ii].getSubscriber().inform(ev);
}
}
}
-
/**
* Adds advice to the advice list.
*
* @param advice the advice to apply
*/
- public void apply( RoutingAdvice advice )
- {
- adviceList.add( advice );
+ public void apply(RoutingAdvice advice) {
+ adviceList.add(advice);
}
-
/**
* Sets the event router's monitor.
- *
+ *
* @param monitor the monitor
*/
- public void setMonitor( EventRouterMonitor monitor )
- {
+ public void setMonitor(EventRouterMonitor monitor) {
this.monitor = monitor;
}
-
-
+
/**
* Gets the event router's monitor.
- *
+ *
* @return the monitor
*/
- public EventRouterMonitor getMonitor()
- {
+ public EventRouterMonitor getMonitor() {
return monitor;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,31 +14,29 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
-import org.apache.seda.listener.ClientKey ;
+import org.apache.seda.listener.ClientKey;
/**
* Represents the acceptance by the server of a new client socket connection.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DisconnectEvent extends ClientEvent
-{
+public class DisconnectEvent extends ClientEvent {
/**
* Creates a new disconnect event using the client key associated with the
- * client socket connection that was lost or dropped.
- *
+ * client socket connection that was lost or dropped.
+ *
* @param source the object that created this event which in a server
- * would be a component reponsible for dropping or detecting client
+ * would be a component reponsible for dropping or detecting client
* disconnections
* @param clientKey the client socket connection
*/
- public DisconnectEvent( Object source, ClientKey clientKey )
- {
- super( source, clientKey ) ;
+ public DisconnectEvent(Object source, ClientKey clientKey) {
+ super(source, clientKey);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/DisconnectSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,23 +14,22 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
/**
* Subscriber interface for DisconnectEvents which represent the loss or drop
* of client socket connections by a server.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface DisconnectSubscriber extends Subscriber
-{
+public interface DisconnectSubscriber extends Subscriber {
/**
* DisconnectEvent handler for this Subscriber type.
- *
+ *
* @param event the connection drop or loss event to handle
*/
- void inform( DisconnectEvent event );
+ void inform(DisconnectEvent event);
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouter.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
@@ -23,56 +23,55 @@
/**
* Event service based on an exact version of the event notifier pattern found
* <a
href="http://www.dralasoft.com/products/eventbroker/whitepaper/">here</a>.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface EventRouter
-{
+public interface EventRouter {
/**
* Subscribes an event subscriber.
- *
+ *
* @param type an event type enumeration value
* @param filter an event filter if any to apply
* @param subscriber the Subscriber to subscribe
*/
- void subscribe( Class type, Filter filter, Subscriber subscriber );
-
+ void subscribe(Class type, Filter filter, Subscriber subscriber);
+
/**
* Subscribes an event subscriber.
- *
+ *
* @param type an event type
* @param subscriber the Subscriber to subscribe
*/
- void subscribe( Class type, Subscriber subscriber );
-
+ void subscribe(Class type, Subscriber subscriber);
+
/**
* Unsubscribes an event subscriber.
- *
+ *
* @param subscriber the Subscriber to unsubscribe
*/
- void unsubscribe( Subscriber subscriber );
-
+ void unsubscribe(Subscriber subscriber);
+
/**
* Unsubscribes an event subscriber.
- *
+ *
* @param type an event type
* @param subscriber the Subscriber to unsubscribe
*/
- void unsubscribe( Class type, Subscriber subscriber );
-
+ void unsubscribe(Class type, Subscriber subscriber);
+
/**
- * Fires an event synchronously in the thread of the caller to all
+ * Fires an event synchronously in the thread of the caller to all
* subscribers registered for a specific event type.
- *
+ *
* @param event the event to publish
*/
- void publish( EventObject event );
+ void publish(EventObject event);
/**
* Applies some routing advice to applicable events.
*
* @param advice the advice to apply
*/
- void apply( RoutingAdvice advice );
+ void apply(RoutingAdvice advice);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
@@ -27,26 +27,25 @@
* Apache Directory Project</a>
* @version $Rev$
*/
-public interface EventRouterMonitor
-{
+public interface EventRouterMonitor {
/**
* Monitors events that are published.
- *
- * @param event the published event object
+ *
+ * @param event the published event object
*/
- void eventPublished( EventObject event );
-
+ void eventPublished(EventObject event);
+
/**
* Monitores the addition of new subscriptions.
- *
+ *
* @param subscription
*/
- void addedSubscription( Subscription subscription );
-
+ void addedSubscription(Subscription subscription);
+
/**
* Monitors the removal of new subscriptions
- *
+ *
* @param subscription
*/
- void removedSubscription( Subscription subscription );
+ void removedSubscription(Subscription subscription);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/EventRouterMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
@@ -27,31 +27,25 @@
* Apache Directory Project</a>
* @version $Rev$
*/
-public class EventRouterMonitorAdapter implements EventRouterMonitor
-{
+public class EventRouterMonitorAdapter implements EventRouterMonitor {
/* (non-Javadoc)
* @see org.apache.stage.event.EventRouterMonitor#eventPublished(
* java.util.EventObject)
*/
- public void eventPublished( EventObject event )
- {
+ public void eventPublished(EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.stage.event.EventRouterMonitor#addedSubscription(
* org.apache.stage.event.Subscription)
*/
- public void addedSubscription( Subscription subscription )
- {
+ public void addedSubscription(Subscription subscription) {
}
-
/* (non-Javadoc)
* @see org.apache.stage.event.EventRouterMonitor#removedSubscription(
* org.apache.stage.event.Subscription)
*/
- public void removedSubscription( Subscription subscription )
- {
+ public void removedSubscription(Subscription subscription) {
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Filter.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/event/Filter.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/event/Filter.java
Sat Oct 30 04:31:52 2004
@@ -14,26 +14,25 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
/**
- * A filter in the event router is used to further prune the subscriber's
+ * A filter in the event router is used to further prune the subscriber's
* interest list.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface Filter
-{
+public interface Filter {
/**
* Determines whether or not to inform a subscriber of an event.
- *
+ *
* @param event the event to test
* @return true if the event can be sent, false if it cannot
*/
- boolean accept( EventObject event );
+ boolean accept(EventObject event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.nio.ByteBuffer;
@@ -25,64 +25,56 @@
/**
* Input event used to indicate the availability of more data from the client.
* The data has already been read in from the client.
- *
- * Note that this is an abstract event whose methods to claim and release
- * interest in the buffer payload are abstract. This has purposefully been
- * left that way so concrete subclasses created by stages can manage the
+ *
+ * Note that this is an abstract event whose methods to claim and release
+ * interest in the buffer payload are abstract. This has purposefully been
+ * left that way so concrete subclasses created by stages can manage the
* interactions required with the buffer pool without creating a dependency
* on the BufferPool spi or its implementation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public abstract class InputEvent extends ClientEvent
-{
+public abstract class InputEvent extends ClientEvent {
/** the buffer used to store the read input */
private final ByteBuffer buffer;
-
/**
- * Creates an InputEvent
+ * Creates an InputEvent
*
* @param source the source which created this event
- * @param client the key of the client
+ * @param client the key of the client
* @param buffer the buffer containing the input chunk
*/
- public InputEvent( Object source, ClientKey client, ByteBuffer buffer )
- {
- super( source, client );
+ public InputEvent(Object source, ClientKey client, ByteBuffer buffer) {
+ super(source, client);
this.buffer = buffer;
}
-
/**
- * Gets a handle on a read-only buffer using the original as the backing
+ * Gets a handle on a read-only buffer using the original as the backing
* store and registers the accessing party as interested in the buffer.
- *
+ *
* @param party the party interested in the buffer
* @return the buffer with the partial input data
*/
- public abstract ByteBuffer claimInterest( Object party );
+ public abstract ByteBuffer claimInterest(Object party);
-
/**
- * Releases the interest for the ByteBuffer held within this InputEvent.
+ * Releases the interest for the ByteBuffer held within this InputEvent.
* Once all interested parties have released their interest in the buffer
it
* is reclaimed.
- *
+ *
* @param party the party that originally claimed interest
*/
- public abstract void releaseInterest( Object party );
+ public abstract void releaseInterest(Object party);
-
/**
* Gets the underlying byte buffer associated with this InputEvent.
- *
+ *
* @return the underlying byte buffer
*/
- protected ByteBuffer getBuffer()
- {
+ protected ByteBuffer getBuffer() {
return buffer;
}
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/InputSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,23 +14,22 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
/**
* Subscriber interface for InputEvents which represents the arrival of a chunk
* of client socket connection data.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface InputSubscriber extends Subscriber
-{
+public interface InputSubscriber extends Subscriber {
/**
* InputEvent handler for this Subscriber type.
- *
+ *
* @param event the input event to handle incoming data
*/
- void inform( InputEvent event );
+ void inform(InputEvent event);
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputEvent.java
Sat Oct 30 04:31:52 2004
@@ -1,62 +1,57 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import java.nio.ByteBuffer;
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * An event used to denote output to send to a client. The output event
- * only connotates that data is available for output but not yet delivered.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class OutputEvent extends ClientEvent
-{
- /** the data chunk to send */
- private final ByteBuffer buf;
-
-
- /**
- * Creates an output event using a clientKey, buf of data and the source
- * for this event.
- *
- * @param source the source which created this event
- * @param clientKey the key of the client
- * @param buf the buffer containing the chunk to output
- */
- public OutputEvent( Object source, ClientKey clientKey, ByteBuffer buf )
- {
- super( source, clientKey );
- this.buf = buf;
- }
-
-
- /**
- * Gets the buffer containing the chunk to output.
- *
- * @return the chunk to flush back to the client
- */
- public ByteBuffer getBuffer()
- {
- return buf;
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import java.nio.ByteBuffer;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * An event used to denote output to send to a client. The output event
+ * only connotates that data is available for output but not yet delivered.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class OutputEvent extends ClientEvent {
+ /** the data chunk to send */
+ private final ByteBuffer buf;
+
+ /**
+ * Creates an output event using a clientKey, buf of data and the source
+ * for this event.
+ *
+ * @param source the source which created this event
+ * @param clientKey the key of the client
+ * @param buf the buffer containing the chunk to output
+ */
+ public OutputEvent(Object source, ClientKey clientKey, ByteBuffer buf) {
+ super(source, clientKey);
+ this.buf = buf;
+ }
+
+ /**
+ * Gets the buffer containing the chunk to output.
+ *
+ * @return the chunk to flush back to the client
+ */
+ public ByteBuffer getBuffer() {
+ return buf;
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/OutputSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -1,36 +1,36 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event ;
-
-
-/**
- * Subscriber interface for OutputEvents which represents the need to send a
- * chunk of response data to the client.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface OutputSubscriber extends Subscriber
-{
- /**
- * Informs a Subscriber of an OutputEvent denoting the need to send a
- * chunk of response data back to a client.
- *
- * @param event the event carrying the chunk payload to send
- */
- void inform( OutputEvent event ) ;
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+
+/**
+ * Subscriber interface for OutputEvents which represents the need to send a
+ * chunk of response data to the client.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface OutputSubscriber extends Subscriber {
+ /**
+ * Informs a Subscriber of an OutputEvent denoting the need to send a
+ * chunk of response data back to a client.
+ *
+ * @param event the event carrying the chunk payload to send
+ */
+ void inform(OutputEvent event);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolEvent.java
Sat Oct 30 04:31:52 2004
@@ -1,53 +1,49 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import org.apache.seda.protocol.ProtocolProvider;
-
-import java.util.EventObject;
-
-
-/**
- * A base for protocol configuration specific events.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ProtocolEvent extends EventObject
-{
- /**
- * Creates a protocol event with the protocol provider as the source.
- *
- * @param proto the protocol provider associated with this event
- */
- public ProtocolEvent( ProtocolProvider proto )
- {
- super( proto );
- }
-
-
- /**
- * Gets the protocol provider associated with this protocol event.
- *
- * @return the protocol provider that caused this event
- */
- public ProtocolProvider getProtocolProvider()
- {
- return ( ProtocolProvider ) getSource();
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import java.util.EventObject;
+
+import org.apache.seda.protocol.ProtocolProvider;
+
+
+/**
+ * A base for protocol configuration specific events.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ProtocolEvent extends EventObject {
+ /**
+ * Creates a protocol event with the protocol provider as the source.
+ *
+ * @param proto the protocol provider associated with this event
+ */
+ public ProtocolEvent(ProtocolProvider proto) {
+ super(proto);
+ }
+
+ /**
+ * Gets the protocol provider associated with this protocol event.
+ *
+ * @return the protocol provider that caused this event
+ */
+ public ProtocolProvider getProtocolProvider() {
+ return (ProtocolProvider) getSource();
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ProtocolSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -1,34 +1,35 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-/**
- * Type specific subscriber for all protocol events which represent protocol
- * configuration changes.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface ProtocolSubscriber extends Subscriber
-{
- /**
- * Informs this subscriber of a protocol event.
- *
- * @param event the protocol event to inform of
- */
- void inform( ProtocolEvent event );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+
+/**
+ * Type specific subscriber for all protocol events which represent protocol
+ * configuration changes.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ProtocolSubscriber extends Subscriber {
+ /**
+ * Informs this subscriber of a protocol event.
+ *
+ * @param event the protocol event to inform of
+ */
+ void inform(ProtocolEvent event);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestEvent.java
Sat Oct 30 04:31:52 2004
@@ -1,58 +1,53 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * An event used to denote the arrival of a protocol client request.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class RequestEvent extends ClientEvent
-{
- /** the request message */
- private final Object request;
-
-
- /**
- * Creates an event used to denote the arrival of a client request.
- *
- * @param source the source that created this event
- * @param clientKey the key of the client associated with this event
- * @param request the request message
- */
- public RequestEvent( Object source, ClientKey clientKey, Object request )
- {
- super( source, clientKey );
- this.request = request;
- }
-
-
- /**
- * Gets the request message associated with this event.
- *
- * @return the request message associated with this event
- */
- public Object getRequest()
- {
- return request;
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * An event used to denote the arrival of a protocol client request.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class RequestEvent extends ClientEvent {
+ /** the request message */
+ private final Object request;
+
+ /**
+ * Creates an event used to denote the arrival of a client request.
+ *
+ * @param source the source that created this event
+ * @param clientKey the key of the client associated with this event
+ * @param request the request message
+ */
+ public RequestEvent(Object source, ClientKey clientKey, Object request) {
+ super(source, clientKey);
+ this.request = request;
+ }
+
+ /**
+ * Gets the request message associated with this event.
+ *
+ * @return the request message associated with this event
+ */
+ public Object getRequest() {
+ return request;
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RequestSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -1,34 +1,34 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event ;
-
-
-/**
- * A subscriber that recieves RequestEvents.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface RequestSubscriber extends Subscriber
-{
- /**
- * RequestEvent handler for this Subscriber type.
- *
- * @param event the request event to handle an incoming client request
- */
- void inform( RequestEvent event ) ;
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+
+/**
+ * A subscriber that recieves RequestEvents.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface RequestSubscriber extends Subscriber {
+ /**
+ * RequestEvent handler for this Subscriber type.
+ *
+ * @param event the request event to handle an incoming client request
+ */
+ void inform(RequestEvent event);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseEvent.java
Sat Oct 30 04:31:52 2004
@@ -1,61 +1,56 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * An event used to denote the response to a client request. The response
event
- * only connotates that a response was made not delivered. The delivery is an
- * output event.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ResponseEvent extends ClientEvent
-{
- /** the response message */
- private final Object response;
-
-
- /**
- * Creates an event used to denote the response to a request before it is
- * delivered.
- *
- * @param source the source that created this event
- * @param clientKey the key of the client associated with this event
- * @param response the response message
- */
- public ResponseEvent( Object source, ClientKey clientKey, Object response )
- {
- super( source, clientKey );
- this.response = response;
- }
-
-
- /**
- * Gets the response message associated with this event.
- *
- * @return the response message associated with this event
- */
- public Object getResponse()
- {
- return response;
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * An event used to denote the response to a client request. The response
event
+ * only connotates that a response was made not delivered. The delivery is an
+ * output event.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ResponseEvent extends ClientEvent {
+ /** the response message */
+ private final Object response;
+
+ /**
+ * Creates an event used to denote the response to a request before it is
+ * delivered.
+ *
+ * @param source the source that created this event
+ * @param clientKey the key of the client associated with this event
+ * @param response the response message
+ */
+ public ResponseEvent(Object source, ClientKey clientKey, Object response) {
+ super(source, clientKey);
+ this.response = response;
+ }
+
+ /**
+ * Gets the response message associated with this event.
+ *
+ * @return the response message associated with this event
+ */
+ public Object getResponse() {
+ return response;
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/ResponseSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -1,35 +1,35 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-/**
- * A subscriber that recieves ResponseEvents.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface ResponseSubscriber extends Subscriber
-{
- /**
- * ResponseEvent handler for this Subscriber type.
- *
- * @param event the response event to handle an incoming client request
- */
- void inform( ResponseEvent event );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+
+/**
+ * A subscriber that recieves ResponseEvents.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ResponseSubscriber extends Subscriber {
+ /**
+ * ResponseEvent handler for this Subscriber type.
+ *
+ * @param event the response event to handle an incoming client request
+ */
+ void inform(ResponseEvent event);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RoutingAdvice.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RoutingAdvice.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/RoutingAdvice.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.EventObject;
@@ -33,8 +33,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface RoutingAdvice
-{
+public interface RoutingAdvice {
/**
* Returns an alternative list of Subscriptions which may or may not be
* the same as those already registered with the router service.
@@ -43,8 +42,9 @@
* @param subscriptions the subscriptions already registered with the
router
* @return the advised list of subscriptions to use instead
*/
- public Subscription[] getSubscriptions( EventObject ev, Subscription[]
subscriptions );
-
+ public Subscription[] getSubscriptions(
+ EventObject ev,
+ Subscription[] subscriptions);
/**
* Gets an alternative event to use as the argument to inform Subscribers
@@ -53,8 +53,7 @@
* @param ev the event being published
* @return the advised event to use instead
*/
- public EventObject getEvent( EventObject ev );
-
+ public EventObject getEvent(EventObject ev);
/**
* Checks to see if this advice is applicable to an event.
@@ -62,5 +61,5 @@
* @param ev the event to check for advice applicability
* @return true if this advice applies, false otherwise
*/
- public boolean isApplicable( EventObject ev );
+ public boolean isApplicable(EventObject ev);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import org.apache.seda.session.ClientSession;
@@ -25,38 +25,32 @@
* with the establishment of a new client connection. Attempts to rebind to
* the directory may destroy an existing session and create another one without
* droping the socket connection.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class SessionCreationEvent extends ClientEvent
-{
+public class SessionCreationEvent extends ClientEvent {
/** the newly created client session */
private final ClientSession session;
-
-
+
/**
- * Creates a new event using a source, a client and the newly created
+ * Creates a new event using a source, a client and the newly created
* session object.
- *
+ *
* @param source the source that created this event
* @param session the newly created client session
*/
- public SessionCreationEvent( Object source, ClientSession session )
- {
- super( source, session.getClientKey() );
+ public SessionCreationEvent(Object source, ClientSession session) {
+ super(source, session.getClientKey());
this.session = session;
}
-
/**
* Gets the newly created session object.
- *
+ *
* @return the newly created session object
*/
- public ClientSession getClientSession()
- {
+ public ClientSession getClientSession() {
return this.session;
}
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationSubscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationSubscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionCreationSubscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,21 +14,21 @@
* limitations under the License.
*
*/
-package org.apache.seda.event ;
+
+package org.apache.seda.event;
/**
* Type safe Subscriber for session creation events for clients.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface SessionCreationSubscriber extends Subscriber
-{
+public interface SessionCreationSubscriber extends Subscriber {
/**
* Informs the Subscriber interested in SessionCreationEvents.
- *
+ *
* @param event the event to inform this Subscriber about.
*/
- public void inform( SessionCreationEvent event );
+ public void inform(SessionCreationEvent event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionEvent.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionEvent.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionEvent.java
Sat Oct 30 04:31:52 2004
@@ -14,49 +14,43 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import org.apache.seda.session.ClientSession;
/**
- * Denotes the destruction of a client session which does not necessarily
+ * Denotes the destruction of a client session which does not necessarily
* coincide with the loss of a socket connection. Attempts to rebind to
* the directory may destroy an existing session and create another one without
* droping the socket connection.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class SessionDestructionEvent extends ClientEvent
-{
+public class SessionDestructionEvent extends ClientEvent {
/** the newly created client session */
private final ClientSession session;
-
-
+
/**
* Creates a new event using a source, a client and the destroyed client
* session object.
- *
+ *
* @param source the source that created this event
* @param session the newly created client session
*/
- public SessionDestructionEvent( Object source, ClientSession session )
- {
- super( source, session.getClientKey() );
+ public SessionDestructionEvent(Object source, ClientSession session) {
+ super(source, session.getClientKey());
this.session = session;
}
-
/**
* Gets the destroyed client session object.
- *
+ *
* @return the destroyed session object
*/
- public ClientSession getClientSession()
- {
+ public ClientSession getClientSession() {
return this.session;
}
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionListener.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionListener.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SessionDestructionListener.java
Sat Oct 30 04:31:52 2004
@@ -14,21 +14,21 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
/**
* Type safe Subscriber interested in session deletion events.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface SessionDestructionListener
-{
+public interface SessionDestructionListener {
/**
* Informs this Subscriber of session destruction events.
- *
+ *
* @param event the destruction event to inform of
*/
- public void inform( SessionDestructionEvent event );
+ public void inform(SessionDestructionEvent event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscriber.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscriber.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscriber.java
Sat Oct 30 04:31:52 2004
@@ -14,26 +14,25 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
-import java.util.EventObject ;
-import java.util.EventListener ;
+import java.util.EventListener;
+import java.util.EventObject;
/**
- * A Subscriber from the Event Notifier pattern.
- *
+ * A Subscriber from the Event Notifier pattern.
+ *
* @see <a
href="http://www.dralasoft.com/products/eventbroker/whitepaper/">Event Notifier
Pattern</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface Subscriber extends EventListener
-{
+public interface Subscriber extends EventListener {
/**
* Informs this Subscriber of an event.
- *
- * @param event the event notified of
+ *
+ * @param event the event notified of
*/
- void inform( EventObject event );
+ void inform(EventObject event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SubscriberMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SubscriberMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/SubscriberMonitor.java
Sat Oct 30 04:31:52 2004
@@ -1,40 +1,40 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.event;
-
-
-import java.util.EventObject;
-
-
-/**
- * Monitors noteworthy Subscriber activities.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface SubscriberMonitor
-{
- /**
- * Monitors failures occuring while handling events.
- *
- * @param subscriber the Subscriber that failed on inform
- * @param eventObject the EventObject fired
- * @param throwable the resulting failure exception if any
- */
- void failedOnInform( Subscriber subscriber, EventObject eventObject,
- Throwable throwable );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.event;
+
+import java.util.EventObject;
+
+
+/**
+ * Monitors noteworthy Subscriber activities.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SubscriberMonitor {
+ /**
+ * Monitors failures occuring while handling events.
+ *
+ * @param subscriber the Subscriber that failed on inform
+ * @param eventObject the EventObject fired
+ * @param throwable the resulting failure exception if any
+ */
+ void failedOnInform(
+ Subscriber subscriber, EventObject eventObject,
+ Throwable throwable);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/event/Subscription.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.event;
@@ -23,129 +24,112 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class Subscription
-{
+public class Subscription {
/** the filter if any used to filter out events */
private final Filter filter;
+
/** the event class */
private final Class type;
+
/** the subscriber */
private final Subscriber subscriber;
-
/**
- * Creates a subscription for a type of event using a filter and a
+ * Creates a subscription for a type of event using a filter and a
* subscriber.
- *
+ *
* @param type the class of event to be informed on
* @param filter the Filter to use weed out unwanted events
* @param subscriber the subscriber to deliever the event to
*/
- public Subscription( Class type, Filter filter, Subscriber subscriber )
- {
+ public Subscription(Class type, Filter filter, Subscriber subscriber) {
this.type = type;
this.filter = filter;
this.subscriber = subscriber;
}
-
-
+
/**
* Get the event class/type
*
* @return the event class/type
*/
- public Class getType()
- {
+ public Class getType() {
return type;
}
-
/**
* Get the filter used with this subscription.
*
* @return The filter
*/
- public Filter getFilter()
- {
+ public Filter getFilter() {
return filter;
}
-
/**
* Get the subscriber.
*
* @return the subscriber
*/
- public Subscriber getSubscriber()
- {
+ public Subscriber getSubscriber() {
return subscriber;
}
-
/**
* Compare two Subscriptions to each other.
*
* @param obj the object to compare this Subscription to
* @return <code>true</code> if the two Subscription objects are the same
*/
- public boolean equals( Object obj )
- {
- if ( this == obj )
- {
+ public boolean equals(Object obj) {
+ if (this == obj) {
return true;
}
-
- if ( ! ( obj instanceof Subscription ) )
- {
+
+ if (!(obj instanceof Subscription)) {
return false;
}
- final Subscription l_subscription = ( Subscription ) obj;
+ final Subscription l_subscription = (Subscription) obj;
- if ( ! type.equals( l_subscription.getType() ) )
- {
+ if (!type.equals(l_subscription.getType())) {
return false;
}
-
- if ( filter != null )
- {
- if ( l_subscription.getFilter() == null )
- {
+
+ if (filter != null) {
+ if (l_subscription.getFilter() == null) {
return false;
}
-
- if ( ! filter.equals( l_subscription.getFilter() ) )
- {
+
+ if (!filter.equals(l_subscription.getFilter())) {
return false;
}
}
-
- if ( ! subscriber.equals( l_subscription.getSubscriber() ) )
- {
+
+ if (!subscriber.equals(l_subscription.getSubscriber())) {
return false;
}
return true;
}
-
/**
* Get the hashcode (used in HashMaps).
*
* hashCode = 37 * (37 * (629 + event.hashCode()) + filter.hashCode())
* + subscriber.hashCode()
- *
+ *
* This method was borrowed from Berin Loritsch.
- *
+ *
* @return the hashCode value
*/
- public int hashCode()
- {
+ public int hashCode() {
int l_result = 17;
- l_result = 37 * l_result + type.hashCode();
- l_result = 37 * l_result +
- ( filter != null ? filter.hashCode() : 0 );
- l_result = 37 * l_result + subscriber.hashCode();
+ l_result = (37 * l_result) + type.hashCode();
+ l_result = (37 * l_result) + (
+ (filter != null) ? filter.hashCode() : 0
+ );
+ l_result = (37 * l_result) + subscriber.hashCode();
return l_result;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/Enum.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/Enum.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/Enum.java
Sat Oct 30 04:31:52 2004
@@ -1,23 +1,27 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
*/
+
package org.apache.seda.impl.util;
import java.io.Serializable;
+
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -26,7 +30,6 @@
import java.util.Map;
-
/**
* <p>Abstract superclass for type-safe enums.</p>
*
@@ -39,10 +42,10 @@
* <p><em>NOTE:</em>Due to the way in which Java ClassLoaders work, comparing
* Enum objects should always be done using <code>equals()</code>, not
<code>==</code>.
* The equals() method will try == first so in most cases the effect is the
same.</p>
- *
+ *
* <p>Of course, if you actually want (or don't mind) Enums in different class
* loaders being non-equal, then you can use <code>==</code>.</p>
- *
+ *
* <h4>Simple Enums</h4>
*
* <p>To use this class, it must be subclassed. For example:</p>
@@ -56,19 +59,19 @@
* private ColorEnum(String color) {
* super(color);
* }
- *
+ *
* public static ColorEnum getEnum(String color) {
* return (ColorEnum) getEnum(ColorEnum.class, color);
* }
- *
+ *
* public static Map getEnumMap() {
* return getEnumMap(ColorEnum.class);
* }
- *
+ *
* public static List getEnumList() {
* return getEnumList(ColorEnum.class);
* }
- *
+ *
* public static Iterator iterator() {
* return iterator(ColorEnum.class);
* }
@@ -80,7 +83,7 @@
* <p>The <code>getEnum</code> and <code>iterator</code> methods are
recommended.
* Unfortunately, Java restrictions require these to be coded as shown in each
subclass.
* An alternative choice is to use the [EMAIL PROTECTED] EnumUtils} class.</p>
- *
+ *
* <h4>Subclassed Enums</h4>
* <p>A hierarchy of Enum classes can be built. In this case, the superclass is
* unaffected by the addition of subclasses (as per normal Java). The
subclasses
@@ -97,19 +100,19 @@
* private ExtraColorEnum(String color) {
* super(color);
* }
- *
+ *
* public static ColorEnum getEnum(String color) {
* return (ColorEnum) getEnum(ExtraColorEnum.class, color);
* }
- *
+ *
* public static Map getEnumMap() {
* return getEnumMap(ExtraColorEnum.class);
* }
- *
+ *
* public static List getEnumList() {
* return getEnumList(ExtraColorEnum.class);
* }
- *
+ *
* public static Iterator iterator() {
* return iterator(ExtraColorEnum.class);
* }
@@ -117,15 +120,15 @@
* </pre>
*
* <p>This example will return RED, GREEN, BLUE, YELLOW from the List and
iterator
- * methods in that order. The RED, GREEN and BLUE instances will be the same
(==)
+ * methods in that order. The RED, GREEN and BLUE instances will be the same
(==)
* as those from the superclass ColorEnum. Note that YELLOW is declared as a
* ColorEnum and not an ExtraColorEnum.</p>
- *
+ *
* <h4>Functional Enums</h4>
*
* <p>The enums can have functionality by defining subclasses and
* overriding the <code>getEnumClass()</code> method:</p>
- *
+ *
* <pre>
* public static final OperationEnum PLUS = new PlusOperation();
* private static final class PlusOperation extends OperationEnum {
@@ -149,25 +152,25 @@
* private OperationEnum(String color) {
* super(color);
* }
- *
+ *
* public final Class getEnumClass() { // NOTE: new method!
* return OperationEnum.class;
* }
*
* public abstract double eval(double a, double b);
- *
+ *
* public static OperationEnum getEnum(String name) {
* return (OperationEnum) getEnum(OperationEnum.class, name);
* }
- *
+ *
* public static Map getEnumMap() {
* return getEnumMap(OperationEnum.class);
* }
- *
+ *
* public static List getEnumList() {
* return getEnumList(OperationEnum.class);
* }
- *
+ *
* public static Iterator iterator() {
* return iterator(OperationEnum.class);
* }
@@ -175,7 +178,7 @@
* </pre>
* <p>The code above will work on JDK 1.2. If JDK1.3 and later is used,
* the subclasses may be defined as anonymous.</p>
- *
+ *
* <h4>Nested class Enums</h4>
*
* <p>Care must be taken with class loading when defining a static nested class
@@ -191,17 +194,17 @@
*
* // static nested enum class
* public static final class BWEnum extends Enum {
- *
+ *
* static {
* // explicitly reference BWEnum class to force constants to load
* Object obj = Outer.BLACK;
* }
- *
+ *
* // ... other methods omitted
* }
* }
* </pre>
- *
+ *
* <p>Although the above solves the problem, it is not recommended. The best
solution
* is to define the constants in the enum class, and hold references in the
outer class:
*
@@ -215,49 +218,50 @@
* // only define constants in enum classes - private if desired
* private static final BWEnum BLACK = new BWEnum("Black");
* private static final BWEnum WHITE = new BWEnum("White");
- *
+ *
* // ... other methods omitted
* }
* }
* </pre>
- *
+ *
* <p>For more details, see the 'Nested' test cases.
- *
+ *
* @see org.apache.seda.impl.util.Enum
* @author Apache Avalon project
* @author Stephen Colebourne
* @author Chris Webb
* @author Mike Bowler
* @since 1.0
- * @version $Id: Enum.java,v 1.28 2004/02/23 04:34:20 ggregory Exp $
+ * @version $Id$
*/
public abstract class Enum implements Comparable, Serializable {
-
/** Lang version 1.0.1 serial compatibility */
private static final long serialVersionUID = -487045951170455942L;
-
+
// After discussion, the default size for HashMaps is used, as the
// sizing algorithm changes across the JDK versions
+
/**
* An empty <code>Map</code>, as JDK1.2 didn't have an empty map.
*/
- private static final Map EMPTY_MAP = Collections.unmodifiableMap(new
HashMap(0));
-
+ private static final Map EMPTY_MAP =
+ Collections.unmodifiableMap(new HashMap(0));
+
/**
* <code>Map</code>, key of class name, value of <code>Entry</code>.
*/
private static final Map cEnumClasses = new HashMap();
-
+
/**
* The string representation of the Enum.
*/
private final String iName;
-
+
/**
* The hashcode representation of the Enum.
*/
- private transient final int iHashCode;
-
+ private final transient int iHashCode;
+
/**
* The toString representation of the Enum.
* @since 2.0
@@ -265,34 +269,6 @@
protected transient String iToString = null;
/**
- * <p>Enable the iterator to retain the source code order.</p>
- */
- private static class Entry {
- /**
- * Map of Enum name to Enum.
- */
- final Map map = new HashMap();
- /**
- * Map of Enum name to Enum.
- */
- final Map unmodifiableMap = Collections.unmodifiableMap(map);
- /**
- * List of Enums in source code order.
- */
- final List list = new ArrayList(25);
- /**
- * Map of Enum name to Enum.
- */
- final List unmodifiableList = Collections.unmodifiableList(list);
-
- /**
- * <p>Restrictive constructor.</p>
- */
- private Entry() {
- }
- }
-
- /**
* <p>Constructor to add a new named item to the enumeration.</p>
*
* @param name the name of the enum object,
@@ -306,48 +282,61 @@
super();
init(name);
iName = name;
- iHashCode = 7 + getEnumClass().hashCode() + 3 * name.hashCode();
+ iHashCode = 7 + getEnumClass().hashCode() + (3 * name.hashCode());
+
// cannot create toString here as subclasses may want to include other
data
}
/**
* Initializes the enumeration.
- *
+ *
* @param name the enum name
* @throws IllegalArgumentException if the name is null or empty or
duplicate
* @throws IllegalArgumentException if the enumClass is null or invalid
*/
private void init(String name) {
- if ( name == null || name.equals( "" ) ) {
+ if ((name == null) || name.equals("")) {
throw new IllegalArgumentException("The Enum name must not be
empty or null");
}
-
+
Class enumClass = getEnumClass();
+
if (enumClass == null) {
throw new IllegalArgumentException("getEnumClass() must not be
null");
}
+
Class cls = getClass();
boolean ok = false;
- while (cls != null && cls != Enum.class && cls != ValuedEnum.class) {
+
+ while (
+ (cls != null) && (cls != Enum.class)
+ && (cls != ValuedEnum.class)) {
if (cls == enumClass) {
ok = true;
break;
}
+
cls = cls.getSuperclass();
}
+
if (ok == false) {
throw new IllegalArgumentException("getEnumClass() must return a
superclass of this class");
}
-
+
// create entry
Entry entry = (Entry) cEnumClasses.get(enumClass);
+
if (entry == null) {
entry = createEntry(enumClass);
cEnumClasses.put(enumClass, entry);
}
+
if (entry.map.containsKey(name)) {
- throw new IllegalArgumentException("The Enum name must be unique,
'" + name + "' has already been added");
+ throw new IllegalArgumentException("The Enum name must be unique,
'"
+ + name
+ + "' has already been added");
}
+
entry.map.put(name, this);
entry.list.add(this);
}
@@ -360,17 +349,19 @@
*/
protected Object readResolve() {
Entry entry = (Entry) cEnumClasses.get(getEnumClass());
+
if (entry == null) {
return null;
}
+
return (Enum) entry.map.get(getName());
}
-
+
//--------------------------------------------------------------------------------
/**
* <p>Gets an <code>Enum</code> object by class and name.</p>
- *
+ *
* @param enumClass the class of the Enum to get, must not
* be <code>null</code>
* @param name the name of the <code>Enum</code> to get,
@@ -381,9 +372,11 @@
*/
protected static Enum getEnum(Class enumClass, String name) {
Entry entry = getEntry(enumClass);
+
if (entry == null) {
return null;
}
+
return (Enum) entry.map.get(name);
}
@@ -393,7 +386,7 @@
*
* <p>If the requested class has no enum objects an empty
* <code>Map</code> is returned.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get,
* must not be <code>null</code>
* @return the enum object Map
@@ -402,9 +395,11 @@
*/
protected static Map getEnumMap(Class enumClass) {
Entry entry = getEntry(enumClass);
+
if (entry == null) {
return EMPTY_MAP;
}
+
return entry.unmodifiableMap;
}
@@ -415,7 +410,7 @@
* <p>The list is in the order that the objects were created (source code
order).
* If the requested class has no enum objects an empty <code>List</code> is
* returned.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get,
* must not be <code>null</code>
* @return the enum object Map
@@ -424,9 +419,11 @@
*/
protected static List getEnumList(Class enumClass) {
Entry entry = getEntry(enumClass);
+
if (entry == null) {
return Collections.EMPTY_LIST;
}
+
return entry.unmodifiableList;
}
@@ -437,7 +434,7 @@
* <p>The <code>Iterator</code> is in the order that the objects were
* created (source code order). If the requested class has no enum
* objects an empty <code>Iterator</code> is returned.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get,
* must not be <code>null</code>
* @return an iterator of the Enum objects
@@ -449,9 +446,10 @@
}
//-----------------------------------------------------------------------
+
/**
* <p>Gets an <code>Entry</code> from the map of Enums.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @return the enum entry
*/
@@ -459,40 +457,49 @@
if (enumClass == null) {
throw new IllegalArgumentException("The Enum Class must not be
null");
}
+
if (Enum.class.isAssignableFrom(enumClass) == false) {
throw new IllegalArgumentException("The Class must be a subclass
of Enum");
}
+
Entry entry = (Entry) cEnumClasses.get(enumClass);
return entry;
}
-
+
/**
* <p>Creates an <code>Entry</code> for storing the Enums.</p>
*
* <p>This accounts for subclassed Enums.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @return the enum entry
*/
private static Entry createEntry(Class enumClass) {
Entry entry = new Entry();
Class cls = enumClass.getSuperclass();
- while (cls != null && cls != Enum.class && cls != ValuedEnum.class) {
+
+ while (
+ (cls != null) && (cls != Enum.class)
+ && (cls != ValuedEnum.class)) {
Entry loopEntry = (Entry) cEnumClasses.get(cls);
+
if (loopEntry != null) {
entry.list.addAll(loopEntry.list);
entry.map.putAll(loopEntry.map);
- break; // stop here, as this will already have had
superclasses added
+ break; // stop here, as this will already have had
superclasses added
}
+
cls = cls.getSuperclass();
}
+
return entry;
}
-
+
//-----------------------------------------------------------------------
+
/**
* <p>Retrieve the name of this Enum item, set in the constructor.</p>
- *
+ *
* @return the <code>String</code> name of this Enum item
*/
public final String getName() {
@@ -501,11 +508,11 @@
/**
* <p>Retrieves the Class of this Enum item, set in the constructor.</p>
- *
+ *
* <p>This is normally the same as <code>getClass()</code>, but for
* advanced Enums may be different. If overridden, it must return a
* constant value.</p>
- *
+ *
* @return the <code>Class</code> of the enum
* @since 2.0
*/
@@ -519,7 +526,7 @@
* <p>Two Enum objects are considered equal
* if they have the same class names and the same names.
* Identity is tested for first, so this method usually runs fast.</p>
- *
+ *
* <p>If the parameter is in a different class loader than this instance,
* reflection is used to compare the names.</p>
*
@@ -549,10 +556,11 @@
} catch (InvocationTargetException e) {
// ignore - should never happen
}
+
return false;
}
}
-
+
/**
* <p>Returns a suitable hashCode for the enumeration.</p>
*
@@ -567,7 +575,7 @@
*
* <p>The default ordering is alphabetic by name, but this
* can be overridden by subclasses.</p>
- *
+ *
* @see java.lang.Comparable#compareTo(Object)
* @param other the other object to compare to
* @return -ve if this is less than the other object, +ve if greater
@@ -579,12 +587,13 @@
if (other == this) {
return 0;
}
+
return iName.compareTo(((Enum) other).iName);
}
/**
* <p>Human readable description of this Enum item.</p>
- *
+ *
* @return String in the form <code>type[name]</code>, for example:
* <code>Color[Red]</code>. Note that the package name is stripped from
* the type name.
@@ -593,25 +602,58 @@
if (iToString == null) {
String shortName = null;
- if ( getEnumClass() == null )
- {
+ if (getEnumClass() == null) {
shortName = "";
- }
- else {
- char[] chars =
getEnumClass().getClass().getName().toCharArray();
+ } else {
+ char[] chars =
+ getEnumClass().getClass().getName().toCharArray();
int lastDot = 0;
+
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '.') {
lastDot = i + 1;
- } else if (chars[i] == '$') { // handle inner classes
+ } else if (chars[i] == '$') { // handle inner classes
chars[i] = '.';
}
}
+
shortName = new String(chars, lastDot, chars.length - lastDot);
}
iToString = shortName + "[" + getName() + "]";
}
+
return iToString;
+ }
+
+ /**
+ * <p>Enable the iterator to retain the source code order.</p>
+ */
+ private static class Entry {
+ /**
+ * Map of Enum name to Enum.
+ */
+ final Map map = new HashMap();
+
+ /**
+ * Map of Enum name to Enum.
+ */
+ final Map unmodifiableMap = Collections.unmodifiableMap(map);
+
+ /**
+ * List of Enums in source code order.
+ */
+ final List list = new ArrayList(25);
+
+ /**
+ * Map of Enum name to Enum.
+ */
+ final List unmodifiableList = Collections.unmodifiableList(list);
+
+ /**
+ * <p>Restrictive constructor.</p>
+ */
+ private Entry() {
+ }
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/EnumUtils.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/EnumUtils.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/EnumUtils.java
Sat Oct 30 04:31:52 2004
@@ -1,18 +1,20 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
*/
+
package org.apache.seda.impl.util;
import java.util.Iterator;
@@ -29,10 +31,9 @@
* @author Stephen Colebourne
* @author Gary Gregory
* @since 1.0
- * @version $Id: EnumUtils.java,v 1.12 2004/02/23 04:34:20 ggregory Exp $
+ * @version $Id$
*/
public class EnumUtils {
-
/**
* Public constructor. This class should not normally be instantiated.
* @since 2.0
@@ -42,7 +43,7 @@
/**
* <p>Gets an <code>Enum</code> object by class and name.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @param name the name of the Enum to get, may be <code>null</code>
* @return the enum object
@@ -54,7 +55,7 @@
/**
* <p>Gets a <code>ValuedEnum</code> object by class and value.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @param value the value of the <code>Enum</code> to get
* @return the enum object, or null if the enum does not exist
@@ -70,7 +71,7 @@
*
* <p>If the requested class has no enum objects an empty
* <code>Map</code> is returned. The <code>Map</code> is unmodifiable.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @return the enum object Map
* @throws IllegalArgumentException if the enum class is <code>null</code>
@@ -90,7 +91,7 @@
*
* <p>If the requested class has no enum objects an empty
* <code>List</code> is returned. The <code>List</code> is
unmodifiable.</p>
- *
+ *
* @param enumClass the class of the Enum to get
* @return the enum object Map
* @throws IllegalArgumentException if the enum class is <code>null</code>
@@ -111,7 +112,7 @@
* <p>If the requested class has no enum objects an empty
* <code>Iterator</code> is returned. The <code>Iterator</code>
* is unmodifiable.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @return an <code>Iterator</code> of the <code>Enum</code> objects
* @throws IllegalArgumentException if the enum class is <code>null</code>
@@ -120,5 +121,4 @@
public static Iterator iterator(Class enumClass) {
return Enum.getEnumList(enumClass).iterator();
}
-
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/ValuedEnum.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/ValuedEnum.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/impl/util/ValuedEnum.java
Sat Oct 30 04:31:52 2004
@@ -1,25 +1,26 @@
/*
- * Copyright 2002-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
*/
+
package org.apache.seda.impl.util;
import java.util.Iterator;
import java.util.List;
-
/**
* <p>Abstract superclass for type-safe enums with integer values suitable
* for use in <code>switch</code> statements.</p>
@@ -46,23 +47,23 @@
* private JavaVersionEnum(String name, int value) {
* super( name, value );
* }
- *
+ *
* public static JavaVersionEnum getEnum(String javaVersion) {
* return (JavaVersionEnum) getEnum(JavaVersionEnum.class, javaVersion);
* }
- *
+ *
* public static JavaVersionEnum getEnum(int javaVersion) {
* return (JavaVersionEnum) getEnum(JavaVersionEnum.class, javaVersion);
* }
- *
+ *
* public static Map getEnumMap() {
* return getEnumMap(JavaVersionEnum.class);
* }
- *
+ *
* public static List getEnumList() {
* return getEnumList(JavaVersionEnum.class);
* }
- *
+ *
* public static Iterator iterator() {
* return iterator(JavaVersionEnum.class);
* }
@@ -96,13 +97,12 @@
* @author Apache Avalon project
* @author Stephen Colebourne
* @since 1.0
- * @version $Id: ValuedEnum.java,v 1.16 2004/02/23 04:34:20 ggregory Exp $
+ * @version $Id$
*/
public abstract class ValuedEnum extends Enum {
-
/** Lang version 1.0.1 serial compatibility */
private static final long serialVersionUID = -7129650521543789085L;
-
+
/**
* The value contained in enum.
*/
@@ -125,7 +125,7 @@
* <p>This method loops through the list of <code>Enum</code>,
* thus if there are many <code>Enum</code>s this will be
* slow.</p>
- *
+ *
* @param enumClass the class of the <code>Enum</code> to get
* @param value the value of the <code>Enum</code> to get
* @return the enum object, or null if the enum does not exist
@@ -135,13 +135,17 @@
if (enumClass == null) {
throw new IllegalArgumentException("The Enum Class must not be
null");
}
+
List list = Enum.getEnumList(enumClass);
+
for (Iterator it = list.iterator(); it.hasNext();) {
ValuedEnum enum = (ValuedEnum) it.next();
+
if (enum.getValue() == value) {
return enum;
}
}
+
return null;
}
@@ -159,7 +163,7 @@
*
* <p>The default ordering is numeric by value, but this
* can be overridden by subclasses.</p>
- *
+ *
* @see java.lang.Comparable#compareTo(Object)
* @param other the other object to compare to
* @return -ve if this is less than the other object, +ve if greater than,
@@ -182,25 +186,27 @@
if (iToString == null) {
String shortName = null;
- if ( getEnumClass() == null )
- {
+ if (getEnumClass() == null) {
shortName = "";
- }
- else {
- char[] chars =
getEnumClass().getClass().getName().toCharArray();
+ } else {
+ char[] chars =
+ getEnumClass().getClass().getName().toCharArray();
int lastDot = 0;
+
for (int i = 0; i < chars.length; i++) {
if (chars[i] == '.') {
lastDot = i + 1;
- } else if (chars[i] == '$') { // handle inner classes
+ } else if (chars[i] == '$') { // handle inner classes
chars[i] = '.';
}
}
+
shortName = new String(chars, lastDot, chars.length - lastDot);
}
iToString = shortName + "[" + getName() + "=" + getValue() + "]";
}
+
return iToString;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManager.java
Sat Oct 30 04:31:52 2004
@@ -14,16 +14,16 @@
* limitations under the License.
*
*/
+
package org.apache.seda.input;
/**
* Service interface for server modules that monitor incomming PDU requests on
* a client's inputs.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface InputManager
-{
+public interface InputManager {
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.input;
+package org.apache.seda.input;
import java.io.IOException;
@@ -36,125 +36,123 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface InputManagerMonitor
-{
+public interface InputManagerMonitor {
/**
* Monitors client disconnections.
- *
+ *
* @param key the key of the client that was disconnected
*/
- void disconnectedClient( ClientKey key );
-
+ void disconnectedClient(ClientKey key);
+
/**
* Monitors channel registrations which occur on client sockets.
- *
+ *
* @param key the key of the client whose channel got registered
* @param selector the selector used to register the client's channel
*/
- void registeredChannel( ClientKey key, Selector selector );
-
+ void registeredChannel(ClientKey key, Selector selector);
+
/**
* Monitors returns from the selector denoting a timeout or a wakeup due to
* input availability.
*
* @param selector the selector that has returned
*/
- void selectorReturned( Selector selector );
-
+ void selectorReturned(Selector selector);
+
/**
* Monitors input read from a client socket channel.
- *
+ *
* @param key the key of the client sending the request
*/
- void inputRecieved( ClientKey key );
+ void inputRecieved(ClientKey key);
/**
* Monitors input read from a client socket channel.
- *
+ *
* @param buffer the input recieved
* @param key the key of the client sending the request
*/
- void inputRecieved( ByteBuffer buffer, ClientKey key );
+ void inputRecieved(ByteBuffer buffer, ClientKey key);
-
// ------------------------------------------------------------------------
// failure monitoring methods
// ------------------------------------------------------------------------
-
/**
* Monitor method for handling selector select call failures.
- *
+ *
* @param selector the selector the select was called on
* @param fault the faulting exception
*/
- void selectFailure( Selector selector, IOException fault );
-
+ void selectFailure(Selector selector, IOException fault);
+
/**
* Monitors attempts to use client key's that have expired.
- *
+ *
* @param key the client key that expired
* @param fault the faulting exception
*/
- void keyExpiryFailure( ClientKey key, KeyExpiryException fault );
-
+ void keyExpiryFailure(ClientKey key, KeyExpiryException fault);
+
/**
* Monitors failed read attempts from client socket channel.
- *
+ *
* @param key the key of the client the read failed on
* @param fault the faulting exception
*/
- void readFailed( ClientKey key, IOException fault );
+ void readFailed(ClientKey key, IOException fault);
/**
* Monitors failed attempts to acquire a buffer from the BufferPool.
- *
+ *
* @param bp the buffer pool a buffer was requested from
* @param fault the faulting exception
*/
- void bufferUnavailable( BufferPool bp, ResourceException fault );
-
+ void bufferUnavailable(BufferPool bp, ResourceException fault);
+
/**
* Monitors failures to register channels with a selector.
- *
+ *
* @param selector the selector the register method was called on
* @param channel the channel that failed registeration
* @param selectionKey the selection key used to register
* @param fault the faulting exception
*/
- void channelRegistrationFailure( Selector selector, SocketChannel channel,
- int selectionKey, IOException fault );
-
+ void channelRegistrationFailure(
+ Selector selector, SocketChannel channel,
+ int selectionKey, IOException fault);
+
/**
* Monitors failures to close a client's socket channel.
- *
+ *
* @param channel the channel that failed to close
* @param fault the faulting exception
*/
- void channelCloseFailure( SocketChannel channel, IOException fault );
-
+ void channelCloseFailure(SocketChannel channel, IOException fault);
+
/**
* Monitors the occurrence of successful select timeouts on a selector
- *
+ *
* @param selector
*/
- void selectTimedOut( Selector selector );
-
+ void selectTimedOut(Selector selector);
+
/**
* A select call is about to be made.
*
* @param selector the selector on which the select is called
*/
- void enteringSelect( Selector selector );
-
+ void enteringSelect(Selector selector);
+
/**
* Monitors the removal of stale keys from the selection set. This occurs
- * when connections are abrubtly dropped by clients and are left
- * inconsistant. These keys wakeup threads in select calls yet have
+ * when connections are abrubtly dropped by clients and are left
+ * inconsistant. These keys wakeup threads in select calls yet have
* no incomming IO on them. They are removed to cleanup and this method
* is called when one is cleaned up.
- *
+ *
* @param key the selection key of the client that was cleaned up
*/
- void cleanedStaleKey( SelectionKey key );
+ void cleanedStaleKey(SelectionKey key);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,14 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.input;
+package org.apache.seda.input;
import java.io.IOException;
import java.nio.ByteBuffer;
-import java.nio.channels.Selector;
import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import org.apache.seda.ResourceException;
@@ -36,155 +36,125 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class InputManagerMonitorAdapter implements InputManagerMonitor
-{
+public class InputManagerMonitorAdapter implements InputManagerMonitor {
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* disconnectedClient(org.apache.seda.listener.ClientKey)
*/
- public void disconnectedClient( ClientKey key )
- {
+ public void disconnectedClient(ClientKey key) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* registeredChannel(org.apache.seda.listener.ClientKey,
* java.nio.channels.Selector)
*/
- public void registeredChannel( ClientKey key, Selector selector )
- {
+ public void registeredChannel(ClientKey key, Selector selector) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* selectorReturned(java.nio.channels.Selector)
*/
- public void selectorReturned( Selector selector )
- {
+ public void selectorReturned(Selector selector) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* inputRecieved(org.apache.seda.listener.ClientKey)
*/
- public void inputRecieved( ClientKey key )
- {
+ public void inputRecieved(ClientKey key) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* selectFailure(java.nio.channels.Selector, java.io.IOException)
*/
- public void selectFailure( Selector selector, IOException fault )
- {
- dump( fault );
+ public void selectFailure(Selector selector, IOException fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#keyExpiryFailure(
* org.apache.seda.listener.ClientKey,
* org.apache.seda.listener.KeyExpiryException)
*/
- public void keyExpiryFailure( ClientKey key, KeyExpiryException fault )
- {
- dump( fault );
+ public void keyExpiryFailure(ClientKey key, KeyExpiryException fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* readFailed(org.apache.seda.listener.ClientKey, java.io.IOException)
*/
- public void readFailed( ClientKey key, IOException fault )
- {
- dump( fault );
+ public void readFailed(ClientKey key, IOException fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* bufferUnavailable(org.apache.seda.buffer.BufferPool,
* org.apache.seda.ResourceException)
*/
- public void bufferUnavailable( BufferPool bp, ResourceException fault )
- {
- dump( fault );
+ public void bufferUnavailable(BufferPool bp, ResourceException fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
- * channelRegistrationFailure(java.nio.channels.Selector,
+ * channelRegistrationFailure(java.nio.channels.Selector,
* java.nio.channels.SocketChannel, int, java.io.IOException)
*/
- public void channelRegistrationFailure( Selector selector,
- SocketChannel channel, int key, IOException fault)
- {
- dump( fault );
+ public void channelRegistrationFailure(
+ Selector selector,
+ SocketChannel channel, int key,
+ IOException fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#
* channelCloseFailure(java.nio.channels.SocketChannel,
java.io.IOException)
*/
- public void channelCloseFailure( SocketChannel channel,
- IOException fault )
- {
- dump( fault );
+ public void channelCloseFailure(SocketChannel channel, IOException fault) {
+ dump(fault);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#enteringSelect(
* java.nio.channels.Selector)
*/
- public void enteringSelect( Selector selector )
- {
+ public void enteringSelect(Selector selector) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#selectTimedOut(
* java.nio.channels.Selector)
*/
- public void selectTimedOut( Selector selector )
- {
+ public void selectTimedOut(Selector selector) {
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#inputRecieved(
* java.nio.ByteBuffer, org.apache.seda.listener.ClientKey)
*/
- public void inputRecieved( ByteBuffer buffer, ClientKey key )
- {
+ public void inputRecieved(ByteBuffer buffer, ClientKey key) {
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.input.InputManagerMonitor#cleanedStaleKey(
* java.nio.channels.SelectionKey)
*/
- public void cleanedStaleKey( SelectionKey key )
- {
+ public void cleanedStaleKey(SelectionKey key) {
}
-
/**
* Perform simple null pointer check before dumping a stack trace.
*
* @param t the throwables stack to dump to stderr
*/
- private void dump( Throwable t )
- {
- if ( t != null )
- {
+ private void dump(Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/input/TCPInputManager.java
Sat Oct 30 04:31:52 2004
@@ -14,14 +14,16 @@
* limitations under the License.
*
*/
-package org.apache.seda.input;
+package org.apache.seda.input;
import java.io.IOException;
+
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
+
import java.util.ArrayList;
import java.util.Iterator;
@@ -43,118 +45,115 @@
* Default InputManager implementation based on NIO selectors and channels.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev: 1452 $
+ * @version $Rev$
*/
-public class TCPInputManager extends AbstractSubscriber
- implements InputManager, ConnectSubscriber, DisconnectSubscriber, Runnable
-{
- /** the thread driving this Runnable */
+public class TCPInputManager extends AbstractSubscriber implements
InputManager,
+
ConnectSubscriber,
+
DisconnectSubscriber,
+ Runnable {
+ /** the thread driving this Runnable */
private Thread thread = null;
+
/** parameter used to politely stop running thread */
private Boolean hasStarted = null;
+
/** the buffer pool we get direct buffers from */
private BufferPool bp = null;
+
/** event router used to decouple source to sink relationships */
private EventRouter router = null;
+
/** selector used to select a ready socket channel */
private Selector selector = null;
+
/** contains the batch of new connect events and channels to register */
private final ArrayList connectEvents = new ArrayList();
+
/** contains the batch of disconnect events & selection keys to cancel */
private final ArrayList disconnectEvents = new ArrayList();
+
/** the input manager's monitor */
private InputManagerMonitor monitor = new InputManagerMonitorAdapter();
-
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
// ------------------------------------------------------------------------
-
-
+
/**
* Creates a default InputManager implementation
- *
+ *
* @param router an event router service
* @param bp a buffer pool service
*/
- public TCPInputManager( EventRouter router, BufferPool bp )
- throws IOException
- {
+ public TCPInputManager(EventRouter router, BufferPool bp)
+ throws IOException {
this.bp = bp;
- hasStarted = new Boolean( false );
+ hasStarted = new Boolean(false);
selector = Selector.open();
this.router = router;
- this.router.subscribe( ConnectEvent.class, null, this );
- this.router.subscribe( DisconnectEvent.class, null, this );
+ this.router.subscribe(ConnectEvent.class, null, this);
+ this.router.subscribe(DisconnectEvent.class, null, this);
}
-
// ------------------------------------------------------------------------
// start, stop and runnable code
// ------------------------------------------------------------------------
-
/**
* Runnable run method implementation.
*/
- public void run()
- {
+ public void run() {
/*
* Loop here solves a bug where some lingering phantom clients (that
are
* long gone) have sockets and channels that appear valid and
connected.
- * These sockets and channels are cleaned up here in this loop. Keep
- * in mind they have triggered a wakeup on select() and are appear
- * ready for reads yet were not selected w/i the last iteration since
- * the selected count was zero. For more information on this you can
+ * These sockets and channels are cleaned up here in this loop. Keep
+ * in mind they have triggered a wakeup on select() and are appear
+ * ready for reads yet were not selected w/i the last iteration since
+ * the selected count was zero. For more information on this you can
* refer to the Jira Issue:
- *
+ *
* http://nagoya.apache.org/jira/secure/ViewIssue.jspa?key=DIR-18
*/
- while ( hasStarted.booleanValue() )
- {
- try
- {
+ while (hasStarted.booleanValue()) {
+ try {
/*
- * Register newly arrived connections and unregister thosed
+ * Register newly arrived connections and unregister thosed
* that were dropped while we were blocked on the select call
*/
registerNewConnections();
unregisterDroppedConnections();
// report that we're about to enter the select call
- monitor.enteringSelect( selector );
-
+ monitor.enteringSelect(selector);
+
/*
* Clean stale connections that do not have and data: select
* returns indicating that the count of active connections with
- * input is 0. However the list still has these "stale"
+ * input is 0. However the list still has these "stale"
* connections lingering around. We remove them since they
* are prematurely triggering selection to return w/o input.
- */
- if ( 0 == selector.select() )
- {
+ */
+ if (0 == selector.select()) {
Iterator l_list = selector.selectedKeys().iterator();
- while( l_list.hasNext() )
- {
- SelectionKey l_key = ( SelectionKey ) l_list.next();
+
+ while (l_list.hasNext()) {
+ SelectionKey l_key = (SelectionKey) l_list.next();
l_key.channel().close();
l_key.cancel();
l_list.remove();
-
- monitor.cleanedStaleKey( l_key );
+
+ monitor.cleanedStaleKey(l_key);
}
-
- monitor.selectTimedOut( selector );
+
+ monitor.selectTimedOut(selector);
continue;
}
- }
- catch( IOException e )
- {
- monitor.selectFailure( selector, e );
+ } catch (IOException e) {
+ monitor.selectFailure(selector, e);
continue;
}
-
+
/*
* At this point we've come out of the select call with valid
* input on channels and need to process that input.
@@ -163,191 +162,154 @@
}
}
-
/**
* Starts up this module.
*/
- public void start()
- {
- synchronized( hasStarted )
- {
- if ( hasStarted.booleanValue() )
- {
- throw new IllegalStateException( "Already started!" );
+ public void start() {
+ synchronized (hasStarted) {
+ if (hasStarted.booleanValue()) {
+ throw new IllegalStateException("Already started!");
}
-
- hasStarted = new Boolean( true );
- thread = new Thread( this );
+
+ hasStarted = new Boolean(true);
+ thread = new Thread(this);
thread.start();
}
}
-
-
+
/**
* Blocks calling thread until this module gracefully stops.
*/
- public void stop() throws InterruptedException
- {
- synchronized( hasStarted )
- {
- hasStarted = new Boolean( false );
+ public void stop() throws InterruptedException {
+ synchronized (hasStarted) {
+ hasStarted = new Boolean(false);
selector.wakeup();
-
- while ( thread.isAlive() )
- {
- Thread.sleep( 100 );
+
+ while (thread.isAlive()) {
+ Thread.sleep(100);
}
}
}
-
-
+
// ------------------------------------------------------------------------
// subscriber methods
// ------------------------------------------------------------------------
-
-
+
/**
* @see
org.apache.seda.event.ConnectSubscriber#inform(org.apache.seda.event.ConnectEvent)
*/
- public void inform( ConnectEvent an_event )
- {
- synchronized ( connectEvents )
- {
- connectEvents.add( an_event );
+ public void inform(ConnectEvent an_event) {
+ synchronized (connectEvents) {
+ connectEvents.add(an_event);
}
-
+
selector.wakeup();
}
-
/**
* @see
org.apache.seda.event.DisconnectSubscriber#inform(org.apache.seda.event.DisconnectEvent)
*/
- public void inform( DisconnectEvent an_event )
- {
- synchronized ( disconnectEvents )
- {
- disconnectEvents.add( an_event );
+ public void inform(DisconnectEvent an_event) {
+ synchronized (disconnectEvents) {
+ disconnectEvents.add(an_event);
}
-
+
selector.wakeup();
}
-
// ------------------------------------------------------------------------
// private utilities
// ------------------------------------------------------------------------
-
-
+
/**
- * Register new connections that have arrived since the last select call.
+ * Register new connections that have arrived since the last select call.
*/
- private void registerNewConnections()
- {
+ private void registerNewConnections() {
// copy of newly arrived events batched in the list of ConnectEvents
ConnectEvent[] l_events = null;
- synchronized( connectEvents )
- {
+
+ synchronized (connectEvents) {
l_events = new ConnectEvent[connectEvents.size()];
- l_events = ( ConnectEvent[] )
- connectEvents.toArray( l_events );
+ l_events = (ConnectEvent[]) connectEvents.toArray(l_events);
connectEvents.clear();
}
// cycle through connections and register them with the selector
- for ( int ii = 0; ii < l_events.length; ii++ )
- {
+ for (int ii = 0; ii < l_events.length; ii++) {
TCPClientKey l_key = null;
SocketChannel l_channel = null;
-
- try
- {
+
+ try {
l_key = (TCPClientKey) l_events[ii].getClientKey();
l_channel = l_key.getSocket().getChannel();
-
+
// hands-off blocking sockets!
- if ( null == l_channel )
- {
+ if (null == l_channel) {
continue;
}
-
- l_channel.configureBlocking( false );
- l_channel.register( selector, SelectionKey.OP_READ, l_key );
- monitor.registeredChannel( l_key, selector );
- }
- catch ( KeyExpiryException e )
- {
- monitor.keyExpiryFailure( l_key, e );
- }
- catch ( IOException e )
- {
- monitor.channelRegistrationFailure( selector, l_channel,
- SelectionKey.OP_READ, e );
+
+ l_channel.configureBlocking(false);
+ l_channel.register(selector, SelectionKey.OP_READ, l_key);
+ monitor.registeredChannel(l_key, selector);
+ } catch (KeyExpiryException e) {
+ monitor.keyExpiryFailure(l_key, e);
+ } catch (IOException e) {
+ monitor.channelRegistrationFailure(
+ selector, l_channel,
+ SelectionKey.OP_READ, e);
}
}
}
-
/**
* Cancel/Unregister dropped connections since the last call to select.
- *
+ *
* @see <a
href="http://nagoya.apache.org/jira/secure/ViewIssue.jspa?id=13574">JIRA
Issue</a>
*/
- private void unregisterDroppedConnections()
- {
+ private void unregisterDroppedConnections() {
SelectionKey l_key = null;
DisconnectEvent[] l_events = null;
// synchronized copy all events into a separate list first and clear
- synchronized( disconnectEvents )
- {
+ synchronized (disconnectEvents) {
l_events = new DisconnectEvent[disconnectEvents.size()];
- l_events = ( DisconnectEvent[] )
- disconnectEvents.toArray( l_events );
+ l_events = (DisconnectEvent[]) disconnectEvents.toArray(l_events);
disconnectEvents.clear();
}
// cancel selection key for the disconnect event's client
- for ( int ii = 0; ii < l_events.length; ii++ )
- {
+ for (int ii = 0; ii < l_events.length; ii++) {
Iterator l_keys = selector.keys().iterator();
ClientKey l_clientKey = l_events[ii].getClientKey();
- while ( l_keys.hasNext() )
- {
- l_key = ( SelectionKey ) l_keys.next();
- if ( l_key.attachment().equals( l_clientKey ) )
- {
+ while (l_keys.hasNext()) {
+ l_key = (SelectionKey) l_keys.next();
+
+ if (l_key.attachment().equals(l_clientKey)) {
break;
}
}
- if ( null == l_key )
- {
+ if (null == l_key) {
return;
}
-
- try
- {
+
+ try {
l_key.channel().close();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
monitor.channelCloseFailure(
- ( SocketChannel ) l_key.channel(), e );
+ (SocketChannel) l_key.channel(),
e);
}
-
+
l_key.cancel();
- monitor.disconnectedClient( l_clientKey );
+ monitor.disconnectedClient(l_clientKey);
}
}
-
-
+
/**
* Processes input on channels of the read ready selected keys.
*/
- private void processInput()
- {
+ private void processInput() {
/*
* Process the selectors that are ready. For each selector that
* is ready we read some data into a buffer we claim from a buffer
@@ -355,112 +317,96 @@
* it using the event notifier/router.
*/
Iterator l_list = selector.selectedKeys().iterator();
- while ( l_list.hasNext() )
- {
- SelectionKey l_key = ( SelectionKey ) l_list.next();
- ClientKey l_client = ( ClientKey ) l_key.attachment();
-
- if ( l_key.isReadable() )
- {
+
+ while (l_list.hasNext()) {
+ SelectionKey l_key = (SelectionKey) l_list.next();
+ ClientKey l_client = (ClientKey) l_key.attachment();
+
+ if (l_key.isReadable()) {
ByteBuffer l_buf = null;
- SocketChannel l_channel = ( SocketChannel ) l_key.channel();
-
+ SocketChannel l_channel = (SocketChannel) l_key.channel();
+
/*
- * claim a buffer, read from channel into it and remove
+ * claim a buffer, read from channel into it and remove
* the current selection key from selected set
- */
- try
- {
- l_buf = bp.getBuffer( this );
+ */
+ try {
+ l_buf = bp.getBuffer(this);
- if ( l_channel.read( l_buf ) == -1 )
- {
+ if (l_channel.read(l_buf) == -1) {
l_channel.socket().close();
l_channel.close();
l_key.cancel();
return;
}
-
+
l_buf.flip();
- monitor.inputRecieved(
- l_buf.asReadOnlyBuffer(), l_client );
+ monitor.inputRecieved(l_buf.asReadOnlyBuffer(), l_client);
l_list.remove();
- }
- catch ( ResourceException e )
- {
- monitor.bufferUnavailable( bp, e );
+ } catch (ResourceException e) {
+ monitor.bufferUnavailable(bp, e);
continue;
- }
- catch ( IOException e )
- {
- monitor.readFailed( l_client, e );
- bp.releaseClaim( l_buf, this );
+ } catch (IOException e) {
+ monitor.readFailed(l_client, e);
+ bp.releaseClaim(l_buf, this);
continue;
}
-
+
/*
* Monitor input and create the event publishing it. Note that
- * releasing claim to the buffer does not free it. It just
+ * releasing claim to the buffer does not free it. It just
* removes this object as an interested party from the list
- * of interested parties. After synchronously publishing the
- * input event there are other interesed parties that have
+ * of interested parties. After synchronously publishing the
+ * input event there are other interesed parties that have
* increased the reference count.
- */
- monitor.inputRecieved( l_client );
- InputEvent l_event = new ConcreteInputEvent( l_client, l_buf );
- router.publish( l_event );
- bp.releaseClaim( l_buf, this );
+ */
+ monitor.inputRecieved(l_client);
+
+ InputEvent l_event = new ConcreteInputEvent(l_client, l_buf);
+ router.publish(l_event);
+ bp.releaseClaim(l_buf, this);
}
}
}
-
-
- /**
- * A concrete InputEvent that uses the buffer pool to properly implement
- * the interest claim and release methods.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision$
- */
- class ConcreteInputEvent extends InputEvent
- {
- ConcreteInputEvent( ClientKey key, ByteBuffer buffer )
- {
- super( TCPInputManager.this, key, buffer );
- }
-
- public ByteBuffer claimInterest( Object party )
- {
- bp.claimInterest( getBuffer(), party );
- return getBuffer().asReadOnlyBuffer();
- }
-
- public void releaseInterest( Object party )
- {
- bp.releaseClaim( getBuffer(), party );
- }
- }
-
-
+
/**
* Gets the monitor associated with this InputManager.
- *
+ *
* @return returns the monitor
*/
- public InputManagerMonitor getMonitor()
- {
+ public InputManagerMonitor getMonitor() {
return monitor;
}
-
/**
* Sets the monitor associated with this InputManager.
- *
+ *
* @param monitor the monitor to set
*/
- public void setMonitor( InputManagerMonitor monitor )
- {
+ public void setMonitor(InputManagerMonitor monitor) {
this.monitor = monitor;
+ }
+
+ /**
+ * A concrete InputEvent that uses the buffer pool to properly implement
+ * the interest claim and release methods.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+ class ConcreteInputEvent extends InputEvent {
+ ConcreteInputEvent(ClientKey key, ByteBuffer buffer) {
+ super(TCPInputManager.this, key, buffer);
+ }
+
+ public ByteBuffer claimInterest(Object party) {
+ bp.claimInterest(getBuffer(), party);
+ return getBuffer().asReadOnlyBuffer();
+ }
+
+ public void releaseInterest(Object party) {
+ bp.releaseClaim(getBuffer(), party);
+ }
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/AvailablePortFinder.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -113,7 +114,8 @@
* <code>fromPort</code> if greater than <code>toPort</code>.
*/
public Set getAvailablePorts(int fromPort, int toPort) {
- if ((fromPort < MIN_PORT_NUMBER) || (toPort > MAX_PORT_NUMBER)
+ if (
+ (fromPort < MIN_PORT_NUMBER) || (toPort > MAX_PORT_NUMBER)
|| (fromPort > toPort)) {
throw new IllegalArgumentException("Invalid port range: "
+ fromPort + " ~ " + toPort);
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ClientKey.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ClientKey.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ClientKey.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -59,18 +60,18 @@
// ----------------------------------------------
/**
- * Generates a unique connection/client identifier String for a client
- * socket connection. The key is composed of the local server address
- * and port attached to the remote client address and port. If the
- * server ip and port are 192.168.1.1:1389 and the client's ip and port
are
- * 34.23.12.1:5678 then the key string would be:
- *
- * 192.168.1.1:1389<-34.23.12.1:5678
- *
- * This makes the key unique at any single point in time.
- *
- * @param clientId the id of this client key
- */
+ * Generates a unique connection/client identifier String for a client
+ * socket connection. The key is composed of the local server address
+ * and port attached to the remote client address and port. If the
+ * server ip and port are 192.168.1.1:1389 and the client's ip and port are
+ * 34.23.12.1:5678 then the key string would be:
+ *
+ * 192.168.1.1:1389<-34.23.12.1:5678
+ *
+ * This makes the key unique at any single point in time.
+ *
+ * @param clientId the id of this client key
+ */
ClientKey(String clientId) {
this.clientId = clientId;
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/KeyExpiryException.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/KeyExpiryException.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/KeyExpiryException.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManager.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -50,13 +51,15 @@
public void selectTimedOut(Selector selector) {
}
- public void failedToBind(ListenerConfig listenerConfig, IOException
failure) {
+ public void failedToBind(
+ ListenerConfig listenerConfig, IOException
failure) {
if (failure != null) {
failure.printStackTrace();
}
}
- public void failedToUnbind(ListenerConfig listenerConfig,
+ public void failedToUnbind(
+ ListenerConfig listenerConfig,
IOException failure) {
if (failure != null) {
failure.printStackTrace();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/SocketListenerConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.net.InetAddress;
@@ -41,7 +42,8 @@
* @param servEnt the inet service entry for the service this listner
* provides
*/
- public SocketListenerConfig(InetAddress inetAddress,
+ public SocketListenerConfig(
+ InetAddress inetAddress,
InetServiceEntry servEnt) {
this.servEnt = servEnt;
this.inetAddress = inetAddress;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPClientKey.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPClientKey.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPClientKey.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -57,19 +58,19 @@
// ----------------------------------------------
/**
- * Generates a unique connection/client identifier String for a client
- * socket connection. The key is composed of the local server address
- * and port attached to the remote client address and port. If the
- * server ip and port are 192.168.1.1:1389 and the client's ip and port
are
- * 34.23.12.1:5678 then the key string would be:
- *
- * 192.168.1.1:1389<-34.23.12.1:5678
- *
- * This makes the key unique at any single point in time.
- *
- * @param a_socket newly established client socket connection to the
- * server.
- */
+ * Generates a unique connection/client identifier String for a client
+ * socket connection. The key is composed of the local server address
+ * and port attached to the remote client address and port. If the
+ * server ip and port are 192.168.1.1:1389 and the client's ip and port are
+ * 34.23.12.1:5678 then the key string would be:
+ *
+ * 192.168.1.1:1389<-34.23.12.1:5678
+ *
+ * This makes the key unique at any single point in time.
+ *
+ * @param a_socket newly established client socket connection to the
+ * server.
+ */
TCPClientKey(final Socket a_socket) {
super(getClientId(a_socket));
socket = a_socket;
@@ -103,13 +104,15 @@
public InetSocketAddress getLocalAddress() throws KeyExpiryException {
checkExpiry();
- return new InetSocketAddress(socket.getLocalAddress(),
+ return new InetSocketAddress(
+ socket.getLocalAddress(),
socket.getLocalPort());
}
public InetSocketAddress getRemoteAddress() throws KeyExpiryException {
checkExpiry();
- return new InetSocketAddress(socket.getInetAddress(),
socket.getPort());
+ return new InetSocketAddress(
+ socket.getInetAddress(),
socket.getPort());
}
// ----------------------------------------------
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.net.InetAddress;
@@ -39,7 +40,8 @@
* @param servEnt the inet service entry for the service this listner
* provides
*/
- public TCPListenerConfig(InetAddress inetAddress, InetServiceEntry
servEnt) {
+ public TCPListenerConfig(
+ InetAddress inetAddress, InetServiceEntry
servEnt) {
super(inetAddress, servEnt);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/TCPListenerManager.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -171,12 +172,14 @@
try {
ServerSocketChannel channel = ServerSocketChannel.open();
InetSocketAddress address =
- new InetSocketAddress(listener.getInetAddress(),
+ new InetSocketAddress(
+ listener.getInetAddress(),
listener.getInetServiceEntry()
.getPort());
channel.socket().bind(address, listener.getBacklog());
channel.configureBlocking(false);
- channel.register(selector, SelectionKey.OP_ACCEPT,
listener);
+ channel.register(
+ selector, SelectionKey.OP_ACCEPT,
listener);
synchronized (listeners) {
listeners.add(listener);
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPClientKey.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPClientKey.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPClientKey.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -60,20 +61,21 @@
// ----------------------------------------------
/**
- * Generates a unique connection/client identifier String for a client
- * socket connection. The key is composed of the local server address
- * and port attached to the remote client address and port. If the
- * server ip and port are 192.168.1.1:1389 and the client's ip and port
are
- * 34.23.12.1:5678 then the key string would be:
- *
- * 192.168.1.1:1389<-34.23.12.1:5678
- *
- * This makes the key unique at any single point in time.
- *
- * @param a_socket newly established client socket connection to the
- * server.
- */
- UDPClientKey(final DatagramSocket a_socket,
+ * Generates a unique connection/client identifier String for a client
+ * socket connection. The key is composed of the local server address
+ * and port attached to the remote client address and port. If the
+ * server ip and port are 192.168.1.1:1389 and the client's ip and port are
+ * 34.23.12.1:5678 then the key string would be:
+ *
+ * 192.168.1.1:1389<-34.23.12.1:5678
+ *
+ * This makes the key unique at any single point in time.
+ *
+ * @param a_socket newly established client socket connection to the
+ * server.
+ */
+ UDPClientKey(
+ final DatagramSocket a_socket,
final InetSocketAddress clientAddress) {
super(getClientId(a_socket, clientAddress));
@@ -81,7 +83,8 @@
this.clientAddress = clientAddress;
}
- private static String getClientId(DatagramSocket a_socket,
+ private static String getClientId(
+ DatagramSocket a_socket,
InetSocketAddress clientAddress) {
// build the key ...
StringBuffer l_buf = new StringBuffer();
@@ -104,7 +107,8 @@
public InetSocketAddress getLocalAddress() throws KeyExpiryException {
checkExpiry();
- return new InetSocketAddress(socket.getLocalAddress(),
+ return new InetSocketAddress(
+ socket.getLocalAddress(),
socket.getLocalPort());
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.net.InetAddress;
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/listener/UDPListenerManager.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
import java.io.IOException;
@@ -177,7 +178,8 @@
try {
DatagramChannel channel = DatagramChannel.open();
InetSocketAddress address =
- new InetSocketAddress(listener.getInetAddress(),
+ new InetSocketAddress(
+ listener.getInetAddress(),
listener.getInetServiceEntry()
.getPort());
channel.socket().bind(address);
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/LoggingOutputMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/LoggingOutputMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/LoggingOutputMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,17 +14,16 @@
* limitations under the License.
*
*/
-package org.apache.seda.output;
+package org.apache.seda.output;
import java.util.EventObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.seda.event.ConnectEvent;
-import org.apache.seda.listener.ClientKey;
import org.apache.seda.event.DisconnectEvent;
+import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
@@ -34,119 +33,97 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class LoggingOutputMonitor implements OutputMonitor
-{
- private final Log log = LogFactory.getLog( "OutputManager" );
+public class LoggingOutputMonitor implements OutputMonitor {
+ private final Log log = LogFactory.getLog("OutputManager");
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#failedOnWrite(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey,
* java.lang.Throwable)
*/
- public void failedOnWrite( OutputManager manager, ClientKey key,
- Throwable t )
- {
- if ( log.isErrorEnabled() )
- {
- log.error( manager + " failed while trying to write to client "
- + key, t );
+ public void failedOnWrite(
+ OutputManager manager, ClientKey key, Throwable
t) {
+ if (log.isErrorEnabled()) {
+ log.error(
+ manager + " failed while trying to write to client "
+ + key, t);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#writeOccurred(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void writeOccurred( OutputManager manager, ClientKey key )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( manager + " wrote to client " + key );
+ public void writeOccurred(OutputManager manager, ClientKey key) {
+ if (log.isDebugEnabled()) {
+ log.debug(manager + " wrote to client " + key);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#writeLockAcquired(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void writeLockAcquired( OutputManager manager, ClientKey key )
- {
- if ( log.isTraceEnabled() )
- {
- log.trace( manager + " locked channel for client " + key );
+ public void writeLockAcquired(OutputManager manager, ClientKey key) {
+ if (log.isTraceEnabled()) {
+ log.trace(manager + " locked channel for client " + key);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#channelMissing(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void channelMissing( OutputManager manager, ClientKey key )
- {
- if ( log.isWarnEnabled() )
- {
- log.warn( manager + " could not find channel for client " + key );
+ public void channelMissing(OutputManager manager, ClientKey key) {
+ if (log.isWarnEnabled()) {
+ log.warn(manager + " could not find channel for client " + key);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#keyExpired(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey,
* org.apache.seda.listener.KeyExpiryException)
*/
- public void keyExpired( OutputManager manager, ClientKey key,
- KeyExpiryException e )
- {
- if ( log.isWarnEnabled() )
- {
- log.warn( manager + " can't use expired key for client " + key, e
);
+ public void keyExpired(
+ OutputManager manager, ClientKey key,
+ KeyExpiryException e) {
+ if (log.isWarnEnabled()) {
+ log.warn(manager + " can't use expired key for client " + key, e);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#failedOnInform(
* org.apache.seda.output.OutputManager, java.util.EventObject,
* java.lang.Throwable)
*/
- public void failedOnInform( OutputManager manager, EventObject event,
- Throwable fault
)
- {
- if ( log.isErrorEnabled() )
- {
- log.error( manager + " failed to be informed of " + event );
+ public void failedOnInform(
+ OutputManager manager, EventObject event,
+ Throwable fault) {
+ if (log.isErrorEnabled()) {
+ log.error(manager + " failed to be informed of " + event);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#addedClient(
* org.apache.seda.output.OutputManager,
org.apache.seda.event.ConnectEvent)
*/
- public void addedClient( OutputManager manager, ConnectEvent event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( manager + " added client " + event.getClientKey() );
+ public void addedClient(OutputManager manager, ConnectEvent event) {
+ if (log.isDebugEnabled()) {
+ log.debug(manager + " added client " + event.getClientKey());
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#removedClient(
* org.apache.seda.output.OutputManager,
* org.apache.seda.event.DisconnectEvent)
*/
- public void removedClient( OutputManager manager, DisconnectEvent event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( manager + " removed client " + event.getClientKey() );
+ public void removedClient(OutputManager manager, DisconnectEvent event) {
+ if (log.isDebugEnabled()) {
+ log.debug(manager + " removed client " + event.getClientKey());
}
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputManager.java
Sat Oct 30 04:31:52 2004
@@ -1,43 +1,42 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.output;
-
-
-import java.io.IOException;
-
-import java.nio.ByteBuffer;
-
-import org.apache.seda.listener.ClientKey;
-
-
-/**
- * Service interface used to manage output.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev: 9555 $
- */
-public interface OutputManager
-{
- /**
- * Writes or rather sends a peice of PDU data to a client.
- *
- * @param key the key of the client to send the buffer to
- * @param buf the buffer of PDU data
- * @throws IOException if there is a failure while sending the data
- */
- void write( ClientKey key, ByteBuffer buf ) throws IOException;
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.output;
+
+import java.io.IOException;
+
+import java.nio.ByteBuffer;
+
+import org.apache.seda.listener.ClientKey;
+
+
+/**
+ * Service interface used to manage output.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface OutputManager {
+ /**
+ * Writes or rather sends a peice of PDU data to a client.
+ *
+ * @param key the key of the client to send the buffer to
+ * @param buf the buffer of PDU data
+ * @throws IOException if there is a failure while sending the data
+ */
+ void write(ClientKey key, ByteBuffer buf) throws IOException;
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitor.java
Sat Oct 30 04:31:52 2004
@@ -1,108 +1,108 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.output;
-
-
-import java.util.EventObject;
-
-import org.apache.seda.event.ConnectEvent;
-import org.apache.seda.event.DisconnectEvent;
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-
-
-/**
- * A monitor for the OutputManager.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface OutputMonitor
-{
- /**
- * Monitors failed send events to a client.
- *
- * @param manager the OutputManager sending the data
- * @param key the key of the client data is sent to
- * @param t the fault causing the failure
- */
- void failedOnWrite( OutputManager manager, ClientKey key, Throwable t );
-
- /**
- * Monitors send events to a client.
- *
- * @param manager the OutputManager sending the data
- * @param key the key of the client data is sent to
- */
- void writeOccurred( OutputManager manager, ClientKey key );
-
- /**
- * Monitors locks acquired to write to a client's output channel.
- *
- * @param manager the OutputManager write locking
- * @param key the key of the client lock is for
- */
- void writeLockAcquired( OutputManager manager, ClientKey key );
-
- /**
- * Monitors situations where a channel is no longer present for a client.
- *
- * @param manager the OutputManager detecting the missing channel
- * @param key the key of the client the channel was missing from
- */
- void channelMissing( OutputManager manager, ClientKey key );
-
- /**
- * Monitors failures resulting from accessing a client key that has been
- * expired.
- *
- * @param manager the OutputManager accessing the key
- * @param key the key of the client that expired
- * @param e the key expiration exception
- */
- void keyExpired( OutputManager manager, ClientKey key,
- KeyExpiryException e );
-
- /**
- * Monitors failures on inform events to subscriber methods.
- *
- * @param manager the OutputManager that failed to inform
- * @param event the event that failed to be routed
- * @param fault the faulting exception associated with the failure
- */
- void failedOnInform( OutputManager manager, EventObject event,
- Throwable fault );
-
- /**
- * Called when connections are established and clients are registered with
- * the OutputManager.
- *
- * @param manager the output manager with which a client was registered
- * @param event the ConnectEvent that caused registration
- */
- void addedClient( OutputManager manager, ConnectEvent event );
-
- /**
- * Called when connections are dropped and clients are unregistered with
- * the OutputManager.
- *
- * @param manager the output manager with which a client was unregistered
- * @param event the DisconnectEvent that caused unregistration
- */
- void removedClient( OutputManager manager, DisconnectEvent event );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.output;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.ConnectEvent;
+import org.apache.seda.event.DisconnectEvent;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
+
+
+/**
+ * A monitor for the OutputManager.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface OutputMonitor {
+ /**
+ * Monitors failed send events to a client.
+ *
+ * @param manager the OutputManager sending the data
+ * @param key the key of the client data is sent to
+ * @param t the fault causing the failure
+ */
+ void failedOnWrite(OutputManager manager, ClientKey key, Throwable t);
+
+ /**
+ * Monitors send events to a client.
+ *
+ * @param manager the OutputManager sending the data
+ * @param key the key of the client data is sent to
+ */
+ void writeOccurred(OutputManager manager, ClientKey key);
+
+ /**
+ * Monitors locks acquired to write to a client's output channel.
+ *
+ * @param manager the OutputManager write locking
+ * @param key the key of the client lock is for
+ */
+ void writeLockAcquired(OutputManager manager, ClientKey key);
+
+ /**
+ * Monitors situations where a channel is no longer present for a client.
+ *
+ * @param manager the OutputManager detecting the missing channel
+ * @param key the key of the client the channel was missing from
+ */
+ void channelMissing(OutputManager manager, ClientKey key);
+
+ /**
+ * Monitors failures resulting from accessing a client key that has been
+ * expired.
+ *
+ * @param manager the OutputManager accessing the key
+ * @param key the key of the client that expired
+ * @param e the key expiration exception
+ */
+ void keyExpired(
+ OutputManager manager, ClientKey key, KeyExpiryException
e);
+
+ /**
+ * Monitors failures on inform events to subscriber methods.
+ *
+ * @param manager the OutputManager that failed to inform
+ * @param event the event that failed to be routed
+ * @param fault the faulting exception associated with the failure
+ */
+ void failedOnInform(
+ OutputManager manager, EventObject event,
+ Throwable fault);
+
+ /**
+ * Called when connections are established and clients are registered with
+ * the OutputManager.
+ *
+ * @param manager the output manager with which a client was registered
+ * @param event the ConnectEvent that caused registration
+ */
+ void addedClient(OutputManager manager, ConnectEvent event);
+
+ /**
+ * Called when connections are dropped and clients are unregistered with
+ * the OutputManager.
+ *
+ * @param manager the output manager with which a client was unregistered
+ * @param event the DisconnectEvent that caused unregistration
+ */
+ void removedClient(OutputManager manager, DisconnectEvent event);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/OutputMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,118 +14,100 @@
* limitations under the License.
*
*/
-package org.apache.seda.output;
+package org.apache.seda.output;
import java.util.EventObject;
import org.apache.seda.event.ConnectEvent;
-import org.apache.seda.listener.ClientKey;
import org.apache.seda.event.DisconnectEvent;
+import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
/**
* A do nothing output monitor adapter. For safety's sake error conditions are
- * printed to the console.
+ * printed to the console.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class OutputMonitorAdapter implements OutputMonitor
-{
-
+public class OutputMonitorAdapter implements OutputMonitor {
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#
* failedOnWrite(org.apache.seda.output.OutputManager,
* org.apache.seda.listener.ClientKey, java.lang.Throwable)
*/
- public void failedOnWrite( OutputManager manager, ClientKey key,
- Throwable t )
- {
- dump( t );
+ public void failedOnWrite(
+ OutputManager manager, ClientKey key, Throwable
t) {
+ dump(t);
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#writeOccurred(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void writeOccurred( OutputManager manager, ClientKey key )
- {
+ public void writeOccurred(OutputManager manager, ClientKey key) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#writeLockAcquired(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void writeLockAcquired( OutputManager manager, ClientKey key )
- {
+ public void writeLockAcquired(OutputManager manager, ClientKey key) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#channelMissing(
* org.apache.seda.output.OutputManager,
org.apache.seda.listener.ClientKey)
*/
- public void channelMissing( OutputManager manager, ClientKey key )
- {
+ public void channelMissing(OutputManager manager, ClientKey key) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#keyExpired(
* org.apache.seda.output.OutputManager,
* org.apache.seda.listener.KeyExpiryException)
*/
- public void keyExpired( OutputManager manager, ClientKey key,
- KeyExpiryException e )
- {
- dump( e );
+ public void keyExpired(
+ OutputManager manager, ClientKey key,
+ KeyExpiryException e) {
+ dump(e);
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#failedOnInform(
* org.apache.seda.output.OutputManager, java.util.EventObject,
* java.lang.Throwable)
*/
- public void failedOnInform( OutputManager manager, EventObject event,
- Throwable fault )
- {
- dump( fault );
+ public void failedOnInform(
+ OutputManager manager, EventObject event,
+ Throwable fault) {
+ dump(fault);
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#addedClient(
* org.apache.seda.output.OutputManager,
org.apache.seda.event.ConnectEvent)
*/
- public void addedClient( OutputManager manager, ConnectEvent event )
- {
+ public void addedClient(OutputManager manager, ConnectEvent event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.output.OutputMonitor#removedClient(
* org.apache.seda.output.OutputManager,
* org.apache.seda.event.DisconnectEvent)
*/
- public void removedClient( OutputManager manager, DisconnectEvent event )
- {
+ public void removedClient(OutputManager manager, DisconnectEvent event) {
}
-
/**
* Perform simple null pointer check before dumping a stack trace.
*
* @param t the throwables stack to dump to stderr
*/
- private void dump( Throwable t )
- {
- if ( t != null )
- {
+ private void dump(Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/TCPOutputManager.java
Sat Oct 30 04:31:52 2004
@@ -14,12 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.output;
+package org.apache.seda.output;
import java.io.IOException;
+
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
+
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
@@ -47,183 +49,148 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class TCPOutputManager extends DefaultStage
- implements
- OutputManager,
- OutputSubscriber,
- ConnectSubscriber,
- DisconnectSubscriber
-{
+public class TCPOutputManager extends DefaultStage implements OutputManager,
+ OutputSubscriber,
+
ConnectSubscriber,
+
DisconnectSubscriber {
/** the router we subscribe for OutputEvents on */
private final EventRouter router;
+
/** the monitor used to track notable events in this OutputManager */
private OutputMonitor monitor;
+
/** a map of channels by ClientKey */
private Map channels = new HashMap();
-
-
+
// ------------------------------------------------------------------------
// constructors
// ------------------------------------------------------------------------
-
-
+
/**
* Creates a defualt OutputManager.
- *
+ *
* @param router the router we subscribe for OutputEvents on
* @param config the configuration for this Stage
*/
- public TCPOutputManager( EventRouter router, DefaultStageConfig config )
- {
- super( config );
+ public TCPOutputManager(EventRouter router, DefaultStageConfig config) {
+ super(config);
this.router = router;
- this.router.subscribe( OutputEvent.class, this );
- this.router.subscribe( ConnectEvent.class, this );
- this.router.subscribe( DisconnectEvent.class, this );
- config.setHandler( new OutputStageHandler() );
- this.setMonitor( new LoggingStageMonitor() );
- this.setOutputMonitor( new LoggingOutputMonitor() );
+ this.router.subscribe(OutputEvent.class, this);
+ this.router.subscribe(ConnectEvent.class, this);
+ this.router.subscribe(DisconnectEvent.class, this);
+ config.setHandler(new OutputStageHandler());
+ this.setMonitor(new LoggingStageMonitor());
+ this.setOutputMonitor(new LoggingOutputMonitor());
}
-
// ------------------------------------------------------------------------
// subscriber inform methods
// ------------------------------------------------------------------------
-
-
- /*
+
+ /*
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch( Throwable t )
- {
- monitor.failedOnInform( this, event, t );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Throwable t) {
+ monitor.failedOnInform(this, event, t);
}
}
-
-
+
/*
* @see org.apache.seda.event.OutputSubscriber#inform(
* org.apache.seda.event.OutputEvent)
*/
- public void inform( OutputEvent event )
- {
- enqueue( event );
+ public void inform(OutputEvent event) {
+ enqueue(event);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.ConnectSubscriber#inform(
* org.apache.seda.event.ConnectEvent)
*/
- public void inform( ConnectEvent event )
- {
+ public void inform(ConnectEvent event) {
TCPClientKey key = (TCPClientKey) event.getClientKey();
-
- try
- {
- channels.put( key, key.getSocket().getChannel() );
- }
- catch( KeyExpiryException e )
- {
- monitor.keyExpired( this, key, e );
+
+ try {
+ channels.put(key, key.getSocket().getChannel());
+ } catch (KeyExpiryException e) {
+ monitor.keyExpired(this, key, e);
}
-
- monitor.addedClient( this, event );
+
+ monitor.addedClient(this, event);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.DisconnectSubscriber#inform(
* org.apache.seda.event.DisconnectEvent)
*/
- public void inform( DisconnectEvent event )
- {
- channels.remove( event.getClientKey() );
- monitor.removedClient( this, event );
+ public void inform(DisconnectEvent event) {
+ channels.remove(event.getClientKey());
+ monitor.removedClient(this, event);
}
-
-
+
// ------------------------------------------------------------------------
// OutputManager method
// ------------------------------------------------------------------------
-
-
+
/*
* (non-Javadoc)
* @see org.apache.seda.output.OutputManager#write(
* org.apache.seda.listener.ClientKey, java.nio.ByteBuffer)
*/
- public void write( ClientKey key, ByteBuffer buf )
- throws IOException
- {
+ public void write(ClientKey key, ByteBuffer buf)
+ throws IOException {
Object lock = null;
- SocketChannel channel = ( SocketChannel ) channels.get( key );
-
- if ( null == channel )
- {
- monitor.channelMissing( this, key );
+ SocketChannel channel = (SocketChannel) channels.get(key);
+
+ if (null == channel) {
+ monitor.channelMissing(this, key);
return;
}
// Obtain output lock for write to client.
- try
- {
+ try {
lock = key.getOutputLock();
- }
- catch ( KeyExpiryException e )
- {
- monitor.keyExpired( this, key, e );
+ } catch (KeyExpiryException e) {
+ monitor.keyExpired(this, key, e);
return;
}
// synchronize on client output stream lock object.
- synchronized( lock )
- {
- monitor.writeLockAcquired( this, key ) ;
- channel.write( buf );
+ synchronized (lock) {
+ monitor.writeLockAcquired(this, key);
+ channel.write(buf);
lock.notifyAll();
}
-
- monitor.writeOccurred( this, key );
+
+ monitor.writeOccurred(this, key);
}
-
-
+
/**
* Sets the output manager's monitor.
- *
+ *
* @param monitor the monitor used by this output manager
*/
- public void setOutputMonitor( OutputMonitor monitor )
- {
+ public void setOutputMonitor(OutputMonitor monitor) {
this.monitor = monitor;
}
-
/**
* EventHandler designed for processing output events.
*/
- class OutputStageHandler implements StageHandler
- {
- public void handleEvent( EventObject generic )
- {
- if ( generic instanceof OutputEvent )
- {
- OutputEvent event = ( OutputEvent ) generic;
-
- try
- {
- write( event.getClientKey(), event.getBuffer() );
- }
- catch ( IOException e )
- {
- monitor.failedOnWrite( TCPOutputManager.this,
- event.getClientKey(), e );
+ class OutputStageHandler implements StageHandler {
+ public void handleEvent(EventObject generic) {
+ if (generic instanceof OutputEvent) {
+ OutputEvent event = (OutputEvent) generic;
+
+ try {
+ write(event.getClientKey(), event.getBuffer());
+ } catch (IOException e) {
+ monitor.failedOnWrite(
+ TCPOutputManager.this,
+ event.getClientKey(), e);
}
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/output/UDPOutputManager.java
Sat Oct 30 04:31:52 2004
@@ -14,12 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.output;
+package org.apache.seda.output;
import java.io.IOException;
+
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
+
import java.util.EventObject;
import java.util.HashMap;
import java.util.Map;
@@ -47,183 +49,148 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class UDPOutputManager extends DefaultStage
- implements
- OutputManager,
- OutputSubscriber,
- ConnectSubscriber,
- DisconnectSubscriber
-{
+public class UDPOutputManager extends DefaultStage implements OutputManager,
+ OutputSubscriber,
+
ConnectSubscriber,
+
DisconnectSubscriber {
/** the router we subscribe for OutputEvents on */
private final EventRouter router;
+
/** the monitor used to track notable events in this OutputManager */
private OutputMonitor monitor;
+
/** a map of channels by ClientKey */
private Map channels = new HashMap();
-
-
+
// ------------------------------------------------------------------------
// constructors
// ------------------------------------------------------------------------
-
-
+
/**
* Creates a defualt OutputManager.
- *
+ *
* @param router the router we subscribe for OutputEvents on
* @param config the configuration for this Stage
*/
- public UDPOutputManager( EventRouter router, DefaultStageConfig config )
- {
- super( config );
+ public UDPOutputManager(EventRouter router, DefaultStageConfig config) {
+ super(config);
this.router = router;
- this.router.subscribe( OutputEvent.class, this );
- this.router.subscribe( ConnectEvent.class, this );
- this.router.subscribe( DisconnectEvent.class, this );
- config.setHandler( new OutputStageHandler() );
- this.setMonitor( new LoggingStageMonitor() );
- this.setOutputMonitor( new LoggingOutputMonitor() );
+ this.router.subscribe(OutputEvent.class, this);
+ this.router.subscribe(ConnectEvent.class, this);
+ this.router.subscribe(DisconnectEvent.class, this);
+ config.setHandler(new OutputStageHandler());
+ this.setMonitor(new LoggingStageMonitor());
+ this.setOutputMonitor(new LoggingOutputMonitor());
}
-
// ------------------------------------------------------------------------
// subscriber inform methods
// ------------------------------------------------------------------------
-
-
- /*
+
+ /*
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch( Throwable t )
- {
- monitor.failedOnInform( this, event, t );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Throwable t) {
+ monitor.failedOnInform(this, event, t);
}
}
-
-
+
/*
* @see org.apache.seda.event.OutputSubscriber#inform(
* org.apache.seda.event.OutputEvent)
*/
- public void inform( OutputEvent event )
- {
- enqueue( event );
+ public void inform(OutputEvent event) {
+ enqueue(event);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.ConnectSubscriber#inform(
* org.apache.seda.event.ConnectEvent)
*/
- public void inform( ConnectEvent event )
- {
+ public void inform(ConnectEvent event) {
UDPClientKey key = (UDPClientKey) event.getClientKey();
-
- try
- {
- channels.put( key, key.getSocket().getChannel() );
- }
- catch( KeyExpiryException e )
- {
- monitor.keyExpired( this, key, e );
+
+ try {
+ channels.put(key, key.getSocket().getChannel());
+ } catch (KeyExpiryException e) {
+ monitor.keyExpired(this, key, e);
}
-
- monitor.addedClient( this, event );
+
+ monitor.addedClient(this, event);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.DisconnectSubscriber#inform(
* org.apache.seda.event.DisconnectEvent)
*/
- public void inform( DisconnectEvent event )
- {
- channels.remove( event.getClientKey() );
- monitor.removedClient( this, event );
+ public void inform(DisconnectEvent event) {
+ channels.remove(event.getClientKey());
+ monitor.removedClient(this, event);
}
-
-
+
// ------------------------------------------------------------------------
// OutputManager method
// ------------------------------------------------------------------------
-
-
+
/*
* (non-Javadoc)
* @see org.apache.seda.output.OutputManager#write(
* org.apache.seda.listener.ClientKey, java.nio.ByteBuffer)
*/
- public void write( ClientKey key, ByteBuffer buf )
- throws IOException
- {
+ public void write(ClientKey key, ByteBuffer buf)
+ throws IOException {
Object lock = null;
- DatagramChannel channel = ( DatagramChannel ) channels.get( key );
-
- if ( null == channel )
- {
- monitor.channelMissing( this, key );
+ DatagramChannel channel = (DatagramChannel) channels.get(key);
+
+ if (null == channel) {
+ monitor.channelMissing(this, key);
return;
}
// Obtain output lock for write to client.
- try
- {
+ try {
lock = key.getOutputLock();
- }
- catch ( KeyExpiryException e )
- {
- monitor.keyExpired( this, key, e );
+ } catch (KeyExpiryException e) {
+ monitor.keyExpired(this, key, e);
return;
}
// synchronize on client output stream lock object.
- synchronized( lock )
- {
- monitor.writeLockAcquired( this, key ) ;
- channel.send( buf, key.getRemoteAddress() );
+ synchronized (lock) {
+ monitor.writeLockAcquired(this, key);
+ channel.send(buf, key.getRemoteAddress());
lock.notifyAll();
}
-
- monitor.writeOccurred( this, key );
+
+ monitor.writeOccurred(this, key);
}
-
-
+
/**
* Sets the output manager's monitor.
- *
+ *
* @param monitor the monitor used by this output manager
*/
- public void setOutputMonitor( OutputMonitor monitor )
- {
+ public void setOutputMonitor(OutputMonitor monitor) {
this.monitor = monitor;
}
-
/**
* EventHandler designed for processing output events.
*/
- class OutputStageHandler implements StageHandler
- {
- public void handleEvent( EventObject generic )
- {
- if ( generic instanceof OutputEvent )
- {
- OutputEvent event = ( OutputEvent ) generic;
-
- try
- {
- write( event.getClientKey(), event.getBuffer() );
- }
- catch ( IOException e )
- {
- monitor.failedOnWrite( UDPOutputManager.this,
- event.getClientKey(), e );
+ class OutputStageHandler implements StageHandler {
+ public void handleEvent(EventObject generic) {
+ if (generic instanceof OutputEvent) {
+ OutputEvent event = (OutputEvent) generic;
+
+ try {
+ write(event.getClientKey(), event.getBuffer());
+ } catch (IOException e) {
+ monitor.failedOnWrite(
+ UDPOutputManager.this,
+ event.getClientKey(), e);
}
}
}
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
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.protocol;
+package org.apache.seda.protocol;
import java.util.*;
@@ -26,108 +26,102 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultInetServicesDatabase implements InetServicesDatabase
-{
+public class DefaultInetServicesDatabase implements InetServicesDatabase {
/** maintains a list of entries mapped by the authoritative name */
private final Map entriesByName = new HashMap();
+
/** maintains a list of entries mapped by the service port */
private final Map entriesByPort = new HashMap();
+
/** maps a port number to the authoritative service protocol name */
private final Map protoByPort = new HashMap();
-
- public DefaultInetServicesDatabase( InetServiceEntry[] entries )
- {
- for ( int ii = 0; ii < entries.length; ii++ )
- {
+ public DefaultInetServicesDatabase(InetServiceEntry[] entries) {
+ for (int ii = 0; ii < entries.length; ii++) {
// first add entry to entriesByName map
- List list = ( List ) entriesByName.get( entries[ii].getName() );
- if ( list == null )
- {
- list = new ArrayList( 2 );
- entriesByName.put( entries[ii].getName(), list );
+ List list = (List) entriesByName.get(entries[ii].getName());
+
+ if (list == null) {
+ list = new ArrayList(2);
+ entriesByName.put(entries[ii].getName(), list);
}
- list.add( entries[ii] );
+
+ list.add(entries[ii]);
// now add entry to the entriesByPort map
- Integer iport = new Integer( entries[ii].getPort() );
- list = ( List ) entriesByPort.get( iport );
- if ( list == null )
- {
- list = new ArrayList( 2 );
- entriesByPort.put( iport, list );
+ Integer iport = new Integer(entries[ii].getPort());
+ list = (List) entriesByPort.get(iport);
+
+ if (list == null) {
+ list = new ArrayList(2);
+ entriesByPort.put(iport, list);
}
- list.add( entries[ii] );
+
+ list.add(entries[ii]);
// now map the port to the auth service name (protocol)
- protoByPort.put( iport, entries[ii].getName() );
+ protoByPort.put(iport, entries[ii].getName());
}
}
-
/**
* Adds an entry to this database removing any other entry with the same
* port and authoritative service protocol identifier.
*
* @param entry the entry to add
*/
- public void addEntry( InetServiceEntry entry )
- {
- Integer iport = new Integer( entry.getPort() );
-
- if ( protoByPort.containsKey( iport ) )
- {
- protoByPort.remove( iport );
+ public void addEntry(InetServiceEntry entry) {
+ Integer iport = new Integer(entry.getPort());
+
+ if (protoByPort.containsKey(iport)) {
+ protoByPort.remove(iport);
}
- protoByPort.put( iport, entry.getName() );
+
+ protoByPort.put(iport, entry.getName());
ArrayList list = null;
- if ( entriesByPort.containsKey( iport ) )
- {
- list = ( ArrayList ) entriesByPort.get( iport );
- for ( int ii = 0; ii < list.size(); ii++ )
- {
- InetServiceEntry ise = ( InetServiceEntry ) list.get( ii );
- if ( ise != null && ise.getProtocol() == entry.getProtocol() )
- {
- list.remove( ise );
- }
- }
- list.add( entry );
- }
- else
- {
- list = new ArrayList( 2 );
- list.add( entry );
- entriesByPort.put( iport, list );
- }
+ if (entriesByPort.containsKey(iport)) {
+ list = (ArrayList) entriesByPort.get(iport);
+ for (int ii = 0; ii < list.size(); ii++) {
+ InetServiceEntry ise = (InetServiceEntry) list.get(ii);
- if ( entriesByName.containsKey( entry.getName() ) )
- {
- list = ( ArrayList ) entriesByName.get( entry.getName() );
-
- for ( int ii = 0; ii < list.size(); ii++ )
- {
- InetServiceEntry ise = ( InetServiceEntry ) list.get( ii );
- if ( ise != null && ise.getProtocol() == entry.getProtocol() )
- {
- list.remove( ise );
+ if (
+ (ise != null)
+ && (ise.getProtocol() == entry.getProtocol())) {
+ list.remove(ise);
}
}
- list.add( entry );
- }
- else
- {
- list = new ArrayList( 2 );
- list.add( entry );
- entriesByName.put( entry.getName(), list );
+ list.add(entry);
+ } else {
+ list = new ArrayList(2);
+ list.add(entry);
+ entriesByPort.put(iport, list);
+ }
+
+ if (entriesByName.containsKey(entry.getName())) {
+ list = (ArrayList) entriesByName.get(entry.getName());
+
+ for (int ii = 0; ii < list.size(); ii++) {
+ InetServiceEntry ise = (InetServiceEntry) list.get(ii);
+
+ if (
+ (ise != null)
+ && (ise.getProtocol() == entry.getProtocol())) {
+ list.remove(ise);
+ }
+ }
+
+ list.add(entry);
+ } else {
+ list = new ArrayList(2);
+ list.add(entry);
+ entriesByName.put(entry.getName(), list);
}
}
-
/**
* Gets an iteration over all the entries for a service by the name of the
* service.
@@ -135,11 +129,10 @@
* @param name the authoritative name of the service
* @return an Iterator over InetServiceEntry objects
*/
- public Iterator getByName( String name )
- {
- List list = ( List ) entriesByName.get( name );
- if ( list == null )
- {
+ public Iterator getByName(String name) {
+ List list = (List) entriesByName.get(name);
+
+ if (list == null) {
list = Collections.EMPTY_LIST;
}
@@ -154,11 +147,10 @@
* @param port the port one which the service resides
* @return an Iterator over InetServiceEntry objects
*/
- public Iterator getByPort( int port )
- {
- List list = ( List ) entriesByPort.get( new Integer( port ) );
- if ( list == null )
- {
+ public Iterator getByPort(int port) {
+ List list = (List) entriesByPort.get(new Integer(port));
+
+ if (list == null) {
list = Collections.EMPTY_LIST;
}
@@ -170,9 +162,8 @@
*
* @param port the port one which the service resides
*/
- public String getProtoByPort( int port )
- {
- return ( String ) protoByPort.get( new Integer( port ) );
+ public String getProtoByPort(int port) {
+ return (String) protoByPort.get(new Integer(port));
}
/**
@@ -183,9 +174,8 @@
* @param proto the transport protocol used for the service
* @return the internet service entry
*/
- public InetServiceEntry getByName( String name, String proto )
- {
- throw new UnsupportedOperationException( "not needed yet" );
+ public InetServiceEntry getByName(String name, String proto) {
+ throw new UnsupportedOperationException("not needed yet");
}
/**
@@ -195,8 +185,7 @@
* @param proto the transport protocol used for the service
* @return the internet service entry
*/
- public InetServiceEntry getByPort( String port, String proto )
- {
- throw new UnsupportedOperationException( "not needed yet" );
+ public InetServiceEntry getByPort(String port, String proto) {
+ throw new UnsupportedOperationException("not needed yet");
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/DefaultRequestProcessor.java
Sat Oct 30 04:31:52 2004
@@ -14,16 +14,15 @@
* limitations under the License.
*
*/
-package org.apache.seda.protocol;
+package org.apache.seda.protocol;
-import java.util.Iterator;
import java.util.EventObject;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
import org.apache.seda.event.*;
-
import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
import org.apache.seda.stage.*;
@@ -36,206 +35,173 @@
* @version $Rev$
*/
public class DefaultRequestProcessor extends DefaultStage
- implements RequestProcessor, RequestSubscriber, ProtocolSubscriber
-{
+ implements RequestProcessor, RequestSubscriber, ProtocolSubscriber {
private final Map protocols;
private final EventRouter router;
private final InetServicesDatabase inetDb;
-
private RequestProcessorMonitor monitor = null;
-
/**
* Creates a default RequestProcessor.
- *
+ *
* @param router the event router we subscribe and publish to
- * @param config the configuration for this stage
+ * @param config the configuration for this stage
*/
- public DefaultRequestProcessor( EventRouter router, StageConfig config,
- InetServicesDatabase inetDb )
- {
- super( config );
-
- DefaultStageConfig defaultConfig = ( DefaultStageConfig ) config;
- defaultConfig.setHandler( new ProcessorStageHandler() );
- super.setMonitor( new LoggingStageMonitor( getClass() ) );
+ public DefaultRequestProcessor(
+ EventRouter router, StageConfig config,
+ InetServicesDatabase inetDb) {
+ super(config);
+
+ DefaultStageConfig defaultConfig = (DefaultStageConfig) config;
+ defaultConfig.setHandler(new ProcessorStageHandler());
+ super.setMonitor(new LoggingStageMonitor(getClass()));
this.inetDb = inetDb;
this.router = router;
- this.router.subscribe( RequestEvent.class, this );
- this.router.subscribe( ProtocolEvent.class, this );
- this.protocols = new HashMap( 3 );
+ this.router.subscribe(RequestEvent.class, this);
+ this.router.subscribe(ProtocolEvent.class, this);
+ this.protocols = new HashMap(3);
this.monitor = new RequestProcessorMonitorAdapter();
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.RequestSubscriber#inform(
* org.apache.seda.event.RequestEvent)
*/
- public void inform( RequestEvent event )
- {
- enqueue( event );
+ public void inform(RequestEvent event) {
+ enqueue(event);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch ( Throwable t )
- {
- monitor.failedOnInform( this, event, t );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Throwable t) {
+ monitor.failedOnInform(this, event, t);
}
}
-
/**
* Informs this subscriber of a protocol event.
*
* @param event the protocol event to inform of
*/
- public void inform( ProtocolEvent event )
- {
+ public void inform(ProtocolEvent event) {
ProtocolProvider proto = event.getProtocolProvider();
- protocols.put( proto.getName(), proto );
- }
-
-
- class ProcessorStageHandler implements StageHandler
- {
- /**
- * Event handler method for processing RequestEvents.
- *
- * @param nonspecific the RequestEvent to process.
- */
- public void handleEvent( EventObject nonspecific )
- {
- RequestEvent event = ( RequestEvent ) nonspecific;
- ClientKey key = event.getClientKey();
-
- RequestHandler handler = getProtocolHandler( event.getClientKey(),
- event.getRequest() );
-
- switch( handler.getHandlerType().getValue() )
- {
- case( HandlerTypeEnum.NOREPLY_VAL ):
- NoReplyHandler noreply = ( NoReplyHandler ) handler;
- noreply.handle( event.getRequest() );
- break;
- case( HandlerTypeEnum.SINGLEREPLY_VAL ):
- SingleReplyHandler single = ( SingleReplyHandler ) handler;
- reply( single, event.getRequest(), key );
- break;
- case( HandlerTypeEnum.MANYREPLY_VAL ):
- ManyReplyHandler many = ( ManyReplyHandler ) handler;
- reply( many, event.getRequest(), key );
- break;
- default:
- throw new IllegalArgumentException(
- "Unrecognized handler type: "
- + handler.getHandlerType() );
- }
- }
+ protocols.put(proto.getName(), proto);
}
-
- private RequestHandler getProtocolHandler( ClientKey key, Object request )
- {
+ private RequestHandler getProtocolHandler(ClientKey key, Object request) {
String name = null;
- try
- {
- name = inetDb.getProtoByPort( key.getLocalAddress().getPort() );
- }
- catch ( KeyExpiryException e )
- {
- monitor.keyExpired( key, request, e );
- throw new IllegalStateException( "key expired can't service req" );
+ try {
+ name = inetDb.getProtoByPort(key.getLocalAddress().getPort());
+ } catch (KeyExpiryException e) {
+ monitor.keyExpired(key, request, e);
+ throw new IllegalStateException("key expired can't service req");
}
- ProtocolProvider proto = ( ProtocolProvider ) protocols.get( name );
- return proto.getHandler( request );
+ ProtocolProvider proto = (ProtocolProvider) protocols.get(name);
+ return proto.getHandler(request);
}
-
/**
* Handles the generation and return of multiple responses.
- *
+ *
* @param handler the handler that generates the responses
* @param request the request responded to
*/
- private void reply( ManyReplyHandler handler,
- Object request,
- ClientKey key )
- {
+ private void reply(
+ ManyReplyHandler handler, Object request, ClientKey
key) {
Object response = null;
- try
- {
- Iterator list = handler.handle( request );
-
- if ( handler.isSequential() )
- {
- while ( list.hasNext() )
- {
- response = list.next();
-
- // @todo: need to force serialized response processing
- // perhaps we need to add an isResponseOrdered or a
- // response sequence number for multi-part responses
-
- throw new UnsupportedOperationException(
- "need response serialization" );
- }
- }
- else
- {
- while ( list.hasNext() )
- {
- response = list.next();
- router.publish( new ResponseEvent( this, key, response )
);
- }
- }
- }
-
- catch( Throwable t )
- {
- monitor.failedOnSingleReply( key, request, t );
- }
+ try {
+ Iterator list = handler.handle(request);
+
+ if (handler.isSequential()) {
+ while (list.hasNext()) {
+ response = list.next();
+
+ // @todo: need to force serialized response processing
+ // perhaps we need to add an isResponseOrdered or a
+ // response sequence number for multi-part responses
+ throw new UnsupportedOperationException("need response
serialization");
+ }
+ } else {
+ while (list.hasNext()) {
+ response = list.next();
+ router.publish(new ResponseEvent(this, key, response));
+ }
+ }
+ }
+ catch (Throwable t) {
+ monitor.failedOnSingleReply(key, request, t);
+ }
}
-
-
+
/**
* Handles the generation and return of a single response.
- *
+ *
* @param handler the handler that generates the single response
* @param request the request responded to
*/
- private void reply( SingleReplyHandler handler, Object request,
- ClientKey key )
- {
+ private void reply(
+ SingleReplyHandler handler, Object request,
+ ClientKey key) {
Object response = null;
- try
- {
- response = handler.handle( request );
+ try {
+ response = handler.handle(request);
}
-
// If the individual handlers do not do a global catch and report this
// will sheild the server from complete failure on a request reporting
// at a minimum the stack trace that cause the request to fail.
- catch( Throwable t )
- {
- monitor.failedOnSingleReply( key, request, t );
+ catch (Throwable t) {
+ monitor.failedOnSingleReply(key, request, t);
return;
}
- router.publish( new ResponseEvent( this, key, response ) );
+ router.publish(new ResponseEvent(this, key, response));
+ }
+
+ class ProcessorStageHandler implements StageHandler {
+ /**
+ * Event handler method for processing RequestEvents.
+ *
+ * @param nonspecific the RequestEvent to process.
+ */
+ public void handleEvent(EventObject nonspecific) {
+ RequestEvent event = (RequestEvent) nonspecific;
+ ClientKey key = event.getClientKey();
+
+ RequestHandler handler =
+ getProtocolHandler(event.getClientKey(), event.getRequest());
+
+ switch (handler.getHandlerType().getValue()) {
+ case (HandlerTypeEnum.NOREPLY_VAL):
+
+ NoReplyHandler noreply = (NoReplyHandler) handler;
+ noreply.handle(event.getRequest());
+ break;
+
+ case (HandlerTypeEnum.SINGLEREPLY_VAL):
+
+ SingleReplyHandler single = (SingleReplyHandler) handler;
+ reply(single, event.getRequest(), key);
+ break;
+
+ case (HandlerTypeEnum.MANYREPLY_VAL):
+
+ ManyReplyHandler many = (ManyReplyHandler) handler;
+ reply(many, event.getRequest(), key);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unrecognized handler type:
"
+ + handler.getHandlerType());
+ }
+ }
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
Sat Oct 30 04:31:52 2004
@@ -1,61 +1,62 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-import org.apache.seda.impl.util.ValuedEnum;
-
-
-/**
- * Valued enumeration for the three types of handlers: NOREPLY, SINGLEREPLY,
- * and MANYREPLY.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public class HandlerTypeEnum extends ValuedEnum
-{
- /** Value for noreply enumeration type */
- public static final int NOREPLY_VAL = 0;
- /** Value for singlereply enumeration type */
- public static final int SINGLEREPLY_VAL = 1;
- /** Value for manyreply enumeration type */
- public static final int MANYREPLY_VAL = 2;
-
- /** Enum for noreply type */
- public static final HandlerTypeEnum NOREPLY =
- new HandlerTypeEnum( "NOREPLY", NOREPLY_VAL );
- /** Enum for singlereply type */
- public static final HandlerTypeEnum SINGLEREPLY =
- new HandlerTypeEnum( "SINGLEREPLY", SINGLEREPLY_VAL );
- /** Enum for manyreply type */
- public static final HandlerTypeEnum MANYREPLY =
- new HandlerTypeEnum( "MANYREPLY", MANYREPLY_VAL );
-
-
- /**
- * Enables creation of constants in this class only.
- *
- * @param name the name of the enum
- * @param value the value of the enum
- */
- private HandlerTypeEnum( String name, int value )
- {
- super( name, value );
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+import org.apache.seda.impl.util.ValuedEnum;
+
+
+/**
+ * Valued enumeration for the three types of handlers: NOREPLY, SINGLEREPLY,
+ * and MANYREPLY.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class HandlerTypeEnum extends ValuedEnum {
+ /** Value for noreply enumeration type */
+ public static final int NOREPLY_VAL = 0;
+
+ /** Value for singlereply enumeration type */
+ public static final int SINGLEREPLY_VAL = 1;
+
+ /** Value for manyreply enumeration type */
+ public static final int MANYREPLY_VAL = 2;
+
+ /** Enum for noreply type */
+ public static final HandlerTypeEnum NOREPLY =
+ new HandlerTypeEnum("NOREPLY", NOREPLY_VAL);
+
+ /** Enum for singlereply type */
+ public static final HandlerTypeEnum SINGLEREPLY =
+ new HandlerTypeEnum("SINGLEREPLY", SINGLEREPLY_VAL);
+
+ /** Enum for manyreply type */
+ public static final HandlerTypeEnum MANYREPLY =
+ new HandlerTypeEnum("MANYREPLY", MANYREPLY_VAL);
+
+ /**
+ * Enables creation of constants in this class only.
+ *
+ * @param name the name of the enum
+ * @param value the value of the enum
+ */
+ private HandlerTypeEnum(String name, int value) {
+ super(name, value);
+ }
+}
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
Sat Oct 30 04:31:52 2004
@@ -1,144 +1,130 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-/**
- * An internet service entry from the services database.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class InetServiceEntry
-{
- /** an empty string array for no aliases */
- private static final String[] EMPTY_ALIASES = new String[0];
-
- /** the authoritative name of the service */
- private final String name;
- /** the port the service runs on */
- private final int port;
- /** alternative names for the service */
- private final String[] aliases;
- /** the transport protocol used by the service */
- private final TransportTypeEnum proto;
-
-
- /**
- * Creates an internet service entry without any aliases using TCP as the
- * transport protocol.
- *
- * @param name the authoritative name of the service
- * @param port the port the service runs on
- */
- public InetServiceEntry( String name, int port )
- {
- this( name, port, TransportTypeEnum.TCP, null );
- }
-
-
- /**
- * Creates an internet service entry without any aliases.
- *
- * @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
- */
- public InetServiceEntry( String name, int port, TransportTypeEnum proto )
- {
- this( name, port, proto, null );
- }
-
-
- /**
- * Creates an internet service entry.
- *
- * @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 aliases alternative names for the service
- */
- public InetServiceEntry( String name, int port, TransportTypeEnum proto,
- String[] aliases )
- {
- if ( name == null )
- {
- throw new NullPointerException( "service name can't be null" );
- }
-
- this.name = name;
- this.port = port;
- this.proto = proto;
-
- if ( proto == null )
- {
- throw new NullPointerException( "transport can't be null" );
- }
-
- if ( aliases == null )
- {
- this.aliases = EMPTY_ALIASES;
- }
- else
- {
- this.aliases = aliases;
- }
- }
-
-
- /**
- * Gets the authoritative name of the service.
- *
- * @return the authoritative name of the service
- */
- public String getName()
- {
- return name;
- }
-
-
- /**
- * Gets the port this entry's service runs on.
- *
- * @return the port this entry's service runs on
- */
- public int getPort()
- {
- return port;
- }
-
-
- /**
- * Gets the alternative names for this entry's service.
- *
- * @return the alternative names for this entry's service
- */
- public String[] getAliases()
- {
- return aliases;
- }
-
-
- /**
- * Gets the transport protocol used for this service.
- *
- * @return the transport protocol used for this service
- */
- public TransportTypeEnum getProtocol()
- {
- return proto;
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+
+/**
+ * An internet service entry from the services database.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class InetServiceEntry {
+ /** an empty string array for no aliases */
+ private static final String[] EMPTY_ALIASES = new String[0];
+
+ /** the authoritative name of the service */
+ private final String name;
+
+ /** the port the service runs on */
+ private final int port;
+
+ /** alternative names for the service */
+ private final String[] aliases;
+
+ /** the transport protocol used by the service */
+ private final TransportTypeEnum proto;
+
+ /**
+ * Creates an internet service entry without any aliases using TCP as the
+ * transport protocol.
+ *
+ * @param name the authoritative name of the service
+ * @param port the port the service runs on
+ */
+ public InetServiceEntry(String name, int port) {
+ this(name, port, TransportTypeEnum.TCP, null);
+ }
+
+ /**
+ * Creates an internet service entry without any aliases.
+ *
+ * @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
+ */
+ public InetServiceEntry(String name, int port, TransportTypeEnum proto) {
+ this(name, port, proto, null);
+ }
+
+ /**
+ * Creates an internet service entry.
+ *
+ * @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 aliases alternative names for the service
+ */
+ public InetServiceEntry(
+ String name, int port, TransportTypeEnum proto,
+ String[] aliases) {
+ if (name == null) {
+ throw new NullPointerException("service name can't be null");
+ }
+
+ this.name = name;
+ this.port = port;
+ this.proto = proto;
+
+ if (proto == null) {
+ throw new NullPointerException("transport can't be null");
+ }
+
+ if (aliases == null) {
+ this.aliases = EMPTY_ALIASES;
+ } else {
+ this.aliases = aliases;
+ }
+ }
+
+ /**
+ * Gets the authoritative name of the service.
+ *
+ * @return the authoritative name of the service
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the port this entry's service runs on.
+ *
+ * @return the port this entry's service runs on
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * Gets the alternative names for this entry's service.
+ *
+ * @return the alternative names for this entry's service
+ */
+ public String[] getAliases() {
+ return aliases;
+ }
+
+ /**
+ * Gets the transport protocol used for this service.
+ *
+ * @return the transport protocol used for this service
+ */
+ public TransportTypeEnum getProtocol() {
+ return proto;
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServicesDatabase.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServicesDatabase.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/InetServicesDatabase.java
Sat Oct 30 04:31:52 2004
@@ -1,76 +1,75 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-import java.util.Iterator;
-
-
-/**
- * Interface for the internet services database. The database is used by
- * seda to associate services with ports and transport protocols.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface InetServicesDatabase
-{
- /**
- * Gets an iteration over all the entries for a service by the name of the
- * service.
- *
- * @param name the authoritative name of the service
- * @return an Iterator over InetServiceEntry objects
- */
- Iterator getByName( String name );
-
- /**
- * Gets an iteration over all the entries for a service by port number.
- * This method returns an Iterator over the set of InetServiceEntry objects
- * since more than one transport protocol can be used on the same port.
- *
- * @param port the port one which the service resides
- * @return an Iterator over InetServiceEntry objects
- */
- Iterator getByPort( int port );
-
- /**
- * Gets the service/protocol associated with a port.
- *
- * @param port the port one which the service resides
- */
- String getProtoByPort( int port );
-
- /**
- * Gets the service entry by name using the authoritative service name and
- * a transport protocol.
- *
- * @param name the authoritative name of the service
- * @param proto the transport protocol used for the service
- * @return the internet service entry
- */
- InetServiceEntry getByName( String name, String proto );
-
- /**
- * Gets the service entry by port using the port and a transport protocol.
- *
- * @param port the port on which the service resides
- * @param proto the transport protocol used for the service
- * @return the internet service entry
- */
- InetServiceEntry getByPort( String port, String proto );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+import java.util.Iterator;
+
+
+/**
+ * Interface for the internet services database. The database is used by
+ * seda to associate services with ports and transport protocols.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface InetServicesDatabase {
+ /**
+ * Gets an iteration over all the entries for a service by the name of the
+ * service.
+ *
+ * @param name the authoritative name of the service
+ * @return an Iterator over InetServiceEntry objects
+ */
+ Iterator getByName(String name);
+
+ /**
+ * Gets an iteration over all the entries for a service by port number.
+ * This method returns an Iterator over the set of InetServiceEntry objects
+ * since more than one transport protocol can be used on the same port.
+ *
+ * @param port the port one which the service resides
+ * @return an Iterator over InetServiceEntry objects
+ */
+ Iterator getByPort(int port);
+
+ /**
+ * Gets the service/protocol associated with a port.
+ *
+ * @param port the port one which the service resides
+ */
+ String getProtoByPort(int port);
+
+ /**
+ * Gets the service entry by name using the authoritative service name and
+ * a transport protocol.
+ *
+ * @param name the authoritative name of the service
+ * @param proto the transport protocol used for the service
+ * @return the internet service entry
+ */
+ InetServiceEntry getByName(String name, String proto);
+
+ /**
+ * Gets the service entry by port using the port and a transport protocol.
+ *
+ * @param port the port on which the service resides
+ * @param proto the transport protocol used for the service
+ * @return the internet service entry
+ */
+ InetServiceEntry getByPort(String port, String proto);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ManyReplyHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ManyReplyHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ManyReplyHandler.java
Sat Oct 30 04:31:52 2004
@@ -1,48 +1,47 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-import java.util.Iterator;
-
-
-/**
- * A handler for requests that can generate zero, one or more responses.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface ManyReplyHandler extends RequestHandler
-{
- /**
- * A handler for a request that can create multiple responses of
- * heterogenous messages.
- *
- * @param request the request that may generate many replies
- * @return an enumeration over the responses
- */
- Iterator handle( Object request );
-
- /**
- * Determinates whether or not a multi-reply request's responses should be
- * returned in sequence to a client.
- *
- * @return true if order of replies are required by the protocol, false
- * if response order is insignificant.
- */
- boolean isSequential();
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+import java.util.Iterator;
+
+
+/**
+ * A handler for requests that can generate zero, one or more responses.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface ManyReplyHandler extends RequestHandler {
+ /**
+ * A handler for a request that can create multiple responses of
+ * heterogenous messages.
+ *
+ * @param request the request that may generate many replies
+ * @return an enumeration over the responses
+ */
+ Iterator handle(Object request);
+
+ /**
+ * Determinates whether or not a multi-reply request's responses should be
+ * returned in sequence to a client.
+ *
+ * @return true if order of replies are required by the protocol, false
+ * if response order is insignificant.
+ */
+ boolean isSequential();
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/NoReplyHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/NoReplyHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/NoReplyHandler.java
Sat Oct 30 04:31:52 2004
@@ -1,36 +1,35 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-/**
- * Represents handlers that do not return a response to the client.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface NoReplyHandler
- extends RequestHandler
-{
- /**
- * Handles requests that do not reply to the requesting client with a
- * response.
- *
- * @param request the request without a response.
- */
- void handle( Object request );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+
+/**
+ * Represents handlers that do not return a response to the client.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface NoReplyHandler extends RequestHandler {
+ /**
+ * Handles requests that do not reply to the requesting client with a
+ * response.
+ *
+ * @param request the request without a response.
+ */
+ void handle(Object request);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ProtocolProvider.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ProtocolProvider.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/ProtocolProvider.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.protocol;
+package org.apache.seda.protocol;
import org.apache.commons.codec.stateful.DecoderFactory;
import org.apache.commons.codec.stateful.EncoderFactory;
@@ -27,8 +27,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory Project</a>
* @version $Rev$
*/
-public interface ProtocolProvider
-{
+public interface ProtocolProvider {
/**
* Gets the authoritative name for the service of this provider.
*
@@ -39,7 +38,7 @@
/**
* Gets a factory used to create a new StatefulDecoder for this service's
* protocol.
- *
+ *
* @return a new StatefulDecoder for this service's protocol
*/
DecoderFactory getDecoderFactory();
@@ -58,5 +57,5 @@
* @param request the protocol request to handle
* @return the protocol request handler for the request object
*/
- RequestHandler getHandler( Object request );
+ RequestHandler getHandler(Object request);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestHandler.java
Sat Oct 30 04:31:52 2004
@@ -1,34 +1,34 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-/**
- * Root of all request handler types.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface RequestHandler
-{
- /**
- * Gets the handler type.
- *
- * @return a HandlerTypeEnum constant.
- */
- HandlerTypeEnum getHandlerType();
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+
+/**
+ * Root of all request handler types.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface RequestHandler {
+ /**
+ * Gets the handler type.
+ *
+ * @return a HandlerTypeEnum constant.
+ */
+ HandlerTypeEnum getHandlerType();
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessor.java
Sat Oct 30 04:31:52 2004
@@ -1,29 +1,29 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-/**
- * A service designed to process requests.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface RequestProcessor
-{
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+
+/**
+ * A service designed to process requests.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface RequestProcessor {
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
Sat Oct 30 04:31:52 2004
@@ -1,56 +1,54 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-import java.util.EventObject;
-
-import org.apache.seda.event.Subscriber;
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-
-
-/**
- * A monitor interface for the RequestProcessor.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">
- * Apache Directory Project</a>
- * @version $Rev$
- */
-public interface RequestProcessorMonitor
-{
- /**
- * Monitors failures while processing inform methods if any.
- *
- * @param subscriber the subscriber
- * @param event the event being delievered
- * @param t the throwable that prevented delivery
- */
- void failedOnInform( Subscriber subscriber, EventObject event,
- Throwable t );
-
- /**
- * Monitors failures while applying a single reply handler to a request.
- *
- * @param key the key of the client associated with the request
- * @param request the request to process/handle
- * @param t the failure that occurred while processing the request
- */
- void failedOnSingleReply( ClientKey key, Object request, Throwable t );
-
- void keyExpired( ClientKey key, Object request, KeyExpiryException e );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+import java.util.EventObject;
+
+import org.apache.seda.event.Subscriber;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
+
+
+/**
+ * A monitor interface for the RequestProcessor.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">
+ * Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface RequestProcessorMonitor {
+ /**
+ * Monitors failures while processing inform methods if any.
+ *
+ * @param subscriber the subscriber
+ * @param event the event being delievered
+ * @param t the throwable that prevented delivery
+ */
+ void failedOnInform(Subscriber subscriber, EventObject event, Throwable t);
+
+ /**
+ * Monitors failures while applying a single reply handler to a request.
+ *
+ * @param key the key of the client associated with the request
+ * @param request the request to process/handle
+ * @param t the failure that occurred while processing the request
+ */
+ void failedOnSingleReply(ClientKey key, Object request, Throwable t);
+
+ void keyExpired(ClientKey key, Object request, KeyExpiryException e);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.protocol;
+package org.apache.seda.protocol;
import java.util.EventObject;
@@ -31,41 +31,33 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class RequestProcessorMonitorAdapter implements RequestProcessorMonitor
-{
+public class RequestProcessorMonitorAdapter implements RequestProcessorMonitor
{
/* @see org.apache.seda.protocol.RequestProcessorMonitor#failedOnInform(
- * org.apache.seda.event.Subscriber, java.util.EventObject,
+ * org.apache.seda.event.Subscriber, java.util.EventObject,
* java.lang.Throwable)
*/
- public void failedOnInform( Subscriber subscriber, EventObject event,
- Throwable t )
- {
- if ( t != null )
- {
+ public void failedOnInform(
+ Subscriber subscriber, EventObject event,
+ Throwable t) {
+ if (t != null) {
t.printStackTrace();
}
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.protocol.RequestProcessorMonitor#failedOnSingleReply
- * (org.apache.seda.listener.ClientKey,
+ * (org.apache.seda.listener.ClientKey,
* org.apache.ldap.common.message.Request, java.lang.Throwable)
*/
- public void failedOnSingleReply( ClientKey key, Object request,
- Throwable t )
- {
- if ( t != null )
- {
+ public void failedOnSingleReply(
+ ClientKey key, Object request, Throwable
t) {
+ if (t != null) {
t.printStackTrace();
}
}
-
- public void keyExpired( ClientKey key, Object req, KeyExpiryException e )
- {
- if ( e != null )
- {
+ public void keyExpired(ClientKey key, Object req, KeyExpiryException e) {
+ if (e != null) {
e.printStackTrace();
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/SingleReplyHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/SingleReplyHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/SingleReplyHandler.java
Sat Oct 30 04:31:52 2004
@@ -1,37 +1,37 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-/**
- * Request handler signature for those requests that generate a single response
- * for a request.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public interface SingleReplyHandler extends RequestHandler
-{
- /**
- * Handles a request that generates a sole response by returning the
- * response object back to the caller.
- *
- * @param request the request to handle.
- * @return the response to the request argument.
- */
- Object handle( Object request );
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+
+/**
+ * Request handler signature for those requests that generate a single response
+ * for a request.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public interface SingleReplyHandler extends RequestHandler {
+ /**
+ * Handles a request that generates a sole response by returning the
+ * response object back to the caller.
+ *
+ * @param request the request to handle.
+ * @return the response to the request argument.
+ */
+ Object handle(Object request);
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/TransportTypeEnum.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/TransportTypeEnum.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/protocol/TransportTypeEnum.java
Sat Oct 30 04:31:52 2004
@@ -1,59 +1,60 @@
-/*
- * Copyright 2004 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.seda.protocol;
-
-
-import org.apache.seda.impl.util.ValuedEnum;
-
-
-/**
- * Valued enumeration for the types transports: TCP, UDP, and PIPE for now.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class TransportTypeEnum extends ValuedEnum
-{
- /** Value for TCP transport enumeration type */
- public static final int TCP_VAL = 0;
- /** Value for UDP transport enumeration type */
- public static final int UDP_VAL = 1;
- /** Value for PIPE transport enumeration type */
- public static final int PIPE_VAL = 2;
-
- /** Enum for TCP type */
- public static final TransportTypeEnum TCP =
- new TransportTypeEnum( "TCP", TCP_VAL );
- /** Enum for UDP type */
- public static final TransportTypeEnum UDP =
- new TransportTypeEnum( "UDP", UDP_VAL );
- /** Enum for PIPE type */
- public static final TransportTypeEnum PIPE =
- new TransportTypeEnum( "PIPE", PIPE_VAL );
-
-
- /**
- * Enables creation of constants in this class only.
- *
- * @param name the name of the enum
- * @param value the value of the enum
- */
- private TransportTypeEnum( String name, int value )
- {
- super( name, value );
- }
-}
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.seda.protocol;
+
+import org.apache.seda.impl.util.ValuedEnum;
+
+
+/**
+ * Valued enumeration for the types transports: TCP, UDP, and PIPE for now.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TransportTypeEnum extends ValuedEnum {
+ /** Value for TCP transport enumeration type */
+ public static final int TCP_VAL = 0;
+
+ /** Value for UDP transport enumeration type */
+ public static final int UDP_VAL = 1;
+
+ /** Value for PIPE transport enumeration type */
+ public static final int PIPE_VAL = 2;
+
+ /** Enum for TCP type */
+ public static final TransportTypeEnum TCP =
+ new TransportTypeEnum("TCP", TCP_VAL);
+
+ /** Enum for UDP type */
+ public static final TransportTypeEnum UDP =
+ new TransportTypeEnum("UDP", UDP_VAL);
+
+ /** Enum for PIPE type */
+ public static final TransportTypeEnum PIPE =
+ new TransportTypeEnum("PIPE", PIPE_VAL);
+
+ /**
+ * Enables creation of constants in this class only.
+ *
+ * @param name the name of the enum
+ * @param value the value of the enum
+ */
+ private TransportTypeEnum(String name, int value) {
+ super(name, value);
+ }
+}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/session/ClientSession.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/session/ClientSession.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/session/ClientSession.java
Sat Oct 30 04:31:52 2004
@@ -14,13 +14,13 @@
* limitations under the License.
*
*/
+
package org.apache.seda.session;
+import java.security.Principal;
-import java.util.Locale;
import java.util.Iterator;
-
-import java.security.Principal;
+import java.util.Locale;
import org.apache.seda.listener.ClientKey;
@@ -31,11 +31,10 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface ClientSession
-{
+public interface ClientSession {
/**
* Gets the unique client key associated with this session.
- *
+ *
* @return the unique client key
*/
ClientKey getClientKey();
@@ -45,83 +44,83 @@
* corresponds to a connected client. Sessions are invalidated once the
* client connection is lost or dropped or when sessions are destroyed to
* bind as a different user.
- *
- * @return true if this session is still valid, false if it is not
+ *
+ * @return true if this session is still valid, false if it is not
*/
boolean isValid();
/**
* Gets an iterator over all the attribute names stored in this session.
- *
+ *
* @return an iterator of key names
*/
Iterator getAttributeNames();
/**
* Gets the value for a session attribute name.
- *
+ *
* @param an_attrName the name of the session attribute key
* @return the value of the session attribute
*/
- Object getAttribute( String an_attrName );
+ Object getAttribute(String an_attrName);
/**
* Removes a session attribute key and value from this session.
- *
+ *
* @param an_attrName the name of the session attribute key
*/
- void removeAttribute( String an_attrName );
+ void removeAttribute(String an_attrName);
/**
* Sets the value of a session attribute.
- *
+ *
* @param an_attrName the name of the session attribute key
* @param a_attrValue the value to set for the session attribute
*/
- void setAttribute( String an_attrName, Object a_attrValue );
+ void setAttribute(String an_attrName, Object a_attrValue);
/**
- * Determines if this session is newly created before an appropriate
+ * Determines if this session is newly created before an appropriate
* authenticated principal could be set.
- *
+ *
* @return true if the principal has yet to be authenticated
*/
boolean isNew();
/**
* Gets the creation time of this session in milliseconds.
- *
+ *
* @return the creation time in milliseconds
*/
long getCreationTime();
/**
* Gets the time this session was accessed in milliseconds.
- *
+ *
* @return the last access time in milliseconds
*/
long getLastAccessedTime();
/**
- * Gets the maximum inactivity time in seconds before timing out this
+ * Gets the maximum inactivity time in seconds before timing out this
* session.
- *
+ *
* @return the timeout period in seconds
*/
int getMaxInactiveInterval();
/**
* Gets the locale of the session's client.
- *
+ *
* @return the locale of the client
*/
Locale getLocale();
/**
- * Gets the principal for the client this session belongs to. If the
- * session is new or annonymous authentication is allowed then this
+ * Gets the principal for the client this session belongs to. If the
+ * session is new or annonymous authentication is allowed then this
* principal will return the empty string for getName().
- *
+ *
* @return the principal owning this session
*/
Principal getPrincipal();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStage.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStage.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStage.java
Sat Oct 30 04:31:52 2004
@@ -14,13 +14,13 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
-import java.util.Set;
+import java.util.EventObject;
import java.util.HashSet;
import java.util.LinkedList;
-import java.util.EventObject;
+import java.util.Set;
/**
@@ -29,72 +29,66 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultStage implements Stage
-{
- /**
+public class DefaultStage implements Stage {
+ /**
* time to sleep in milliseconds waiting for this stage to stop
* @todo migth want add this to config and use this as the default value
*/
private static final long STOP_WAIT = 100;
-
+
/** the configuration bean */
protected final StageConfig config;
+
/** this Stage's event queue */
private final LinkedList queue = new LinkedList();
+
/** this Stage's active handler threads */
private final Set activeWorkers = new HashSet();
/** this Stage's StageDriver's driving thread */
private Thread thread = null;
+
/** the start stop control variable */
- private Boolean hasStarted = new Boolean( false );
+ private Boolean hasStarted = new Boolean(false);
+
/** this Stage's monitor */
private StageMonitor monitor = new StageMonitorAdapter();
-
// ------------------------------------------------------------------------
// C O N S T R U C T O R S
// ------------------------------------------------------------------------
-
/**
* Creates a DefaultStage using a configuration bean.
- *
+ *
* @param config the configuration bean
*/
- public DefaultStage( StageConfig config )
- {
+ public DefaultStage(StageConfig config) {
this.config = config;
- hasStarted = new Boolean( false );
+ hasStarted = new Boolean(false);
}
-
-
+
// ------------------------------------------------------------------------
// Stage Methods
// ------------------------------------------------------------------------
-
/**
* @see org.apache.seda.stage.Stage#addPredicate(
* org.apache.seda.stage.EnqueuePredicate)
* addPredicate(org.apache.seda.seda.EnqueuePredicate)
*/
- public void addPredicate( EnqueuePredicate predicate )
- {
- config.getPredicates().add( predicate );
- monitor.predicateAdded( this, predicate );
+ public void addPredicate(EnqueuePredicate predicate) {
+ config.getPredicates().add(predicate);
+ monitor.predicateAdded(this, predicate);
}
-
-
+
/**
* @see org.apache.seda.stage.Stage#getConfig()
*/
- public StageConfig getConfig()
- {
+ public StageConfig getConfig() {
return config;
}
-
/**
* Enqueue's an event onto the event queue of this stage if the stage
* predicates permit the operation and the stage has started. The event
@@ -102,219 +96,178 @@
*
* @see org.apache.seda.stage.Stage#enqueue(java.util.EventObject)
*/
- public void enqueue( final EventObject event )
- {
+ public void enqueue(final EventObject event) {
boolean isAccepted = true;
- if ( ! hasStarted.booleanValue() )
- {
- monitor.enqueueRejected( this, event );
+ if (!hasStarted.booleanValue()) {
+ monitor.enqueueRejected(this, event);
return;
}
- for ( int ii = 0; ii < config.getPredicates().size() && isAccepted;
- ii++ )
- {
- EnqueuePredicate test =
- ( EnqueuePredicate ) config.getPredicates().get( ii );
- isAccepted &= test.accept( event );
+ for (int ii = 0; (ii < config.getPredicates().size()) && isAccepted;
+ ii++) {
+ EnqueuePredicate test =
+ (EnqueuePredicate) config.getPredicates().get(ii);
+ isAccepted &= test.accept(event);
}
- if( isAccepted )
- {
- synchronized ( queue )
- {
- monitor.lockedQueue( this, event );
- queue.addFirst( event );
+ if (isAccepted) {
+ synchronized (queue) {
+ monitor.lockedQueue(this, event);
+ queue.addFirst(event);
queue.notifyAll();
}
- monitor.enqueueOccurred( this, event );
- }
- else
- {
- monitor.enqueueRejected( this, event );
- }
- }
-
-
- // ------------------------------------------------------------------------
- // Runnable Implementations
- // ------------------------------------------------------------------------
-
-
- /**
- * The runnable driving the main thread of this Stage.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision$
- */
- class StageDriver implements Runnable
- {
- public final void run()
- {
- monitor.startedDriver( DefaultStage.this );
-
- /*
- * keep processing until the hasStarted variable is toggled off
- * and there are no queue events left. Before without the queue
- * term events would be left unprocessed on the queue on stop calls
- */
- while( hasStarted.booleanValue() || !queue.isEmpty() )
- {
- synchronized ( queue )
- {
- monitor.lockedQueue( DefaultStage.this );
-
- if( queue.isEmpty() )
- {
- try
- {
- monitor.waiting( DefaultStage.this );
- queue.wait();
- monitor.notified( DefaultStage.this );
- }
- catch( InterruptedException e )
- {
- try { stop(); } catch ( Exception e2 )
- {/*NOT THROWN*/}
- monitor.driverFailed( DefaultStage.this, e );
- }
- }
- else
- {
- EventObject event = ( EventObject ) queue.removeLast();
- monitor.eventDequeued( DefaultStage.this, event );
- Runnable l_runnable = new ExecutableHandler( event );
- config.getThreadPool().execute( l_runnable );
- monitor.eventHandled( DefaultStage.this, event );
- }
- }
- }
- }
- }
-
-
- /**
- * The runnable driving the work of this Stage's handler.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
- * @author $Author: akarasulu $
- * @version $Revision$
- */
- class ExecutableHandler implements Runnable
- {
- final EventObject m_event;
-
- public ExecutableHandler( EventObject event )
- {
- m_event = event;
- }
-
- public void run()
- {
- activeWorkers.add( Thread.currentThread() );
-
- try
- {
- if ( config.getHandler() == null )
- {
- monitor.handlerMissing( DefaultStage.this );
- }
- else
- {
- config.getHandler().handleEvent( m_event );
- }
- }
- catch( Throwable t )
- {
- monitor.handlerFailed( DefaultStage.this, m_event, t );
- }
- finally
- {
- activeWorkers.remove( Thread.currentThread() );
- }
+ monitor.enqueueOccurred(this, event);
+ } else {
+ monitor.enqueueRejected(this, event);
}
}
-
// ------------------------------------------------------------------------
// start stop controls
// ------------------------------------------------------------------------
-
-
+
/**
* Starts up this Stage's driver.
*/
- public void start()
- {
- if ( hasStarted.booleanValue() )
- {
- throw new IllegalStateException( "Already started!" );
+ public void start() {
+ if (hasStarted.booleanValue()) {
+ throw new IllegalStateException("Already started!");
}
-
- hasStarted = new Boolean( true );
- thread = new Thread( new StageDriver() );
+
+ hasStarted = new Boolean(true);
+ thread = new Thread(new StageDriver());
thread.start();
-
- monitor.started( this );
+
+ monitor.started(this);
}
-
-
+
/**
* Blocks calling thread until this Stage gracefully stops its driver and
* all its worker threads.
*/
- public void stop() throws InterruptedException
- {
- hasStarted = new Boolean( false );
- monitor.stopping( this );
-
- while ( thread.isAlive() || ! activeWorkers.isEmpty() )
- {
- monitor.stopping( this, STOP_WAIT );
- Thread.sleep( STOP_WAIT );
-
- synchronized( queue )
- {
+ public void stop() throws InterruptedException {
+ hasStarted = new Boolean(false);
+ monitor.stopping(this);
+
+ while (thread.isAlive() || !activeWorkers.isEmpty()) {
+ monitor.stopping(this, STOP_WAIT);
+ Thread.sleep(STOP_WAIT);
+
+ synchronized (queue) {
queue.notifyAll();
}
}
-
- monitor.stopped( this );
- }
+ monitor.stopped(this);
+ }
/**
* Tests to see if this stage has started.
*
* @return true if this stage has started, false otherwise
*/
- public boolean hasStarted()
- {
+ public boolean hasStarted() {
return hasStarted.booleanValue();
}
-
/**
* Gets this Stage's monitor.
- *
+ *
* @return the monitor for this Stage
*/
- public StageMonitor getStageMonitor()
- {
+ public StageMonitor getStageMonitor() {
return monitor;
}
-
/**
* Sets this Stage's monitor.
- *
+ *
* @param monitor the monitor to set for this Stage
*/
- public void setMonitor( StageMonitor monitor )
- {
+ public void setMonitor(StageMonitor monitor) {
this.monitor = monitor;
+ }
+
+ // ------------------------------------------------------------------------
+ // Runnable Implementations
+ // ------------------------------------------------------------------------
+
+ /**
+ * The runnable driving the main thread of this Stage.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+ class StageDriver implements Runnable {
+ public final void run() {
+ monitor.startedDriver(DefaultStage.this);
+
+ /*
+ * keep processing until the hasStarted variable is toggled off
+ * and there are no queue events left. Before without the queue
+ * term events would be left unprocessed on the queue on stop calls
+ */
+ while (hasStarted.booleanValue() || !queue.isEmpty()) {
+ synchronized (queue) {
+ monitor.lockedQueue(DefaultStage.this);
+
+ if (queue.isEmpty()) {
+ try {
+ monitor.waiting(DefaultStage.this);
+ queue.wait();
+ monitor.notified(DefaultStage.this);
+ } catch (InterruptedException e) {
+ try {
+ stop();
+ } catch (Exception e2) { /*NOT THROWN*/
+ }
+
+ monitor.driverFailed(DefaultStage.this, e);
+ }
+ } else {
+ EventObject event = (EventObject) queue.removeLast();
+ monitor.eventDequeued(DefaultStage.this, event);
+
+ Runnable l_runnable = new ExecutableHandler(event);
+ config.getThreadPool().execute(l_runnable);
+ monitor.eventHandled(DefaultStage.this, event);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * The runnable driving the work of this Stage's handler.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
+ * @author $Author$
+ * @version $Revision$
+ */
+ class ExecutableHandler implements Runnable {
+ final EventObject m_event;
+
+ public ExecutableHandler(EventObject event) {
+ m_event = event;
+ }
+
+ public void run() {
+ activeWorkers.add(Thread.currentThread());
+
+ try {
+ if (config.getHandler() == null) {
+ monitor.handlerMissing(DefaultStage.this);
+ } else {
+ config.getHandler().handleEvent(m_event);
+ }
+ } catch (Throwable t) {
+ monitor.handlerFailed(DefaultStage.this, m_event, t);
+ } finally {
+ activeWorkers.remove(Thread.currentThread());
+ }
+ }
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStageConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStageConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/DefaultStageConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,11 +14,11 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import org.apache.seda.thread.ThreadPool;
@@ -29,107 +29,91 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultStageConfig implements StageConfig
-{
+public class DefaultStageConfig implements StageConfig {
/** the name of this Stage */
private final String name;
+
/** this Stage's handler */
private StageHandler handler;
+
/** the enqueue predicates for this Stage */
private final List predicates;
+
/** the thread pool used for this Stages workers */
private final ThreadPool tp;
-
/**
* Creates a default stage configuration bean.
- *
+ *
* @param name the name of this Stage
- * @param handler this Stage's handler
+ * @param handler this Stage's handler
* @param predicates the enqueue predicates for this Stage
* @param tp the thread pool used for this Stages workers
*/
- public DefaultStageConfig( String name, StageHandler handler,
- List predicates, ThreadPool tp )
- {
+ public DefaultStageConfig(
+ String name, StageHandler handler,
+ List predicates, ThreadPool tp) {
this.tp = tp;
this.name = name;
this.handler = handler;
-
- if ( predicates == null )
- {
+
+ if (predicates == null) {
this.predicates = new ArrayList();
- }
- else
- {
+ } else {
this.predicates = predicates;
}
}
-
/**
* Creates a default stage configuration bean.
- *
+ *
* @param name the name of this Stage
* @param predicates the enqueue predicates for this Stage
* @param tp the thread pool used for this Stages workers
*/
- public DefaultStageConfig( String name, List predicates, ThreadPool tp )
- {
- this( name, null, predicates, tp );
+ public DefaultStageConfig(String name, List predicates, ThreadPool tp) {
+ this(name, null, predicates, tp);
}
-
/**
* Creates a default stage configuration bean.
- *
+ *
* @param name the name of this Stage
* @param tp the thread pool used for this Stage's workers
*/
- public DefaultStageConfig( String name, ThreadPool tp )
- {
- this( name, null, null, tp );
+ public DefaultStageConfig(String name, ThreadPool tp) {
+ this(name, null, null, tp);
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageConfig#getName()
*/
- public String getName()
- {
+ public String getName() {
return name;
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageConfig#getHandler()
*/
- public StageHandler getHandler()
- {
+ public StageHandler getHandler() {
return handler;
}
-
-
- public void setHandler( StageHandler handler )
- {
+
+ public void setHandler(StageHandler handler) {
this.handler = handler;
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageConfig#getPredicates()
*/
- public List getPredicates()
- {
+ public List getPredicates() {
return predicates;
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageConfig#getThreadPool()
*/
- public ThreadPool getThreadPool()
- {
+ public ThreadPool getThreadPool() {
return tp;
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/EnqueuePredicate.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/EnqueuePredicate.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/EnqueuePredicate.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
import java.util.EventObject;
@@ -26,13 +26,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface EnqueuePredicate
-{
+public interface EnqueuePredicate {
/**
* Determines whether or not an event gets enqueued onto a Stage queue.
- *
+ *
* @param event the event to enqueue
* @return true if an enqueue operation is allowed false if it is denied
*/
- public boolean accept( EventObject event );
+ public boolean accept(EventObject event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/LoggingStageMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/LoggingStageMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/LoggingStageMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
import java.util.EventObject;
@@ -24,286 +24,226 @@
/**
- * A do nothing adapter for a stage. For safty's sake this adapter reports
+ * A do nothing adapter for a stage. For safty's sake this adapter reports
* exceptions that occur on failure exception notifications to stderr. This
* is just for safty since we do not want to ignore these exceptions.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class LoggingStageMonitor implements StageMonitor
-{
+public class LoggingStageMonitor implements StageMonitor {
/** the commons-logging log to log to */
private final Log log;
-
-
+
/**
* Presumes the logged class is the DefaultStage.
*/
- public LoggingStageMonitor()
- {
- log = LogFactory.getLog( DefaultStage.class );
+ public LoggingStageMonitor() {
+ log = LogFactory.getLog(DefaultStage.class);
}
-
-
+
/**
* Logs a specific Stage implementing class.
- *
+ *
* @param clazz the class of the stage
* @throws IllegalArgumentException if clazz does not implement Stage
*/
- public LoggingStageMonitor( Class clazz )
- {
- log = LogFactory.getLog( clazz );
+ public LoggingStageMonitor(Class clazz) {
+ log = LogFactory.getLog(clazz);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#
* handlerMissing(org.apache.seda.seda.Stage)
*/
- public void handlerMissing( Stage stage )
- {
- if ( log.isErrorEnabled() )
- {
- log.error( "Stage " + stage.getConfig().getName()
- + " does not have a handler assigned" );
+ public void handlerMissing(Stage stage) {
+ if (log.isErrorEnabled()) {
+ log.error("Stage " + stage.getConfig().getName()
+ + " does not have a handler assigned");
}
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#started(org.apache.eve.seda.Stage)
*/
- public void started( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName() + " has started!" );
+ public void started(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName() + " has started!");
}
}
-
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopped(org.apache.eve.seda.Stage)
*/
- public void stopped( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName() + " has stopped!" );
+ public void stopped(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName() + " has stopped!");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#startedDriver(
* org.apache.seda.seda.Stage)
*/
- public void startedDriver( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName()
- + "'s driver started execution!" );
+ public void startedDriver(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName()
+ + "'s driver started execution!");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#enqueueOccurred(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void enqueueOccurred( Stage stage, EventObject event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName() + " had event "
- + getDesc( event ) + " enqueued!" );
+ public void enqueueOccurred(Stage stage, EventObject event) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName() + " had event "
+ + getDesc(event) + " enqueued!");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#enqueueRejected(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void enqueueRejected( Stage stage, EventObject event )
- {
- if ( log.isWarnEnabled() )
- {
- log.warn( stage.getConfig().getName() + " had event "
- + getDesc( event ) + " enqueue REJECTED!" );
+ public void enqueueRejected(Stage stage, EventObject event) {
+ if (log.isWarnEnabled()) {
+ log.warn(stage.getConfig().getName() + " had event "
+ + getDesc(event) + " enqueue REJECTED!");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#lockedQueue(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void lockedQueue( Stage stage, EventObject event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName()
- + "'s queue locked for processing " + getDesc( event ) );
+ public void lockedQueue(Stage stage, EventObject event) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName()
+ + "'s queue locked for processing " + getDesc(event));
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#lockedQueue(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void lockedQueue( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName()
- + "'s queue locked by awoken stage driver thread" );
+ public void lockedQueue(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName()
+ + "'s queue locked by awoken stage driver thread");
}
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#notified(org.apache.eve.seda.Stage)
*/
- public void notified( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName()
- + "'s driver thread notified out of waiting" );
+ public void notified(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName()
+ + "'s driver thread notified out of waiting");
}
}
-
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopping(org.apache.eve.seda.Stage)
*/
- public void stopping( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Graceful shutdown of stage "
- + stage.getConfig().getName() + " was requested" );
+ public void stopping(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug("Graceful shutdown of stage "
+ + stage.getConfig().getName() + " was requested");
}
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopping(org.apache.eve.seda.Stage,
* long)
*/
- public void stopping( Stage stage, long millis )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "Waiting " + millis + " for graceful shutdown of stage "
- + stage.getConfig().getName() );
+ public void stopping(Stage stage, long millis) {
+ if (log.isDebugEnabled()) {
+ log.debug("Waiting " + millis + " for graceful shutdown of stage "
+ + stage.getConfig().getName());
}
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#lockedQueue(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void waiting( Stage stage )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName()
- + "'s stage queue is empty, driver thread is waiting" );
+ public void waiting(Stage stage) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName()
+ + "'s stage queue is empty, driver thread is waiting");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#eventDequeued(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void eventDequeued( Stage stage, EventObject event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName() + " had event "
- + getDesc( event ) + " dequeued!" );
+ public void eventDequeued(Stage stage, EventObject event) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName() + " had event "
+ + getDesc(event) + " dequeued!");
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#eventHandled(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void eventHandled( Stage stage, EventObject event )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( stage.getConfig().getName() + " handled "
- + getDesc( event ) );
+ public void eventHandled(Stage stage, EventObject event) {
+ if (log.isDebugEnabled()) {
+ log.debug(stage.getConfig().getName() + " handled "
+ + getDesc(event));
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#driverFailed(
* org.apache.seda.seda.Stage, java.lang.InterruptedException)
*/
- public void driverFailed( Stage stage, InterruptedException fault )
- {
- if ( log.isErrorEnabled() )
- {
- log.error( stage.getConfig().getName()
- + "'s driver failed", fault );
+ public void driverFailed(Stage stage, InterruptedException fault) {
+ if (log.isErrorEnabled()) {
+ log.error(stage.getConfig().getName() + "'s driver failed", fault);
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#handlerFailed(
* org.apache.seda.seda.Stage, java.util.EventObject, java.lang.Throwable)
*/
- public void handlerFailed( Stage stage, EventObject event, Throwable fault
)
- {
- if ( log.isErrorEnabled() )
- {
- log.error( stage.getConfig().getName()
- + "'s handler failed", fault );
+ public void handlerFailed(Stage stage, EventObject event, Throwable fault)
{
+ if (log.isErrorEnabled()) {
+ log.error(
+ stage.getConfig().getName() + "'s handler failed",
fault);
}
}
-
/**
* Monitors enqueue predicate additions.
*
* @param stage the default stage the predicate is added to
* @param predicate the enqueue predicate added to the stage
*/
- public void predicateAdded( Stage stage, EnqueuePredicate predicate )
- {
- if ( log.isDebugEnabled() )
- {
- log.debug( "predicate added to stage "
- + stage.getConfig().getName() );
+ public void predicateAdded(Stage stage, EnqueuePredicate predicate) {
+ if (log.isDebugEnabled()) {
+ log.debug("predicate added to stage "
+ + stage.getConfig().getName());
}
}
-
/**
* Gets a short string description for an event.
*
* @param event the event to create a description string for
* @return the description string for the event
*/
- private String getDesc( EventObject event )
- {
- return getShortClassName( event.getClass().getName() );
+ private String getDesc(EventObject event) {
+ return getShortClassName(event.getClass().getName());
}
-
/**
* <p>Gets the class name minus the package name from a String.</p>
* Got this straight out of ClassUtils in commons-lang to remove deps.
@@ -313,29 +253,25 @@
* empty string
*/
public static String getShortClassName(String className) {
- if ( className == null )
- {
+ if (className == null) {
return "";
}
- if ( className.length() == 0 )
- {
+ if (className.length() == 0) {
return "";
}
char[] chars = className.toCharArray();
int lastDot = 0;
- for ( int i = 0; i < chars.length; i++ )
- {
- if ( chars[i] == '.' )
- {
+
+ for (int i = 0; i < chars.length; i++) {
+ if (chars[i] == '.') {
lastDot = i + 1;
- }
- else if ( chars[i] == '$' )
- {
+ } else if (chars[i] == '$') {
chars[i] = '.';
}
}
- return new String( chars, lastDot, chars.length - lastDot );
+
+ return new String(chars, lastDot, chars.length - lastDot);
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/Stage.java
==============================================================================
--- incubator/directory/seda/trunk/src/java/org/apache/seda/stage/Stage.java
(original)
+++ incubator/directory/seda/trunk/src/java/org/apache/seda/stage/Stage.java
Sat Oct 30 04:31:52 2004
@@ -14,13 +14,13 @@
* limitations under the License.
*
*/
+
package org.apache.seda.stage;
+import java.util.EventObject;
import org.apache.seda.stage.EnqueuePredicate;
-import java.util.EventObject;
-
/**
* Simple SEDA Stage interface.
@@ -28,28 +28,26 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface Stage
-{
+public interface Stage {
/**
* Gets the configuration for this Stage.
- *
- * @return this Stage's configuration bean
+ *
+ * @return this Stage's configuration bean
*/
StageConfig getConfig();
-
+
/**
* Enqueues an event onto this stage.
- *
+ *
* @param event the event to enqueue
*/
- void enqueue( EventObject event );
-
+ void enqueue(EventObject event);
+
/**
- * Adds an EnqueuePredicate to control what events can and cannot be
+ * Adds an EnqueuePredicate to control what events can and cannot be
* enqueued onto this Stage.
- *
+ *
* @param predicate the enqueue predecate to add
*/
- void addPredicate( EnqueuePredicate predicate );
+ void addPredicate(EnqueuePredicate predicate);
}
-
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageConfig.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageConfig.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageConfig.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
import java.util.List;
@@ -28,33 +28,32 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface StageConfig
-{
+public interface StageConfig {
/**
* Gets the name of the Stage.
- *
+ *
* @return the name of the stage
*/
String getName();
-
+
/**
- * Gets the Stage's handler.
- *
+ * Gets the Stage's handler.
+ *
* @return the Stage's handler
*/
StageHandler getHandler();
-
+
/**
- * Gets the set of enqueue predicates used by the Stage to throttle and
+ * Gets the set of enqueue predicates used by the Stage to throttle and
* control the enqueue operation.
- *
+ *
* @return the enqueue predicates used by the Stage
*/
List getPredicates();
-
+
/**
* Gets the Stage's thread pool.
- *
+ *
* @return the thread pool used by the Stage
*/
ThreadPool getThreadPool();
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageHandler.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageHandler.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageHandler.java
Sat Oct 30 04:31:52 2004
@@ -14,11 +14,11 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage ;
+package org.apache.seda.stage;
-import java.util.EventObject ;
-import java.util.EventListener ;
+import java.util.EventListener;
+import java.util.EventObject;
/**
@@ -27,12 +27,11 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface StageHandler extends EventListener
-{
+public interface StageHandler extends EventListener {
/**
* Handles an event for the Stage.
*
* @param event the event to process or handle.
*/
- void handleEvent( EventObject event ) ;
+ void handleEvent(EventObject event);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitor.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitor.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitor.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
import java.util.EventObject;
@@ -27,135 +27,134 @@
* Apache Directory Project</a>
* @version $Rev$
*/
-public interface StageMonitor
-{
+public interface StageMonitor {
/**
* Reports when the Stage is missing its handler.
- *
+ *
* @param stage the stage reporting a missing handler
*/
- void handlerMissing( Stage stage );
-
+ void handlerMissing(Stage stage);
+
/**
* A has been made to gracefully stop the Stage.
- *
+ *
* @param stage the Stage being stopped
*/
- void stopping( Stage stage );
-
+ void stopping(Stage stage);
+
/**
- * A has been made to gracefully stop the Stage but we're waiting for some
+ * A has been made to gracefully stop the Stage but we're waiting for some
* active workers to complete.
- *
+ *
* @param stage the Stage being stopped
* @param millis the time in milliseconds waiting for workers to complete
*/
- void stopping( Stage stage, long millis );
-
+ void stopping(Stage stage, long millis);
+
/**
- * The stage driver thread was notified out of the wait state due to an
+ * The stage driver thread was notified out of the wait state due to an
* enqueue operation or to the driver being requested to stop.
- *
- * @param stage the notified Stage
+ *
+ * @param stage the notified Stage
*/
- void notified( Stage stage );
-
+ void notified(Stage stage);
+
/**
- * Notification of stage driver thread going into wait state due to an
+ * Notification of stage driver thread going into wait state due to an
* empty queue.
- *
- * @param stage the waiting Stage
+ *
+ * @param stage the waiting Stage
*/
- void waiting( Stage stage );
-
+ void waiting(Stage stage);
+
/**
* Monitors Stage has starts.
- *
- * @param stage the started Stage
+ *
+ * @param stage the started Stage
*/
- void started( Stage stage );
+ void started(Stage stage);
/**
* Monitors Stage has stops.
- *
- * @param stage the stopped Stage
+ *
+ * @param stage the stopped Stage
*/
- void stopped( Stage stage );
-
+ void stopped(Stage stage);
+
/**
* Monitors StageDriver starts.
- *
+ *
* @param stage the Stage whose driver started
*/
- void startedDriver( Stage stage );
-
+ void startedDriver(Stage stage);
+
/**
* Monitor for successful enqueue operations on the stage.
- *
+ *
* @param stage the stage enqueued on
* @param event the event enqueued
*/
- void enqueueOccurred( Stage stage, EventObject event );
-
+ void enqueueOccurred(Stage stage, EventObject event);
+
/**
* Monitor for failed enqueue operations on the stage.
- *
+ *
* @param stage the stage where enqueue failed
* @param event the event enqueue failed on
*/
- void enqueueRejected( Stage stage, EventObject event );
-
+ void enqueueRejected(Stage stage, EventObject event);
+
/**
* Queue lock acquired to enqueue an event.
- *
+ *
* @param stage the Stage whose queue lock was acquired
* @param event the event to be enqueued
*/
- void lockedQueue( Stage stage, EventObject event );
-
+ void lockedQueue(Stage stage, EventObject event);
+
/**
* Queue lock acquired by awoken Stage driver thread.
- *
+ *
* @param stage the Stage whose queue lock was acquired
*/
- void lockedQueue( Stage stage );
-
+ void lockedQueue(Stage stage);
+
/**
* Monitor for dequeue operations.
- *
+ *
* @param stage the Stage dequeued
* @param event the event that was dequeued
*/
- void eventDequeued( Stage stage, EventObject event );
-
+ void eventDequeued(Stage stage, EventObject event);
+
/**
* Monitor for successfully completing the handling of an event.
- *
- * @param stage the Stage processing the event
+ *
+ * @param stage the Stage processing the event
* @param event the event that was handled
*/
- void eventHandled( Stage stage, EventObject event );
-
+ void eventHandled(Stage stage, EventObject event);
+
// ------------------------------------------------------------------------
// failure monitors
// ------------------------------------------------------------------------
/**
* Monitors driver thread interruption failures.
- *
+ *
* @param stage the stage that caused the failure
* @param fault the faulting exception
*/
- void driverFailed( Stage stage, InterruptedException fault );
-
+ void driverFailed(Stage stage, InterruptedException fault);
+
/**
* Monitors handler failures.
- *
+ *
* @param stage the stage that caused the failure
* @param event the event the handler failed on
* @param fault the faulting exception
*/
- void handlerFailed( Stage stage, EventObject event, Throwable fault );
+ void handlerFailed(Stage stage, EventObject event, Throwable fault);
/**
* Monitors enqueue predicate additions.
@@ -163,6 +162,5 @@
* @param stage the default stage the predicate is added to
* @param predicate the enqueue predicate added to the stage
*/
- void predicateAdded( Stage stage,
- EnqueuePredicate predicate );
+ void predicateAdded(Stage stage, EnqueuePredicate predicate);
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitorAdapter.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/stage/StageMonitorAdapter.java
Sat Oct 30 04:31:52 2004
@@ -14,14 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.stage;
+package org.apache.seda.stage;
import java.util.EventObject;
/**
- * A do nothing adapter for a stage. For safty's sake this adapter reports
+ * A do nothing adapter for a stage. For safty's sake this adapter reports
* exceptions that occur on failure exception notifications to stderr. This
* is just for safty since we do not want to ignore these exceptions.
*
@@ -29,162 +29,126 @@
* Apache Directory Project</a>
* @version $Rev$
*/
-public class StageMonitorAdapter implements StageMonitor
-{
+public class StageMonitorAdapter implements StageMonitor {
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#handlerMissing(
* org.apache.seda.seda.Stage)
*/
- public void handlerMissing( Stage stage )
- {
+ public void handlerMissing(Stage stage) {
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopping(org.apache.eve.seda.Stage)
*/
- public void stopping( Stage stage )
- {
+ public void stopping(Stage stage) {
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopping(org.apache.eve.seda.Stage,
* long)
*/
- public void stopping( Stage stage, long millis )
- {
+ public void stopping(Stage stage, long millis) {
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#notified(org.apache.eve.seda.Stage)
*/
- public void notified( Stage stage )
- {
+ public void notified(Stage stage) {
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#waiting( Stage )
*/
- public void waiting( Stage stage )
- {
+ public void waiting(Stage stage) {
}
-
-
+
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#started(org.apache.eve.seda.Stage)
*/
- public void started( Stage stage )
- {
+ public void started(Stage stage) {
}
-
/* (non-Javadoc)
* @see
org.apache.seda.seda.StageMonitor#stopped(org.apache.eve.seda.Stage)
*/
- public void stopped( Stage stage )
- {
+ public void stopped(Stage stage) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#startedDriver(
* org.apache.seda.seda.Stage)
*/
- public void startedDriver( Stage stage )
- {
+ public void startedDriver(Stage stage) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#enqueueOccurred(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void enqueueOccurred( Stage stage, EventObject event )
- {
+ public void enqueueOccurred(Stage stage, EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#enqueueRejected(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void enqueueRejected( Stage stage, EventObject event )
- {
+ public void enqueueRejected(Stage stage, EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#lockedQueue(
* org.apache.seda.seda.Stage)
*/
- public void lockedQueue( Stage stage )
- {
+ public void lockedQueue(Stage stage) {
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#lockedQueue(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void lockedQueue( Stage stage, EventObject event )
- {
+ public void lockedQueue(Stage stage, EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#eventDequeued(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void eventDequeued( Stage stage, EventObject event )
- {
+ public void eventDequeued(Stage stage, EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#eventHandled(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void eventHandled( Stage stage, EventObject event )
- {
+ public void eventHandled(Stage stage, EventObject event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#driverFailed(
* org.apache.seda.seda.Stage, java.lang.InterruptedException)
*/
- public void driverFailed( Stage stage, InterruptedException fault )
- {
- if ( fault != null )
- {
+ public void driverFailed(Stage stage, InterruptedException fault) {
+ if (fault != null) {
fault.printStackTrace();
}
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#handlerFailed(
* org.apache.seda.seda.Stage, java.util.EventObject, java.lang.Throwable)
*/
- public void handlerFailed( Stage stage, EventObject event, Throwable fault
)
- {
- if ( fault != null )
- {
+ public void handlerFailed(Stage stage, EventObject event, Throwable fault)
{
+ if (fault != null) {
fault.printStackTrace();
}
}
-
/**
* Monitors enqueue predicate additions.
*
* @param stage the default stage the predicate is added to
* @param predicate the enqueue predicate added to the stage
*/
- public void predicateAdded( Stage stage, EnqueuePredicate predicate )
- {
+ public void predicateAdded(Stage stage, EnqueuePredicate predicate) {
}
}
Modified:
incubator/directory/seda/trunk/src/java/org/apache/seda/thread/ThreadPool.java
==============================================================================
---
incubator/directory/seda/trunk/src/java/org/apache/seda/thread/ThreadPool.java
(original)
+++
incubator/directory/seda/trunk/src/java/org/apache/seda/thread/ThreadPool.java
Sat Oct 30 04:31:52 2004
@@ -14,6 +14,7 @@
* limitations under the License.
*
*/
+
package org.apache.seda.thread;
@@ -23,13 +24,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public interface ThreadPool
-{
+public interface ThreadPool {
/**
- * Allocates Thread from pool to execute a runnable and releases it on
+ * Allocates Thread from pool to execute a runnable and releases it on
* completion.
- *
+ *
* @param runnable the runnable to execute
*/
- void execute( Runnable runnable );
+ void execute(Runnable runnable);
}
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
Sat Oct 30 04:31:52 2004
@@ -14,10 +14,13 @@
* limitations under the License.
*
*/
+
package org.apache.seda;
+import java.io.IOException;
+
+import java.net.InetAddress;
-import junit.framework.TestCase;
import org.apache.commons.net.EchoTCPClient;
import org.apache.seda.examples.EchoProtocolProvider;
import org.apache.seda.listener.AvailablePortFinder;
@@ -26,8 +29,7 @@
import org.apache.seda.protocol.DefaultInetServicesDatabase;
import org.apache.seda.protocol.InetServiceEntry;
-import java.io.IOException;
-import java.net.InetAddress;
+import junit.framework.TestCase;
/**
@@ -36,91 +38,84 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultFrontendFactoryTest extends TestCase
-{
+public class DefaultFrontendFactoryTest extends TestCase {
/** the frontend used to test the protocol */
protected DefaultFrontend fe = null;
-
/**
* Stops the created frontend.
*
* @throws Exception due to super call and stop method
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
fe.stop();
fe = null;
}
-
/**
* Instantiates the factory then gets a handle on the Frontend.
*
* @throws Exception due to super call and create()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
- fe = ( DefaultFrontend ) new DefaultFrontendFactory().create();
+ fe = (DefaultFrontend) new DefaultFrontendFactory().create();
}
-
/**
* Tests to make sure setup of the apparatus works.
*/
- public void testSetup()
- {
- assertNotNull( fe );
- assertNotNull( fe.getBufferPool() );
- assertNotNull( fe.getDecoderManager() );
- assertNotNull( fe.getEncoderManager() );
- assertNotNull( fe.getEventRouter() );
- assertNotNull( fe.getInetServicesDatabase() );
- assertNotNull( fe.getInputManager() );
- assertNotNull( fe.getListenerManager() );
- assertNotNull( fe.getOutputManager() );
- assertNotNull( fe.getRequestProcessor() );
+ public void testSetup() {
+ assertNotNull(fe);
+ assertNotNull(fe.getBufferPool());
+ assertNotNull(fe.getDecoderManager());
+ assertNotNull(fe.getEncoderManager());
+ assertNotNull(fe.getEventRouter());
+ assertNotNull(fe.getInetServicesDatabase());
+ assertNotNull(fe.getInputManager());
+ assertNotNull(fe.getListenerManager());
+ assertNotNull(fe.getOutputManager());
+ assertNotNull(fe.getRequestProcessor());
}
-
/**
* Tests to make sure the bind operation works.
*
* @throws IOException
*/
- public void testBind() throws IOException
- {
+ public void testBind() throws IOException {
int port = AvailablePortFinder.getNextAvailable();
ListenerConfig config = null;
- config = new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry( "ldap", port ) );
- fe.getListenerManager().bind( config );
- fe.getListenerManager().unbind( config );
+ config =
+ new TCPListenerConfig(
+ InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port));
+ fe.getListenerManager().bind(config);
+ fe.getListenerManager().unbind(config);
}
+ public void testEcho() throws IOException {
+ InetServiceEntry srvEntry =
+ new InetServiceEntry(
+ "echo",
+ AvailablePortFinder.getNextAvailable(6666));
+ ((DefaultInetServicesDatabase)
fe.getInetServicesDatabase()).addEntry(srvEntry);
- public void testEcho() throws IOException
- {
- InetServiceEntry srvEntry = new InetServiceEntry( "echo",
- AvailablePortFinder.getNextAvailable( 6666 ) );
- ( ( DefaultInetServicesDatabase ) fe.getInetServicesDatabase() )
- .addEntry( srvEntry );
ListenerConfig config = null;
- config = new TCPListenerConfig( InetAddress.getLocalHost(), srvEntry );
- fe.getListenerManager().bind( config );
- fe.register( new EchoProtocolProvider() );
+ config = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry);
+ fe.getListenerManager().bind(config);
+ fe.register(new EchoProtocolProvider());
EchoTCPClient client = new EchoTCPClient();
- client.connect( InetAddress.getLocalHost(), srvEntry.getPort() );
+ client.connect(InetAddress.getLocalHost(), srvEntry.getPort());
+
byte[] toSend = "Hello world!".getBytes();
byte[] recieved = new byte[toSend.length];
- client.getOutputStream().write( toSend );
- client.getInputStream().read( recieved );
+ client.getOutputStream().write(toSend);
+ client.getInputStream().read(recieved);
client.disconnect();
- assertEquals( new String( toSend ), new String( recieved ) );
- fe.getListenerManager().unbind( config );
+ assertEquals(new String(toSend), new String(recieved));
+ fe.getListenerManager().unbind(config);
}
}
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
Sat Oct 30 04:31:52 2004
@@ -14,12 +14,11 @@
* limitations under the License.
*
*/
+
package org.apache.seda;
import java.net.InetAddress;
-import junit.framework.TestCase;
-
import org.apache.seda.listener.AvailablePortFinder;
import org.apache.seda.listener.ListenerConfig;
import org.apache.seda.listener.TCPListenerConfig;
@@ -27,6 +26,8 @@
import org.apache.seda.protocol.InetServiceEntry;
import org.apache.seda.protocol.ProtocolProvider;
+import junit.framework.TestCase;
+
/**
* A test harness using the standalone default frontend hardwired using the
@@ -35,51 +36,48 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class ProtocolTestCase extends TestCase
-{
+public class ProtocolTestCase extends TestCase {
/** the frontend used to test the protocol */
protected DefaultFrontend fe = null;
+
/** the protocol provider tested */
protected ProtocolProvider proto = null;
+
/** the listener configuration for the protocol */
protected ListenerConfig config = null;
-
- public ProtocolTestCase( ProtocolProvider proto )
- {
+ public ProtocolTestCase(ProtocolProvider proto) {
this.proto = proto;
}
-
/**
* Stops the created frontend.
*
* @throws Exception due to super call and stop method
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
- fe.getListenerManager().unbind( config );
+ fe.getListenerManager().unbind(config);
fe.stop();
fe = null;
}
-
/**
* Instantiates the factory then gets a handle on the Frontend.
*
* @throws Exception due to super call and create()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
- fe = ( DefaultFrontend ) new DefaultFrontendFactory().create();
- InetServiceEntry srvEntry = new InetServiceEntry( proto.getName(),
- AvailablePortFinder.getNextAvailable( 6666 ) );
- ( ( DefaultInetServicesDatabase ) fe.getInetServicesDatabase() )
- .addEntry( srvEntry );
- config = new TCPListenerConfig( InetAddress.getLocalHost(), srvEntry );
- fe.getListenerManager().bind( config );
- fe.register( proto );
+ fe = (DefaultFrontend) new DefaultFrontendFactory().create();
+
+ InetServiceEntry srvEntry =
+ new InetServiceEntry(
+ proto.getName(),
+ AvailablePortFinder.getNextAvailable(6666));
+ ((DefaultInetServicesDatabase)
fe.getInetServicesDatabase()).addEntry(srvEntry);
+ config = new TCPListenerConfig(InetAddress.getLocalHost(), srvEntry);
+ fe.getListenerManager().bind(config);
+ fe.register(proto);
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.buffer;
+package org.apache.seda.buffer;
import java.nio.ByteBuffer;
@@ -30,208 +30,159 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultBufferPoolTest extends TestCase
-{
-
- public static void main( String[] args )
- {
- junit.textui.TestRunner.run( DefaultBufferPoolTest.class );
- }
+public class DefaultBufferPoolTest extends TestCase {
+ DefaultBufferPool m_bp = null;
-
/**
* Constructor for DefaultBufferPoolTest.
* @param arg0
*/
- public DefaultBufferPoolTest( String arg0 )
- {
- super( arg0 );
+ public DefaultBufferPoolTest(String arg0) {
+ super(arg0);
}
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(DefaultBufferPoolTest.class);
+ }
- DefaultBufferPool m_bp = null;
-
-
-
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
- public void setUp() throws Exception
- {
+ public void setUp() throws Exception {
super.setUp();
- DefaultBufferPoolConfig l_config = new DefaultBufferPoolConfig(
- "default", 4, 10, 2, 4096 );
- m_bp = new DefaultBufferPool( l_config );
- m_bp.setMonitor( new LoggingBufferMonitor() );
+
+ DefaultBufferPoolConfig l_config =
+ new DefaultBufferPoolConfig("default", 4, 10, 2, 4096);
+ m_bp = new DefaultBufferPool(l_config);
+ m_bp.setMonitor(new LoggingBufferMonitor());
}
-
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
- public void tearDown() throws Exception
- {
+ public void tearDown() throws Exception {
m_bp = null;
super.tearDown();
}
-
-
- public void testGetConfig() throws Exception
- {
+
+ public void testGetConfig() throws Exception {
BufferPoolConfig l_config = m_bp.getConfig();
- assertNotNull( "Configuration was null", l_config );
+ assertNotNull("Configuration was null", l_config);
}
-
- public void testGetBuffer() throws Exception
- {
+ public void testGetBuffer() throws Exception {
final int l_max = m_bp.getConfig().getMaximumSize();
- ByteBuffer[] l_buffers = new ByteBuffer[ l_max ];
-
- for ( int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++ )
- {
- l_buffers[ii] = m_bp.getBuffer( this );
- assertNotNull( "Got null ByteBuffer", l_buffers[ii] );
+ ByteBuffer[] l_buffers = new ByteBuffer[l_max];
+
+ for (int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++) {
+ l_buffers[ii] = m_bp.getBuffer(this);
+ assertNotNull("Got null ByteBuffer", l_buffers[ii]);
}
-
+
ByteBuffer l_buf = null;
- try
- {
- l_buf = m_bp.getBuffer( this );
- }
- catch( ResourceException e )
- {
- assertNull( l_buf );
- assertNotNull( e );
+
+ try {
+ l_buf = m_bp.getBuffer(this);
+ } catch (ResourceException e) {
+ assertNull(l_buf);
+ assertNotNull(e);
}
}
-
- public void testGetFreeCount() throws Exception
- {
+ public void testGetFreeCount() throws Exception {
final int l_max = m_bp.getConfig().getMaximumSize();
- ByteBuffer[] l_buffers = new ByteBuffer[ l_max ];
-
- for ( int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++ )
- {
- l_buffers[ii] = m_bp.getBuffer( this );
- assertNotNull( "Got null ByteBuffer", l_buffers[ii] );
- assertEquals( "Free count was off", m_bp.size() - ii - 1,
- m_bp.getFreeCount() );
+ ByteBuffer[] l_buffers = new ByteBuffer[l_max];
+
+ for (int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++) {
+ l_buffers[ii] = m_bp.getBuffer(this);
+ assertNotNull("Got null ByteBuffer", l_buffers[ii]);
+ assertEquals(
+ "Free count was off", m_bp.size() - ii - 1,
+ m_bp.getFreeCount());
}
-
+
ByteBuffer l_buf = null;
- try
- {
- l_buf = m_bp.getBuffer( this );
- }
- catch( ResourceException e )
- {
- assertNull( l_buf );
- assertNotNull( e );
+
+ try {
+ l_buf = m_bp.getBuffer(this);
+ } catch (ResourceException e) {
+ assertNull(l_buf);
+ assertNotNull(e);
}
}
-
- public void testGetInUseCount() throws Exception
- {
+ public void testGetInUseCount() throws Exception {
final int l_max = m_bp.getConfig().getMaximumSize();
- ByteBuffer[] l_buffers = new ByteBuffer[ l_max ];
-
- for ( int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++ )
- {
- l_buffers[ii] = m_bp.getBuffer( this );
- assertNotNull( "Got null ByteBuffer", l_buffers[ii] );
- assertEquals( "In use count was off", ii+1,
- m_bp.getInUseCount() );
+ ByteBuffer[] l_buffers = new ByteBuffer[l_max];
+
+ for (int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++) {
+ l_buffers[ii] = m_bp.getBuffer(this);
+ assertNotNull("Got null ByteBuffer", l_buffers[ii]);
+ assertEquals("In use count was off", ii + 1, m_bp.getInUseCount());
}
-
+
ByteBuffer l_buf = null;
- try
- {
- l_buf = m_bp.getBuffer( this );
- }
- catch( ResourceException e )
- {
- assertNull( l_buf );
- assertNotNull( e );
+
+ try {
+ l_buf = m_bp.getBuffer(this);
+ } catch (ResourceException e) {
+ assertNull(l_buf);
+ assertNotNull(e);
}
}
-
-
- public void testGetInterestedCount()
- throws Exception
- {
+
+ public void testGetInterestedCount() throws Exception {
final int l_max = m_bp.getConfig().getMaximumSize();
- ByteBuffer[] l_buffers = new ByteBuffer[ l_max ];
-
- for ( int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++ )
- {
- l_buffers[ii] = m_bp.getBuffer( this );
- assertNotNull( "Got null ByteBuffer", l_buffers[ii] );
- assertEquals( "In use count was off", ii+1,
- m_bp.getInUseCount() );
- assertEquals( "Interest count was off",
- 1, m_bp.getInterestedCount( l_buffers[ii] ) );
+ ByteBuffer[] l_buffers = new ByteBuffer[l_max];
+
+ for (int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++) {
+ l_buffers[ii] = m_bp.getBuffer(this);
+ assertNotNull("Got null ByteBuffer", l_buffers[ii]);
+ assertEquals("In use count was off", ii + 1, m_bp.getInUseCount());
+ assertEquals(
+ "Interest count was off", 1,
+ m_bp.getInterestedCount(l_buffers[ii]));
}
-
+
ByteBuffer l_buf = null;
- try
- {
- l_buf = m_bp.getBuffer( this );
- }
- catch( ResourceException e )
- {
- assertNull( l_buf );
- assertNotNull( e );
+
+ try {
+ l_buf = m_bp.getBuffer(this);
+ } catch (ResourceException e) {
+ assertNull(l_buf);
+ assertNotNull(e);
}
}
-
- public void testReleaseClaim()
- throws Exception
- {
+ public void testReleaseClaim() throws Exception {
}
-
- public void testSize()
- throws Exception
- {
+ public void testSize() throws Exception {
final int l_max = m_bp.getConfig().getMaximumSize();
- ByteBuffer[] l_buffers = new ByteBuffer[ l_max ];
-
- for ( int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++ )
- {
- l_buffers[ii] = m_bp.getBuffer( this );
- assertNotNull( "Got null ByteBuffer", l_buffers[ii] );
-
- if ( ii < 2 )
- {
- assertEquals( "size was off", 2, m_bp.size() );
- }
- else if ( ii >= 2 && ii < 6 )
- {
- assertEquals( "size was off", 6, m_bp.size() );
- }
- else if ( ii >= 6 && ii < 10 )
- {
- assertEquals( "size was off", 10, m_bp.size() );
- }
- else
- {
- throw new IllegalStateException( "should never get here!" );
+ ByteBuffer[] l_buffers = new ByteBuffer[l_max];
+
+ for (int ii = 0; ii < m_bp.getConfig().getMaximumSize(); ii++) {
+ l_buffers[ii] = m_bp.getBuffer(this);
+ assertNotNull("Got null ByteBuffer", l_buffers[ii]);
+
+ if (ii < 2) {
+ assertEquals("size was off", 2, m_bp.size());
+ } else if ((ii >= 2) && (ii < 6)) {
+ assertEquals("size was off", 6, m_bp.size());
+ } else if ((ii >= 6) && (ii < 10)) {
+ assertEquals("size was off", 10, m_bp.size());
+ } else {
+ throw new IllegalStateException("should never get here!");
}
}
-
+
ByteBuffer l_buf = null;
- try
- {
- l_buf = m_bp.getBuffer( this );
- }
- catch( ResourceException e )
- {
- assertNull( l_buf );
- assertNotNull( e );
+
+ try {
+ l_buf = m_bp.getBuffer(this);
+ } catch (ResourceException e) {
+ assertNull(l_buf);
+ assertNotNull(e);
}
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
Sat Oct 30 04:31:52 2004
@@ -14,8 +14,8 @@
* limitations under the License.
*
*/
-package org.apache.seda.decoder;
+package org.apache.seda.decoder;
import java.util.EventObject;
import java.util.Iterator;
@@ -25,15 +25,14 @@
import org.apache.seda.buffer.DefaultBufferPool;
import org.apache.seda.buffer.DefaultBufferPoolConfig;
import org.apache.seda.event.AbstractSubscriber;
-import org.apache.seda.event.EventRouter;
import org.apache.seda.event.DefaultEventRouter;
+import org.apache.seda.event.EventRouter;
import org.apache.seda.event.RequestEvent;
import org.apache.seda.event.RequestSubscriber;
-
-import org.apache.seda.thread.ThreadPool;
-import org.apache.seda.stage.DefaultStageConfig;
-import org.apache.seda.protocol.InetServicesDatabase;
import org.apache.seda.protocol.InetServiceEntry;
+import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.stage.DefaultStageConfig;
+import org.apache.seda.thread.ThreadPool;
import junit.framework.TestCase;
@@ -44,9 +43,8 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultDecoderManagerTest extends TestCase implements
- RequestSubscriber
-{
+public class DefaultDecoderManagerTest extends TestCase
+ implements RequestSubscriber {
private ThreadPool tpool = null;
private EventRouter router = null;
private BufferPoolConfig bpConfig = null;
@@ -55,77 +53,76 @@
private DefaultDecoderManager decodeMan = null;
private RequestEvent event = null;
+ /**
+ * Constructor for DefaultDecoderManagerTest.
+ * @param arg0
+ */
+ public DefaultDecoderManagerTest(String arg0) {
+ super(arg0);
+ }
- public static void main( String[] args )
- {
- junit.textui.TestRunner.run( DefaultDecoderManagerTest.class );
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(DefaultDecoderManagerTest.class);
}
-
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
-
- bpConfig = new DefaultBufferPoolConfig( "default", 10, 100, 10, 1024 );
- bp = new DefaultBufferPool( bpConfig );
+
+ bpConfig = new DefaultBufferPoolConfig("default", 10, 100, 10, 1024);
+ bp = new DefaultBufferPool(bpConfig);
router = new DefaultEventRouter();
- router.subscribe( RequestEvent.class, this );
- tpool = new ThreadPool()
- {
- /* (non-Javadoc)
- * @see
org.apache.seda.thread.ThreadPool#execute(java.lang.Runnable)
- */
- public void execute( Runnable runnable )
- {
- // fake it out
- runnable.run();
- }
- };
-
- config = new DefaultStageConfig( "default", tpool );
- decodeMan = new DefaultDecoderManager( router, config,
- new InetServicesDatabase()
- {
- public Iterator getByName( String name )
- {
- return null;
- }
-
- public Iterator getByPort( int port )
- {
- return null;
- }
-
- public String getProtoByPort( int port )
- {
- return null;
- }
-
- public InetServiceEntry getByName( String name, String proto )
- {
- return null;
- }
-
- public InetServiceEntry getByPort( String port, String proto )
- {
- return null;
- }
- });
- config.setHandler( new DecodeStageHandler( decodeMan ) );
+ router.subscribe(RequestEvent.class, this);
+ tpool =
+ new ThreadPool() {
+ /* (non-Javadoc)
+ * @see
org.apache.seda.thread.ThreadPool#execute(java.lang.Runnable)
+ */
+ public void execute(Runnable runnable) {
+ // fake it out
+ runnable.run();
+ }
+ };
+
+ config = new DefaultStageConfig("default", tpool);
+ decodeMan =
+ new DefaultDecoderManager(
+ router, config,
+ new InetServicesDatabase() {
+ public Iterator getByName(String name) {
+ return null;
+ }
+
+ public Iterator getByPort(int port) {
+ return null;
+ }
+
+ public String getProtoByPort(int port) {
+ return null;
+ }
+
+ public InetServiceEntry getByName(
+ String name, String
proto) {
+ return null;
+ }
+
+ public InetServiceEntry getByPort(
+ String port, String
proto) {
+ return null;
+ }
+ });
+ config.setHandler(new DecodeStageHandler(decodeMan));
decodeMan.start();
}
-
/*
* @see TestCase#tearDown()
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
-
+
tpool = null;
router = null;
bpConfig = null;
@@ -136,120 +133,76 @@
event = null;
}
-
- /**
- * Constructor for DefaultDecoderManagerTest.
- * @param arg0
- */
- public DefaultDecoderManagerTest(String arg0)
- {
- super( arg0 );
- }
-
-
- public void inform( RequestEvent event )
- {
- System.out.println( "\n\nRequestEvent Set!!!\n\n" );
+ public void inform(RequestEvent event) {
+ System.out.println("\n\nRequestEvent Set!!!\n\n");
this.event = event;
}
-
-
/* (non-Javadoc)
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- try
- {
- AbstractSubscriber.inform( this, event );
- }
- catch ( Exception e )
- {
- fail( "we should be able to inform just fine" );
+ public void inform(EventObject event) {
+ try {
+ AbstractSubscriber.inform(this, event);
+ } catch (Exception e) {
+ fail("we should be able to inform just fine");
}
}
-
/*
* Class to test for void inform(EventObject)
*/
- public void testInformEventObject()
- {
+ public void testInformEventObject() {
}
-
/*
* Class to test for void inform(InputEvent)
*/
- public void testInformInputEvent()
- {
+ public void testInformInputEvent() {
}
-
/*
* Class to test for void inform(DisconnectEvent)
*/
- public void testInformDisconnectEvent()
- {
+ public void testInformDisconnectEvent() {
}
-
/*
* Class to test for void inform(ConnectEvent)
*/
- public void testInformConnectEvent()
- {
+ public void testInformConnectEvent() {
}
-
- public void testDecodeOccurred()
- {
+ public void testDecodeOccurred() {
}
-
- public void testSetCallback()
- {
+ public void testSetCallback() {
}
-
- public void testSetDecoderMonitor()
- {
+ public void testSetDecoderMonitor() {
}
-
- public void testDisable()
- {
+ public void testDisable() {
}
-
/*
* Class to test for void decode(ClientKey, ByteBuffer)
*/
- public void testDecodeClientKeyByteBuffer()
- {
+ public void testDecodeClientKeyByteBuffer() {
}
-
/*
* Class to test for Object decode(ByteBuffer)
*/
- public void testDecodeByteBuffer()
- {
+ public void testDecodeByteBuffer() {
}
-
- public void testGetMonitor()
- {
+ public void testGetMonitor() {
}
-
- public void testSetMonitor()
- {
+ public void testSetMonitor() {
}
-
- public void testGetDecoder()
- {
+ public void testGetDecoder() {
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/event/AbstractSubscriberTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/event/AbstractSubscriberTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/event/AbstractSubscriberTest.java
Sat Oct 30 04:31:52 2004
@@ -14,10 +14,11 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.nio.ByteBuffer;
+
import java.util.EventObject;
import org.apache.seda.listener.ClientKey;
@@ -31,106 +32,84 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class AbstractSubscriberTest extends TestCase
-{
+public class AbstractSubscriberTest extends TestCase {
TestSubscriber subscriber = null;
-
+
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
subscriber = new TestSubscriber();
}
-
/*
* @see TestCase#tearDown()
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
subscriber = null;
}
-
/*
* Class to test for void AbstractSubscriber()
*/
- public void testAbstractSubscriber()
- {
+ public void testAbstractSubscriber() {
}
-
/*
* Class to test for void AbstractSubscriber(SubscriberMonitor)
*/
- public void testAbstractSubscriberSubscriberMonitor()
- {
+ public void testAbstractSubscriberSubscriberMonitor() {
}
-
/*
* Class to test for void inform(EventObject)
*/
- public void testInformEventObject()
- {
- EventObject e = new EventSubclass( null, null );
- subscriber.inform( e );
+ public void testInformEventObject() {
+ EventObject e = new EventSubclass(null, null);
+ subscriber.inform(e);
subscriber.assertDelivery();
- subscriber.inform( e );
+ subscriber.inform(e);
subscriber.assertDelivery();
}
-
/*
* Class to test for void inform(Subscriber, EventObject,
SubscriberMonitor)
*/
- public void testInformSubscriberEventObjectSubscriberMonitor()
- {
+ public void testInformSubscriberEventObjectSubscriberMonitor() {
}
-
- class EventSubclass extends InputEvent
- {
- public EventSubclass( ClientKey key, ByteBuffer buf )
- {
- super( AbstractSubscriberTest.this, key, buf );
+ class EventSubclass extends InputEvent {
+ public EventSubclass(ClientKey key, ByteBuffer buf) {
+ super(AbstractSubscriberTest.this, key, buf);
}
-
+
/* (non-Javadoc)
* @see
org.apache.seda.event.InputEvent#claimInterest(java.lang.Object)
*/
- public ByteBuffer claimInterest( Object party )
- {
+ public ByteBuffer claimInterest(Object party) {
return null;
}
/* (non-Javadoc)
* @see
org.apache.seda.event.InputEvent#releaseInterest(java.lang.Object)
*/
- public void releaseInterest( Object party )
- {
+ public void releaseInterest(Object party) {
}
- };
-
+ }
- class TestSubscriber extends AbstractSubscriber
- {
+ class TestSubscriber extends AbstractSubscriber {
InputEvent e = null;
-
- public void assertDelivery()
- {
- assertNotNull( e );
+
+ public void assertDelivery() {
+ assertNotNull(e);
e = null;
}
-
- public void inform( InputEvent event )
- {
- assertNotNull( event );
+
+ public void inform(InputEvent event) {
+ assertNotNull(event);
e = event;
}
- };
-
+ }
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/event/DefaultStageTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/event/DefaultStageTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/event/DefaultStageTest.java
Sat Oct 30 04:31:52 2004
@@ -14,14 +14,14 @@
* limitations under the License.
*
*/
-package org.apache.seda.event;
+package org.apache.seda.event;
import java.util.ArrayList;
import java.util.EventObject;
-import org.apache.seda.thread.ThreadPool;
import org.apache.seda.stage.*;
+import org.apache.seda.thread.ThreadPool;
import junit.framework.TestCase;
@@ -32,23 +32,20 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultStageTest extends TestCase
-{
+public class DefaultStageTest extends TestCase {
DefaultStage stage = null;
ThreadPool pool = null;
DefaultStageConfig config = null;
StageHandler handler = null;
ArrayList events = null;
-
-
+
/* (non-Javadoc)
* @see junit.framework.TestCase#tearDown()
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
// @todo Auto-generated method stub
super.tearDown();
-
+
events = null;
handler = null;
config = null;
@@ -56,90 +53,70 @@
stage.stop();
stage = null;
}
-
-
+
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
-
- pool = new ThreadPool()
- {
- /* (non-Javadoc)
- * @see
org.apache.seda.thread.ThreadPool#execute(java.lang.Runnable)
- */
- public void execute( Runnable runnable )
- {
- runnable.run();
- }
- };
-
+
+ pool =
+ new ThreadPool() {
+ /* (non-Javadoc)
+ * @see
org.apache.seda.thread.ThreadPool#execute(java.lang.Runnable)
+ */
+ public void execute(Runnable runnable) {
+ runnable.run();
+ }
+ };
+
events = new ArrayList();
-
- handler = new StageHandler()
- {
- public void handleEvent( EventObject event )
- {
- events.add( event );
- }
- };
-
- config = new DefaultStageConfig( "test", pool );
- config.setHandler( handler );
- stage = new DefaultStage( config );
- stage.setMonitor( new LoggingStageMonitor(stage.getClass()) );
+
+ handler =
+ new StageHandler() {
+ public void handleEvent(EventObject event) {
+ events.add(event);
+ }
+ };
+
+ config = new DefaultStageConfig("test", pool);
+ config.setHandler(handler);
+ stage = new DefaultStage(config);
+ stage.setMonitor(new LoggingStageMonitor(stage.getClass()));
stage.start();
}
+ public void testAddPredicateAccept() throws Exception {
+ stage.addPredicate(new EnqueuePredicate() {
+ public boolean accept(EventObject event) {
+ return true;
+ }
+ });
- public void testAddPredicateAccept() throws Exception
- {
- stage.addPredicate( new EnqueuePredicate()
- {
- public boolean accept( EventObject event )
- {
- return true;
- }
- } );
-
- stage.enqueue( new EventObject( this ) );
+ stage.enqueue(new EventObject(this));
stage.stop();
- assertEquals( 1, events.size() );
+ assertEquals(1, events.size());
}
-
- public void testAddPredicateDeny() throws Exception
- {
- stage.addPredicate( new EnqueuePredicate()
- {
- public boolean accept( EventObject event )
- {
- return false;
- }
- } );
-
- stage.enqueue( new EventObject( this ) );
+ public void testAddPredicateDeny() throws Exception {
+ stage.addPredicate(new EnqueuePredicate() {
+ public boolean accept(EventObject event) {
+ return false;
+ }
+ });
+
+ stage.enqueue(new EventObject(this));
stage.stop();
- assertEquals( 0, events.size() );
+ assertEquals(0, events.size());
}
-
- public void testGetConfig()
- {
- assertEquals( config, stage.getConfig() );
+ public void testGetConfig() {
+ assertEquals(config, stage.getConfig());
}
-
- public void testEnqueue()
- {
-
+ public void testEnqueue() {
}
-
- public void testSetMonitor()
- {
-
+ public void testSetMonitor() {
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
Sat Oct 30 04:31:52 2004
@@ -14,10 +14,12 @@
* limitations under the License.
*
*/
+
package org.apache.seda.examples;
import org.apache.seda.ProtocolTestCase;
+
/**
* Document me.
*
@@ -25,16 +27,12 @@
* Project</a>
* @version $Rev$
*/
-public class DiscardProtocolProviderTest extends ProtocolTestCase
-{
-
- public DiscardProtocolProviderTest()
- {
- super( new DiscardProtocolProvider() );
+public class DiscardProtocolProviderTest extends ProtocolTestCase {
+ public DiscardProtocolProviderTest() {
+ super(new DiscardProtocolProvider());
}
- public void testDiscardProtocol()
- {
+ public void testDiscardProtocol() {
//DiscardTCPClient client = new DiscardTCPClient();
}
}
Modified:
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
==============================================================================
---
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
(original)
+++
incubator/directory/seda/trunk/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
Sat Oct 30 04:31:52 2004
@@ -14,11 +14,11 @@
* limitations under the License.
*
*/
-package org.apache.seda.listener;
+package org.apache.seda.listener;
-import junit.framework.TestCase;
import junit.framework.Assert;
+import junit.framework.TestCase;
/**
@@ -27,60 +27,47 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class AvailablePortFinderTest extends TestCase
-{
- public void testDefault()
- {
+public class AvailablePortFinderTest extends TestCase {
+ public void testDefault() {
AvailablePortFinder finder = new AvailablePortFinder();
+
// this just scan just takes too much time
//finder.getAvailablePorts();
-
// keep range short so it does not take too long
- finder.getAvailablePorts( 1024, 1048 );
+ finder.getAvailablePorts(1024, 1048);
}
-
- public void testExceptions()
- {
+ public void testExceptions() {
AvailablePortFinder finder = new AvailablePortFinder();
- try
- {
+ try {
finder.getAvailablePorts(
- AvailablePortFinder.MIN_PORT_NUMBER - 1, 10 );
- Assert.fail( "IllegalArgumentException must be thrown." );
- }
- catch ( IllegalArgumentException e )
- {
+ AvailablePortFinder.MIN_PORT_NUMBER - 1,
+ 10);
+ Assert.fail("IllegalArgumentException must be thrown.");
+ } catch (IllegalArgumentException e) {
}
- try
- {
- finder.getAvailablePorts( AvailablePortFinder.MAX_PORT_NUMBER - 1,
- AvailablePortFinder.MAX_PORT_NUMBER + 1 );
- Assert.fail( "IllegalArgumentException must be thrown." );
- }
- catch ( IllegalArgumentException e )
- {
+ try {
+ finder.getAvailablePorts(
+ AvailablePortFinder.MAX_PORT_NUMBER - 1,
+ AvailablePortFinder.MAX_PORT_NUMBER + 1);
+ Assert.fail("IllegalArgumentException must be thrown.");
+ } catch (IllegalArgumentException e) {
}
- try
- {
- finder.getAvailablePorts( 10, 5 );
- Assert.fail( "IllegalArgumentException must be thrown." );
- }
- catch ( IllegalArgumentException e )
- {
+ try {
+ finder.getAvailablePorts(10, 5);
+ Assert.fail("IllegalArgumentException must be thrown.");
+ } catch (IllegalArgumentException e) {
}
}
-
- public void testNextAvailable()
- {
- int port = AvailablePortFinder.getNextAvailable(
- AvailablePortFinder.MIN_PORT_NUMBER );
- assertTrue( port >= AvailablePortFinder.MIN_PORT_NUMBER );
- assertTrue( port <= AvailablePortFinder.MAX_PORT_NUMBER );
- assertEquals( port, AvailablePortFinder.getNextAvailable() );
+ public void testNextAvailable() {
+ int port =
+
AvailablePortFinder.getNextAvailable(AvailablePortFinder.MIN_PORT_NUMBER);
+ assertTrue(port >= AvailablePortFinder.MIN_PORT_NUMBER);
+ assertTrue(port <= AvailablePortFinder.MAX_PORT_NUMBER);
+ assertEquals(port, AvailablePortFinder.getNextAvailable());
}
}
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
Sat Oct 30 04:31:52 2004
@@ -14,17 +14,17 @@
* limitations under the License.
*
*/
+
package org.apache.seda.listener;
+import java.net.InetAddress;
-import org.apache.seda.event.EventRouter;
import org.apache.seda.event.DefaultEventRouter;
+import org.apache.seda.event.EventRouter;
import org.apache.seda.protocol.InetServiceEntry;
import junit.framework.TestCase;
-import java.net.InetAddress;
-
/**
* Tests the default ListenerManager's operations.
@@ -32,68 +32,60 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class TCPListenerManagerTest extends TestCase
-{
+public class TCPListenerManagerTest extends TestCase {
/** An event router to use for testing */
private EventRouter router = null;
+
/** the defualt ListenerManager to test */
private TCPListenerManager listener = null;
-
-
+
+ /**
+ * Constructor for DefaultListenerManagerTest.
+ * @param arg0
+ */
+ public TCPListenerManagerTest(String arg0) {
+ super(arg0);
+ }
+
/*
* @see TestCase#setUp()
*/
- protected void setUp() throws Exception
- {
+ protected void setUp() throws Exception {
super.setUp();
-
+
router = new DefaultEventRouter();
- listener = new TCPListenerManager( router );
+ listener = new TCPListenerManager(router);
listener.start();
}
-
/*
* @see TestCase#tearDown()
*/
- protected void tearDown() throws Exception
- {
+ protected void tearDown() throws Exception {
super.tearDown();
-
+
router = null;
listener.stop();
listener = null;
}
-
-
- /**
- * Constructor for DefaultListenerManagerTest.
- * @param arg0
- */
- public TCPListenerManagerTest( String arg0 )
- {
- super( arg0 );
- }
-
- public void testBind() throws Exception
- {
+ public void testBind() throws Exception {
int port = AvailablePortFinder.getNextAvailable();
- ListenerConfig config = new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry( "ldap", port ) );
- listener.bind( config );
- listener.unbind( config );
+ ListenerConfig config =
+ new TCPListenerConfig(
+ InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port));
+ listener.bind(config);
+ listener.unbind(config);
}
-
- public void testUnbind() throws Exception
- {
+ public void testUnbind() throws Exception {
int port = AvailablePortFinder.getNextAvailable();
- ListenerConfig config = new TCPListenerConfig(
- InetAddress.getLocalHost(),
- new InetServiceEntry( "ldap", port ) );
- listener.bind( config );
- listener.unbind( config );
+ ListenerConfig config =
+ new TCPListenerConfig(
+ InetAddress.getLocalHost(),
+ new InetServiceEntry("ldap", port));
+ listener.bind(config);
+ listener.unbind(config);
}
}