users@jersey.java.net

Re: [Jersey] reload unique singleton resource

From: Guilhem <guilhem.legal_at_geomatys.fr>
Date: Wed, 20 Oct 2010 17:45:58 +0200

hi pavel,

thanks for replying to me. I guess that "reset" is the good word for
what i want to do. when i launch my web-application, i create with
jersey some singleton resource.

The constructor of these resources make a lot of things (connecting
database, reading configuration file, etc) and they are sometimes very
long to be completely executed.

At some point, i have changed some configuration file (switching from a
database from another for example), and i want to "reset" the resource
using this configuration.
but i don't want to reset all the other resource that have been started
because it will take a long time.

I guess that when you are saying that : "in this case it would be more
transparent to have something like reset() method. "
you think of a method reset() on my resource that i can call?

but i don't want that anybody can call this method, this is why i use a
protected resource to do this job.


for Jrebel, i try the jersey tutorial some month ago, my goal here is
not to reload a class, i'm not in a context of development but in a
context of administration.
however, if Jrebel allow me to "reload" one of my resource without
shutting down the others i can use it.

Guilhem Legal


Le 20/10/2010 16:38, Pavel Bucek a écrit :
>
> Hello Guilhem,
>
> just curious - what do you want to achieve? Do you want just "reset"
> singletons state or actually really reload "new" class?
>
> if answer is "reset", your solution might work but I don't think that
> it's best way - in this case it would be more transparent to have
> something like reset() method.
>
> if you want to actually reload that class, it would not work, because
> you are reusing already created AbstractResource instance. If it is
> for development purposes, you might want to use jrebel, see [1].
>
> I guess I just need to better understand what are you trying to do and
> why, so if you can, please provide more details.
>
> Thanks!
> Pavel
>
> [1] https://jersey.dev.java.net/nonav/documentation/latest/jrebel.html
>
> On 10/15/10 4:18 PM, Guilhem wrote:
>> hi,
>>
>> since i use jersey, i always search a way to reload only one
>> singleton resource instead of reload all.
>> finally, i have download the jersey sources and add some piece of
>> code in the module server.
>>
>> here is the classes and methods that i have added, could someone tell
>> me if its a good aproach to do that :
>>
>> 1) I add an extension of containerListener :
>>
>> public interface ContainerListenerExt extends ContainerListener {
>>
>> void reloadResource(Class c);
>> }
>>
>>
>> 2) I add the follonwing in package
>> com.sun.jersey.spi.container.servlet.WebComponent.java
>>
>>
>> public class WebComponent implements ContainerListener,
>> ContainerListenerExt {
>>
>> .......
>> .......
>>
>> @Override
>> public void reloadResource(Class c) {
>> application.reloadResource(c);
>> }
>>
>> .....
>>
>> }
>>
>> 3) I add and implements a method in
>> com.sun.jersey.spi.container.WebApplication and
>> com.sun.jersey.server.impl.application.WebApplicationImpl
>>
>> public interface WebApplication extends Traceable {
>>
>> ......
>> ......
>>
>> /**
>> * Destroy and recreate the resource of class c.
>> *
>> * @param c The class of the resource to reload.
>> */
>> void reloadResource(Class c);
>>
>> }
>>
>> public final class WebApplicationImpl implements WebApplication {
>>
>> ......
>> ......
>>
>> @Override
>> public void reloadResource(Class c) {
>> for (ResourceComponentProvider rcp : providerMap.values()) {
>> if ( rcp.getInstance().getClass().equals(c)) {
>> LOGGER.info("removing and destroying the class:" +
>> c.getName());
>> rcp.destroy();
>> rcp.init(getAbstractResource(c));
>> }
>> }
>> }
>> ......
>> ......
>> }
>>
>>
>> thanks for your return,
>>
>> Guilhem legal
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>