Simple Java Server
A brief intro to the Simple Java
Server.
In September 2004, I was contracted to write a
Java-based server architecture for creating
inetd-like
daemons in an object oriented manner, which could be dynamically plugged and
unplugged, with a full administrative interface using
RMI.The project was a success
development wise, but after the customer signed off on the project, they
disappeared without payment (the full, sordid details in in two SlashDot journal
entries here and here). Out $1000 (CDN), I decided to cut my
losses, learn a lesson about taking on a project from another country without
receiving an up-front payment, and decided to Open Source
everything.SJS is a very powerful
architecture which is especially suited to creating servers which use a
request/response style service, such as those used in POP3 and SMTP (indeed,
originally I was supposed to be contracted to write plug-ins for the server for
each of these protocols, but that fell through once the jokers who contracted me
buggered off and stopped responding to my messages). And you don't even need to
know anything about networking to use it -- just create a subclass of the
AbstractRequestResponseAdapter
class and implement a single method --
processRequest()
which takes as input a single String (the request), and which returns a single
String (the response). With that built, create an XML file describing what port
to listen against, the maximum number of simultaneous requests to handle (if
desired), a service name, and presto -- you have a complete server that does
what you want.There is also an
AbstractAdapter
class which you can use to create services which aren't request-response based
if you want to do something more complex, but you're going to need to know a bit
about Java network programming to use
it.SJS's administrative interface uses
RMI to connect to the server and modify any of its services in real time. The
command set for the administrative tool
includes: CREATE
<ip address>:<port> name="<service name>" adapter="<full
path>" SET
[<ip address>:<port> | name="<service name>"] <parameter
name>="<parameter
value>" DESCRIBE
[<ip address>:<port> | name="<service
name>"] DESCRIBE
[<ip address>:<port> | name="<service name>"] <parameter
name> REMOVE
[<ip address>:<port> | name="<service
name>"] REMOVE
[<ip address>:<port> | name="<service name>"] <parameter
name> DENY
INCOMING REQUESTS [<ip address>:<port> | name="<service
name>"] ACCEPT
INCOMING REQUESTS [<ip address>:<port> | name="<service
name>"] STATUS
[<ip address>:<port> |
name="name"] START
SERVER [server config
file] SHUTDOWN
[NOW]Many of these commands will
also modify the XML data files to reflect your changes -- so if you change the
listen-to port for a service, it not only changes immediately, but the change
will be saved in the XML configuration file for the service as
well.I'm extremely proud of this piece
of work, as it makes creating a server in Java a complete snap which even a
neophyte network programmer can use to create robust server applications.
Unfortunately it's little known, and so far as I know isn't used anywhere. If
you're looking to write your own server software in Java, especially if it's
request-response style, take a look at what SJS can do for you (but note that
SJS is 100% GPL -- if the company which screwed me wants to sell solutions based
on this code as they originally intended, they have to give their customers all
the source as this is the only license SJS is available
under).
Posted: Saturday - April 02, 2005 at 01:41 AM