LimeWire Consolidated API

org.limewire.http
Class BasicHttpAcceptor

java.lang.Object
  extended by org.limewire.http.BasicHttpAcceptor
All Implemented Interfaces:
Service, ConnectionAcceptor
Direct Known Subclasses:
HTTPAcceptor, LocalHTTPAcceptor

public class BasicHttpAcceptor
extends Object
implements ConnectionAcceptor, Service

Processes HTTP requests which are forwarded to HttpRequestHandler objects that can be registered for a URL pattern.

The acceptor uses HttpCore and LimeWire's HTTP component for connection handling. BasicHttpAcceptor needs to be started by invoking #start(ConnectionDispatcher) in order to accept connection.


Field Summary
static String[] DEFAULT_METHODS
           
 
Constructor Summary
BasicHttpAcceptor(org.apache.http.params.HttpParams params, AuthenticationInterceptor authenticationInterceptor, String... supportedMethods)
           
 
Method Summary
 void acceptConnection(String word, Socket socket)
          Notification that a new incoming socket has been opened.
 void addAcceptorListener(HttpAcceptorListener listener)
          Adds a listener for acceptor events.
 void addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
          Adds an interceptor for incoming requests.
 void addResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
          Adds an interceptor for outgoing responses.
static org.apache.http.params.HttpParams createDefaultParams(String userAgent, int timeout)
           
 String[] getHttpMethods()
          Returns the supported HTTP methods, e.g.
protected  DispatchedIOReactor getReactor()
          Returns the reactor.
 String getServiceName()
           
 void initialize()
           
 boolean isBlocking()
          Returns true, if ConnectionAcceptor.acceptConnection(String, Socket) needs to be invoked in a separate thread.
 void registerHandler(String pattern, org.apache.http.nio.protocol.NHttpRequestHandler handler)
          Registers a request handler for a request pattern.
 void removeAcceptorListener(HttpAcceptorListener listener)
          Removes listener from the list of acceptor listeners.
 void removeRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
          Removes an interceptor for incoming requests.
 void removeResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
          Adds an interceptor for outgoing responses.
 void start()
          Initializes the reactor.
 void stop()
           
 void unregisterHandler(String pattern)
          Unregisters the handlers for pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_METHODS

public static final String[] DEFAULT_METHODS
Constructor Detail

BasicHttpAcceptor

public BasicHttpAcceptor(org.apache.http.params.HttpParams params,
                         AuthenticationInterceptor authenticationInterceptor,
                         String... supportedMethods)
Method Detail

createDefaultParams

public static org.apache.http.params.HttpParams createDefaultParams(String userAgent,
                                                                    int timeout)

acceptConnection

public void acceptConnection(String word,
                             Socket socket)
Description copied from interface: ConnectionAcceptor
Notification that a new incoming socket has been opened.

Specified by:
acceptConnection in interface ConnectionAcceptor
Parameters:
word - first word that arrived on the wire
socket - the newly opened socket.

isBlocking

public boolean isBlocking()
Description copied from interface: ConnectionAcceptor
Returns true, if ConnectionAcceptor.acceptConnection(String, Socket) needs to be invoked in a separate thread.

Specified by:
isBlocking in interface ConnectionAcceptor

getHttpMethods

public String[] getHttpMethods()
Returns the supported HTTP methods, e.g. "GET" or "HEAD".


addAcceptorListener

public void addAcceptorListener(HttpAcceptorListener listener)
Adds a listener for acceptor events.


addRequestInterceptor

public void addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Adds an interceptor for incoming requests.

See Also:
HttpProcessor

addResponseInterceptor

public void addResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
Adds an interceptor for outgoing responses.

See Also:
HttpProcessor

getReactor

protected DispatchedIOReactor getReactor()
Returns the reactor.

Note: Needs to be called from the NIODispatcher thread.

Returns:
null, if the acceptor has not been started, yet.

removeAcceptorListener

public void removeAcceptorListener(HttpAcceptorListener listener)
Removes listener from the list of acceptor listeners.

See Also:
addAcceptorListener(HttpAcceptorListener)

removeRequestInterceptor

public void removeRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Removes an interceptor for incoming requests.

See Also:
addRequestInterceptor(HttpRequestInterceptor)

removeResponseInterceptor

public void removeResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
Adds an interceptor for outgoing responses.

See Also:
addResponseInterceptor(HttpResponseInterceptor)

registerHandler

public void registerHandler(String pattern,
                            org.apache.http.nio.protocol.NHttpRequestHandler handler)
Registers a request handler for a request pattern. See HttpRequestHandlerRegistry for a description of valid patterns.

If a request matches multiple handlers, the handler with the longer pattern is preferred.

Only a single handler may be registered per pattern.

Parameters:
pattern - the URI pattern to handle requests for
handler - the handler that processes the request

unregisterHandler

public void unregisterHandler(String pattern)
Unregisters the handlers for pattern.

See Also:
#registerHandler(String, HttpRequestHandler)

start

public void start()
Initializes the reactor.

Specified by:
start in interface Service
See Also:
stop()

stop

public void stop()
Specified by:
stop in interface Service
See Also:
start()

initialize

public void initialize()
Specified by:
initialize in interface Service

getServiceName

public String getServiceName()
Specified by:
getServiceName in interface Service

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.