You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by tr...@apache.org on 2007/11/06 09:59:44 UTC
svn commit: r592337 [4/7] - in /mina/sandbox/asyncweb:
core/src/main/java/org/safehaus/asyncweb/codec/
core/src/main/java/org/safehaus/asyncweb/codec/decoder/
core/src/main/java/org/safehaus/asyncweb/codec/decoder/support/
core/src/main/java/org/safeha...
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ContainerLifecycleException.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ContainerLifecycleException.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ContainerLifecycleException.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ContainerLifecycleException.java Tue Nov 6 00:59:36 2007
@@ -22,31 +22,31 @@
/**
* Exception thrown when a problem is encountered whilst transitioning
* a <code>ServiceContainer</code> through its lifecycle
- *
+ *
* @author irvingd
*
*/
public class ContainerLifecycleException extends Exception {
- private static final long serialVersionUID = 3257564018624574256L;
+ private static final long serialVersionUID = 3257564018624574256L;
+
+ /**
+ * Constructs with a description of the problem
+ *
+ * @param desc description of the problem
+ */
+ public ContainerLifecycleException(String desc) {
+ super(desc);
+ }
+
+ /**
+ * Constructs with a description and a root cause
+ *
+ * @param desc description of the problem
+ * @param cause the root cause
+ */
+ public ContainerLifecycleException(String desc, Throwable cause) {
+ super(desc, cause);
+ }
- /**
- * Constructs with a description of the problem
- *
- * @param desc description of the problem
- */
- public ContainerLifecycleException(String desc) {
- super (desc);
- }
-
- /**
- * Constructs with a description and a root cause
- *
- * @param desc description of the problem
- * @param cause the root cause
- */
- public ContainerLifecycleException(String desc, Throwable cause) {
- super (desc, cause);
- }
-
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpService.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpService.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpService.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpService.java Tue Nov 6 00:59:36 2007
@@ -19,19 +19,18 @@
*/
package org.safehaus.asyncweb.service;
-
/**
* An application-level HTTP request processor.
- *
+ *
* @author irvingd
*
*/
public interface HttpService {
- public void handleRequest(HttpServiceContext context) throws Exception;
-
- public void start();
-
- public void stop();
-
+ public void handleRequest(HttpServiceContext context) throws Exception;
+
+ public void start();
+
+ public void stop();
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceContext.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceContext.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceContext.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceContext.java Tue Nov 6 00:59:36 2007
@@ -25,78 +25,77 @@
import org.safehaus.asyncweb.common.HttpResponse;
import org.safehaus.asyncweb.common.HttpResponseStatus;
-
/**
* Provides conversational context between a HTTP client and a {@link HttpService}.
- *
+ *
* @author trustin
*/
public interface HttpServiceContext {
-
- /**
- * Returns the socket address of the client (or last proxy).
- */
- InetSocketAddress getRemoteAddress();
-
- /**
- * Returns the request which is received from the client.
- */
- HttpRequest getRequest();
-
- /**
- * Returns <tt>true</tt> if a response for the request is committed.
- */
- boolean isResponseCommitted();
-
- /**
- * @return The <code>Response</code> committed to this <code>Request</code>,
- * or <code>null</code> if no response has been comitted
- */
- HttpResponse getCommittedResponse();
-
- /**
- * Writes the specified response back to the client.
- * The response <i>must not</i> be modified after it has been
- * submitted for comittment - irrespective of whether a commit
- * is successful or not.
- * <p>
- * A request may have only one response committed to it. The return
- * value of this method can be used to determine whether the
- * supplied response will be used as the single response for this
- * request.
- * <p>
- * Application code must not modify a response in any way after it
- * has been committed to a request. The results of doing so are
- * undefined.
- *
- * @param response The response to provide
- * @return <code>true</code> if the response was accepted
- */
- boolean commitResponse(HttpResponse response);
-
- /**
- * Commits a default response with a specified {@link HttpResponseStatus}.
- *
- * @return <code>true</code> if the response was accepted
- */
- boolean commitResponse(HttpResponseStatus status);
-
- /**
- * Returns the {@link HttpSession} which is associated with the client.
- * If no session is currently associated with the client, a new session is created.
- *
- * @return The session associated with the client
- */
- HttpSession getSession();
-
- /**
- * Returns the <code>Session</code> associated with this request.
- *
- * @param create If <code>true</code>, a new session is created if no session is currently
- * associated with the client.
- * @return The {@link HttpSession}, or <code>null</code> if no session
- * is associated with the client and <code>create</code> is
- * <code>false</code>
- */
- HttpSession getSession(boolean create);
+
+ /**
+ * Returns the socket address of the client (or last proxy).
+ */
+ InetSocketAddress getRemoteAddress();
+
+ /**
+ * Returns the request which is received from the client.
+ */
+ HttpRequest getRequest();
+
+ /**
+ * Returns <tt>true</tt> if a response for the request is committed.
+ */
+ boolean isResponseCommitted();
+
+ /**
+ * @return The <code>Response</code> committed to this <code>Request</code>,
+ * or <code>null</code> if no response has been comitted
+ */
+ HttpResponse getCommittedResponse();
+
+ /**
+ * Writes the specified response back to the client.
+ * The response <i>must not</i> be modified after it has been
+ * submitted for comittment - irrespective of whether a commit
+ * is successful or not.
+ * <p>
+ * A request may have only one response committed to it. The return
+ * value of this method can be used to determine whether the
+ * supplied response will be used as the single response for this
+ * request.
+ * <p>
+ * Application code must not modify a response in any way after it
+ * has been committed to a request. The results of doing so are
+ * undefined.
+ *
+ * @param response The response to provide
+ * @return <code>true</code> if the response was accepted
+ */
+ boolean commitResponse(HttpResponse response);
+
+ /**
+ * Commits a default response with a specified {@link HttpResponseStatus}.
+ *
+ * @return <code>true</code> if the response was accepted
+ */
+ boolean commitResponse(HttpResponseStatus status);
+
+ /**
+ * Returns the {@link HttpSession} which is associated with the client.
+ * If no session is currently associated with the client, a new session is created.
+ *
+ * @return The session associated with the client
+ */
+ HttpSession getSession();
+
+ /**
+ * Returns the <code>Session</code> associated with this request.
+ *
+ * @param create If <code>true</code>, a new session is created if no session is currently
+ * associated with the client.
+ * @return The {@link HttpSession}, or <code>null</code> if no session
+ * is associated with the client and <code>create</code> is
+ * <code>false</code>
+ */
+ HttpSession getSession(boolean create);
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceFilter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceFilter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceFilter.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceFilter.java Tue Nov 6 00:59:36 2007
@@ -19,49 +19,50 @@
*/
package org.safehaus.asyncweb.service;
-
public interface HttpServiceFilter {
-
- /**
- * Notifies this handler of the incoming request for a specified request.
- *
- * This handler should call <code>invokeNext</code> when it has completed
- * its duties. This invocation may occur asyncronously - but <i>must</i>
- * occur for each notification
- *
- * @param next The next filter in the filter chain
- * @param context The service context
- */
- void handleRequest(NextFilter next, HttpServiceContext context) throws Exception;
-
- /**
- * Notifies this handler of the committed response for a specified request.
- *
- * This handler should call <code>invokeNext</code> when it has completed
- * its duties. This invocation may occur asyncronously - but <i>must</i>
- * occur for each notification
- *
- * @param next The next filter in the filter chain
- * @param context The service context
- */
- void handleResponse(NextFilter next, HttpServiceContext context) throws Exception;
-
- void start();
-
- void stop();
-
- /**
- * Encapsuates a location within a chain of tasks to be performed.
- *
- * @author irvingd
- * @author trustin
- * @version $Rev$, $Date$
- */
- public interface NextFilter {
/**
- * Causes the next task in the chain to be performed
+ * Notifies this handler of the incoming request for a specified request.
+ *
+ * This handler should call <code>invokeNext</code> when it has completed
+ * its duties. This invocation may occur asyncronously - but <i>must</i>
+ * occur for each notification
+ *
+ * @param next The next filter in the filter chain
+ * @param context The service context
+ */
+ void handleRequest(NextFilter next, HttpServiceContext context)
+ throws Exception;
+
+ /**
+ * Notifies this handler of the committed response for a specified request.
+ *
+ * This handler should call <code>invokeNext</code> when it has completed
+ * its duties. This invocation may occur asyncronously - but <i>must</i>
+ * occur for each notification
+ *
+ * @param next The next filter in the filter chain
+ * @param context The service context
+ */
+ void handleResponse(NextFilter next, HttpServiceContext context)
+ throws Exception;
+
+ void start();
+
+ void stop();
+
+ /**
+ * Encapsuates a location within a chain of tasks to be performed.
+ *
+ * @author irvingd
+ * @author trustin
+ * @version $Rev$, $Date$
*/
- void invoke();
- }
+ public interface NextFilter {
+
+ /**
+ * Causes the next task in the chain to be performed
+ */
+ void invoke();
+ }
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceHandler.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceHandler.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpServiceHandler.java Tue Nov 6 00:59:36 2007
@@ -20,8 +20,8 @@
package org.safehaus.asyncweb.service;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import org.safehaus.asyncweb.common.DefaultHttpResponse;
import org.safehaus.asyncweb.common.HttpRequest;
@@ -31,133 +31,135 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* A <code>ServiceHandler</code> which employs a <code>ServiceResolver</code>
* to map incoming requests to an <code>HttpService</code> which is
* then invoked.
* If an incoming request can not be mapped to an <code>HttpService</code>,
* a <code>404</code> response status is returned to the client
- *
+ *
* @author irvingd
*
*/
public class HttpServiceHandler implements HttpServiceFilter {
- private static final Logger LOG = LoggerFactory.getLogger(HttpServiceHandler.class);
-
- private ServiceResolver resolver;
- private Map<String, HttpService> serviceMap = new HashMap<String, HttpService>();
-
- /**
- * Adds an <code>HttpService</code> against a service name.
- * The service will be invoked this handlers associated
- * <code>ServiceResolver</code> resolves a request to the
- * specified service name.<br/>
- *
- * Any existing registration against the given name is overwritten.
- *
- * @param name The service name
- * @param httpService The service
- */
- public void addHttpService(String name, HttpService httpService) {
- Object oldService = serviceMap.put(name, httpService);
- if (oldService != null && LOG.isWarnEnabled()) {
- LOG.warn("Duplicate mapping for '" + name +
- "'. Previous mapping removed");
- }
- LOG.info("New HttpService registered against key '" + name + "'");
- }
-
- /**
- * Associates this handler with the <code>ServiceResolver</code>
- * it is to employ
- *
- * @param resolver The resolver to employ
- */
- public void setServiceResolver(ServiceResolver resolver) {
- LOG.info("Associated with service resolver [ " + resolver + "]");
- this.resolver = resolver;
- }
-
- /**
- * Attempts to resolve the specified request to an <code>HttpService</code>
- * known to this handler by employing this handlers associated
- * <code>ServiceResolver</code>.<br/>
- * If an <code>HttpService</code> is located for the request, it is provided
- * with the request. Otherwise, a <code>404</code> response is committed
- * for the request
- */
- public void handleRequest(NextFilter next, HttpServiceContext context) throws Exception {
- HttpService service = null;
- HttpRequest request = context.getRequest();
- String serviceName = resolver.resolveService(request);
- if (serviceName != null) {
- service = serviceMap.get(serviceName);
- }
- if (service == null) {
- handleUnmappedRequest(context);
- } else {
- if (LOG.isInfoEnabled()) {
- LOG.info("Mapped request [" + request.getRequestUri() + "] to " +
- "service '" + serviceName + "'");
+ private static final Logger LOG = LoggerFactory
+ .getLogger(HttpServiceHandler.class);
+
+ private ServiceResolver resolver;
+
+ private Map<String, HttpService> serviceMap = new HashMap<String, HttpService>();
+
+ /**
+ * Adds an <code>HttpService</code> against a service name.
+ * The service will be invoked this handlers associated
+ * <code>ServiceResolver</code> resolves a request to the
+ * specified service name.<br/>
+ *
+ * Any existing registration against the given name is overwritten.
+ *
+ * @param name The service name
+ * @param httpService The service
+ */
+ public void addHttpService(String name, HttpService httpService) {
+ Object oldService = serviceMap.put(name, httpService);
+ if (oldService != null && LOG.isWarnEnabled()) {
+ LOG.warn("Duplicate mapping for '" + name
+ + "'. Previous mapping removed");
+ }
+ LOG.info("New HttpService registered against key '" + name + "'");
+ }
+
+ /**
+ * Associates this handler with the <code>ServiceResolver</code>
+ * it is to employ
+ *
+ * @param resolver The resolver to employ
+ */
+ public void setServiceResolver(ServiceResolver resolver) {
+ LOG.info("Associated with service resolver [ " + resolver + "]");
+ this.resolver = resolver;
+ }
+
+ /**
+ * Attempts to resolve the specified request to an <code>HttpService</code>
+ * known to this handler by employing this handlers associated
+ * <code>ServiceResolver</code>.<br/>
+ * If an <code>HttpService</code> is located for the request, it is provided
+ * with the request. Otherwise, a <code>404</code> response is committed
+ * for the request
+ */
+ public void handleRequest(NextFilter next, HttpServiceContext context)
+ throws Exception {
+ HttpService service = null;
+ HttpRequest request = context.getRequest();
+ String serviceName = resolver.resolveService(request);
+ if (serviceName != null) {
+ service = serviceMap.get(serviceName);
+ }
+ if (service == null) {
+ handleUnmappedRequest(context);
+ } else {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("Mapped request [" + request.getRequestUri() + "] to "
+ + "service '" + serviceName + "'");
+ }
+ service.handleRequest(context);
+ next.invoke();
+ }
+ }
+
+ /**
+ * Handles a response. This handler does not perform any
+ * action for responses - so the specified {@link NextFilter} is invoked immediately.
+ */
+ public void handleResponse(NextFilter next, HttpServiceContext context) {
+ next.invoke();
+ }
+
+ /**
+ * Starts this handler.
+ */
+ public void start() {
+ LOG.info("HttpServiceHandler starting");
+ for (Entry<String, HttpService> entry : serviceMap
+ .entrySet()) {
+ String serviceName = entry.getKey();
+ HttpService service = entry.getValue();
+ LOG.info("Starting HttpService '" + serviceName + "'");
+ service.start();
+ LOG.info("HttpService '" + serviceName + "' started");
}
- service.handleRequest(context);
- next.invoke();
}
- }
-
- /**
- * Handles a response. This handler does not perform any
- * action for responses - so the specified {@link NextFilter} is invoked immediately.
- */
- public void handleResponse(NextFilter next, HttpServiceContext context) {
- next.invoke();
- }
-
- /**
- * Starts this handler.
- */
- public void start() {
- LOG.info("HttpServiceHandler starting");
- for (Iterator<Map.Entry<String, HttpService>> iter=serviceMap.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry<String, HttpService> entry = iter.next();
- String serviceName = entry.getKey();
- HttpService service = entry.getValue();
- LOG.info("Starting HttpService '" + serviceName + "'");
- service.start();
- LOG.info("HttpService '" + serviceName + "' started");
- }
- }
-
- /**
- * Stops this handler
- */
- public void stop() {
- LOG.info("HttpServiceHandler stopping");
- for (Iterator<Map.Entry<String, HttpService>> iter=serviceMap.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry<String, HttpService> entry = iter.next();
- String serviceName = entry.getKey();
- HttpService service = entry.getValue();
- LOG.info("Stopping HttpService '" + serviceName + "'");
- service.stop();
- LOG.info("HttpService '" + serviceName + "' stopped");
- }
- }
-
- /**
- * Handles an unmapped request by issuing a <code>404</code>
- * response to the client
- */
- private void handleUnmappedRequest(HttpServiceContext context) {
- HttpRequest request = context.getRequest();
- if (LOG.isWarnEnabled()) {
- LOG.warn("Failed to map '" + request.getRequestUri() + "' to " +
- "a resource");
- }
- MutableHttpResponse response = new DefaultHttpResponse();
- response.setStatus(HttpResponseStatus.NOT_FOUND);
- response.setStatusReasonPhrase(request.getRequestUri().toString());
- context.commitResponse(response);
- }
+
+ /**
+ * Stops this handler
+ */
+ public void stop() {
+ LOG.info("HttpServiceHandler stopping");
+ for (Entry<String, HttpService> entry : serviceMap
+ .entrySet()) {
+ String serviceName = entry.getKey();
+ HttpService service = entry.getValue();
+ LOG.info("Stopping HttpService '" + serviceName + "'");
+ service.stop();
+ LOG.info("HttpService '" + serviceName + "' stopped");
+ }
+ }
+
+ /**
+ * Handles an unmapped request by issuing a <code>404</code>
+ * response to the client
+ */
+ private void handleUnmappedRequest(HttpServiceContext context) {
+ HttpRequest request = context.getRequest();
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("Failed to map '" + request.getRequestUri() + "' to "
+ + "a resource");
+ }
+ MutableHttpResponse response = new DefaultHttpResponse();
+ response.setStatus(HttpResponseStatus.NOT_FOUND);
+ response.setStatusReasonPhrase(request.getRequestUri().toString());
+ context.commitResponse(response);
+ }
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpSession.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpSession.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpSession.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/HttpSession.java Tue Nov 6 00:59:36 2007
@@ -21,68 +21,68 @@
/**
* Provides a mechanism to store data across multiple requests from the same client.
- *
+ *
* @author irvingd
*
*/
public interface HttpSession {
- /**
- * @return This sessions identifier
- */
- public String getId();
-
- /**
- * Returns the value bound to this session with the specified key, if any.
- *
- * @param key The key for which the bound session value is required
- * @return The session value bound against the specified key, or <code>null</code>
- * if no such value exists
- */
- public Object getValue(String key);
-
- /**
- * Binds a value against a specified key.
- * Any value currently held for the given key is unbound.
- *
- * @param key The key against which the session value is to be bound
- * @param value The session value to bind
- */
- public void setValue(String key, Object value);
-
- /**
- * Removes a session value from this session.
- * If a value is currently bound against the specified key, it is unbound and
- * returned. If no value is bound against the given key, this method returns
- * <code>null</code>
- *
- * @param key The key for which the existing binding - if any - is to be removed
- * @return The removed value - or <code>null</code> if no value was bound against
- * the specified key
- */
- public Object removeValue(String key);
-
- /**
- * Determines whether the client is aware of this session and has opted-in
- * to using it.
- * For newly created sessions, this method will always return <code>false</code>.
- *
- * @return <code>true</code> if the client is aware of this session, and is using it
- */
- public boolean isAttached();
-
- /**
- * Determines whether this session is valid for use.
- *
- * @return <code>true</code> if this session is neither destroyed nor timed out
- */
- public boolean isValid();
-
- /**
- * Destroys this session, releasing any resources it may be consuming.
- * Further client requests using the same session identifier will no longer
- * be associated with this <code>Session</code>
- */
- public void destroy();
-
+ /**
+ * @return This sessions identifier
+ */
+ public String getId();
+
+ /**
+ * Returns the value bound to this session with the specified key, if any.
+ *
+ * @param key The key for which the bound session value is required
+ * @return The session value bound against the specified key, or <code>null</code>
+ * if no such value exists
+ */
+ public Object getValue(String key);
+
+ /**
+ * Binds a value against a specified key.
+ * Any value currently held for the given key is unbound.
+ *
+ * @param key The key against which the session value is to be bound
+ * @param value The session value to bind
+ */
+ public void setValue(String key, Object value);
+
+ /**
+ * Removes a session value from this session.
+ * If a value is currently bound against the specified key, it is unbound and
+ * returned. If no value is bound against the given key, this method returns
+ * <code>null</code>
+ *
+ * @param key The key for which the existing binding - if any - is to be removed
+ * @return The removed value - or <code>null</code> if no value was bound against
+ * the specified key
+ */
+ public Object removeValue(String key);
+
+ /**
+ * Determines whether the client is aware of this session and has opted-in
+ * to using it.
+ * For newly created sessions, this method will always return <code>false</code>.
+ *
+ * @return <code>true</code> if the client is aware of this session, and is using it
+ */
+ public boolean isAttached();
+
+ /**
+ * Determines whether this session is valid for use.
+ *
+ * @return <code>true</code> if this session is neither destroyed nor timed out
+ */
+ public boolean isValid();
+
+ /**
+ * Destroys this session, releasing any resources it may be consuming.
+ * Further client requests using the same session identifier will no longer
+ * be associated with this <code>Session</code>
+ */
+ public void destroy();
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ServiceContainer.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ServiceContainer.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ServiceContainer.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/ServiceContainer.java Tue Nov 6 00:59:36 2007
@@ -25,74 +25,73 @@
import org.safehaus.asyncweb.service.errorReporting.ErrorResponseFormatter;
import org.safehaus.asyncweb.service.session.HttpSessionAccessor;
-
public interface ServiceContainer {
- /**
- * Adds a {@link HttpServiceFilter} to this container.
- * Requests dispatched to this container are run through filters
- * in the order they are added
- *
- * @param handler The handler to add
- * @throws IllegalStateException If this container has been started
- */
- void addServiceFilter(HttpServiceFilter handler);
-
- /**
- * Adds a <code>Transport</code> to this container.
- * The transport is provided with a <code></code>, and is started
- * when this container starts
- *
- * @param transport The transport to add
- * @throws IllegalStateException If this container has been started
- */
- void addTransport(Transport transport);
-
- /**
- * Returns the read-only {@link List} of {@link HttpServiceFilter}s.
- */
- List<HttpServiceFilter> getServiceFilters();
-
- /**
- * Returns the employed {@link KeepAliveStrategy} of this container.
- */
- KeepAliveStrategy getKeepAliveStrategy();
-
- /**
- * Returns the employes {@link HttpSessionAccessor} to be supplied to each request
- * as it passes through the container.
- * The accessor is shutdown when this container is stopped
- */
- HttpSessionAccessor getSessionAccessor();
-
- /**
- * Sets the <code>SessionAccessor</code> to be supplied to each request
- * as it passes through the container.
- * The accessor is shutdown when this container is stopped
- *
- * @param sessionAccessor The accessor
- */
- void setSessionAccessor(HttpSessionAccessor accessor);
-
- ErrorResponseFormatter getErrorResponseFormatter();
-
- boolean isSendServerHeader();
-
- /**
- * Starts this container.
- * Requests may be dispatched to this container after it has been
- * started.
- * During start-up, this container starts all associated transports
- * and service handlers.
- *
- * @throws ContainerLifecycleException If a transport fails to start
- */
- void start() throws ContainerLifecycleException;
-
- /**
- * Stops this container.
- * During shut-down, this container stops all associated transports
- * and service handlers.
- */
- void stop();
+ /**
+ * Adds a {@link HttpServiceFilter} to this container.
+ * Requests dispatched to this container are run through filters
+ * in the order they are added
+ *
+ * @param handler The handler to add
+ * @throws IllegalStateException If this container has been started
+ */
+ void addServiceFilter(HttpServiceFilter handler);
+
+ /**
+ * Adds a <code>Transport</code> to this container.
+ * The transport is provided with a <code></code>, and is started
+ * when this container starts
+ *
+ * @param transport The transport to add
+ * @throws IllegalStateException If this container has been started
+ */
+ void addTransport(Transport transport);
+
+ /**
+ * Returns the read-only {@link List} of {@link HttpServiceFilter}s.
+ */
+ List<HttpServiceFilter> getServiceFilters();
+
+ /**
+ * Returns the employed {@link KeepAliveStrategy} of this container.
+ */
+ KeepAliveStrategy getKeepAliveStrategy();
+
+ /**
+ * Returns the employes {@link HttpSessionAccessor} to be supplied to each request
+ * as it passes through the container.
+ * The accessor is shutdown when this container is stopped
+ */
+ HttpSessionAccessor getSessionAccessor();
+
+ /**
+ * Sets the <code>SessionAccessor</code> to be supplied to each request
+ * as it passes through the container.
+ * The accessor is shutdown when this container is stopped
+ *
+ * @param sessionAccessor The accessor
+ */
+ void setSessionAccessor(HttpSessionAccessor accessor);
+
+ ErrorResponseFormatter getErrorResponseFormatter();
+
+ boolean isSendServerHeader();
+
+ /**
+ * Starts this container.
+ * Requests may be dispatched to this container after it has been
+ * started.
+ * During start-up, this container starts all associated transports
+ * and service handlers.
+ *
+ * @throws ContainerLifecycleException If a transport fails to start
+ */
+ void start() throws ContainerLifecycleException;
+
+ /**
+ * Stops this container.
+ * During shut-down, this container stops all associated transports
+ * and service handlers.
+ */
+ void stop();
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/Transport.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/Transport.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/Transport.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/Transport.java Tue Nov 6 00:59:36 2007
@@ -19,40 +19,39 @@
*/
package org.safehaus.asyncweb.service;
-
/**
* A mechanism over which <code>Request</code>s are received.
- *
+ *
* @author irvingd
*
*/
public interface Transport {
- /**
- * Associates this <code>Transport</code> with its container.
- *
- * @param container The container to which incoming requests should
- * be provided
- */
- public void setServiceContainer(ServiceContainer container);
-
- /**
- * Starts this <code>Transport</code>.
- * Once a <code>Transport</code> has been started, it may begin
- * submitting <code>Request</code>s to its associated
- * <code>ServiceContainer</code>
- *
- * @throws TransportException If the transport can not be started
- */
- public void start() throws TransportException;
-
- /**
- * Stops this <code>Transport</code>.
- * No further requests should be sent to the transports associated
- * <code>ServiceContainer</code>
- *
- * @throws TransportException If there were problems stopping the transport
- */
- public void stop() throws TransportException;
-
+ /**
+ * Associates this <code>Transport</code> with its container.
+ *
+ * @param container The container to which incoming requests should
+ * be provided
+ */
+ public void setServiceContainer(ServiceContainer container);
+
+ /**
+ * Starts this <code>Transport</code>.
+ * Once a <code>Transport</code> has been started, it may begin
+ * submitting <code>Request</code>s to its associated
+ * <code>ServiceContainer</code>
+ *
+ * @throws TransportException If the transport can not be started
+ */
+ public void start() throws TransportException;
+
+ /**
+ * Stops this <code>Transport</code>.
+ * No further requests should be sent to the transports associated
+ * <code>ServiceContainer</code>
+ *
+ * @throws TransportException If there were problems stopping the transport
+ */
+ public void stop() throws TransportException;
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/TransportException.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/TransportException.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/TransportException.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/TransportException.java Tue Nov 6 00:59:36 2007
@@ -21,14 +21,14 @@
public class TransportException extends Exception {
- private static final long serialVersionUID = 3258132466186270517L;
+ private static final long serialVersionUID = 3258132466186270517L;
+
+ public TransportException(String description) {
+ super(description);
+ }
+
+ public TransportException(String description, Throwable cause) {
+ super(description, cause);
+ }
- public TransportException(String description) {
- super(description);
- }
-
- public TransportException(String description, Throwable cause) {
- super(description, cause);
- }
-
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/AbstractHttpServiceContext.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/AbstractHttpServiceContext.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/AbstractHttpServiceContext.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/AbstractHttpServiceContext.java Tue Nov 6 00:59:36 2007
@@ -35,137 +35,152 @@
/**
* A default implementation of {@link HttpServiceContext}.
- *
+ *
* @author trustin
* @version $Rev:167 $, $Date:2006-11-15 11:10:05 +0000 (ì, 15 11ì 2006) $
*/
public abstract class AbstractHttpServiceContext implements HttpServiceContext {
- private final Logger log = LoggerFactory.getLogger(AbstractHttpServiceContext.class);
- private final InetSocketAddress remoteAddress;
- private final HttpRequest request;
- private HttpResponse committedResponse;
- private HttpSession session;
- private boolean createdSession;
- private final ServiceContainer container;
-
- public AbstractHttpServiceContext(
- InetSocketAddress remoteAddress, HttpRequest request, ServiceContainer container) {
- if (remoteAddress == null) {
- throw new NullPointerException("remoteAddress");
- }
- if (request == null) {
- throw new NullPointerException("request");
- }
- if (container == null) {
- throw new NullPointerException("container");
- }
-
- this.remoteAddress = remoteAddress;
- this.request = request;
- this.container = container;
- this.session = container.getSessionAccessor().getSession(this, false);
- }
-
- public synchronized boolean isResponseCommitted() {
- return committedResponse != null;
- }
-
- /**
- * Commits a <code>HttpResponse</code> to this <code>Request</code>.
- *
- * @param response The response to commit
- * @return <code>true</code> iff the response was committed
- */
- public boolean commitResponse(HttpResponse response) {
- synchronized (this) {
- if (isResponseCommitted()) {
+ private final Logger log = LoggerFactory
+ .getLogger(AbstractHttpServiceContext.class);
+
+ private final InetSocketAddress remoteAddress;
+
+ private final HttpRequest request;
+
+ private HttpResponse committedResponse;
+
+ private HttpSession session;
+
+ private boolean createdSession;
+
+ private final ServiceContainer container;
+
+ public AbstractHttpServiceContext(InetSocketAddress remoteAddress,
+ HttpRequest request, ServiceContainer container) {
+ if (remoteAddress == null) {
+ throw new NullPointerException("remoteAddress");
+ }
+ if (request == null) {
+ throw new NullPointerException("request");
+ }
+ if (container == null) {
+ throw new NullPointerException("container");
+ }
+
+ this.remoteAddress = remoteAddress;
+ this.request = request;
+ this.container = container;
+ this.session = container.getSessionAccessor().getSession(this, false);
+ }
+
+ public synchronized boolean isResponseCommitted() {
+ return committedResponse != null;
+ }
+
+ /**
+ * Commits a <code>HttpResponse</code> to this <code>Request</code>.
+ *
+ * @param response The response to commit
+ * @return <code>true</code> iff the response was committed
+ */
+ public boolean commitResponse(HttpResponse response) {
+ synchronized (this) {
+ if (isResponseCommitted()) {
+ if (log.isDebugEnabled()) {
+ log
+ .info("Request already comitted to a response. Disposing response");
+ }
+ return false;
+ }
+
+ committedResponse = response;
+ }
+
+ // Add the session identifier if the session was newly created.
+ if (createdSession) {
+ container.getSessionAccessor().addSessionIdentifier(this,
+ (MutableHttpResponse) response);
+ }
+
+ // Only parsed requests can be formatted.
+ if (getRequest().getMethod() != null) {
+ container.getErrorResponseFormatter().formatResponse(getRequest(),
+ (MutableHttpResponse) response);
+ }
+
+ if (container.isSendServerHeader()) {
+ ((MutableHttpResponse) response).setHeader(
+ HttpHeaderConstants.KEY_SERVER, "AsyncWeb");
+ }
+
+ // Normalize the response.
+ ((MutableHttpResponse) response).normalize(getRequest());
+
+ // Override connection header if needed.
+ if (!container.getKeepAliveStrategy().keepAlive(this, response)) {
+ ((MutableHttpResponse) response).setHeader(
+ HttpHeaderConstants.KEY_CONNECTION,
+ HttpHeaderConstants.VALUE_CLOSE);
+ }
+
+ boolean requiresClosure = !HttpHeaderConstants.VALUE_KEEP_ALIVE
+ .equalsIgnoreCase(response
+ .getHeader(HttpHeaderConstants.KEY_CONNECTION));
+
+ if (requiresClosure && log.isDebugEnabled()) {
+ log.debug("Response status: " + response.getStatus());
+ log.debug("Keep-alive strategy requires closure of "
+ + getRemoteAddress());
+ }
+
if (log.isDebugEnabled()) {
- log.info("Request already comitted to a response. Disposing response");
+ log.debug("Committing a response:");
+ log.debug("Status: " + response.getStatus() + ' '
+ + response.getStatusReasonPhrase());
+ log.debug("Headers: " + response.getHeaders());
+ }
+
+ doWrite(requiresClosure);
+
+ return true;
+ }
+
+ public boolean commitResponse(HttpResponseStatus status) {
+ MutableHttpResponse response = new DefaultHttpResponse();
+ response.setStatus(status);
+ return commitResponse(response);
+ }
+
+ public synchronized HttpResponse getCommittedResponse() {
+ return committedResponse;
+ }
+
+ public InetSocketAddress getRemoteAddress() {
+ return remoteAddress;
+ }
+
+ public HttpRequest getRequest() {
+ return request;
+ }
+
+ public HttpSession getSession() {
+ return getSession(true);
+ }
+
+ public synchronized HttpSession getSession(boolean create) {
+ if (session != null && !session.isValid()) {
+ session = null;
+ }
+ if (session == null) {
+ session = container.getSessionAccessor().getSession(this, create);
+ if (create) {
+ createdSession = true;
+ }
}
- return false;
- }
-
- committedResponse = response;
- }
-
- // Add the session identifier if the session was newly created.
- if (createdSession) {
- container.getSessionAccessor().addSessionIdentifier(this, (MutableHttpResponse) response);
- }
-
- // Only parsed requests can be formatted.
- if (getRequest().getMethod() != null) {
- container.getErrorResponseFormatter().formatResponse(getRequest(), (MutableHttpResponse) response);
- }
-
- if (container.isSendServerHeader()) {
- ((MutableHttpResponse) response).setHeader(HttpHeaderConstants.KEY_SERVER, "AsyncWeb");
- }
-
- // Normalize the response.
- ((MutableHttpResponse) response).normalize(getRequest());
-
- // Override connection header if needed.
- if (!container.getKeepAliveStrategy().keepAlive(this, response)) {
- ((MutableHttpResponse) response).setHeader(
- HttpHeaderConstants.KEY_CONNECTION, HttpHeaderConstants.VALUE_CLOSE);
- }
-
- boolean requiresClosure = !HttpHeaderConstants.VALUE_KEEP_ALIVE.equalsIgnoreCase(
- response.getHeader(HttpHeaderConstants.KEY_CONNECTION));
-
- if (requiresClosure && log.isDebugEnabled()) {
- log.debug("Response status: " + response.getStatus());
- log.debug("Keep-alive strategy requires closure of " + getRemoteAddress());
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Committing a response:");
- log.debug("Status: " + response.getStatus() + ' ' + response.getStatusReasonPhrase());
- log.debug("Headers: " + response.getHeaders());
- }
-
- doWrite(requiresClosure);
-
- return true;
- }
-
- public boolean commitResponse(HttpResponseStatus status) {
- MutableHttpResponse response = new DefaultHttpResponse();
- response.setStatus(status);
- return commitResponse(response);
- }
-
- public synchronized HttpResponse getCommittedResponse() {
- return committedResponse;
- }
-
- public InetSocketAddress getRemoteAddress() {
- return remoteAddress;
- }
-
- public HttpRequest getRequest() {
- return request;
- }
-
- public HttpSession getSession() {
- return getSession(true);
- }
-
- public synchronized HttpSession getSession(boolean create) {
- if (session != null && !session.isValid()) {
- session = null;
- }
- if (session == null) {
- session = container.getSessionAccessor().getSession(this, create);
- if (create) {
- createdSession = true;
- }
- }
-
- return session;
- }
-
- protected abstract void doWrite(boolean requiresClosure);
+
+ return session;
+ }
+
+ protected abstract void doWrite(boolean requiresClosure);
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/BasicKeepAliveStrategy.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/BasicKeepAliveStrategy.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/BasicKeepAliveStrategy.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/BasicKeepAliveStrategy.java Tue Nov 6 00:59:36 2007
@@ -24,7 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Defines common sensible behaviour for the rules under which a
* connection should be kept alive.
@@ -37,61 +36,65 @@
* </ul>
* Implementations should override <code></code> to provide additional
* constraints
- *
+ *
* @author irvingd
*
*/
public class BasicKeepAliveStrategy implements KeepAliveStrategy {
- private static final Logger LOG = LoggerFactory.getLogger(BasicKeepAliveStrategy.class);
-
- /**
- * Determines whether a connection should be kept alive based
- * on a response.
- * This method returns true iff either:
- * <ul>
- * <li>The request is not committed</li>
- * </u>
- * or (in order):
- * <ul>
- * <li>The status of a response does not force closure</li>
- * <li>The request indicates that it wants the connection to remain
- * open</li>
- * <li><code>doIsKeepAlive</code> returns true</li>
- * </ul>
- *
- * @param response The response to examine
- * @return <code>true</code> iff a connection should be kept alive
- */
- public final boolean keepAlive(HttpServiceContext context, HttpResponse response) {
- boolean isKeepAlive;
- if (!context.isResponseCommitted()) {
- isKeepAlive = true;
- } else {
- isKeepAlive = !response.getStatus().forcesConnectionClosure() &&
- context.getRequest().isKeepAlive() &&
- doIsKeepAlive(context, response);
- if (!isKeepAlive && LOG.isDebugEnabled() &&
- response.getStatus().forcesConnectionClosure()) {
- LOG.debug("Response status forces closure: " + response.getStatus());
- }
+ private static final Logger LOG = LoggerFactory
+ .getLogger(BasicKeepAliveStrategy.class);
+
+ /**
+ * Determines whether a connection should be kept alive based
+ * on a response.
+ * This method returns true iff either:
+ * <ul>
+ * <li>The request is not committed</li>
+ * </u>
+ * or (in order):
+ * <ul>
+ * <li>The status of a response does not force closure</li>
+ * <li>The request indicates that it wants the connection to remain
+ * open</li>
+ * <li><code>doIsKeepAlive</code> returns true</li>
+ * </ul>
+ *
+ * @param response The response to examine
+ * @return <code>true</code> iff a connection should be kept alive
+ */
+ public final boolean keepAlive(HttpServiceContext context,
+ HttpResponse response) {
+ boolean isKeepAlive;
+ if (!context.isResponseCommitted()) {
+ isKeepAlive = true;
+ } else {
+ isKeepAlive = !response.getStatus().forcesConnectionClosure()
+ && context.getRequest().isKeepAlive()
+ && doIsKeepAlive(context, response);
+ if (!isKeepAlive && LOG.isDebugEnabled()
+ && response.getStatus().forcesConnectionClosure()) {
+ LOG.debug("Response status forces closure: "
+ + response.getStatus());
+ }
+ }
+ return isKeepAlive;
+ }
+
+ /**
+ * Simply returns <code>true</code> by default.
+ * Implementations should override this method to provide any
+ * additional keep-alive conditions
+ *
+ * @param context The context to check
+ * @param response The request to check
+ * @return <code>true</code> if the connection should
+ * be kept alive
+ */
+ @SuppressWarnings("unused")
+ protected boolean doIsKeepAlive(HttpServiceContext context,
+ HttpResponse response) {
+ return true;
}
- return isKeepAlive;
- }
-
- /**
- * Simply returns <code>true</code> by default.
- * Implementations should override this method to provide any
- * additional keep-alive conditions
- *
- * @param context The context to check
- * @param response The request to check
- * @return <code>true</code> if the connection should
- * be kept alive
- */
- @SuppressWarnings("unused")
- protected boolean doIsKeepAlive(HttpServiceContext context, HttpResponse response) {
- return true;
- }
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/CounterKeepAliveStrategy.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/CounterKeepAliveStrategy.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/CounterKeepAliveStrategy.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/CounterKeepAliveStrategy.java Tue Nov 6 00:59:36 2007
@@ -22,30 +22,32 @@
import org.safehaus.asyncweb.common.HttpResponse;
import org.safehaus.asyncweb.service.HttpServiceContext;
-
public class CounterKeepAliveStrategy extends BasicKeepAliveStrategy {
- private static final int DEFAULT_KEEP_ALIVES = 100;
-
- private int maxKeepAlives = DEFAULT_KEEP_ALIVES;
- private int keptAliveCount;
-
- /**
- * @param maxKeepAlives The maximum number of requests for which
- * a connection should be kept alive
- */
- public CounterKeepAliveStrategy(int maxKeepAlives) {
- this.maxKeepAlives = maxKeepAlives;
- }
-
- /**
- * Determines whether a connection should be "kept alive" based on
- * the number of requests for which the connection has previously
- * been kept alive.
- *
- * @param response The response to check
- */
- protected boolean doIsKeepAlive(HttpServiceContext context, HttpResponse response) {
- return ++keptAliveCount < maxKeepAlives;
- }
+ private static final int DEFAULT_KEEP_ALIVES = 100;
+
+ private int maxKeepAlives = DEFAULT_KEEP_ALIVES;
+
+ private int keptAliveCount;
+
+ /**
+ * @param maxKeepAlives The maximum number of requests for which
+ * a connection should be kept alive
+ */
+ public CounterKeepAliveStrategy(int maxKeepAlives) {
+ this.maxKeepAlives = maxKeepAlives;
+ }
+
+ /**
+ * Determines whether a connection should be "kept alive" based on
+ * the number of requests for which the connection has previously
+ * been kept alive.
+ *
+ * @param response The response to check
+ */
+ @Override
+ protected boolean doIsKeepAlive(HttpServiceContext context,
+ HttpResponse response) {
+ return ++keptAliveCount < maxKeepAlives;
+ }
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/KeepAliveStrategy.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/KeepAliveStrategy.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/KeepAliveStrategy.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/context/KeepAliveStrategy.java Tue Nov 6 00:59:36 2007
@@ -22,25 +22,24 @@
import org.safehaus.asyncweb.common.HttpResponse;
import org.safehaus.asyncweb.service.HttpServiceContext;
-
/**
* Defines a strategy for deciding whether a connection should
* remain open after a response has been handled
- *
+ *
* @author irvingd
*
*/
public interface KeepAliveStrategy {
- /**
- * Determines whether a connection should remain open after a
- * response has been handled
- *
- * @param context The context to check
- * @param response The response to check
- * @return <code>true</code> iff a connection should
- * remain open after processing the specified response
- */
- public boolean keepAlive(HttpServiceContext context, HttpResponse response);
-
+ /**
+ * Determines whether a connection should remain open after a
+ * response has been handled
+ *
+ * @param context The context to check
+ * @param response The response to check
+ * @return <code>true</code> iff a connection should
+ * remain open after processing the specified response
+ */
+ public boolean keepAlive(HttpServiceContext context, HttpResponse response);
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/CSS.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/CSS.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/CSS.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/CSS.java Tue Nov 6 00:59:36 2007
@@ -25,48 +25,55 @@
/**
* Manages the stylesheet info used for generated pages
- *
+ *
* TODO: Should be moved out to a configuration file when we sort out a
* standard resource strategy
- *
+ *
* @author irvingd
*
*/
public class CSS {
- //525D76
- private static final String BG = "3300cc";
-
- private static final String CSS_STRING =
- "H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#" + BG + ";font-size:22px;} " +
- "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#" + BG + ";font-size:16px;} " +
- "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#" + BG + ";font-size:14px;} " +
- "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} " +
- "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#" + BG + ";} " +
- "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}" +
- "A {color : black;}" +
- "A.name {color : black;}\n" +
- "TABLE {cellpadding:20;border-color:black;border-width:1px;border-style:solid;border-collapse:collapse}" +
- "TD {border-width:1px;border-color:black;border-style:solid;font-family:Tahoma,Arial,sans-serif;color:black;font-size:12px;}" +
- "TH {border-width:1px;border-color:black;border-style:solid;font-family:Tahoma,Arial,sans-serif;background-color:FF99FF;color:black;font-size:12px;}" +
- "HR {color : #" + BG + ";}";
-
- private static byte[] BYTES;
-
- static {
- try {
- BYTES = CSS_STRING.getBytes("US-ASCII");
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException("Must support US-ASCII");
+ //525D76
+ private static final String BG = "3300cc";
+
+ private static final String CSS_STRING = "H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#"
+ + BG
+ + ";font-size:22px;} "
+ + "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#"
+ + BG
+ + ";font-size:16px;} "
+ + "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#"
+ + BG
+ + ";font-size:14px;} "
+ + "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} "
+ + "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#"
+ + BG
+ + ";} "
+ + "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}"
+ + "A {color : black;}"
+ + "A.name {color : black;}\n"
+ + "TABLE {cellpadding:20;border-color:black;border-width:1px;border-style:solid;border-collapse:collapse}"
+ + "TD {border-width:1px;border-color:black;border-style:solid;font-family:Tahoma,Arial,sans-serif;color:black;font-size:12px;}"
+ + "TH {border-width:1px;border-color:black;border-style:solid;font-family:Tahoma,Arial,sans-serif;background-color:FF99FF;color:black;font-size:12px;}"
+ + "HR {color : #" + BG + ";}";
+
+ private static byte[] BYTES;
+
+ static {
+ try {
+ BYTES = CSS_STRING.getBytes("US-ASCII");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException("Must support US-ASCII");
+ }
+ }
+
+ public static void writeTo(IoBuffer buf) {
+ buf.put(BYTES);
+ }
+
+ public static StringBuilder appendTo(StringBuilder buff) {
+ buff.append(CSS_STRING);
+ return buff;
}
- }
-
- public static void writeTo(IoBuffer buf) {
- buf.put(BYTES);
- }
-
- public static StringBuilder appendTo(StringBuilder buff) {
- buff.append(CSS_STRING);
- return buff;
- }
-
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/ErrorResponseFormatter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/ErrorResponseFormatter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/ErrorResponseFormatter.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/ErrorResponseFormatter.java Tue Nov 6 00:59:36 2007
@@ -24,18 +24,18 @@
/**
* Formats error responses to include a descriptive body where appropriate
- *
+ *
* @author irvingd
- *
+ *
*/
public interface ErrorResponseFormatter {
- /**
- * Applies any appropriate formatting to a <code>Response</code> based on its
- * response status code
- *
- * @param response The response to format
- */
- public void formatResponse(HttpRequest request, MutableHttpResponse response);
-
+ /**
+ * Applies any appropriate formatting to a <code>Response</code> based on its
+ * response status code
+ *
+ * @param response The response to format
+ */
+ public void formatResponse(HttpRequest request, MutableHttpResponse response);
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/StandardResponseFormatter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/StandardResponseFormatter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/StandardResponseFormatter.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/errorReporting/StandardResponseFormatter.java Tue Nov 6 00:59:36 2007
@@ -29,85 +29,85 @@
import org.safehaus.asyncweb.common.content.ByteBufferContent;
import org.safehaus.asyncweb.util.StringBundle;
-
public class StandardResponseFormatter implements ErrorResponseFormatter {
- private static final StringBundle bundle
- = StringBundle.getBundle(StandardResponseFormatter.class.getPackage().getName());
-
- public void formatResponse(HttpRequest request, MutableHttpResponse response) {
- if (shouldFormat(response)) {
- doFormat(request, response);
- response.addHeader("content-type", "text/html");
+ private static final StringBundle bundle = StringBundle
+ .getBundle(StandardResponseFormatter.class.getPackage().getName());
+
+ public void formatResponse(HttpRequest request, MutableHttpResponse response) {
+ if (shouldFormat(response)) {
+ doFormat(request, response);
+ response.addHeader("content-type", "text/html");
+ }
+ }
+
+ private boolean shouldFormat(MutableHttpResponse response) {
+ boolean shouldFormat = false;
+ // FIXME Should be able to handler other content types.
+ if (!(response.getContent() instanceof ByteBufferContent)) {
+ HttpResponseStatus status = response.getStatus();
+ HttpResponseStatus.Category category = response.getStatus()
+ .getCategory();
+ shouldFormat = status.allowsMessageBody()
+ && (category == Category.CLIENT_ERROR || category == Category.SERVER_ERROR);
+ }
+ return shouldFormat;
}
- }
-
- private boolean shouldFormat(MutableHttpResponse response) {
- boolean shouldFormat = false;
- // FIXME Should be able to handler other content types.
- if (!(response.getContent() instanceof ByteBufferContent)) {
- HttpResponseStatus status = response.getStatus();
- HttpResponseStatus.Category category = response.getStatus().getCategory();
- shouldFormat = status.allowsMessageBody() &&
- (category == Category.CLIENT_ERROR ||
- category == Category.SERVER_ERROR);
+
+ private void doFormat(HttpRequest request, MutableHttpResponse response) {
+ StringBuilder html = new StringBuilder(1024);
+ html.append("<html><head><title>");
+ html.append("AsyncWeb Server - ");
+ html.append(bundle.getString("errorMessage"));
+ html.append("</title><style><!--");
+ CSS.appendTo(html).append("--></style>");
+ html.append("</head></body>");
+ html.append("<h1>");
+ html.append(bundle.getString("errorTitle"));
+ html.append("</h1>");
+ response.getStatusReasonPhrase();
+ String code = String.valueOf(response.getStatus().getCode());
+ html.append("<h1>");
+ html.append(bundle.getString("statusInfo", code));
+ html.append("</h1>");
+ html.append("<HR size=\"1\" noshade=\"noshade\">");
+
+ html.append("<p><table cellpadding=\"5\">");
+ appendInfo("statusCode",
+ String.valueOf(response.getStatus().getCode()), html);
+ appendInfo("description", getErrorMessage(response), html);
+ appendInfo("requestMethod", request.getMethod().toString(), html);
+ html.append("</table></p>");
+
+ html.append("<HR size=\"1\" noshade=\"noshade\">");
+ html.append("<H2>AsyncWeb Server</H2>");
+
+ IoBuffer out = IoBuffer.allocate(html.length());
+
+ // TODO: Need to sort this out when we start dealing with character encodings
+ try {
+ byte[] bytes = html.toString().getBytes("US-ASCII");
+ out.put(bytes);
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(e);
+ }
+
+ out.flip();
+ response.setContent(new ByteBufferContent(out));
}
- return shouldFormat;
- }
- private void doFormat(HttpRequest request, MutableHttpResponse response) {
- StringBuilder html = new StringBuilder(1024);
- html.append("<html><head><title>");
- html.append("AsyncWeb Server - ");
- html.append(bundle.getString("errorMessage"));
- html.append("</title><style><!--");
- CSS.appendTo(html).append("--></style>");
- html.append("</head></body>");
- html.append("<h1>");
- html.append(bundle.getString("errorTitle"));
- html.append("</h1>");
- response.getStatusReasonPhrase();
- String code = String.valueOf(response.getStatus().getCode());
- html.append("<h1>");
- html.append(bundle.getString("statusInfo", code));
- html.append("</h1>");
- html.append("<HR size=\"1\" noshade=\"noshade\">");
-
- html.append("<p><table cellpadding=\"5\">");
- appendInfo("statusCode", String.valueOf(response.getStatus().getCode()), html);
- appendInfo("description", getErrorMessage(response), html);
- appendInfo("requestMethod", request.getMethod().toString(), html);
- html.append("</table></p>");
-
- html.append("<HR size=\"1\" noshade=\"noshade\">");
- html.append("<H2>AsyncWeb Server</H2>");
-
- IoBuffer out = IoBuffer.allocate(html.length());
-
- // TODO: Need to sort this out when we start dealing with character encodings
- try {
- byte[] bytes = html.toString().getBytes("US-ASCII");
- out.put(bytes);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
+ private void appendInfo(String title, String info, StringBuilder html) {
+ html.append("<tr><th>").append(bundle.getString(title)).append("</th>");
+ html.append("<td>").append(info).append("</td>");
}
-
- out.flip();
- response.setContent(new ByteBufferContent(out));
- }
-
- private void appendInfo(String title, String info, StringBuilder html) {
- html.append("<tr><th>").append(bundle.getString(title)).append("</th>");
- html.append("<td>").append(info).append("</td>");
- }
-
- private String getErrorMessage(MutableHttpResponse response) {
- int responseCode = response.getStatus().getCode();
- String errorMessage = response.getStatusReasonPhrase();
- if (errorMessage == null) {
- errorMessage = "";
+
+ private String getErrorMessage(MutableHttpResponse response) {
+ int responseCode = response.getStatus().getCode();
+ String errorMessage = response.getStatusReasonPhrase();
+ if (errorMessage == null) {
+ errorMessage = "";
+ }
+ return bundle.getString("http." + responseCode, errorMessage);
}
- return bundle.getString("http." + responseCode, errorMessage);
- }
-
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/SessionKeepAliveFilter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/SessionKeepAliveFilter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/SessionKeepAliveFilter.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/SessionKeepAliveFilter.java Tue Nov 6 00:59:36 2007
@@ -30,46 +30,47 @@
* each request it handles to be renewed.
* This causes sessions attached to requests to be renewed per-request - even if
* the request does not cause session access to occur.<br/>
- *
+ *
* This handler does not need to be installed for deployments which do not employ
* sessions
- *
+ *
* @author irvingd
*
*/
public class SessionKeepAliveFilter implements HttpServiceFilter {
- private static final Logger LOG = LoggerFactory.getLogger(SessionKeepAliveFilter.class);
-
- /**
- * Handles the specified request.
- * The session associated with the current request - if any - is retrieved -
- * causing its lease to be renewed.
- */
- public void handleRequest(NextFilter next, HttpServiceContext context) {
- HttpSession session = context.getSession(false);
- if (session != null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Session renewed: " + session.getId());
- }
- } else {
- LOG.debug("No session to renew");
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SessionKeepAliveFilter.class);
+
+ /**
+ * Handles the specified request.
+ * The session associated with the current request - if any - is retrieved -
+ * causing its lease to be renewed.
+ */
+ public void handleRequest(NextFilter next, HttpServiceContext context) {
+ HttpSession session = context.getSession(false);
+ if (session != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Session renewed: " + session.getId());
+ }
+ } else {
+ LOG.debug("No session to renew");
+ }
+ next.invoke();
}
- next.invoke();
- }
- public void start() {
- // Not interested in startup
- }
+ public void start() {
+ // Not interested in startup
+ }
- public void stop() {
- // Not interested in shutdown
- }
+ public void stop() {
+ // Not interested in shutdown
+ }
- /**
- * Simply moves the response forward in the chain
- */
- public void handleResponse(NextFilter next, HttpServiceContext context) {
- next.invoke();
- }
+ /**
+ * Simply moves the response forward in the chain
+ */
+ public void handleResponse(NextFilter next, HttpServiceContext context) {
+ next.invoke();
+ }
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/ThreadPoolFilter.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/ThreadPoolFilter.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/ThreadPoolFilter.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/filter/ThreadPoolFilter.java Tue Nov 6 00:59:36 2007
@@ -30,109 +30,116 @@
/**
* A <code>ServiceHandler</code> which offloads requests and optionally
* responses to a thread pool
- *
+ *
* @author irvingd
* @author trustin
* @version $Rev$, $Date$
*/
public class ThreadPoolFilter implements HttpServiceFilter {
- private static final Logger LOG = LoggerFactory.getLogger(ThreadPoolFilter.class);
-
- private static final int DEFAULT_MAX_QUEUE_SIZE = 1000;
- private static final int DEFAULT_MIN_THREADS = 1;
- private static final int DEFAULT_MAX_THREADS = 10;
-
- private PooledExecutor pool;
- private boolean poolResponses;
- private int maxQueueSize = DEFAULT_MAX_QUEUE_SIZE;
- private int minThreads = DEFAULT_MIN_THREADS;
- private int maxThreads = DEFAULT_MAX_THREADS;
-
- /**
- * Handles the specified request.
- * A task is scheduled with our thread pool to
- * initiate onward filter invocation asyncronously
- */
- public void handleRequest(final NextFilter next, HttpServiceContext context) {
- enqueue(new Runnable() {
- public void run() {
- next.invoke();
- }
- });
- }
-
- /**
- * Handles the specified response.
- * If we are configured to offload responses, a task is scheduled
- * with our thread pool to initiate onward filter invocation
- * asyncronously
- */
- public void handleResponse(final NextFilter next, HttpServiceContext context) {
- if (poolResponses) {
- enqueue(new Runnable() {
- public void run() {
- next.invoke();
+ private static final Logger LOG = LoggerFactory
+ .getLogger(ThreadPoolFilter.class);
+
+ private static final int DEFAULT_MAX_QUEUE_SIZE = 1000;
+
+ private static final int DEFAULT_MIN_THREADS = 1;
+
+ private static final int DEFAULT_MAX_THREADS = 10;
+
+ private PooledExecutor pool;
+
+ private boolean poolResponses;
+
+ private int maxQueueSize = DEFAULT_MAX_QUEUE_SIZE;
+
+ private int minThreads = DEFAULT_MIN_THREADS;
+
+ private int maxThreads = DEFAULT_MAX_THREADS;
+
+ /**
+ * Handles the specified request.
+ * A task is scheduled with our thread pool to
+ * initiate onward filter invocation asyncronously
+ */
+ public void handleRequest(final NextFilter next, HttpServiceContext context) {
+ enqueue(new Runnable() {
+ public void run() {
+ next.invoke();
+ }
+ });
+ }
+
+ /**
+ * Handles the specified response.
+ * If we are configured to offload responses, a task is scheduled
+ * with our thread pool to initiate onward filter invocation
+ * asyncronously
+ */
+ public void handleResponse(final NextFilter next, HttpServiceContext context) {
+ if (poolResponses) {
+ enqueue(new Runnable() {
+ public void run() {
+ next.invoke();
+ }
+ });
+ } else {
+ next.invoke();
+ }
+ }
+
+ /**
+ * Starts this filter - creating and configuring the underlying
+ * thread pool
+ */
+ public void start() {
+ LOG.info("ThreadPoolHandler starting: maxQueueSize=" + maxQueueSize
+ + " minThreads= " + minThreads + " maxThreads= " + maxThreads
+ + " poolResponses=" + poolResponses);
+ pool = new PooledExecutor(new BoundedLinkedQueue(maxQueueSize));
+ pool.setMaximumPoolSize(maxThreads);
+ pool.setMinimumPoolSize(minThreads);
+ pool.runWhenBlocked();
+ }
+
+ public void stop() {
+ // TODO: Clean shut-down
+ }
+
+ /**
+ * Sets the minimum number of threads to be employed
+ *
+ * @param minThreads The minimum number of threads
+ */
+ public void setMinThreads(int minThreads) {
+ this.minThreads = minThreads;
+ }
+
+ /**
+ * Sets the maximum number of threads to be employed
+ *
+ * @param maxThreads The maximum number of threads
+ */
+ public void setMaxThreads(int maxThreads) {
+ this.maxThreads = maxThreads;
+ }
+
+ /**
+ * Sets the maximum number of requests which are queued for
+ * asyncronous execution, before tasks are run on the calling
+ * thread
+ *
+ * @param maxQueueSize The maximum queue size
+ */
+ public void setMaxQueueSize(int maxQueueSize) {
+ this.maxQueueSize = maxQueueSize;
+ }
+
+ private void enqueue(Runnable task) {
+ try {
+ pool.execute(task);
+ } catch (InterruptedException e) {
+ LOG.error("Failed to schedule pool task", e);
}
- });
- } else {
- next.invoke();
- }
- }
-
- /**
- * Starts this filter - creating and configuring the underlying
- * thread pool
- */
- public void start() {
- LOG.info("ThreadPoolHandler starting: maxQueueSize=" + maxQueueSize +
- " minThreads= " + minThreads + " maxThreads= " + maxThreads +
- " poolResponses=" + poolResponses);
- pool = new PooledExecutor(new BoundedLinkedQueue(maxQueueSize));
- pool.setMaximumPoolSize(maxThreads);
- pool.setMinimumPoolSize(minThreads);
- pool.runWhenBlocked();
- }
-
- public void stop() {
- // TODO: Clean shut-down
- }
-
- /**
- * Sets the minimum number of threads to be employed
- *
- * @param minThreads The minimum number of threads
- */
- public void setMinThreads(int minThreads) {
- this.minThreads = minThreads;
- }
-
- /**
- * Sets the maximum number of threads to be employed
- *
- * @param maxThreads The maximum number of threads
- */
- public void setMaxThreads(int maxThreads) {
- this.maxThreads = maxThreads;
- }
-
- /**
- * Sets the maximum number of requests which are queued for
- * asyncronous execution, before tasks are run on the calling
- * thread
- *
- * @param maxQueueSize The maximum queue size
- */
- public void setMaxQueueSize(int maxQueueSize) {
- this.maxQueueSize = maxQueueSize;
- }
-
- private void enqueue(Runnable task) {
- try {
- pool.execute(task);
- } catch (InterruptedException e) {
- LOG.error("Failed to schedule pool task", e);
- }
- }
-
+ }
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipeline.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipeline.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipeline.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipeline.java Tue Nov 6 00:59:36 2007
@@ -23,42 +23,41 @@
public interface RequestPipeline {
- /**
- * Adds a request to this pipeline.
- *
- * @return <code>true</code> iff the pipeline accepts the request
- */
- public boolean addRequest(HttpServiceContext context);
-
- /**
- * Frees any responses which may now be provided to the client as a result
- * of the specified response becoming available.
- * If the associated request has not been previously added to this pipeline,
- * it joins the pipeline at the back of the queue: All previously added
- * requests must be responded to before the new request can take its turn<br/>
- */
- public void releaseResponse(HttpServiceContext context);
-
-
- /**
- * Sets the <code>PipelineListener</code> to be notified when
- * a request is released from this pipeline
- *
- * @param listener The listener
- */
- public void setPipelineListener(RequestPipelineListener listener);
-
- /**
- * Disposes of any requests still living in the pipeline
- */
- public void disposeAll();
-
- /**
- * Runs the scheduled command the next time the pipeline is empty.
- * Run immediately if the pipeline is currently empty;
- *
- * @param r The command to run
- */
- public void runWhenEmpty(Runnable r);
-
+ /**
+ * Adds a request to this pipeline.
+ *
+ * @return <code>true</code> iff the pipeline accepts the request
+ */
+ public boolean addRequest(HttpServiceContext context);
+
+ /**
+ * Frees any responses which may now be provided to the client as a result
+ * of the specified response becoming available.
+ * If the associated request has not been previously added to this pipeline,
+ * it joins the pipeline at the back of the queue: All previously added
+ * requests must be responded to before the new request can take its turn<br/>
+ */
+ public void releaseResponse(HttpServiceContext context);
+
+ /**
+ * Sets the <code>PipelineListener</code> to be notified when
+ * a request is released from this pipeline
+ *
+ * @param listener The listener
+ */
+ public void setPipelineListener(RequestPipelineListener listener);
+
+ /**
+ * Disposes of any requests still living in the pipeline
+ */
+ public void disposeAll();
+
+ /**
+ * Runs the scheduled command the next time the pipeline is empty.
+ * Run immediately if the pipeline is currently empty;
+ *
+ * @param r The command to run
+ */
+ public void runWhenEmpty(Runnable r);
+
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipelineListener.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipelineListener.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipelineListener.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/RequestPipelineListener.java Tue Nov 6 00:59:36 2007
@@ -22,5 +22,5 @@
import org.safehaus.asyncweb.service.HttpServiceContext;
public interface RequestPipelineListener {
- public void responseReleased(HttpServiceContext context);
+ public void responseReleased(HttpServiceContext context);
}
Modified: mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/StandardRequestPipeline.java
URL: http://svn.apache.org/viewvc/mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/StandardRequestPipeline.java?rev=592337&r1=592336&r2=592337&view=diff
==============================================================================
--- mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/StandardRequestPipeline.java (original)
+++ mina/sandbox/asyncweb/core/src/main/java/org/safehaus/asyncweb/service/pipeline/StandardRequestPipeline.java Tue Nov 6 00:59:36 2007
@@ -30,90 +30,94 @@
public class StandardRequestPipeline implements RequestPipeline {
- private static final Logger LOG = LoggerFactory.getLogger(StandardRequestPipeline.class);
-
- private int maxPipelinedRequests;
- private RequestPipelineListener listener;
- private Runnable emptyCommand;
- private Map<HttpServiceContext, HttpResponse> entryMap = new LinkedHashMap<HttpServiceContext, HttpResponse>();
-
-
- public StandardRequestPipeline(int maxPipelinedRequests) {
- this.maxPipelinedRequests = maxPipelinedRequests;
- }
-
- public boolean addRequest(HttpServiceContext context) {
- boolean added = false;
- synchronized (entryMap) {
- if (entryMap.size() < maxPipelinedRequests) {
- entryMap.put(context, null);
- added = true;
- }
- }
- if (added && LOG.isDebugEnabled()) {
- LOG.debug("Request added to pipeline ok");
- }
- return added;
- }
-
- public void releaseResponse(HttpServiceContext context) {
- if (context.getCommittedResponse() == null) {
- throw new IllegalStateException("response is not committed.");
- }
- synchronized (entryMap) {
- entryMap.put(context, context.getCommittedResponse());
- releaseRequests();
- }
- }
-
- public void disposeAll() {
- synchronized (entryMap) {
- entryMap.clear();
- }
- }
-
- public void runWhenEmpty(Runnable command) {
- synchronized (entryMap) {
- if (entryMap.isEmpty()) {
- command.run();
- } else {
- emptyCommand = command;
- }
- }
- }
-
- /**
- * Sets the pipeline listener associated with this pipeline
- *
- * @param listener The listener
- */
- public void setPipelineListener(RequestPipelineListener listener) {
- this.listener = listener;
- }
-
- /**
- * Releases any requests which can be freed as a result of a request
- * being freed.
- * We simply iterate through the list (in insertion order) - freeing
- * all responses until we arive at one which has not yet been completed
- */
- private void releaseRequests() {
- for (Iterator<Map.Entry<HttpServiceContext, HttpResponse>> iter = entryMap.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry<HttpServiceContext, HttpResponse> entry = iter.next();
- HttpResponse response = entry.getValue();
- if (response != null) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Response freed from pipeline. Notifying");
- }
- listener.responseReleased(entry.getKey());
- iter.remove();
- } else {
- break;
- }
+ private static final Logger LOG = LoggerFactory
+ .getLogger(StandardRequestPipeline.class);
+
+ private int maxPipelinedRequests;
+
+ private RequestPipelineListener listener;
+
+ private Runnable emptyCommand;
+
+ private Map<HttpServiceContext, HttpResponse> entryMap = new LinkedHashMap<HttpServiceContext, HttpResponse>();
+
+ public StandardRequestPipeline(int maxPipelinedRequests) {
+ this.maxPipelinedRequests = maxPipelinedRequests;
}
- if (emptyCommand != null && entryMap.isEmpty()) {
- emptyCommand.run();
+
+ public boolean addRequest(HttpServiceContext context) {
+ boolean added = false;
+ synchronized (entryMap) {
+ if (entryMap.size() < maxPipelinedRequests) {
+ entryMap.put(context, null);
+ added = true;
+ }
+ }
+ if (added && LOG.isDebugEnabled()) {
+ LOG.debug("Request added to pipeline ok");
+ }
+ return added;
+ }
+
+ public void releaseResponse(HttpServiceContext context) {
+ if (context.getCommittedResponse() == null) {
+ throw new IllegalStateException("response is not committed.");
+ }
+ synchronized (entryMap) {
+ entryMap.put(context, context.getCommittedResponse());
+ releaseRequests();
+ }
}
- }
-
+
+ public void disposeAll() {
+ synchronized (entryMap) {
+ entryMap.clear();
+ }
+ }
+
+ public void runWhenEmpty(Runnable command) {
+ synchronized (entryMap) {
+ if (entryMap.isEmpty()) {
+ command.run();
+ } else {
+ emptyCommand = command;
+ }
+ }
+ }
+
+ /**
+ * Sets the pipeline listener associated with this pipeline
+ *
+ * @param listener The listener
+ */
+ public void setPipelineListener(RequestPipelineListener listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Releases any requests which can be freed as a result of a request
+ * being freed.
+ * We simply iterate through the list (in insertion order) - freeing
+ * all responses until we arive at one which has not yet been completed
+ */
+ private void releaseRequests() {
+ for (Iterator<Map.Entry<HttpServiceContext, HttpResponse>> iter = entryMap
+ .entrySet().iterator(); iter.hasNext();) {
+ Map.Entry<HttpServiceContext, HttpResponse> entry = iter.next();
+ HttpResponse response = entry.getValue();
+ if (response != null) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Response freed from pipeline. Notifying");
+ }
+ listener.responseReleased(entry.getKey());
+ iter.remove();
+ } else {
+ break;
+ }
+ }
+ if (emptyCommand != null && entryMap.isEmpty()) {
+ emptyCommand.run();
+ }
+ }
+
}