You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2011/12/25 19:37:09 UTC
svn commit: r1224623 -
/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
Author: norman
Date: Sun Dec 25 18:37:09 2011
New Revision: 1224623
URL: http://svn.apache.org/viewvc?rev=1224623&view=rev
Log:
Make CommandDispatcher more easy to extend. This will be needed in IMAP later. See PROTOCOLS-73
Modified:
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
Modified: james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java?rev=1224623&r1=1224622&r2=1224623&view=diff
==============================================================================
--- james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java (original)
+++ james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java Sun Dec 25 18:37:09 2011
@@ -139,37 +139,10 @@ public class CommandDispatcher<Session e
try {
Request request = parseRequest(session, line);
- if (session.getLogger().isDebugEnabled()) {
- session.getLogger().debug(getClass().getName() + " received: " + request.getCommand());
+ if (request == null) {
+ return null;
}
- List<CommandHandler<Session>> commandHandlers = getCommandHandlers(request.getCommand(), session);
- // fetch the command handlers registered to the command
-
- Iterator<CommandHandler<Session>> handlers = commandHandlers.iterator();
-
- while (handlers.hasNext()) {
- final long start = System.currentTimeMillis();
- CommandHandler<Session> cHandler = handlers.next();
- Response response = cHandler.onCommand(session, request);
- if (response != null) {
- long executionTime = System.currentTimeMillis() - start;
-
- // now process the result handlers
- for (int a = 0; a < rHandlers.size(); a++) {
- // Disable till PROTOCOLS-37 is implemented
- if (response instanceof FutureResponse) {
- session.getLogger().debug("ProtocolHandlerResultHandler are not supported for FutureResponse yet");
- break;
- }
- response = rHandlers.get(a).onResponse(session, response, executionTime, (CommandHandler<Session>) cHandler);
- }
- }
- if (response != null) {
- return response;
- }
-
- }
- return null;
+ return dispatchCommandHandlers(session, request);
} catch (Exception e) {
session.getLogger().debug("Unable to parse request", e);
return session.newFatalErrorResponse();
@@ -177,6 +150,48 @@ public class CommandDispatcher<Session e
}
+
+ /**
+ * Dispatch the {@link CommandHandler}'s for the given {@link Request} and return a {@link Response} or <code>null</code> if non should get written
+ * back to the client
+ *
+ * @param session
+ * @param request
+ * @return response
+ */
+ protected Response dispatchCommandHandlers(Session session, Request request) {
+ if (session.getLogger().isDebugEnabled()) {
+ session.getLogger().debug(getClass().getName() + " received: " + request.getCommand());
+ }
+ List<CommandHandler<Session>> commandHandlers = getCommandHandlers(request.getCommand(), session);
+ // fetch the command handlers registered to the command
+
+ Iterator<CommandHandler<Session>> handlers = commandHandlers.iterator();
+
+ while (handlers.hasNext()) {
+ final long start = System.currentTimeMillis();
+ CommandHandler<Session> cHandler = handlers.next();
+ Response response = cHandler.onCommand(session, request);
+ if (response != null) {
+ long executionTime = System.currentTimeMillis() - start;
+
+ // now process the result handlers
+ for (int a = 0; a < rHandlers.size(); a++) {
+ // Disable till PROTOCOLS-37 is implemented
+ if (response instanceof FutureResponse) {
+ session.getLogger().debug("ProtocolHandlerResultHandler are not supported for FutureResponse yet");
+ break;
+ }
+ response = rHandlers.get(a).onResponse(session, response, executionTime, (CommandHandler<Session>) cHandler);
+ }
+ }
+ if (response != null) {
+ return response;
+ }
+
+ }
+ return null;
+ }
/**
* Parse the line into a {@link Request}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org