admin@glassfish.java.net

Re: Seeking Guidance

From: Jerome Dochez <Jerome.Dochez_at_sun.com>
Date: Thu, 15 Apr 2010 13:58:39 -0700

On Apr 15, 2010, at 1:53 PM, Byron Nevins wrote:

> Jerome, Bill
>
> I'm about to change a bunch of classes that assume the current server's name is "server".
>
> BEFORE:
> @Param(optional=true)
> String target = SystemPropertyConstants.DEFAULT_SERVER_INSTANCE_NAME;
>
> AFTER:
> // add implements PostConstruct if necessary
>
> @Inject
> private ServerEnvironment env;
>
> @Param(optional=true)
> String target;
>
> public void postConstruct() {
> if(target == null)
> target = env.getInstanceName();
> }
>
> ===============================
>
> I'm doing the more complicated postConstruct() technique because I don't think I can get away with doing the following with 100% certainty.
>
> @Inject
> private ServerEnvironment env;
>
> @Param(optional=true)
> String target = env.getInstanceName();
>
> =================================
>
> Is it guaranteed that the above will work (i.e. order of evaluation by HK2)?
> This is my injection solution. I normally would just use the old-fashioned way of setting a system-wide final String with the instance's name.
>
> What do you recommend?

In order to do 2, you need to ensure that @Inject is injected before @Param (which I think is the case), look in the AdminAdapter for the code. You also need to then change the AdminCommand javadocs to state the order of injection between the two annotations so it is an explicit contract.

then you can use option 1.

otherwise option 2 is clunky yet safe.

>
>
> --
> Byron Nevins - Oracle Corporation
> Home: 650-359-1290
> Cell: 650-784-4123
> Sierra: 209-295-2188
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: admin-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: admin-help_at_glassfish.dev.java.net
>