users@jersey.java.net

Re: [Jersey] Would it be possible to create a RESTful web service and deploy it in a clustered environment?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 26 Feb 2009 13:31:59 +0100

On Feb 26, 2009, at 1:10 PM, Srinivas Naresh Bhimisetty wrote:

> Hi,
>
> one of my colleagues asked me this question today.
> He wants to create a RESTful Web Service using Jersey and deploy it
> in a clustered environment.

If you conform to the REST stateless constraint then you do not
require clustering. Strictly speaking the application is not that
RESTful if it relies on session state.

Say you have a database then rather than manage the high availability
of types of state, session and that in the database, you only need to
manage the latter. You can transform what would previously considered
to be session state into resource state that is stored in the database
and accessible via a URL.


> In order to test this, he said he wants to set some information in
> the service and put in the session, and get one of the nodes on the
> cluster down, and be able to access it from the instance running on
> another node.
> I thought @PerSession might be helpful, but looks like a new
> instance of the application would be running on each node.

An instance of the application *has* to be running at each node for it
to be clustered. The session state is shared between the applications.

@PerSession should work. However, i don't recommend you use that
unless you really have to.

When an instance of a @PerSession resource class is required it will
first ask if there is an instance in the session attributes. If there
is then that will be used. Otherwise a new instance will be created
and stored in the session. The instance is only stored in the session
once, so there are probably some restrictions on if you change the
state of the resource.

Paul.