[
http://jira.amdatu.org/jira/browse/AMDATU-471?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12599#comment-12599
]
Jan Willem Janssen commented on AMDATU-471:
-------------------------------------------
{quote}
1) The servlet spec says that the container must make sure that
init()/destroy() is called only once during the lifetime of a servlet instance.
{quote}
That's indeed what section SRV2.3.2/2.3.4 of the Servlet 2.4/2.5/3
specification states. However, the lifetime of a servlet instance is now
extended due to the use of the Whiteboard pattern. For this situation, this
strict lifecycle no longer can apply to your Servlet.
Would this be a problem? IMO, no, as long as you correctly balance the init() &
destroy() method calls. Suppose you created a DB-connection in your
init()-method, you should release it in the destroy() method (which you
probably already do), allowing a new call to init() to be made.
{quote}
2) The HttpService spec honors this by what you quoted above. On register the
HttpServcie calls init() on unregister it calls destroy(). As long as you make
sure that you do not call register twice with the same servlet instance all is
well.
{quote}
Referring the last remark: the HttpService also specifies this:
{quote}
Therefore, the same Servlet instance must not be reused for registration with
another Http Service, nor can it be registered under multiple names. Unique
instances are required for each registration.
{quote}
{quote}
3) Now the whiteboard pattern introduces a problem as you no longer have
control over the register/unregister. Your servlet may get
registered/unregistered/registered/unregistered simply because the whiteboard
adapter gets updated or any other reason.
{quote}
A whiteboard adapter simply bridges the registration of servlets/filters to the
HttpService. Two situations can arise now:
1. the HttpService is updated; in this case the whiteboard should first
deregister your service (and call destroy() on your servlet) from the old
HttpService and register your service again for the new HttpService, and yes,
call init() on your servlet again;
2. the Whiteboard Adapter is updated; in this case it should do the exact same
as in the previous situation.
If you use Servlets/Filters in a whiteboard style manner, you should always be
prepared to have multiple init()/destroy() calls, otherwise you cannot play
nice in an OSGi environment.
{quote}
4) Thus if you publish a 3rd party servlet that may not be able to handle
multiple init()/destroy() cycles there must be some way to detect and handle
such an event allowing you to unpublished and publish a new instance.
{quote}
Having a dependency on the DispatcherService won't help you much here,
considering the cases of the previous point. There's no way you can shield your
Servlet from having its init() & destroy() methods called multiple times, apart
from doing static variable checks in both methods, but those Servlets won't
work well in a Whiteboard situation anyway, so why bother trying to solve this
issue? If you stumble upon such a servlet, you should wrap it to register
directly against the HttpService yourself.
> Remove DispatcherService marker interface
> -----------------------------------------
>
> Key: AMDATU-471
> URL: http://jira.amdatu.org/jira/browse/AMDATU-471
> Project: Amdatu
> Issue Type: Task
> Components: Amdatu Web
> Reporter: Bram de Kruijff
> Assignee: Jan Willem Janssen
> Fix For: Sprint 4
>
>
> Remove DispatcherService marker interface
> * Do we need it (servlet/filter lifecycle)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
http://jira.amdatu.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
Amdatu-developers mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-developers