Server is the core of the system. A server glues together
Handler s
and
EndPoint s.
EndPoint s are responsible for reading the
HttpRequest from a source and sending the HttpResponse over that source.
EndPoint s then sends the request to the
Handler by calling the post()
method on the server to send the request to this server's
Handler s.
Handler s
process the
HttpRequest and produce an appropriate
HttpResponse .
The server contains the configuration for the entire server. What are the expected values
in the configuration is mainly controlled by what handlers and endpoints are configured.
Depending on which handlers and endpoints have been enabled, the configuration will vary.
The only two parameters are required: handler and <handler's name>.class.
Here is an example configuration:
handler=my\ handler
my\ handler.class=pygmy.handlers.DefaultChainHandler
my\ handler.chain=handler1, handler2
my\ handler.url-prefix=/
handler1.class=pygmy.handlers.FileHandler
handler1.root=C:\temp
handler1.url-prefix=/home-directory
handler2.class=pygmy.handlers.ResourceHandler
handler2.url-prefix=/jar
handler2.resourceMount=/html
handler2.default=index.html
In the above configuration, handler property is the name of first handler.
The name is used to find all the other properties for that particular handler.
The .class property is used to tell the Server the name of the class to instantiate.
The two other properties, .chain and .url-prefix, are particular to the
pygmy.handlers.DefaultChainHandler .
Server's only have one
Handler . However, the power of
Handler s is the ability to have more than one. The
pygmy.handlers.DefaultChainHandler provides the ability to create a
chain of multiple handlers. See
pygmy.handlers.DefaultChainHandler for
information on configuring it.
Server also contains a set of
pygmy.core.EndPoint s. When the server initializes
itself it looks in the configuration for the endpoints parameter. The endpoints
parameter contains a space seperated list of the names of the endpoints this server will
create. For each name in the list it will look for a config parameter
<name of endpoint>.class in the configuration. It will instantiate the classname
using the no-argument constructor and add it to the set of endpoints in the server.
If the server does not find the endpoints parameter, then it will create a default EndPoint
of type
pygmy.core.ServerSocketEndPoint named http. Here is an example of using the endpoints
parameter:
endpoints=endpoint1 endpoint2
handler=handler1
endpoint1.class=my.package.MyEndPoint
endpoint1.param1=foo
endpoint1.param2=bar
endpoint2.class=my.package.AnotherEndPoint
endpoint2.param1=foo
endpoint2.param2=bar
endpoint2.param3=baz
...
Server class looks for the following properties in the configuration:
handler | None | Yes |
endpoints | http | No |
<handler name>.class | None | Yes |
<endpoint name>.class | None | iff endpoints param is defined |
threadpool.size | 5 | No |
|