Author: trustin
Date: Mon Oct 11 02:16:38 2004
New Revision: 54519
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EnqueuePredicate.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventFilter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouterMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Frontend.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/FrontendFactory.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/ResourceException.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Session.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SessionEvent.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Stage.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Subscriber.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberContext.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/EventRouterMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/StageMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPool.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPool.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/ClientDecoder.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecodeStageHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/ClientEncoder.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncodeStageHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/ByteBufferEvent.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationEvent.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationSubscriber.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionEvent.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionListener.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultEventRouter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontend.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontendFactory.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStage.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStageConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/TCPInputManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/AvailablePortFinder.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ClientKey.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/KeyExpiryException.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/SocketListenerConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/UDPListenerConfig.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/DefaultOutputManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/LoggingOutputMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputManager.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServiceEntry.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServicesDatabase.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ManyReplyHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/NoReplyHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ProtocolProvider.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/SingleReplyHandler.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/TransportTypeEnum.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/ByteIoSession.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatefulSession.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatelessSession.java
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/thread/ThreadPool.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/ProtocolTestCase.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/AbstractSubscriberTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/DefaultStageTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
Log:
Code cleanup:
* Added missing headers
* Replaced evil tabs with spaces
* Reformatted with Jalopy
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EnqueuePredicate.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EnqueuePredicate.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EnqueuePredicate.java
Mon Oct 11 02:16:38 2004
@@ -16,23 +16,24 @@
*/
package org.apache.seda;
-
import java.util.EventObject;
/**
- * Predicate used to determine whether or not an event is enqueued onto a
Stage.
+ * Predicate used to determine whether or not an event is enqueued onto a
+ * Stage.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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/branches/trustin_api_redesign/src/java/org/apache/seda/EventFilter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventFilter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventFilter.java
Mon Oct 11 02:16:38 2004
@@ -16,27 +16,29 @@
*/
package org.apache.seda;
+
/**
* 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>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache
+ * Directory Project </a>
* @version $Rev$
*/
public interface EventFilter {
- static EventFilter ALL = new EventFilter() {
- public boolean accept(SessionEvent event) {
- return true;
- }
- };
+ static EventFilter ALL =
+ new EventFilter() {
+ public boolean accept(SessionEvent event) {
+ return true;
+ }
+ };
- /**
- * 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(SessionEvent event);
-}
\ No newline at end of file
+ /**
+ * 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(SessionEvent event);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouter.java
Mon Oct 11 02:16:38 2004
@@ -16,29 +16,31 @@
*/
package org.apache.seda;
+
/**
* 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>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache
+ * Directory Project </a>
* @version $Rev$
*/
public interface EventRouter {
- /**
- * Subscribes an event subscriber.
- *
- * @param subscriber
- * the Subscriber to subscribe
- */
- SubscriberContext add(String name, Subscriber subscriber);
+ /**
+ * Subscribes an event subscriber.
+ *
+ * @param name DOCUMENT ME!
+ * @param subscriber the Subscriber to subscribe
+ *
+ * @return DOCUMENT ME!
+ */
+ SubscriberContext add(String name, Subscriber subscriber);
- /**
- * Unsubscribes an event subscriber.
- *
- * @param name
- * the name of the [EMAIL PROTECTED] Subscriber}.
- */
- void remove(String name);
-}
\ No newline at end of file
+ /**
+ * Unsubscribes an event subscriber.
+ *
+ * @param name the name of the [EMAIL PROTECTED] Subscriber}.
+ */
+ void remove(String name);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouterMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouterMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/EventRouterMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,22 +16,30 @@
*/
package org.apache.seda;
+
/**
* Monitors the activities of the event router.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
- * Project </a>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache
+ * Directory Project </a>
* @version $Rev$
*/
public interface EventRouterMonitor {
- /**
- * Monitores the addition of new subscriptions.
- */
- void addedSubscriber(String name, Subscriber subscriber,
- SubscriberContext ctx);
+ /**
+ * Monitores the addition of new subscriptions.
+ *
+ * @param name DOCUMENT ME!
+ * @param subscriber DOCUMENT ME!
+ * @param ctx DOCUMENT ME!
+ */
+ void addedSubscriber(String name, Subscriber subscriber,
+ SubscriberContext ctx
+ );
- /**
- * Monitors the removal of new subscriptions
- */
- void removedSubscriber(String name);
-}
\ No newline at end of file
+ /**
+ * Monitors the removal of new subscriptions
+ *
+ * @param name DOCUMENT ME!
+ */
+ void removedSubscriber(String name);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Frontend.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Frontend.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Frontend.java
Mon Oct 11 02:16:38 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/branches/trustin_api_redesign/src/java/org/apache/seda/FrontendFactory.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/FrontendFactory.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/FrontendFactory.java
Mon Oct 11 02:16:38 2004
@@ -16,13 +16,14 @@
*/
package org.apache.seda;
+
/**
* Document me.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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/branches/trustin_api_redesign/src/java/org/apache/seda/ResourceException.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/ResourceException.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/ResourceException.java
Mon Oct 11 02:16:38 2004
@@ -18,29 +18,26 @@
/**
- * 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>
+ * @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/branches/trustin_api_redesign/src/java/org/apache/seda/Session.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Session.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Session.java
Mon Oct 11 02:16:38 2004
@@ -1,20 +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.
+ *
+ */
+/*
* @(#) $Id$
*/
package org.apache.seda;
import java.util.Set;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public interface Session {
- Set getAttributeNames();
+ Set getAttributeNames();
- Object getAttribute(String key);
+ Object getAttribute(String key);
- Object setAttribute(String key, Object value);
-}
\ No newline at end of file
+ Object setAttribute(String key, Object value);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SessionEvent.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SessionEvent.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SessionEvent.java
Mon Oct 11 02:16:38 2004
@@ -18,33 +18,36 @@
import java.util.EventObject;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public class SessionEvent extends EventObject {
+ private final Session session;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param source
+ */
+ public SessionEvent(Subscriber source, Session session) {
+ super(source);
+
+ if (session == null) {
+ throw new NullPointerException();
+ }
+
+ this.session = session;
+ }
- private final Session session;
+ public Subscriber getSourceSubscriber() {
+ return (Subscriber) getSource();
+ }
- /**
- * Creates a new instance.
- *
- * @param source
- */
- public SessionEvent(Subscriber source, Session session) {
- super(source);
- if (session == null)
- throw new NullPointerException();
- this.session = session;
- }
-
- public Subscriber getSourceSubscriber() {
- return (Subscriber) getSource();
- }
-
- public Session getSession() {
- return session;
- }
-}
\ No newline at end of file
+ public Session getSession() {
+ return session;
+ }
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Stage.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Stage.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Stage.java
Mon Oct 11 02:16:38 2004
@@ -16,34 +16,34 @@
*/
package org.apache.seda;
+
/**
* Simple SEDA Stage interface.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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( SessionEvent event );
-
+ void enqueue(SessionEvent 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/branches/trustin_api_redesign/src/java/org/apache/seda/StageConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageConfig.java
Mon Oct 11 02:16:38 2004
@@ -16,43 +16,44 @@
*/
package org.apache.seda;
+import org.apache.seda.thread.ThreadPool;
+
import java.util.List;
-import org.apache.seda.thread.ThreadPool;
/**
* The configuration required for a stage.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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/branches/trustin_api_redesign/src/java/org/apache/seda/StageHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageHandler.java
Mon Oct 11 02:16:38 2004
@@ -18,19 +18,19 @@
import java.util.EventListener;
+
/**
* Thread safe Event handler used by Stages.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory
- * Project </a>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache
+ * Directory Project </a>
* @version $Rev$
*/
public interface StageHandler extends EventListener {
- /**
- * Handles an event for the Stage.
- *
- * @param event
- * the event to process or handle.
- */
- void handleEvent(SessionEvent event);
-}
\ No newline at end of file
+ /**
+ * Handles an event for the Stage.
+ *
+ * @param event the event to process or handle.
+ */
+ void handleEvent(SessionEvent event);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/StageMonitor.java
Mon Oct 11 02:16:38 2004
@@ -18,174 +18,148 @@
import java.util.EventObject;
+
/**
* Interface used to monitor Stage protocol.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
- * Project </a>
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]"> Apache
+ * Directory Project </a>
* @version $Rev$
*/
public interface StageMonitor {
- /**
- * Reports when the Stage is missing its handler.
- *
- * @param stage
- * the stage reporting a missing handler
- */
- void handlerMissing(Stage stage);
-
- /**
- * A has been made to gracefully stop the Stage.
- *
- * @param stage
- * the Stage being stopped
- */
- void stopping(Stage stage);
-
- /**
- * 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);
-
- /**
- * 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
- */
- void notified(Stage stage);
-
- /**
- * Notification of stage driver thread going into wait state due to an
empty
- * queue.
- *
- * @param stage
- * the waiting Stage
- */
- void waiting(Stage stage);
-
- /**
- * Monitors Stage has starts.
- *
- * @param stage
- * the started Stage
- */
- void started(Stage stage);
-
- /**
- * Monitors Stage has stops.
- *
- * @param stage
- * the stopped Stage
- */
- void stopped(Stage stage);
-
- /**
- * Monitors StageDriver starts.
- *
- * @param stage
- * the Stage whose driver started
- */
- 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, SessionEvent 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, SessionEvent 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);
-
- /**
- * Queue lock acquired by awoken Stage driver thread.
- *
- * @param stage
- * the Stage whose queue lock was acquired
- */
- 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);
-
- /**
- * Monitor for successfully completing the handling of an event.
- *
- * @param stage
- * the Stage processing the event
- * @param event
- * the event that was handled
- */
- 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);
-
- /**
- * 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);
-
- /**
- * Monitors enqueue predicate additions.
- *
- * @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);
-}
\ No newline at end of file
+ /**
+ * Reports when the Stage is missing its handler.
+ *
+ * @param stage the stage reporting a missing handler
+ */
+ void handlerMissing(Stage stage);
+
+ /**
+ * A has been made to gracefully stop the Stage.
+ *
+ * @param stage the Stage being stopped
+ */
+ void stopping(Stage stage);
+
+ /**
+ * 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);
+
+ /**
+ * 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
+ */
+ void notified(Stage stage);
+
+ /**
+ * Notification of stage driver thread going into wait state due to an
+ * empty queue.
+ *
+ * @param stage the waiting Stage
+ */
+ void waiting(Stage stage);
+
+ /**
+ * Monitors Stage has starts.
+ *
+ * @param stage the started Stage
+ */
+ void started(Stage stage);
+
+ /**
+ * Monitors Stage has stops.
+ *
+ * @param stage the stopped Stage
+ */
+ void stopped(Stage stage);
+
+ /**
+ * Monitors StageDriver starts.
+ *
+ * @param stage the Stage whose driver started
+ */
+ 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, SessionEvent 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, SessionEvent 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);
+
+ /**
+ * Queue lock acquired by awoken Stage driver thread.
+ *
+ * @param stage the Stage whose queue lock was acquired
+ */
+ 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);
+
+ /**
+ * Monitor for successfully completing the handling of an event.
+ *
+ * @param stage the Stage processing the event
+ * @param event the event that was handled
+ */
+ 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);
+
+ /**
+ * 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);
+
+ /**
+ * Monitors enqueue predicate additions.
+ *
+ * @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);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Subscriber.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Subscriber.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/Subscriber.java
Mon Oct 11 02:16:38 2004
@@ -18,22 +18,24 @@
import java.util.EventListener;
+
/**
* A Subscriber from the Event Notifier pattern.
- *
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache
+ * Directory Project </a>
+ * @version $Rev$
+ *
* @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 {
- /**
- * Informs this Subscriber of an event.
- *
- * @param event
- * the event notified of
- */
- void inform(SubscriberContext ctx, SessionEvent event);
-}
\ No newline at end of file
+ /**
+ * Informs this Subscriber of an event.
+ *
+ * @param ctx DOCUMENT ME!
+ * @param event the event notified of
+ */
+ void inform(SubscriberContext ctx, SessionEvent event);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberContext.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberContext.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberContext.java
Mon Oct 11 02:16:38 2004
@@ -1,40 +1,42 @@
/*
- * 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;
import java.util.Collection;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public interface SubscriberContext {
- String getName();
+ String getName();
+
+ void subscribe(String eventSourceName, EventFilter eventFilter);
+
+ void unsubscribe(String eventSourceName, EventFilter eventFilter);
- void subscribe(String eventSourceName, EventFilter eventFilter);
+ void publish(SessionEvent event);
- void unsubscribe(String eventSourceName, EventFilter eventFilter);
+ void publish(Collection eventCollection);
- void publish(SessionEvent event);
+ SubscriberMonitor getMonitor();
- void publish(Collection eventCollection);
-
- SubscriberMonitor getMonitor();
-
- void setMonitor(SubscriberMonitor monitor);
-}
\ No newline at end of file
+ void setMonitor(SubscriberMonitor monitor);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/SubscriberMonitor.java
Mon Oct 11 02:16:38 2004
@@ -1,44 +1,44 @@
-/*
- * 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;
-
-
-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 );
-
- void addedSubscription(String eventSourceName, EventFilter eventFilter);
-
- void removedSubscription(String eventSourceName, EventFilter eventFilter);
-}
+/*
+ * 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;
+
+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
+ );
+
+ void addedSubscription(String eventSourceName, EventFilter eventFilter);
+
+ void removedSubscription(String eventSourceName, EventFilter eventFilter);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/EventRouterMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/EventRouterMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/EventRouterMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -20,17 +20,20 @@
import org.apache.seda.Subscriber;
import org.apache.seda.SubscriberContext;
+
/**
* Does nothing and created by the default constructor.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory
* Project </a>
* @version $Rev: 45930 $
*/
public class EventRouterMonitorAdapter implements EventRouterMonitor {
- public void addedSubscriber(String name, Subscriber subscriber,
SubscriberContext ctx) {
- }
+ public void addedSubscriber(String name, Subscriber subscriber,
+ SubscriberContext ctx
+ ) {
+ }
- public void removedSubscriber(String name) {
- }
-}
\ No newline at end of file
+ public void removedSubscriber(String name) {
+ }
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/StageMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/StageMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/adaptor/StageMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,17 +16,16 @@
*/
package org.apache.seda.adaptor;
-
-import java.util.EventObject;
-
import org.apache.seda.EnqueuePredicate;
import org.apache.seda.SessionEvent;
import org.apache.seda.Stage;
import org.apache.seda.StageMonitor;
+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.
*
@@ -34,162 +33,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, SessionEvent event )
- {
+ public void enqueueOccurred(Stage stage, SessionEvent event) {
}
-
/* (non-Javadoc)
* @see org.apache.seda.seda.StageMonitor#enqueueRejected(
* org.apache.seda.seda.Stage, java.util.EventObject)
*/
- public void enqueueRejected( Stage stage, SessionEvent event )
- {
+ public void enqueueRejected(Stage stage, SessionEvent 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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPool.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPool.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPool.java
Mon Oct 11 02:16:38 2004
@@ -16,11 +16,10 @@
*/
package org.apache.seda.buffer;
+import org.apache.seda.ResourceException;
import java.nio.ByteBuffer;
-import org.apache.seda.ResourceException;
-
/**
* Service interface for an NIO direct memory buffer pool.
@@ -28,82 +27,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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolConfig.java
Mon Oct 11 02:16:38 2004
@@ -16,48 +16,48 @@
*/
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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.buffer;
-
import java.nio.ByteBuffer;
@@ -26,86 +25,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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/BufferPoolMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.buffer;
-
import java.nio.ByteBuffer;
@@ -27,55 +26,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 +73,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 +81,25 @@
* @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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPool.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPool.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPool.java
Mon Oct 11 02:16:38 2004
@@ -16,338 +16,280 @@
*/
package org.apache.seda.buffer;
+import org.apache.seda.ResourceException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
-import org.apache.seda.ResourceException;
-
/**
* 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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/DefaultBufferPoolConfig.java
Mon Oct 11 02:16:38 2004
@@ -24,81 +24,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/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/buffer/LoggingBufferMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,12 +16,11 @@
*/
package org.apache.seda.buffer;
-
-import java.nio.ByteBuffer;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.nio.ByteBuffer;
+
/**
* Logging monitor for a BufferPool.
@@ -29,165 +28,141 @@
* @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/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/ClientDecoder.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/ClientDecoder.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/ClientDecoder.java
Mon Oct 11 02:16:38 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/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecodeStageHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecodeStageHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecodeStageHandler.java
Mon Oct 11 02:16:38 2004
@@ -16,16 +16,16 @@
*/
package org.apache.seda.decoder;
-
-import java.nio.ByteBuffer;
-
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.stateful.StatefulDecoder;
+
import org.apache.seda.Session;
import org.apache.seda.SessionEvent;
import org.apache.seda.StageHandler;
import org.apache.seda.event.ByteBufferEvent;
+import java.nio.ByteBuffer;
+
/**
* A decoder manager's decodeNonBlocking StageHandler for use only with
enqueued
@@ -34,50 +34,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.StageHandler#handleEvent(java.util.EventObject)
*/
- public void handleEvent( SessionEvent event )
- {
- ByteBufferEvent e = ( ByteBufferEvent ) event;
+ public void handleEvent(SessionEvent event) {
+ ByteBufferEvent e = (ByteBufferEvent) event;
Session session = e.getSession();
- ByteBuffer buf = e.claimInterest( this );
- StatefulDecoder decoder = manager.getDecoder( session );
-
- try
- {
- decoder.decode( buf );
- }
- catch( DecoderException ex )
- {
+ ByteBuffer buf = e.claimInterest(this);
+ StatefulDecoder decoder = manager.getDecoder(session);
+
+ 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/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManager.java
Mon Oct 11 02:16:38 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 org.apache.commons.codec.DecoderException;
+
+import org.apache.seda.listener.ClientKey;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * 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/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitor.java
Mon Oct 11 02:16:38 2004
@@ -1,42 +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.decoder;
-
-
-import java.util.EventObject;
-
-import org.apache.seda.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 org.apache.seda.Subscriber;
+
+import java.util.EventObject;
+
+
+/**
+ * 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/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/decoder/DecoderManagerMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,11 +16,10 @@
*/
package org.apache.seda.decoder;
+import org.apache.seda.Subscriber;
import java.util.EventObject;
-import org.apache.seda.Subscriber;
-
/**
* An adapter for decoder manager monitors where all failures actually throw
@@ -29,18 +28,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/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/ClientEncoder.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/ClientEncoder.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/ClientEncoder.java
Mon Oct 11 02:16:38 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: 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);
+ }
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/DefaultEncoderManager.java
Mon Oct 11 02:16:38 2004
@@ -16,26 +16,25 @@
*/
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.EventRouter;
import org.apache.seda.StageConfig;
-import org.apache.seda.stage.*;
-
import org.apache.seda.event.*;
import org.apache.seda.impl.DefaultStage;
import org.apache.seda.impl.util.LoggingStageMonitor;
import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.stage.*;
+
+import java.nio.ByteBuffer;
+
+import java.util.EventObject;
+import java.util.HashMap;
/**
@@ -47,93 +46,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.
@@ -141,15 +125,14 @@
* @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.getSocket().getLocalPort() );
- EncoderFactory factory = ( EncoderFactory ) factories.get( proto );
+ private StatefulEncoder createEncoder(ClientKey key)
+ throws KeyExpiryException {
+ String proto = inetdb.getProtoByPort(key.getSocket().getLocalPort());
+ 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.
@@ -157,97 +140,82 @@
* @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 );
+ 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 );
+ );
+ 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.getSocket().getLocalPort();
- }
- 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/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncodeStageHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncodeStageHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncodeStageHandler.java
Mon Oct 11 02:16:38 2004
@@ -16,12 +16,12 @@
*/
package org.apache.seda.encoder;
+import org.apache.commons.codec.EncoderException;
+import org.apache.commons.codec.stateful.StatefulEncoder;
import org.apache.seda.StageHandler;
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;
@@ -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/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManager.java
Mon Oct 11 02:16:38 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 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;
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitor.java
Mon Oct 11 02:16:38 2004
@@ -1,40 +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.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 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
+ );
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/encoder/EncoderManagerMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.encoder;
-
import org.apache.seda.listener.ClientKey;
import java.util.EventObject;
@@ -28,31 +27,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/branches/trustin_api_redesign/src/java/org/apache/seda/event/ByteBufferEvent.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/ByteBufferEvent.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/ByteBufferEvent.java
Mon Oct 11 02:16:38 2004
@@ -16,41 +16,45 @@
*/
package org.apache.seda.event;
-import java.nio.ByteBuffer;
-
import org.apache.seda.Session;
import org.apache.seda.SessionEvent;
import org.apache.seda.Subscriber;
+import java.nio.ByteBuffer;
+
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public abstract class ByteBufferEvent extends SessionEvent {
- private final ByteBuffer buffer;
-
- /**
- * Creates a new instance.
- *
- * @param source
- * @param session
- */
- public ByteBufferEvent(Subscriber source, Session session,
- ByteBuffer buffer) {
- super(source, session);
- if (buffer == null)
- throw new NullPointerException();
- this.buffer = buffer;
- }
-
- public ByteBuffer getBuffer() {
- return buffer;
- }
+ private final ByteBuffer buffer;
- public abstract void claimInterests(Object party);
+ /**
+ * Creates a new instance.
+ *
+ * @param source
+ * @param session
+ */
+ public ByteBufferEvent(Subscriber source, Session session,
+ ByteBuffer buffer
+ ) {
+ super(source, session);
+
+ if (buffer == null) {
+ throw new NullPointerException();
+ }
+
+ this.buffer = buffer;
+ }
+
+ public ByteBuffer getBuffer() {
+ return buffer;
+ }
- public abstract void releaseInterests(Object party);
+ public abstract void claimInterests(Object party);
-}
\ No newline at end of file
+ public abstract void releaseInterests(Object party);
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationEvent.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationEvent.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationEvent.java
Mon Oct 11 02:16:38 2004
@@ -20,28 +20,28 @@
import org.apache.seda.Subscriber;
import org.apache.seda.session.StatefulSession;
+
/**
* Denotes the creation of a client session which does not necessarily coincide
* 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 SessionEvent {
- /**
- * 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(Subscriber source, StatefulSession session)
{
- super(source, session);
- }
+ /**
+ * 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(Subscriber source, StatefulSession session) {
+ super(source, session);
+ }
}
-
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationSubscriber.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationSubscriber.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionCreationSubscriber.java
Mon Oct 11 02:16:38 2004
@@ -14,23 +14,22 @@
* limitations under the License.
*
*/
-package org.apache.seda.event ;
+package org.apache.seda.event;
import org.apache.seda.Subscriber;
/**
* 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/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionEvent.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionEvent.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionEvent.java
Mon Oct 11 02:16:38 2004
@@ -20,27 +20,28 @@
import org.apache.seda.Subscriber;
import org.apache.seda.session.StatefulSession;
+
/**
* 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 SessionEvent {
- /**
- * 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(Subscriber source, StatefulSession
session) {
- super(source, session);
- }
-}
\ No newline at end of file
+ /**
+ * 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(Subscriber source, StatefulSession session)
{
+ super(source, session);
+ }
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionListener.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionListener.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/event/SessionDestructionListener.java
Mon Oct 11 02:16:38 2004
@@ -19,16 +19,15 @@
/**
* 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/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultEventRouter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultEventRouter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultEventRouter.java
Mon Oct 11 02:16:38 2004
@@ -16,12 +16,6 @@
*/
package org.apache.seda.impl;
-
-import java.util.ArrayList;
-import java.util.EventObject;
-import java.util.Iterator;
-import java.util.List;
-
import org.apache.seda.EventFilter;
import org.apache.seda.EventRouter;
import org.apache.seda.EventRouterMonitor;
@@ -29,6 +23,11 @@
import org.apache.seda.Subscriber;
import org.apache.seda.adaptor.EventRouterMonitorAdapter;
+import java.util.ArrayList;
+import java.util.EventObject;
+import java.util.Iterator;
+import java.util.List;
+
/**
* An synchronous implementation of the event router / notification pattern.
@@ -36,172 +35,152 @@
* @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, EventFilter filter, Subscriber
subscriber )
- {
- if ( ! EventObject.class.isAssignableFrom( type ) )
- {
- throw new IllegalArgumentException( "Invalid event class: "
- + type.getName() );
+ public void subscribe(Class type, EventFilter filter, Subscriber
subscriber) {
+ if (!EventObject.class.isAssignableFrom(type)) {
+ throw new IllegalArgumentException("Invalid event class: "
+ + type.getName()
+ );
}
- Subscription l_subscription =
- new Subscription( type, filter, subscriber );
+ Subscription l_subscription =
+ new Subscription(type, filter, subscriber);
- if ( ! subscriptions.contains( l_subscription ) )
- {
- synchronized ( subscriptions )
- {
- subscriptions.add( l_subscription );
+ if (!subscriptions.contains(l_subscription)) {
+ synchronized (subscriptions) {
+ subscriptions.add(l_subscription);
}
-
- monitor.addedSubscription( l_subscription );
+
+ monitor.addedSubscription(l_subscription);
}
}
-
/**
* @see EventRouter#unsubscribe(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 EventRouter#unsubscribe(java.lang.Class,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 EventRouter#unsubscribe(java.lang.Class,Subscriber)
*/
- public void unsubscribe( Class type, EventFilter filter,
- Subscriber subscriber )
- {
- if ( ! EventObject.class.isAssignableFrom( type ) )
- {
- throw new IllegalArgumentException( "Invalid event class: "
- + type.getName() );
+ public void unsubscribe(Class type, EventFilter 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 );
+
+ final Subscription l_subscription =
+ new Subscription(type, filter, subscriber);
+
+ synchronized (subscriptions) {
+ subscriptions.remove(l_subscription);
}
}
-
/**
* (non-Javadoc)
* @see EventRouter#publish(SessionEvent)
*/
- public void publish( SessionEvent event )
- {
+ public void publish(SessionEvent 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 = (org.apache.seda.Subscription [] ) subscriptions
- .toArray( new Subscription [ subscriptions.size() ] );
+
+ synchronized (subscriptions) {
+ subscrArray =
+ (org.apache.seda.Subscription[]) subscriptions.toArray(new
Subscription[subscriptions
+
.size()]
+ );
}
- if ( applicableAdvice.isEmpty() )
- {
+ if (applicableAdvice.isEmpty()) {
+ publish(event, subscrArray);
- 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
@@ -220,64 +199,49 @@
}
}
*/
-
}
+ private void publish(SessionEvent ev, Subscription[] subscriptions) {
+ for (int ii = 0; ii < subscriptions.length; ii++) {
+ boolean isAssignable =
+ subscriptions[ii].getType().isAssignableFrom(ev.getClass());
-
- private void publish( SessionEvent 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/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontend.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontend.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontend.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.impl;
-
import org.apache.seda.EventRouter;
import org.apache.seda.Frontend;
import org.apache.seda.buffer.BufferPool;
@@ -36,16 +35,15 @@
/**
- * 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;
@@ -56,12 +54,12 @@
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;
@@ -73,72 +71,58 @@
this.inetDb = inetDb;
}
-
- public void register( ProtocolProvider provider )
- {
- // FIXME Have to find the better way to manage protocols.
- // Managing protocols with event-driven way looks fancy, but
- // it looks like over-engineered. I'll provide a dedicated
- // protocol manager later.
-
+ public void register(ProtocolProvider provider) {
+ // FIXME Have to find the better way to manage protocols.
+ // Managing protocols with event-driven way looks fancy, but
+ // it looks like over-engineered. I'll provide a dedicated
+ // protocol manager later.
// AddProtocolEvent event = new AddProtocolEvent( provider );
// router.publish( event );
}
+ public void stop() throws Exception {
+ ((TCPListenerManager) srvMan).stop();
+ ((TCPInputManager) inMan).stop();
+ ((DefaultOutputManager) outMan).stop();
- public void stop() throws Exception
- {
- ( ( TCPListenerManager ) srvMan ).stop();
- ( ( TCPInputManager ) inMan ).stop();
- ( ( DefaultOutputManager ) outMan ).stop();
//( ( DefaultRequestProcessor ) reqProc ).stop();
- ( ( DefaultDecoderManager ) decMan ).stop();
- ( ( DefaultEncoderManager ) encMan ).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/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontendFactory.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontendFactory.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultFrontendFactory.java
Mon Oct 11 02:16:38 2004
@@ -16,11 +16,9 @@
*/
package org.apache.seda.impl;
-
-import java.io.IOException;
-
import org.apache.commons.threadpool.CommonsLoggingThreadPoolMonitor;
import org.apache.commons.threadpool.DefaultThreadPool;
+
import org.apache.seda.EventRouter;
import org.apache.seda.Frontend;
import org.apache.seda.FrontendFactory;
@@ -47,6 +45,8 @@
import org.apache.seda.protocol.RequestProcessor;
import org.apache.seda.thread.ThreadPool;
+import java.io.IOException;
+
/**
* A factory implementation that ties together the frontend components for
@@ -56,149 +56,139 @@
* @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 );
+ 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
+ );
- 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 ) );
- DefaultOutputManager outMan = new DefaultOutputManager( router, config
);
+ private OutputManager createOutputManager(EventRouter router) {
+ DefaultStageConfig config =
+ new DefaultStageConfig("outputManager", createThreadPool(3));
+ DefaultOutputManager outMan = new DefaultOutputManager(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/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStage.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStage.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStage.java
Mon Oct 11 02:16:38 2004
@@ -16,10 +16,6 @@
*/
package org.apache.seda.impl;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Set;
-
import org.apache.seda.EnqueuePredicate;
import org.apache.seda.SessionEvent;
import org.apache.seda.Stage;
@@ -27,247 +23,261 @@
import org.apache.seda.StageMonitor;
import org.apache.seda.adaptor.StageMonitorAdapter;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+
+
/**
* The default Stage implementation.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory
* Project </a>
* @version $Rev$
*/
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);
- /** 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) {
- this.config = config;
- hasStarted = new Boolean(false);
- }
-
- //
------------------------------------------------------------------------
- // Stage Methods
- //
------------------------------------------------------------------------
-
- /**
- * @see Stage#addPredicate(EnqueuePredicate)
- * addPredicate(org.apache.seda.seda.EnqueuePredicate)
- */
- public void addPredicate(EnqueuePredicate predicate) {
- config.getPredicates().add(predicate);
- monitor.predicateAdded(this, predicate);
- }
-
- /**
- * @see Stage#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
- * enqueue is rejected if the stage has not started.
- *
- * @see Stage#enqueue(SessionEvent)
- */
- public void enqueue(final SessionEvent event) {
- boolean isAccepted = true;
-
- 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);
- }
-
- 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 {
- SessionEvent event =
(SessionEvent) 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 SessionEvent m_event;
-
- public ExecutableHandler(SessionEvent 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());
- }
- }
- }
-
- //
------------------------------------------------------------------------
- // start stop controls
- //
------------------------------------------------------------------------
-
- /**
- * Starts up this Stage's driver.
- */
- public void start() {
- if (hasStarted.booleanValue()) {
- throw new IllegalStateException("Already started!");
- }
-
- hasStarted = new Boolean(true);
- thread = new Thread(new StageDriver());
- thread.start();
-
- 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) {
- queue.notifyAll();
- }
- }
-
- monitor.stopped(this);
- }
-
- /**
- * Tests to see if this stage has started.
- *
- * @return true if this stage has started, false otherwise
- */
- public boolean hasStarted() {
- return hasStarted.booleanValue();
- }
-
- /**
- * Gets this Stage's monitor.
- *
- * @return the monitor for this Stage
- */
- public StageMonitor getStageMonitor() {
- return monitor;
- }
-
- /**
- * Sets this Stage's monitor.
- *
- * @param monitor
- * the monitor to set for this Stage
- */
- public void setMonitor(StageMonitor monitor) {
- this.monitor = monitor;
- }
-}
\ No newline at end of file
+ /**
+ * 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);
+
+ /** 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) {
+ this.config = config;
+ hasStarted = new Boolean(false);
+ }
+
+ // ------------------------------------------------------------------------
+ // Stage Methods
+ // ------------------------------------------------------------------------
+
+ /**
+ * @see Stage#addPredicate(EnqueuePredicate)
+ * addPredicate(org.apache.seda.seda.EnqueuePredicate)
+ */
+ public void addPredicate(EnqueuePredicate predicate) {
+ config.getPredicates().add(predicate);
+ monitor.predicateAdded(this, predicate);
+ }
+
+ /**
+ * @see Stage#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
+ * enqueue is rejected if the stage has not started.
+ *
+ * @see Stage#enqueue(SessionEvent)
+ */
+ public void enqueue(final SessionEvent event) {
+ boolean isAccepted = true;
+
+ 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);
+ }
+
+ if (isAccepted) {
+ synchronized (queue) {
+ monitor.lockedQueue(this, event);
+ queue.addFirst(event);
+ queue.notifyAll();
+ }
+
+ 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!");
+ }
+
+ hasStarted = new Boolean(true);
+ thread = new Thread(new StageDriver());
+ thread.start();
+
+ 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) {
+ queue.notifyAll();
+ }
+ }
+
+ monitor.stopped(this);
+ }
+
+ /**
+ * Tests to see if this stage has started.
+ *
+ * @return true if this stage has started, false otherwise
+ */
+ public boolean hasStarted() {
+ return hasStarted.booleanValue();
+ }
+
+ /**
+ * Gets this Stage's monitor.
+ *
+ * @return the monitor for this Stage
+ */
+ public StageMonitor getStageMonitor() {
+ return monitor;
+ }
+
+ /**
+ * Sets this Stage's monitor.
+ *
+ * @param monitor
+ * the monitor to set for this Stage
+ */
+ 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: 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 {
+ SessionEvent event = (SessionEvent) 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 SessionEvent m_event;
+
+ public ExecutableHandler(SessionEvent 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/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStageConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStageConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/impl/DefaultStageConfig.java
Mon Oct 11 02:16:38 2004
@@ -16,14 +16,13 @@
*/
package org.apache.seda.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.seda.StageConfig;
import org.apache.seda.StageHandler;
import org.apache.seda.thread.ThreadPool;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* The default bean implementation for a stage's configuration.
@@ -31,107 +30,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/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManager.java
Mon Oct 11 02:16:38 2004
@@ -20,10 +20,9 @@
/**
* 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/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,6 +16,10 @@
*/
package org.apache.seda.input;
+import org.apache.seda.ResourceException;
+import org.apache.seda.buffer.BufferPool;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
import java.io.IOException;
@@ -24,11 +28,6 @@
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
-import org.apache.seda.ResourceException;
-import org.apache.seda.buffer.BufferPool;
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-
/**
* Monitors input activity managed by the the InputManager.
@@ -36,125 +35,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/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/InputManagerMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,19 +16,18 @@
*/
package org.apache.seda.input;
+import org.apache.seda.ResourceException;
+import org.apache.seda.buffer.BufferPool;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
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;
-import org.apache.seda.buffer.BufferPool;
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-
/**
* An adaptor for the InputManagerMonitor interface.
@@ -36,155 +35,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/branches/trustin_api_redesign/src/java/org/apache/seda/input/TCPInputManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/TCPInputManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/input/TCPInputManager.java
Mon Oct 11 02:16:38 2004
@@ -16,22 +16,24 @@
*/
package org.apache.seda.input;
+import org.apache.seda.EventRouter;
+import org.apache.seda.ResourceException;
+import org.apache.seda.buffer.BufferPool;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
import java.awt.event.InputEvent;
+
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;
-import org.apache.seda.EventRouter;
-import org.apache.seda.ResourceException;
-import org.apache.seda.buffer.BufferPool;
-import org.apache.seda.listener.ClientKey;
-import org.apache.seda.listener.KeyExpiryException;
-
/**
* Default InputManager implementation based on NIO selectors and channels.
@@ -39,116 +41,115 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev: 1452 $
*/
-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.
@@ -157,191 +158,153 @@
}
}
-
/**
* 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++) {
ClientKey l_key = null;
SocketChannel l_channel = null;
-
- try
- {
+
+ try {
l_key = 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) {
+ monitor.channelCloseFailure((SocketChannel) l_key.channel(),
e);
}
- catch ( IOException e )
- {
- monitor.channelCloseFailure(
- ( 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
@@ -349,112 +312,100 @@
* 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: 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);
+ }
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/AvailablePortFinder.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/AvailablePortFinder.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/AvailablePortFinder.java
Mon Oct 11 02:16:38 2004
@@ -16,12 +16,13 @@
*/
package org.apache.seda.listener;
+import java.io.IOException;
+
+import java.net.ServerSocket;
+import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeSet;
-import java.util.NoSuchElementException;
-import java.net.ServerSocket;
-import java.io.IOException;
/**
@@ -33,7 +34,6 @@
* @see <a href="http://www.iana.org/assignments/port-numbers">IANA.org</a>
*/
public class AvailablePortFinder {
-
/**
* The minimum number of server port number.
*/
@@ -44,15 +44,12 @@
*/
public static final int MAX_PORT_NUMBER = 49151;
-
/**
* Creates a new instance.
*/
- public AvailablePortFinder()
- {
+ public AvailablePortFinder() {
}
-
/**
* Returns the [EMAIL PROTECTED] Set} of currently available port numbers
* ([EMAIL PROTECTED] Integer}). This method is identical to
@@ -60,70 +57,56 @@
*
* WARNING: this can take a very long time.
*/
- public Set getAvailablePorts()
- {
- return getAvailablePorts( MIN_PORT_NUMBER, MAX_PORT_NUMBER ) ;
+ public Set getAvailablePorts() {
+ return getAvailablePorts(MIN_PORT_NUMBER, MAX_PORT_NUMBER);
}
-
/**
* Gets the next available port starting at the lowest port number.
*
* @throws NoSuchElementException if there are no ports available
*/
- public static int getNextAvailable()
- {
- return getNextAvailable( MIN_PORT_NUMBER );
+ public static int getNextAvailable() {
+ return getNextAvailable(MIN_PORT_NUMBER);
}
-
/**
* Gets the next available port starting at a port.
*
* @param fromPort the port to scan for availability
* @throws NoSuchElementException if there are no ports available
*/
- public static int getNextAvailable( int fromPort )
- {
- if ( fromPort < MIN_PORT_NUMBER || fromPort > MAX_PORT_NUMBER )
- {
- throw new IllegalArgumentException( "Invalid start port: " +
- fromPort );
+ public static int getNextAvailable(int fromPort) {
+ if ((fromPort < MIN_PORT_NUMBER) || (fromPort > MAX_PORT_NUMBER)) {
+ throw new IllegalArgumentException("Invalid start port: "
+ + fromPort
+ );
}
- for ( int i = fromPort; i <= MAX_PORT_NUMBER; i++ )
- {
+ for (int i = fromPort; i <= MAX_PORT_NUMBER; i++) {
ServerSocket s = null;
- try
- {
- s = new ServerSocket( i );
+ try {
+ s = new ServerSocket(i);
+
return i;
- }
- catch ( IOException e )
- {
- }
- finally
- {
- if ( s != null )
- {
- try
- {
+ } catch (IOException e) {
+ } finally {
+ if (s != null) {
+ try {
s.close();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
/* should not be thrown */
}
}
}
}
- throw new NoSuchElementException( "Could not find an available port " +
- "above " + fromPort );
+ throw new NoSuchElementException("Could not find an available port "
+ + "above " + fromPort
+ );
}
-
/**
* Returns the [EMAIL PROTECTED] Set} of currently avaliable port numbers
([EMAIL PROTECTED] Integer})
* between the specified port range.
@@ -132,40 +115,29 @@
* [EMAIL PROTECTED] #MIN_PORT_NUMBER} and [EMAIL PROTECTED]
#MAX_PORT_NUMBER} or
* <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 ||
- fromPort > toPort )
- {
- throw new IllegalArgumentException( "Invalid port range: " +
- fromPort + " ~ " + toPort );
+ public Set getAvailablePorts(int fromPort, int toPort) {
+ if ((fromPort < MIN_PORT_NUMBER) || (toPort > MAX_PORT_NUMBER)
+ || (fromPort > toPort)
+ ) {
+ throw new IllegalArgumentException("Invalid port range: "
+ + fromPort + " ~ " + toPort
+ );
}
Set result = new TreeSet();
- for ( int i = fromPort; i <= toPort; i++ )
- {
+ for (int i = fromPort; i <= toPort; i++) {
ServerSocket s = null;
- try
- {
- s = new ServerSocket( i );
- result.add( new Integer( i ) );
- }
- catch ( IOException e )
- {
- }
- finally
- {
- if ( s != null )
- {
- try
- {
+ try {
+ s = new ServerSocket(i);
+ result.add(new Integer(i));
+ } catch (IOException e) {
+ } finally {
+ if (s != null) {
+ try {
s.close();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
/* should not be thrown */
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ClientKey.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ClientKey.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ClientKey.java
Mon Oct 11 02:16:38 2004
@@ -16,16 +16,15 @@
*/
package org.apache.seda.listener;
+import java.io.IOException;
import java.net.Socket;
-import java.io.IOException;
-
/**
* Every client that successfully binds anonymously or with a valid identity
- * has a unique client key represented by this class. The key uniquely
- * identifies the client based on the connection parameters: interface and
port
+ * has a unique client key represented by this class. The key uniquely
+ * identifies the client based on the connection parameters: interface and port
* used on the server as well as the interface and port used by the client.
* <p>
* The ClientKey plays a central role in coordinating activities with the
@@ -34,37 +33,37 @@
* ClientKey instance. Socket IO is managed using a pair of lock objects
* specificially for this purpose.
* </p>
- *
+ *
* @todo do we really need these lock objects?
* @todo why are we carrying around the damn socket?
*
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public final class ClientKey
-{
+public final class ClientKey {
// ----------------------------------------------
// Private members.
// ----------------------------------------------
/** Input channel synchronization object */
private final Object inputLock = new Object();
+
/** Output channel synchronization object */
private final Object outputLock = new Object();
+
/** Unique key or client id */
private final String clientId;
+
/** Socket connection to client */
private final Socket socket;
-
+
/** Whether or not this key has expired: the client has disconnected. */
private boolean hasExpired = false;
-
// ----------------------------------------------
// Constructors
// ----------------------------------------------
-
/**
* Generates a unique connection/client identifier String for a client
* socket connection. The key is composed of the local server address
@@ -79,28 +78,25 @@
* @param a_socket newly established client socket connection to the
* server.
*/
- ClientKey( final Socket a_socket )
- {
+ ClientKey(final Socket a_socket) {
// build the key ...
StringBuffer l_buf = new StringBuffer();
- l_buf.append( a_socket.getLocalAddress().getHostAddress() );
- l_buf.append( ':' );
- l_buf.append( a_socket.getLocalPort() ).append( "<-" );
- l_buf.append( a_socket.getInetAddress().getHostAddress() );
- l_buf.append( ':' );
- l_buf.append( a_socket.getPort() );
-
+ l_buf.append(a_socket.getLocalAddress().getHostAddress());
+ l_buf.append(':');
+ l_buf.append(a_socket.getLocalPort()).append("<-");
+ l_buf.append(a_socket.getInetAddress().getHostAddress());
+ l_buf.append(':');
+ l_buf.append(a_socket.getPort());
+
// set finals ...
clientId = l_buf.toString();
socket = a_socket;
}
-
// ----------------------------------------------
// Accessors of conn. parameters to client id
// ----------------------------------------------
-
/**
* Get the unique client id for a connected client based on connection
* parameters.
@@ -110,87 +106,79 @@
* than depending on developers to maintain a convention of checking for
* key expiration before use in other modules.
*/
- public String getClientId() throws KeyExpiryException
- {
+ public String getClientId() throws KeyExpiryException {
checkExpiry();
+
return clientId;
}
-
-
+
/**
* Gets the clients socket connection.
- *
+ *
* @return the client's socket connection
*/
- public Socket getSocket() throws KeyExpiryException
- {
+ public Socket getSocket() throws KeyExpiryException {
checkExpiry();
+
return socket;
}
-
/**
* Gets the client's IP address.
*
* @return the client's ip address.
* @throws KeyExpiryException to force the handling of expired keys
*/
- public String getClientAddress() throws KeyExpiryException
- {
+ public String getClientAddress() throws KeyExpiryException {
checkExpiry();
+
return socket.getInetAddress().getHostAddress();
}
-
/**
* Gets the client's hostname.
*
* @return the client's hostname.
* @throws KeyExpiryException to force the handling of expired keys
*/
- public String getClientHost() throws KeyExpiryException
- {
+ public String getClientHost() throws KeyExpiryException {
checkExpiry();
+
return socket.getInetAddress().getHostName();
}
-
// ----------------------------------------------
// ClientKey lock object accessors.
// ----------------------------------------------
-
/**
* Gets the client's output stream lock object.
*
* @return ouput lock object.
* @throws KeyExpiryException to force the handling of expired keys
*/
- public Object getOutputLock() throws KeyExpiryException
- {
+ public Object getOutputLock() throws KeyExpiryException {
checkExpiry();
+
return outputLock;
}
-
/**
* Gets the client's input stream lock object.
*
* @return input lock object.
* @throws KeyExpiryException to force the handling of expired keys
*/
- public Object getInputLock() throws KeyExpiryException
- {
+ public Object getInputLock() throws KeyExpiryException {
checkExpiry();
+
return inputLock;
}
-
// ----------------------------------------------
// Key expiration methods.
// ----------------------------------------------
-
/**
* Determines if the client represented by this ClientKey is still
* connected to the server. Once disconnected the ClientKey is expired
@@ -199,29 +187,24 @@
* @return true if the client is no longer connected to the server, false
* if the client is connected.
*/
- public boolean hasExpired()
- {
+ public boolean hasExpired() {
return hasExpired;
}
-
/**
* Expires this key to indicate the disconnection of the client represented
* by this key from the server. It is intentionally package friendly to
* only allow access by the ClientModule. Tries to close socket if it is
* still open.
*/
- void expire() throws IOException
- {
+ void expire() throws IOException {
hasExpired = true;
-
- if ( null != socket )
- {
+
+ if (null != socket) {
socket.close();
}
}
-
/**
* Utility method to throw key expiration exception if this ClientKey has
* expired. This method is called by most accessor methods within this
@@ -229,48 +212,40 @@
* purpose for this is to force ClientKey using modules to check for
* expiration rather rely upon them to check to see if the key is valid
* before use everytime.
- *
+ *
* @throws KeyExpiryException to force the handling of expired keys rather
* than depending on developers to maintain a convention of checking for
* key expiration before use in other modules.
*/
- void checkExpiry() throws KeyExpiryException
- {
- if( hasExpired )
- {
- throw new KeyExpiryException( this );
+ void checkExpiry() throws KeyExpiryException {
+ if (hasExpired) {
+ throw new KeyExpiryException(this);
}
}
-
// ----------------------------------------------
// Class java.lang.Object method overrides.
// ----------------------------------------------
-
/**
* For debugging returns the clientId string.
*
* @return the client id string.
*/
- public String toString()
- {
+ public String toString() {
return clientId;
}
-
/**
* Gets the hashCode of the unique clientId String. Overriden to correctly
* manage ClientKey's within Map based collections.
*
* @return the clientId hashCode value.
*/
- public int hashCode()
- {
+ public int hashCode() {
return clientId.hashCode();
}
-
/**
* Determines whether this ClientKey is equivalent to another. If argument
* object is not the same reference the clientId String's are compared
using
@@ -281,23 +256,15 @@
*
* @return true if an_obj equals this ClientKey, false otherwise.
*/
- public boolean equals( Object an_obj )
- {
- if( this == an_obj )
- {
+ public boolean equals(Object an_obj) {
+ if (this == an_obj) {
return true;
- }
- else if( an_obj instanceof String )
- {
- return clientId.equals( an_obj );
- }
- else if( an_obj instanceof ClientKey )
- {
- return ( ( ClientKey ) an_obj ).clientId.equals( clientId );
- }
- else
- {
- return clientId.equals( an_obj.toString() );
+ } else if (an_obj instanceof String) {
+ return clientId.equals(an_obj);
+ } else if (an_obj instanceof ClientKey) {
+ return ((ClientKey) an_obj).clientId.equals(clientId);
+ } else {
+ return clientId.equals(an_obj.toString());
}
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/KeyExpiryException.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/KeyExpiryException.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/KeyExpiryException.java
Mon Oct 11 02:16:38 2004
@@ -16,54 +16,47 @@
*/
package org.apache.seda.listener;
-
import java.io.IOException;
/**
* An exception that is raised when the accessor methods on an expired
ClientKey
* are used.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class KeyExpiryException extends IOException
-{
+public class KeyExpiryException extends IOException {
/** the key that caused this exception by being accessed after expiring */
private final ClientKey key;
-
- /**
+
+ /**
* Constructs an Exception without a message.
- *
+ *
* @param key the unique key for the client which expired.
*/
- public KeyExpiryException( ClientKey key )
- {
+ public KeyExpiryException(ClientKey key) {
super();
this.key = key;
}
-
/**
* Constructs an Exception with a detailed message.
- *
+ *
* @param key the unique key for the client which expired.
* @param message The message associated with the exception.
*/
- public KeyExpiryException( ClientKey key, String message )
- {
- super( message );
+ public KeyExpiryException(ClientKey key, String message) {
+ super(message);
this.key = key;
}
-
/**
* Gets the expired key which caused this exception when it was accessed.
- *
+ *
* @return the expired ClientKey.
*/
- public ClientKey getClientKey()
- {
+ public ClientKey getClientKey() {
return key;
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerConfig.java
Mon Oct 11 02:16:38 2004
@@ -17,26 +17,22 @@
package org.apache.seda.listener;
-
-
-
/**
* A server listener configuration interface.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public abstract class ListenerConfig
-{
+public abstract class ListenerConfig {
/**
* Empty default constructor.
*/
- protected ListenerConfig() {
- }
+ protected ListenerConfig() {
+ }
/**
* Gets the URI for this ListenerConfig using the specified ip address and
- * the tcp port number listened to. The ipaddress is resolved to a host
+ * the tcp port number listened to. The ipaddress is resolved to a host
* name.
*
* @return the URI with scheme like so ldap://localhost:389
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManager.java
Mon Oct 11 02:16:38 2004
@@ -16,31 +16,29 @@
*/
package org.apache.seda.listener;
-
import java.io.IOException;
/**
* Manages a set of server listeners.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author$
* @version $Rev$
*/
-public interface ListenerManager
-{
+public interface ListenerManager {
/**
* Binds and registers a server listener.
- *
+ *
* @param listenerConfig the listener to register and bind
*/
- public void bind( ListenerConfig listenerConfig ) throws IOException;
-
+ public void bind(ListenerConfig listenerConfig) throws IOException;
+
/**
* Unbinds and unregisters a server listener.
- *
+ *
* @param listenerConfig the listener to unregister and unbind
* @throws IOException if there is a problem unbinding a listener
*/
- public void unbind( ListenerConfig listenerConfig ) throws IOException;
+ public void unbind(ListenerConfig listenerConfig) throws IOException;
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,15 +16,15 @@
*/
package org.apache.seda.listener;
-
import java.io.IOException;
-import java.nio.channels.Selector;
+
import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
/**
* Used to monitor the activities of a ListenerManager.
- *
+ *
* @todo why the heck does this interface references to an implementation
object
* like a Selector?
*
@@ -32,13 +32,12 @@
* @author $Author$
* @version $Rev$
*/
-public interface ListenerManagerMonitor
-{
+public interface ListenerManagerMonitor {
/**
* Monitors when the ListnenerManager starts.
*/
void started();
-
+
/**
* Monitors when the ListnenerManager stops.
*/
@@ -46,83 +45,83 @@
/**
* Monitors bind occurences.
- *
+ *
* @param listenerConfig the listener just bound to a port
*/
- void bindOccured( ListenerConfig listenerConfig );
-
+ void bindOccured(ListenerConfig listenerConfig);
+
/**
* Monitors unbind occurences.
- *
+ *
* @param listenerConfig the listener just unbound from a port
*/
- void unbindOccured( ListenerConfig listenerConfig );
-
+ void unbindOccured(ListenerConfig listenerConfig);
+
/**
* Monitors the occurrence of successful socket accept attempts
- *
+ *
* @param key
*/
- void acceptOccured( SelectionKey key );
-
+ void acceptOccured(SelectionKey key);
+
/**
* Monitors the occurrence of successful select calls on a selector
- *
+ *
* @param selector
*/
- void selectOccured( Selector selector );
-
+ void selectOccured(Selector selector);
+
/**
* Monitors the occurrence of successful select timeouts on a selector
- *
+ *
* @param selector
*/
- void selectTimedOut( Selector selector );
-
+ void selectTimedOut(Selector selector);
+
/**
* Monitors bind failures.
- *
+ *
* @param listenerConfig the listener whose bind attempt failed
* @param failure the exception resulting from the failure
*/
- void failedToBind( ListenerConfig listenerConfig, IOException failure );
-
+ void failedToBind(ListenerConfig listenerConfig, IOException failure);
+
/**
* Monitors unbind failures.
- *
+ *
* @param listenerConfig the listener whose unbind attempt failed
* @param failure the exception resulting from the failure
*/
- void failedToUnbind( ListenerConfig listenerConfig, IOException failure );
-
+ void failedToUnbind(ListenerConfig listenerConfig, IOException failure);
+
/**
* Monitors expiration failures on client keys.
- *
+ *
* @param key the client key that caused the failure
* @param failure the exception resulting from the failure
*/
- void failedToExpire( ClientKey key, IOException failure );
-
+ void failedToExpire(ClientKey key, IOException failure);
+
/**
* Monitors accept failures on socket channels.
- *
+ *
* @param key the selector key associated with the channel
* @param failure the exception resulting from the failure
*/
- void failedToAccept( SelectionKey key, IOException failure );
-
+ void failedToAccept(SelectionKey key, IOException failure);
+
/**
* Monitors select failures on a selector.
- *
+ *
* @param selector the selector on which the select failed
* @param failure the exception resulting from the failure
*/
- void failedToSelect( Selector selector, IOException failure );
-
+ void failedToSelect(Selector selector, IOException failure);
+
/**
* 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);
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/ListenerManagerMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -1,102 +1,87 @@
-/*
- * 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.listener;
-
-import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-import java.io.IOException;
-
-/**
- * An null do nothing adapter for the listener manager.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
- * @version $Rev$
- */
-public class ListenerManagerMonitorAdapter implements ListenerManagerMonitor
-{
- public void started()
- {
- }
-
- public void stopped()
- {
- }
-
- public void bindOccured( ListenerConfig listenerConfig )
- {
- }
-
- public void unbindOccured( ListenerConfig listenerConfig )
- {
- }
-
- public void acceptOccured( SelectionKey key )
- {
- }
-
- public void selectOccured( Selector selector )
- {
- }
-
- public void selectTimedOut( Selector selector )
- {
- }
-
- public void failedToBind( ListenerConfig listenerConfig, IOException
failure )
- {
- if ( failure != null )
- {
- failure.printStackTrace();
- }
- }
-
- public void failedToUnbind( ListenerConfig listenerConfig, IOException
failure )
- {
- if ( failure != null )
- {
- failure.printStackTrace();
- }
- }
-
- public void failedToExpire( ClientKey key, IOException failure )
- {
- if ( failure != null )
- {
- failure.printStackTrace();
- }
- }
-
- public void failedToAccept( SelectionKey key, IOException failure )
- {
- if ( failure != null )
- {
- failure.printStackTrace();
- }
- }
-
- public void failedToSelect( Selector selector, IOException failure )
- {
- if ( failure != null )
- {
- failure.printStackTrace();
- }
- }
-
- public void enteringSelect( Selector selector )
- {
- }
-}
+/*
+ * 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.listener;
+
+import java.io.IOException;
+
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+
+
+/**
+ * An null do nothing adapter for the listener manager.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class ListenerManagerMonitorAdapter implements ListenerManagerMonitor {
+ public void started() {
+ }
+
+ public void stopped() {
+ }
+
+ public void bindOccured(ListenerConfig listenerConfig) {
+ }
+
+ public void unbindOccured(ListenerConfig listenerConfig) {
+ }
+
+ public void acceptOccured(SelectionKey key) {
+ }
+
+ public void selectOccured(Selector selector) {
+ }
+
+ public void selectTimedOut(Selector selector) {
+ }
+
+ public void failedToBind(ListenerConfig listenerConfig, IOException
failure) {
+ if (failure != null) {
+ failure.printStackTrace();
+ }
+ }
+
+ public void failedToUnbind(ListenerConfig listenerConfig,
+ IOException failure
+ ) {
+ if (failure != null) {
+ failure.printStackTrace();
+ }
+ }
+
+ public void failedToExpire(ClientKey key, IOException failure) {
+ if (failure != null) {
+ failure.printStackTrace();
+ }
+ }
+
+ public void failedToAccept(SelectionKey key, IOException failure) {
+ if (failure != null) {
+ failure.printStackTrace();
+ }
+ }
+
+ public void failedToSelect(Selector selector, IOException failure) {
+ if (failure != null) {
+ failure.printStackTrace();
+ }
+ }
+
+ public void enteringSelect(Selector selector) {
+ }
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/SocketListenerConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/SocketListenerConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/SocketListenerConfig.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.listener;
-
import org.apache.seda.protocol.InetServiceEntry;
import java.net.InetAddress;
@@ -28,14 +27,13 @@
* @author <a href="mailto:[EMAIL PROTECTED]"> Apache Directory Project</a>
* @version $Rev$
*/
-public class SocketListenerConfig extends ListenerConfig
-{
+public class SocketListenerConfig extends ListenerConfig {
/** the InetAddress associated with this server socket configuration */
private final InetAddress inetAddress;
+
/** the service entry in the inet service database */
private final InetServiceEntry servEnt;
-
/**
* Creates a socket listener config with all the supplied properties.
*
@@ -43,45 +41,40 @@
* @param servEnt the inet service entry for the service this listner
* provides
*/
- public SocketListenerConfig( InetAddress inetAddress, InetServiceEntry
servEnt )
- {
+ public SocketListenerConfig(InetAddress inetAddress,
+ InetServiceEntry servEnt
+ ) {
this.servEnt = servEnt;
this.inetAddress = inetAddress;
}
-
/**
* Gets the InetAddress associated with this server socket configuration.
*
* @return the address for the server socket associated with this config
*/
- public InetAddress getInetAddress()
- {
+ public InetAddress getInetAddress() {
return inetAddress;
}
-
/**
* Gets the service entry in the inet service database associated with
* this server socket configuration.
*
* @return the service entry in the inet service database
*/
- public InetServiceEntry getInetServiceEntry()
- {
+ public InetServiceEntry getInetServiceEntry() {
return servEnt;
}
-
- public String getURI()
- {
+ public String getURI() {
StringBuffer l_buf = new StringBuffer();
- l_buf.append( servEnt.getName() );
- l_buf.append( "://" );
- l_buf.append( inetAddress );
- l_buf.append( ':' );
- l_buf.append( servEnt.getPort() );
+ l_buf.append(servEnt.getName());
+ l_buf.append("://");
+ l_buf.append(inetAddress);
+ l_buf.append(':');
+ l_buf.append(servEnt.getPort());
return l_buf.toString();
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerConfig.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.listener;
-
import org.apache.seda.protocol.InetServiceEntry;
import java.net.InetAddress;
@@ -29,38 +28,32 @@
* @author $LastChangedBy$
* @version $LastChangedRevision$
*/
-public class TCPListenerConfig extends SocketListenerConfig
-{
+public class TCPListenerConfig extends SocketListenerConfig {
/** the connection backlog */
private int backlog;
/**
* Creates a default listener with all the supplied properties.
- *
+ *
* @param inetAddress the inetAddress for the server listener
* @param servEnt the inet service entry for the service this listner
* provides
*/
- public TCPListenerConfig( InetAddress inetAddress, InetServiceEntry
servEnt )
- {
- super( inetAddress, servEnt );
+ public TCPListenerConfig(InetAddress inetAddress, InetServiceEntry
servEnt) {
+ super(inetAddress, servEnt);
}
-
-
+
/* (non-Javadoc)
* @see org.apache.seda.listener.ServerListener#getBacklog()
*/
- public int getBacklog()
- {
+ public int getBacklog() {
return this.backlog;
}
/**
* @param a_backlog The backlog to set.
*/
- protected void setBacklog( int a_backlog )
- {
+ protected void setBacklog(int a_backlog) {
this.backlog = a_backlog;
}
}
-
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/TCPListenerManager.java
Mon Oct 11 02:16:38 2004
@@ -16,14 +16,18 @@
*/
package org.apache.seda.listener;
+import org.apache.seda.EventRouter;
import java.io.IOException;
+
import java.net.InetSocketAddress;
import java.net.Socket;
+
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
+
import java.util.EventObject;
import java.util.HashMap;
import java.util.HashSet;
@@ -31,126 +35,119 @@
import java.util.Map;
import java.util.Set;
-import org.apache.seda.EventRouter;
-
/**
* A listener manager that uses non-blocking NIO based constructs to detect
* client connections on server socket listeners.
- *
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class TCPListenerManager
- implements
- DisconnectSubscriber,
- ProtocolSubscriber,
- ListenerManager,
- Runnable
-{
+public class TCPListenerManager implements DisconnectSubscriber,
+ ProtocolSubscriber, ListenerManager,
+ Runnable {
/** event manager used to decouple source to sink relationships */
private final EventRouter router;
+
/** selector used to select a acceptable socket channel */
private final Selector selector;
+
/** a map of auth service names to their protocol providers */
private final Map protocols;
+
/** the client keys for accepted connections */
private final Set clients;
+
/** the set of listeners managed */
private final Set listeners;
+
/** new listeners waiting to be bound */
private final Set bindListeners;
+
/** old listeners waiting to be unbound */
private final Set unbindListeners;
-
- /** the thread driving this Runnable */
+
+ /** the thread driving this Runnable */
private Thread thread = null;
+
/** parameter used to politely stop running thread */
private Boolean hasStarted = null;
+
/** the listner manager's monitor */
private ListenerManagerMonitor monitor = null;
-
-
+
/**
* Creates a default listener manager using an event router.
- *
+ *
* @param router the router to publish events to
* @throws IOException
*/
- public TCPListenerManager( EventRouter router ) throws IOException
- {
+ public TCPListenerManager(EventRouter router) throws IOException {
this.router = router;
this.clients = new HashSet();
this.selector = Selector.open();
this.protocols = new HashMap();
this.listeners = new HashSet();
- this.hasStarted = new Boolean( false );
+ this.hasStarted = new Boolean(false);
this.bindListeners = new HashSet();
this.unbindListeners = new HashSet();
-
- this.router.subscribe( DisconnectEvent.class, null, this );
+
+ this.router.subscribe(DisconnectEvent.class, null, this);
this.monitor = new ListenerManagerMonitorAdapter();
}
-
-
+
/**
* Gets the monitor.
- *
+ *
* @return Returns the monitor.
*/
- public ListenerManagerMonitor getMonitor()
- {
+ public ListenerManagerMonitor getMonitor() {
return monitor;
}
-
/**
* Sets the monitor.
- *
+ *
* @param monitor The monitor to set.
*/
- public void setMonitor( ListenerManagerMonitor monitor )
- {
+ public void setMonitor(ListenerManagerMonitor monitor) {
this.monitor = monitor;
}
-
/**
* @see org.apache.seda.listener.ListenerManager#bind(ListenerConfig)
*/
- public void bind( ListenerConfig listener ) throws IOException
- {
+ public void bind(ListenerConfig listener) throws IOException {
ensureListenerConfigType(listener);
- synchronized ( bindListeners )
- {
- bindListeners.add( listener );
+ synchronized (bindListeners) {
+ bindListeners.add(listener);
}
-
+
selector.wakeup();
}
-
-
+
/**
* @see org.apache.seda.listener.ListenerManager#unbind(ListenerConfig)
*/
- public void unbind( ListenerConfig listener ) throws IOException
- {
+ public void unbind(ListenerConfig listener) throws IOException {
ensureListenerConfigType(listener);
- synchronized ( unbindListeners )
- {
- unbindListeners.add( listener );
+ synchronized (unbindListeners) {
+ unbindListeners.add(listener);
}
selector.wakeup();
}
private void ensureListenerConfigType(ListenerConfig listener) {
- if (listener == null)
+ if (listener == null) {
throw new NullPointerException();
- if (!(listener instanceof TCPListenerConfig))
+ }
+
+ if (!(listener instanceof TCPListenerConfig)) {
throw new IllegalArgumentException();
+ }
}
/**
@@ -158,283 +155,233 @@
* This is not fail fast - meaning it will try all the connections in the
* ready to bind set even if one fails.
*/
- private void bind()
- {
- synchronized ( bindListeners )
- {
+ private void bind() {
+ synchronized (bindListeners) {
Iterator list = bindListeners.iterator();
- while ( list.hasNext() )
- {
- TCPListenerConfig listener =
- ( TCPListenerConfig ) list.next();
-
- try
- {
+
+ while (list.hasNext()) {
+ TCPListenerConfig listener = (TCPListenerConfig) list.next();
+
+ try {
ServerSocketChannel channel = ServerSocketChannel.open();
InetSocketAddress address =
- new InetSocketAddress(
- listener.getInetAddress(),
- listener.getInetServiceEntry().getPort() );
- channel.socket().bind( address, listener.getBacklog() );
- channel.configureBlocking( false );
- channel.register( selector, SelectionKey.OP_ACCEPT,
- listener );
-
- synchronized ( listeners )
- {
- listeners.add( listener );
+ new InetSocketAddress(listener.getInetAddress(),
+ listener.getInetServiceEntry()
+ .getPort()
+ );
+ channel.socket().bind(address, listener.getBacklog());
+ channel.configureBlocking(false);
+ channel.register(selector, SelectionKey.OP_ACCEPT,
listener);
+
+ synchronized (listeners) {
+ listeners.add(listener);
}
-
- bindListeners.remove( listener );
- }
- catch ( IOException e )
- {
- monitor.failedToBind( listener, e );
+
+ bindListeners.remove(listener);
+ } catch (IOException e) {
+ monitor.failedToBind(listener, e);
}
-
- monitor.bindOccured( listener );
+
+ monitor.bindOccured(listener);
}
}
}
-
-
+
/**
* Unbinds listeners that have been collecting up waiting to be unbound.
* This is not fail fast - meaning it will try all the connections in the
* ready to unbind set even if one fails.
*/
- private void unbind()
- {
+ private void unbind() {
SelectionKey key = null;
-
- synchronized ( unbindListeners )
- {
+
+ synchronized (unbindListeners) {
Iterator keys = selector.keys().iterator();
- while ( keys.hasNext() )
- {
- key = ( SelectionKey ) keys.next();
- ListenerConfig listener =
- ( ListenerConfig ) key.attachment();
-
- if ( unbindListeners.contains( listener ) )
- {
- try
- {
+
+ while (keys.hasNext()) {
+ key = (SelectionKey) keys.next();
+
+ ListenerConfig listener = (ListenerConfig) key.attachment();
+
+ if (unbindListeners.contains(listener)) {
+ try {
key.channel().close();
+ } catch (IOException e) {
+ monitor.failedToUnbind(listener, e);
}
- catch ( IOException e )
- {
- monitor.failedToUnbind( listener, e );
- }
-
+
key.cancel();
-
- synchronized ( listeners )
- {
- listeners.remove( listener );
+
+ synchronized (listeners) {
+ listeners.remove(listener);
}
-
- unbindListeners.remove( listener );
- monitor.unbindOccured( listener );
+
+ unbindListeners.remove(listener);
+ monitor.unbindOccured(listener);
}
}
}
}
-
// ------------------------------------------------------------------------
// DisconnectSubscriber Implementation
// ------------------------------------------------------------------------
-
-
+
/**
* Disconnects a client by removing the clientKey from the listener.
- *
+ *
* @param event the disconnect event
*/
- public void inform( DisconnectEvent event )
- {
- clients.remove( event.getClientKey() );
-
- try
- {
+ public void inform(DisconnectEvent event) {
+ clients.remove(event.getClientKey());
+
+ try {
event.getClientKey().expire();
- }
- catch ( IOException e )
- {
- monitor.failedToExpire( event.getClientKey(), e );
+ } catch (IOException e) {
+ monitor.failedToExpire(event.getClientKey(), e);
}
}
-
-
+
/*
* (non-Javadoc)
* @see org.apache.seda.event.Subscriber#inform(java.util.EventObject)
*/
- public void inform( EventObject event )
- {
- inform( ( DisconnectEvent ) event );
+ public void inform(EventObject event) {
+ inform((DisconnectEvent) event);
}
-
/**
* 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) {
}
-
// ------------------------------------------------------------------------
// Runnable implementation and start/stop controls
// ------------------------------------------------------------------------
-
-
+
/**
* @see java.lang.Runnable#run()
*/
- public void run()
- {
- while ( hasStarted.booleanValue() )
- {
- try
- {
- monitor.enteringSelect( selector );
-
+ public void run() {
+ while (hasStarted.booleanValue()) {
+ try {
+ monitor.enteringSelect(selector);
+
bind();
unbind();
-
- if ( 0 == selector.select() )
- {
- monitor.selectTimedOut( selector );
+
+ if (0 == selector.select()) {
+ monitor.selectTimedOut(selector);
+
continue;
}
- }
- catch( IOException e )
- {
- monitor.failedToSelect( selector, e );
+ } catch (IOException e) {
+ monitor.failedToSelect(selector, e);
+
continue;
}
-
-
+
Iterator list = selector.selectedKeys().iterator();
- while ( list.hasNext() )
- {
- SelectionKey key = ( SelectionKey ) list.next();
-
- if ( key.isAcceptable() )
- {
+
+ while (list.hasNext()) {
+ SelectionKey key = (SelectionKey) list.next();
+
+ if (key.isAcceptable()) {
SocketChannel channel = null;
- ServerSocketChannel server = ( ServerSocketChannel )
- key.channel();
-
- try
- {
+ ServerSocketChannel server =
+ (ServerSocketChannel) key.channel();
+
+ try {
channel = server.accept();
list.remove();
- monitor.acceptOccured( key );
- }
- catch ( IOException e )
- {
- monitor.failedToAccept( key, e );
+ monitor.acceptOccured(key);
+ } catch (IOException e) {
+ monitor.failedToAccept(key, e);
+
continue;
}
-
- ClientKey clientKey = new ClientKey( channel.socket() );
- ConnectEvent event = new ConnectEvent( this, clientKey );
- router.publish( event );
+
+ ClientKey clientKey = new ClientKey(channel.socket());
+ ConnectEvent event = new ConnectEvent(this, clientKey);
+ router.publish(event);
}
}
}
}
-
-
+
/**
* Starts up this ListnerManager service.
- *
+ *
* @throws IllegalStateException if this service has already started
*/
- public void start()
- {
- if ( hasStarted.booleanValue() )
- {
- throw new IllegalStateException( "Already started!" );
- }
-
- hasStarted = new Boolean( true );
- thread = new Thread( this );
+ public void start() {
+ if (hasStarted.booleanValue()) {
+ throw new IllegalStateException("Already started!");
+ }
+
+ hasStarted = new Boolean(true);
+ thread = new Thread(this);
thread.start();
monitor.started();
}
-
-
+
/**
- * Gracefully stops this ListenerManager service. Blocks calling thread
+ * Gracefully stops this ListenerManager service. Blocks calling thread
* until the service has fully stopped.
- *
+ *
* @throws InterruptedException if this service's driver thread cannot
start
*/
- public void stop() throws InterruptedException
- {
- hasStarted = new Boolean( false );
+ public void stop() throws InterruptedException {
+ hasStarted = new Boolean(false);
selector.wakeup();
/*
* First lets shutdown the listeners so we're not open to having new
- * connections created while we are trying to shutdown. Plus we want
+ * connections created while we are trying to shutdown. Plus we want
* to make the thread for this component do the work to prevent locking
* issues with the selector.
*/
- if ( ! listeners.isEmpty() )
- {
+ if (!listeners.isEmpty()) {
Iterator list = listeners.iterator();
- while( list.hasNext() )
- {
- ListenerConfig listener =
- ( ListenerConfig ) list.next();
-
- try
- {
+
+ while (list.hasNext()) {
+ ListenerConfig listener = (ListenerConfig) list.next();
+
+ try {
/*
* put the listening in the set ready to be unbound by
* the runnable's thread of execution
*/
- unbind( listener );
- }
- catch( IOException e )
- {
+ unbind(listener);
+ } catch (IOException e) {
// monitor.doSomthing( e );
e.printStackTrace();
}
}
}
-
+
/*
- * Now we gracefully disconnect the clients that are already connected
- * so they can complete their current requests and recieve a
- * notification of disconnect. At this point we don't know how we're
+ * Now we gracefully disconnect the clients that are already connected
+ * so they can complete their current requests and recieve a
+ * notification of disconnect. At this point we don't know how we're
* going to do that so we just do it abruptly for the time being. This
- * will need to be changed in the future.
+ * will need to be changed in the future.
*/
- if ( ! clients.isEmpty() )
- {
- synchronized( clients )
- {
+ if (!clients.isEmpty()) {
+ synchronized (clients) {
Iterator list = clients.iterator();
- while ( list.hasNext() )
- {
- ClientKey key = ( ClientKey ) list.next();
-
- try
- {
+
+ while (list.hasNext()) {
+ ClientKey key = (ClientKey) list.next();
+
+ try {
Socket socket = key.getSocket();
socket.close();
list.remove();
- }
- catch( IOException e )
- {
+ } catch (IOException e) {
// monitor.doSomthing( e );
e.printStackTrace();
}
@@ -445,9 +392,8 @@
/*
* now wait until the thread of execution for this runnable dies
*/
- if ( this.thread.isAlive() )
- {
- Thread.sleep( 100 );
+ if (this.thread.isAlive()) {
+ Thread.sleep(100);
selector.wakeup();
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/UDPListenerConfig.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/UDPListenerConfig.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/listener/UDPListenerConfig.java
Mon Oct 11 02:16:38 2004
@@ -20,6 +20,7 @@
import java.net.InetAddress;
+
/**
* A default server listener.
*
@@ -27,8 +28,7 @@
* @author $LastChangedBy$
* @version $LastChangedRevision$
*/
-public class UDPListenerConfig extends SocketListenerConfig
-{
+public class UDPListenerConfig extends SocketListenerConfig {
/**
* Creates a default listener with all the supplied properties.
*
@@ -36,8 +36,7 @@
* @param servEnt the inet service entry for the service this listner
* provides
*/
- public UDPListenerConfig( InetAddress a_address, InetServiceEntry servEnt )
- {
- super(a_address, servEnt);
+ public UDPListenerConfig(InetAddress a_address, InetServiceEntry servEnt) {
+ super(a_address, servEnt);
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/DefaultOutputManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/DefaultOutputManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/DefaultOutputManager.java
Mon Oct 11 02:16:38 2004
@@ -16,31 +16,30 @@
*/
package org.apache.seda.output;
-
-import java.io.IOException;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.EventObject;
-
import org.apache.seda.EventRouter;
import org.apache.seda.StageHandler;
+import org.apache.seda.event.AbstractSubscriber;
+import org.apache.seda.event.ConnectEvent;
+import org.apache.seda.event.ConnectSubscriber;
+import org.apache.seda.event.DisconnectEvent;
+import org.apache.seda.event.DisconnectSubscriber;
import org.apache.seda.event.OutputEvent;
+import org.apache.seda.event.OutputSubscriber;
import org.apache.seda.impl.DefaultStage;
import org.apache.seda.impl.DefaultStageConfig;
import org.apache.seda.impl.util.LoggingStageMonitor;
import org.apache.seda.listener.ClientKey;
-import org.apache.seda.event.ConnectEvent;
-import org.apache.seda.event.DisconnectEvent;
-import org.apache.seda.event.OutputSubscriber;
-import org.apache.seda.event.ConnectSubscriber;
-import org.apache.seda.event.AbstractSubscriber;
-import org.apache.seda.event.DisconnectSubscriber;
import org.apache.seda.listener.KeyExpiryException;
+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;
+
/**
* The default OutputManager implementation.
@@ -48,183 +47,149 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
* @version $Rev$
*/
-public class DefaultOutputManager extends DefaultStage
- implements
- OutputManager,
- OutputSubscriber,
- ConnectSubscriber,
- DisconnectSubscriber
-{
+public class DefaultOutputManager 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 DefaultOutputManager( EventRouter router, DefaultStageConfig config
)
- {
- super( config );
+ public DefaultOutputManager(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) {
ClientKey key = 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( DefaultOutputManager.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(DefaultOutputManager.this,
+ event.getClientKey(), e
+ );
}
}
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/LoggingOutputMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/LoggingOutputMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/LoggingOutputMonitor.java
Mon Oct 11 02:16:38 2004
@@ -16,17 +16,16 @@
*/
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;
+import java.util.EventObject;
+
/**
* A logging monitor for any OutputManager.
@@ -34,119 +33,96 @@
* @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/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputManager.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputManager.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputManager.java
Mon Oct 11 02:16:38 2004
@@ -1,43 +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.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 org.apache.seda.listener.ClientKey;
+
+import java.io.IOException;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * 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;
+}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitor.java
Mon Oct 11 02:16:38 2004
@@ -1,108 +1,106 @@
-/*
- * 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 org.apache.seda.event.ConnectEvent;
+import org.apache.seda.event.DisconnectEvent;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
+
+import java.util.EventObject;
+
+
+/**
+ * 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/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/output/OutputMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,116 +16,96 @@
*/
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;
+import java.util.EventObject;
+
/**
* 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/DefaultInetServicesDatabase.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.protocol;
-
import java.util.*;
@@ -26,108 +25,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 +128,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 +146,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 +161,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 +173,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 +184,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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/HandlerTypeEnum.java
Mon Oct 11 02:16:38 2004
@@ -1,61 +1,61 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServiceEntry.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServiceEntry.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServiceEntry.java
Mon Oct 11 02:16:38 2004
@@ -1,144 +1,129 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServicesDatabase.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServicesDatabase.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/InetServicesDatabase.java
Mon Oct 11 02:16:38 2004
@@ -1,76 +1,74 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ManyReplyHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ManyReplyHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ManyReplyHandler.java
Mon Oct 11 02:16:38 2004
@@ -1,48 +1,46 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/NoReplyHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/NoReplyHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/NoReplyHandler.java
Mon Oct 11 02:16:38 2004
@@ -1,36 +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;
-
-
-/**
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ProtocolProvider.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ProtocolProvider.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/ProtocolProvider.java
Mon Oct 11 02:16:38 2004
@@ -16,7 +16,6 @@
*/
package org.apache.seda.protocol;
-
import org.apache.commons.codec.stateful.DecoderFactory;
import org.apache.commons.codec.stateful.EncoderFactory;
@@ -27,8 +26,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 +37,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 +56,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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestHandler.java
Mon Oct 11 02:16:38 2004
@@ -1,34 +1,33 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessor.java
Mon Oct 11 02:16:38 2004
@@ -1,29 +1,28 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitor.java
Mon Oct 11 02:16:38 2004
@@ -1,56 +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.protocol;
-
-
-import java.util.EventObject;
-
-import org.apache.seda.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 org.apache.seda.Subscriber;
+import org.apache.seda.listener.ClientKey;
+import org.apache.seda.listener.KeyExpiryException;
+
+import java.util.EventObject;
+
+
+/**
+ * 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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/RequestProcessorMonitorAdapter.java
Mon Oct 11 02:16:38 2004
@@ -16,13 +16,12 @@
*/
package org.apache.seda.protocol;
-
-import java.util.EventObject;
-
import org.apache.seda.Subscriber;
import org.apache.seda.listener.ClientKey;
import org.apache.seda.listener.KeyExpiryException;
+import java.util.EventObject;
+
/**
* A convenient adapter for request processors monitors. Exceptional
conditions
@@ -31,41 +30,32 @@
* @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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/SingleReplyHandler.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/SingleReplyHandler.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/SingleReplyHandler.java
Mon Oct 11 02:16:38 2004
@@ -1,37 +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.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/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/TransportTypeEnum.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/TransportTypeEnum.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/protocol/TransportTypeEnum.java
Mon Oct 11 02:16:38 2004
@@ -1,59 +1,59 @@
-/*
- * 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/branches/trustin_api_redesign/src/java/org/apache/seda/session/ByteIoSession.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/ByteIoSession.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/ByteIoSession.java
Mon Oct 11 02:16:38 2004
@@ -18,12 +18,12 @@
import org.apache.seda.Session;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public interface ByteIoSession extends Session {
-
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatefulSession.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatefulSession.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatefulSession.java
Mon Oct 11 02:16:38 2004
@@ -18,12 +18,13 @@
import org.apache.seda.Session;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public interface StatefulSession extends Session {
- boolean isConnected();
+ boolean isConnected();
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatelessSession.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatelessSession.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/session/StatelessSession.java
Mon Oct 11 02:16:38 2004
@@ -18,12 +18,12 @@
import org.apache.seda.Session;
+
/**
* TODO Insert type comment.
- *
+ *
* @author Trustin Lee ([EMAIL PROTECTED])
* @version $Rev$, $Date$
*/
public interface StatelessSession extends Session {
-
}
Modified:
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/thread/ThreadPool.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/thread/ThreadPool.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/java/org/apache/seda/thread/ThreadPool.java
Mon Oct 11 02:16:38 2004
@@ -23,13 +23,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/branches/trustin_api_redesign/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/DefaultFrontendFactoryTest.java
Mon Oct 11 02:16:38 2004
@@ -16,9 +16,10 @@
*/
package org.apache.seda;
-
import junit.framework.TestCase;
+
import org.apache.commons.net.EchoTCPClient;
+
import org.apache.seda.examples.EchoProtocolProvider;
import org.apache.seda.impl.DefaultFrontend;
import org.apache.seda.impl.DefaultFrontendFactory;
@@ -29,100 +30,95 @@
import org.apache.seda.protocol.InetServiceEntry;
import java.io.IOException;
+
import java.net.InetAddress;
/**
* Tests the correct operation of the default frontend factory.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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/branches/trustin_api_redesign/src/test/org/apache/seda/ProtocolTestCase.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/ProtocolTestCase.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/ProtocolTestCase.java
Mon Oct 11 02:16:38 2004
@@ -16,8 +16,6 @@
*/
package org.apache.seda;
-import java.net.InetAddress;
-
import junit.framework.TestCase;
import org.apache.seda.impl.DefaultFrontend;
@@ -29,59 +27,59 @@
import org.apache.seda.protocol.InetServiceEntry;
import org.apache.seda.protocol.ProtocolProvider;
+import java.net.InetAddress;
+
/**
* A test harness using the standalone default frontend hardwired using the
* DefaultFrontendFactory.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Apache Directory Project</a>
+ * @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/branches/trustin_api_redesign/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/buffer/DefaultBufferPoolTest.java
Mon Oct 11 02:16:38 2004
@@ -16,12 +16,11 @@
*/
package org.apache.seda.buffer;
-
-import java.nio.ByteBuffer;
+import junit.framework.TestCase;
import org.apache.seda.ResourceException;
-import junit.framework.TestCase;
+import java.nio.ByteBuffer;
/**
@@ -30,208 +29,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/branches/trustin_api_redesign/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/decoder/DefaultDecoderManagerTest.java
Mon Oct 11 02:16:38 2004
@@ -16,9 +16,7 @@
*/
package org.apache.seda.decoder;
-
-import java.util.EventObject;
-import java.util.Iterator;
+import junit.framework.TestCase;
import org.apache.seda.EventRouter;
import org.apache.seda.buffer.BufferPool;
@@ -30,12 +28,12 @@
import org.apache.seda.event.RequestSubscriber;
import org.apache.seda.impl.DefaultEventRouter;
import org.apache.seda.impl.DefaultStageConfig;
-
-import org.apache.seda.thread.ThreadPool;
-import org.apache.seda.protocol.InetServicesDatabase;
import org.apache.seda.protocol.InetServiceEntry;
+import org.apache.seda.protocol.InetServicesDatabase;
+import org.apache.seda.thread.ThreadPool;
-import junit.framework.TestCase;
+import java.util.EventObject;
+import java.util.Iterator;
/**
@@ -44,9 +42,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 +52,74 @@
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 +130,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/branches/trustin_api_redesign/src/test/org/apache/seda/event/AbstractSubscriberTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/AbstractSubscriberTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/AbstractSubscriberTest.java
Mon Oct 11 02:16:38 2004
@@ -16,13 +16,13 @@
*/
package org.apache.seda.event;
-
-import java.nio.ByteBuffer;
-import java.util.EventObject;
+import junit.framework.TestCase;
import org.apache.seda.listener.ClientKey;
-import junit.framework.TestCase;
+import java.nio.ByteBuffer;
+
+import java.util.EventObject;
/**
@@ -31,106 +31,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/branches/trustin_api_redesign/src/test/org/apache/seda/event/DefaultStageTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/DefaultStageTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/event/DefaultStageTest.java
Mon Oct 11 02:16:38 2004
@@ -16,19 +16,18 @@
*/
package org.apache.seda.event;
-
-import java.util.ArrayList;
-import java.util.EventObject;
+import junit.framework.TestCase;
import org.apache.seda.EnqueuePredicate;
import org.apache.seda.StageHandler;
-import org.apache.seda.thread.ThreadPool;
import org.apache.seda.impl.DefaultStage;
import org.apache.seda.impl.DefaultStageConfig;
import org.apache.seda.impl.util.LoggingStageMonitor;
import org.apache.seda.stage.*;
+import org.apache.seda.thread.ThreadPool;
-import junit.framework.TestCase;
+import java.util.ArrayList;
+import java.util.EventObject;
/**
@@ -37,23 +36,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;
@@ -61,90 +57,72 @@
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;
+ public void testAddPredicateDeny() throws Exception {
+ stage.addPredicate(new EnqueuePredicate() {
+ public boolean accept(EventObject event) {
+ return false;
+ }
}
- } );
-
- stage.enqueue( new EventObject( this ) );
+ );
+
+ 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/branches/trustin_api_redesign/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/examples/DiscardProtocolProviderTest.java
Mon Oct 11 02:16:38 2004
@@ -18,6 +18,7 @@
import org.apache.seda.ProtocolTestCase;
+
/**
* Document me.
*
@@ -25,16 +26,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/branches/trustin_api_redesign/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/AvailablePortFinderTest.java
Mon Oct 11 02:16:38 2004
@@ -16,9 +16,8 @@
*/
package org.apache.seda.listener;
-
-import junit.framework.TestCase;
import junit.framework.Assert;
+import junit.framework.TestCase;
/**
@@ -27,60 +26,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
- {
- finder.getAvailablePorts(
- 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( 10, 5 );
- Assert.fail( "IllegalArgumentException must be thrown." );
- }
- catch ( IllegalArgumentException e )
- {
+ try {
+ finder.getAvailablePorts(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(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/branches/trustin_api_redesign/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
==============================================================================
---
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
(original)
+++
incubator/directory/seda/branches/trustin_api_redesign/src/test/org/apache/seda/listener/TCPListenerManagerTest.java
Mon Oct 11 02:16:38 2004
@@ -16,13 +16,12 @@
*/
package org.apache.seda.listener;
+import junit.framework.TestCase;
import org.apache.seda.EventRouter;
import org.apache.seda.impl.DefaultEventRouter;
import org.apache.seda.protocol.InetServiceEntry;
-import junit.framework.TestCase;
-
import java.net.InetAddress;
@@ -32,68 +31,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);
}
}