Use application.setName to set a custom name?

2015-01-20 Thread Thorsten Schöning
Hi all,

I have an application which gets deployed into different web app
contexts of a Tomcat simply be naming the folder of the context
differently. So "application" is hosted as "application1",
"application2" etc. simply by copying the generic folder of
"application" into a new target and do some minor configuration
changes. The point is, that web.xml keeps the same for all
installations within one Tomcat.

Today I had a look at using JMX with Wicket and recognized, that the
name of the application by default is set to the name the Wicket
filter gets in web.xml. Because that's generic in my case I'm unable
to distinguish what the JMX console shows me, it's always called the
same and I can't see to which application it belongs.

Two options now: Either one has to change web.xml for each folder or
provide some logic to set the application name on runtime, e.g.
depending on the folder name.

I would prefer the latter and tested a bit around Application.setName,
but this doesn't seem to work, because setName can only be called
once and WicketFilter currently always calls it. So regardless if
someone wants to call it earlier or afterwards, it will always result
in an error.

Is that expected behavior, should no application be able to provide
another name at all? Or is there any other way to set the name on my
own without WicketFilter trying to do the same?

The relevant code in WicketFilter is the following:

> public void init(final boolean isServlet, final FilterConfig filterConfig)
[...]
>// locate application instance unless it was already 
> specified during construction
>if (application == null)
>{
>applicationFactory = getApplicationFactory();
>application = 
> applicationFactory.createApplication(this);
>}
>
>application.setName(filterConfig.getFilterName());
>application.setWicketFilter(this);

This looks to me as if setName is effectively useless for anyone
except WicketFilter, because it's always called there.

Thanks for your help!

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme  http://www.AM-SoFT.de/

Telefon...05151-  9468- 55
Fax...05151-  9468- 88
Mobil..0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Use application.setName to set a custom name?

2015-01-20 Thread Martin Grigorov
Hi,

This is by design (
https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/Application.java#L944-L945
).
The application name is used for internal caches, keys, etc. and it must be
something stable and unique.
If it was allowed to change it at any time then many things may break.

I think the easiest thing to do is to export yet another JMX ObjectName
with the custom name. See
https://github.com/apache/wicket/blob/master/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java#L109


Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jan 20, 2015 at 8:05 PM, Thorsten Schöning 
wrote:

> Hi all,
>
> I have an application which gets deployed into different web app
> contexts of a Tomcat simply be naming the folder of the context
> differently. So "application" is hosted as "application1",
> "application2" etc. simply by copying the generic folder of
> "application" into a new target and do some minor configuration
> changes. The point is, that web.xml keeps the same for all
> installations within one Tomcat.
>
> Today I had a look at using JMX with Wicket and recognized, that the
> name of the application by default is set to the name the Wicket
> filter gets in web.xml. Because that's generic in my case I'm unable
> to distinguish what the JMX console shows me, it's always called the
> same and I can't see to which application it belongs.
>
> Two options now: Either one has to change web.xml for each folder or
> provide some logic to set the application name on runtime, e.g.
> depending on the folder name.
>
> I would prefer the latter and tested a bit around Application.setName,
> but this doesn't seem to work, because setName can only be called
> once and WicketFilter currently always calls it. So regardless if
> someone wants to call it earlier or afterwards, it will always result
> in an error.
>
> Is that expected behavior, should no application be able to provide
> another name at all? Or is there any other way to set the name on my
> own without WicketFilter trying to do the same?
>
> The relevant code in WicketFilter is the following:
>
> > public void init(final boolean isServlet, final FilterConfig
> filterConfig)
> [...]
> >// locate application instance unless it was
> already specified during construction
> >if (application == null)
> >{
> >applicationFactory =
> getApplicationFactory();
> >application =
> applicationFactory.createApplication(this);
> >}
> >
> >application.setName(filterConfig.getFilterName());
> >application.setWicketFilter(this);
>
> This looks to me as if setName is effectively useless for anyone
> except WicketFilter, because it's always called there.
>
> Thanks for your help!
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
> AM-SoFT IT-Systeme  http://www.AM-SoFT.de/
>
> Telefon...05151-  9468- 55
> Fax...05151-  9468- 88
> Mobil..0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Use application.setName to set a custom name?

2015-01-21 Thread Thorsten Schöning
Guten Tag Martin Grigorov,
am Dienstag, 20. Januar 2015 um 19:21 schrieben Sie:

> This is by design (
> https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/Application.java#L944-L945
> ).
> The application name is used for internal caches, keys, etc. and it must be
> something stable and unique.
> If it was allowed to change it at any time then many things may break.

That's fine, but why am I not allowed to set it myself first?
WicketFilter could just test if it is already set and don't set it
than, it doesn't necessarily provide a better one. The problem
currently is only that it always wants to set it, even if I already
did using a custom constructor.

That's the only thing that doesn't make sense to me.

> I think the easiest thing to do is to export yet another JMX ObjectName
> with the custom name. See
> https://github.com/apache/wicket/blob/master/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java#L109

I had a look at that as well, but didn't understand what I could do to
change the implementation, as there doesn't seem to be any hook or
callback or whatever to change how the variable "domain" is created.
It always uses the application name.

Would I need to implement an own Initializer by overriding the
mentioned "init"? How would I register my Initializer to be used by
wicket-jmx then? I would prefer some way like it's now, either the
wicket-jmx gets deployed or not, so everything is as loose coupled as
now.

Thanks for any more details.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme  http://www.AM-SoFT.de/

Telefon...05151-  9468- 55
Fax...05151-  9468- 88
Mobil..0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Use application.setName to set a custom name?

2015-01-21 Thread Martin Grigorov
On Wed, Jan 21, 2015 at 10:12 AM, Thorsten Schöning 
wrote:

> Guten Tag Martin Grigorov,
> am Dienstag, 20. Januar 2015 um 19:21 schrieben Sie:
>
> > This is by design (
> >
> https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/Application.java#L944-L945
> > ).
> > The application name is used for internal caches, keys, etc. and it must
> be
> > something stable and unique.
> > If it was allowed to change it at any time then many things may break.
>
> That's fine, but why am I not allowed to set it myself first?
> WicketFilter could just test if it is already set and don't set it
> than, it doesn't necessarily provide a better one. The problem
> currently is only that it always wants to set it, even if I already
> did using a custom constructor.
>

But how would you decide what name to use if you do this in the constructor
?
At that time you don't have access to many things, e.g. the servlet context.


>
> That's the only thing that doesn't make sense to me.
>
> > I think the easiest thing to do is to export yet another JMX ObjectName
> > with the custom name. See
> >
> https://github.com/apache/wicket/blob/master/wicket-jmx/src/main/java/org/apache/wicket/jmx/Initializer.java#L109
>
> I had a look at that as well, but didn't understand what I could do to
> change the implementation, as there doesn't seem to be any hook or
> callback or whatever to change how the variable "domain" is created.
> It always uses the application name.
>

I meant to add your own MBean somewhere in the root.
This way it will be easy for you to check the instance "real" name in the
JMX viewer


>
> Would I need to implement an own Initializer by overriding the
> mentioned "init"? How would I register my Initializer to be used by
> wicket-jmx then? I would prefer some way like it's now, either the
> wicket-jmx gets deployed or not, so everything is as loose coupled as
> now.
>
> Thanks for any more details.
>

Here is a quick and dirty workaround for the problem: use Reflection to set
the Application#name field value to anything by-passing the setter and the
check.


>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
> AM-SoFT IT-Systeme  http://www.AM-SoFT.de/
>
> Telefon...05151-  9468- 55
> Fax...05151-  9468- 88
> Mobil..0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Use application.setName to set a custom name?

2015-01-21 Thread Thorsten Schöning
Guten Tag Martin Grigorov,
am Mittwoch, 21. Januar 2015 um 09:46 schrieben Sie:

> But how would you decide what name to use if you do this in the constructor?
> At that time you don't have access to many things, e.g. the servlet context.

I would have implemented a ServletContextListener to create my custom
name depending on it's dir name and save that statically. Such a
listener should always be called before the Wicket filter.

> I meant to add your own MBean somewhere in the root.
> This way it will be easy for you to check the instance "real" name in the
> JMX viewer

I see, but for that to work I would need more than one wicket specific
entry in the console and currently I have only one. It's always just
one "org.apache.wicket.app.WicketFilter", where WicketFilter is the
name of the filter in web.xml, and not two of them. I guess I only see
the first recognized or whatever, if I change one name in web.xml, I
get two entries.

> Here is a quick and dirty workaround for the problem: use Reflection to set
> the Application#name field value to anything by-passing the setter and the
> check.

I will rather stick with documentation in web.xml if I can't guarantee
being the first and only one setting this. Thanks anyways!

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme  http://www.AM-SoFT.de/

Telefon...05151-  9468- 55
Fax...05151-  9468- 88
Mobil..0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Use application.setName to set a custom name?

2015-01-21 Thread Martin Grigorov
On Wed, Jan 21, 2015 at 12:18 PM, Thorsten Schöning 
wrote:

> Guten Tag Martin Grigorov,
> am Mittwoch, 21. Januar 2015 um 09:46 schrieben Sie:
>
> > But how would you decide what name to use if you do this in the
> constructor?
> > At that time you don't have access to many things, e.g. the servlet
> context.
>
> I would have implemented a ServletContextListener to create my custom
> name depending on it's dir name and save that statically. Such a
> listener should always be called before the Wicket filter.
>
> > I meant to add your own MBean somewhere in the root.
> > This way it will be easy for you to check the instance "real" name in the
> > JMX viewer
>
> I see, but for that to work I would need more than one wicket specific
> entry in the console and currently I have only one. It's always just
> one "org.apache.wicket.app.WicketFilter", where WicketFilter is the
> name of the filter in web.xml, and not two of them. I guess I only see
> the first recognized or whatever, if I change one name in web.xml, I
> get two entries.
>

This is a problem that deserves a ticket, IMO.
MyApp#init() method is called *after* the initializers so it would be too
late for changing the name even with Java reflection.
I guess you could override MyApp#internalInit() to set the name (with
reflection) before the initializers, but I'm not sure it will work (I
haven't tried).

If no one else has better idea then I guess we can add the check in
WicketFilter to set the name only if it is not set already.


>
> > Here is a quick and dirty workaround for the problem: use Reflection to
> set
> > the Application#name field value to anything by-passing the setter and
> the
> > check.
>
> I will rather stick with documentation in web.xml if I can't guarantee
> being the first and only one setting this. Thanks anyways!
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
> AM-SoFT IT-Systeme  http://www.AM-SoFT.de/
>
> Telefon...05151-  9468- 55
> Fax...05151-  9468- 88
> Mobil..0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Use application.setName to set a custom name?

2015-01-21 Thread Thorsten Schöning
Guten Tag Martin Grigorov,
am Mittwoch, 21. Januar 2015 um 11:37 schrieben Sie:

> This is a problem that deserves a ticket, IMO.

https://issues.apache.org/jira/browse/WICKET-5816

Thanks for your help!

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning   E-Mail: thorsten.schoen...@am-soft.de
AM-SoFT IT-Systeme  http://www.AM-SoFT.de/

Telefon...05151-  9468- 55
Fax...05151-  9468- 88
Mobil..0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org