users@jersey.java.net

Re: [Jersey] reload unique singleton resource

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 20 Oct 2010 16:38:19 +0200

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
>
>