mmhttp.server
Class Server

java.lang.Object
  extended by mmhttp.server.Server
All Implemented Interfaces:
mmsocketserver.SocketServer

public class Server
extends java.lang.Object
implements mmsocketserver.SocketServer

This is where the action begins. The Server implements the SocketService. Imagine a restaurant. A restaurant provides a service. A server serves each table that comes in for the service. Similarly, this framework (MM-HTTP) provides an HTTP service and the Server serves each socket connecting for the service. When started the Server will start listening to the specified port on a new Thread. Every connection will be processed in a separate thread.


Field Summary
 Authenticator authenticator
          Default: PromiscuousAuthenticator.
 java.net.InetAddress host
          InetAddress to specify specific interfaces.
 Logger logger
          A Logger object that will log each request.
 java.lang.String name
          Server name the will be used in the Server header of each response.
 int port
          The port that the server will listen to.
 java.lang.String realm
          Displayed by the browser when promting for user credentials.
 long requestTimeout
          Time to wait, in milliseconds, for a request to parse.
 ResponderFactory responderFactory
          The ResponderFactory will create Responders for each request.
 
Constructor Summary
Server()
          Constructs a new Server.
Server(int port)
          A convenience constructor that sets the port.
 
Method Summary
 ResponderFactory getResponderFactory()
           
 boolean isRunning()
           
 void register(java.lang.String pattern, java.lang.Class klass)
          Shortcut to ResponderFactory.register.
 void serve(java.net.Socket socket)
          Serves a socket connection.
 void setDefaultResponder(java.lang.Class klass)
          Sets the default Responder.
 void start()
          Starts the server.
 void stop()
          Stops the server gracefully waiting for all the request threads to complete.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

public Logger logger
A Logger object that will log each request. Defaults to null;


responderFactory

public ResponderFactory responderFactory
The ResponderFactory will create Responders for each request. Create on instantiation.


realm

public java.lang.String realm
Displayed by the browser when promting for user credentials. Default: "MM-HTTP"


authenticator

public Authenticator authenticator
Default: PromiscuousAuthenticator. Can be set to a custom Authenticator.


name

public java.lang.String name
Server name the will be used in the Server header of each response.


port

public int port
The port that the server will listen to. Default: 8080


requestTimeout

public long requestTimeout
Time to wait, in milliseconds, for a request to parse. Default: 10000.


host

public java.net.InetAddress host
InetAddress to specify specific interfaces. Defaults to null, which will listen to all interfaces.

Constructor Detail

Server

public Server()
Constructs a new Server. All of the fields of this class are public so that configuration can be done after construction, and before starting the server.


Server

public Server(int port)
A convenience constructor that sets the port.

Parameters:
port -
Method Detail

register

public void register(java.lang.String pattern,
                     java.lang.Class klass)
Shortcut to ResponderFactory.register.

Parameters:
pattern -
klass -

setDefaultResponder

public void setDefaultResponder(java.lang.Class klass)
Sets the default Responder.

Parameters:
klass -

start

public void start()
           throws java.lang.Exception
Starts the server.

Throws:
java.lang.Exception

stop

public void stop()
          throws java.lang.Exception
Stops the server gracefully waiting for all the request threads to complete.

Throws:
java.lang.Exception

serve

public void serve(java.net.Socket socket)
Serves a socket connection.

Specified by:
serve in interface mmsocketserver.SocketServer
Parameters:
socket -

isRunning

public boolean isRunning()
Returns:
true if the server is running

getResponderFactory

public ResponderFactory getResponderFactory()
Returns:
the ResponderFactory


Copyright © 2009 Micah Martin. All Rights Reserved.