users@jersey.java.net

Re: [Jersey] reload unique singleton resource

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 20 Oct 2010 18:30:44 +0200

thanks for clarification.

in this case, I don't think you need (should do) modifications in jersey
sources.

I'm not sure how much "RESTful" this approach would be, but I could
imagine something like protected resource /config, which would be able
to do these kind of tasks and singletons need to be ready for this
(actually I think you will have slightly better performance with this
solution). It will need some additional code, but it should be trivial
to add.

I can see potential problem during this "reset" or "reloadConfig" or
whatever you want to call it - what will happen when some regular
request comes in during reset?

And, more general, we can discuss whether you really need to do
something like this - database connections (jdbs connectors) should be
handled by application server and application settings might not be
needed at all, but I don't have that kind of details about your
application to be more helpful.

Pavel


On 10/20/10 5:45 PM, Guilhem wrote:
> 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
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>