dev@glassfish.java.net

Re: ConfigListener parent notification - Re: svn commit: r807 - trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java

From: Jerome Dochez <Jerome.Dochez_at_Sun.COM>
Date: Tue, 09 Sep 2008 21:19:24 -0700

Amy Roh wrote:
> Jerome Dochez wrote:
>> so it seems to me that you need to register at the http-service level
>> to listen for virtual-server creation.
> That is what I do currently.
>
>> When you receive notification of a new virtual-server created in
>> http-service, you can register a new listener to it manually. would
>> that work ?
>
> That would work and is exactly my question. Is there an API available
> for this (register a new listener to a dynamically created
> virtual-server without actually injecting virtual-server to
> ConfigListener at start time)?
yes of course, sorry I know documentation sucks

((ObservableBean) ConfigSupport.getImpl(XXX)).addListener(YYY);

where XXX is your newly created virtual server, and YYY the listener for
it. Of course you have a removeListener API too.
We might want a more elegant way of doing this later but it should
suffice for prelude.

Jerome
>
> Thanks,
> Amy
>>
>> jerome
>>
>> Amy Roh wrote:
>>> Jerome Dochez wrote:
>>>> don't you have a different listener registered for each virtual
>>>> server ?
>>>> if yes, I think that listener should be notifying the http-service
>>>> itself.
>>>
>>> I do but only for the default virtual server -
>>>
>>> public class HttpServiceConfigListener implements ConfigListener {
>>>
>>> @Inject(name="server")
>>> public VirtualServer virtualServer;
>>>
>>> I don't register ConfigListener for a dynamically created virtual
>>> server since the name hasn't been provided yet.
>>>
>>> Is there a way to dynamically inject the newly created virtual
>>> server so I can register ConfigListener with it?
>>>
>>> Thanks,
>>> Amy
>>>
>>>>
>>>> Amy Roh wrote:
>>>>
>>>>> Hi Jerome,
>>>>>
>>>>> dochez_at_dev.java.net wrote:
>>>>>
>>>>>> Author: dochez
>>>>>> Date: 2008-08-27 04:51:34+0000
>>>>>> New Revision: 807
>>>>>>
>>>>>> Modified:
>>>>>> trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java
>>>>>>
>>>>>> Log:
>>>>>> added parent notification, we could change it to notify the
>>>>>> entire config tree up.
>>>>>>
>>>>>>
>>>>>>
>>>>>> Modified:
>>>>>> trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java
>>>>>> Url:
>>>>>> https://hk2.dev.java.net/source/browse/hk2/trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java?view=diff&rev=807&p1=trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java&p2=trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java&r1=806&r2=807
>>>>>>
>>>>>> ==============================================================================
>>>>>>
>>>>>> ---
>>>>>> trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java
>>>>>> (original)
>>>>>> +++
>>>>>> trunk/hk2/config/src/java/org/jvnet/hk2/config/Transactions.java
>>>>>> 2008-08-27 04:51:34+0000
>>>>>> @@ -227,6 +227,25 @@
>>>>>> final UnprocessedChangeEvent unp = new
>>>>>> UnprocessedChangeEvent(evt, "no ConfigListener listening to dom
>>>>>> element " + dom.getProxyType().getName() );
>>>>>> unprocessedEvents.add( new
>>>>>> UnprocessedChangeEvents(unp) );
>>>>>> }
>>>>>> + + // we notify the immediate parent.
>>>>>> + // dochez : should we notify the parent chain up
>>>>>> to the root or stop at the first parent.
>>>>>
>>>>>
>>>>> Can we notify at least up to the second parent?
>>>>>
>>>>> As described in the issue [1], dynamically created virtual
>>>>> server's property change does not notify http-service.
>>>>>
>>>>> [1] https://glassfish.dev.java.net/issues/show_bug.cgi?id=6003
>>>>>
>>>>> Thanks,
>>>>> Amy
>>>>>
>>>>>> + if (dom.parent()!=null &&
>>>>>> dom.parent().getListeners()!=null) {
>>>>>> + for (ConfigListener parentListener :
>>>>>> dom.parent().getListeners()) {
>>>>>> + if
>>>>>> (!notifiedListeners.contains(parentListener)) {
>>>>>> + try {
>>>>>> + // create a new array each time
>>>>>> to avoid any potential array changes?
>>>>>> + UnprocessedChangeEvents
>>>>>> unprocessed = parentListener.changed(mEvents.toArray(new
>>>>>> PropertyChangeEvent[mEvents.size()]));
>>>>>> + if (unprocessed != null &&
>>>>>> unprocessed.size() != 0 ) {
>>>>>> +
>>>>>> unprocessedEvents.add(unprocessed);
>>>>>> + }
>>>>>> + } catch (Exception e) {
>>>>>> + e.printStackTrace();
>>>>>> + }
>>>>>> + notifiedListeners.add(parentListener);
>>>>>> + }
>>>>>> + }
>>>>>> + }
>>>>>> }
>>>>>> // all the config listeners have been notified,
>>>>>> let's see if we have
>>>>>> // some unprocessed events to notifiy the transation
>>>>>> listeners.
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>>
>>>>>> To unsubscribe, e-mail: commits-unsubscribe_at_hk2.dev.java.net
>>>>>> For additional commands, e-mail: commits-help_at_hk2.dev.java.net
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>