Hi Jayanga,

Why can't register the "CarbonServerShutdownPrepareService" in normal OSGi
service registration manner (without registering it in server shutdown)? Is
that because you need to have synchronized manner or any other particular
reason to do so?

Thanks,

Best Regards,

Lakshitha Harshan
Software Engineer
Mobile: *+94724423048*
Email: hars...@wso2.com
Blog : http://harshanliyanage.blogspot.com/
*WSO2, Inc. :** wso2.com <http://wso2.com/>*
lean.enterprise.middleware.

On Mon, Sep 15, 2014 at 10:13 AM, Jayanga Dissanayake <jaya...@wso2.com>
wrote:

> Hi Amila,
>
> Sorry about the confusion.
> Generally, in OSGi bundles, we register services provided by a particular
> bundle in the bundle activation, That is true.
>
> But in this scenario, I am registering the
> "CarbonServerShutdownPrepareService" in the
> org.wso2.carbon.core.init.CarbonServerManager.shutdownGracefully() method,
> which is called when the server about to shutdown. As actual server
> shutting down process is not yet started, all the bundles are active and
> the server is still in the full operational mode. So, we can register a new
> service without any harm.
>
> In OSGi framework, service registration, activation of dependent bundles,
> notifying listers and trackers happen in synchronized manner. So the
> shutdownGracefully() cannot proceed until the above service registration
> tasks completes. So, the bundles, which was waiting for the
> "CarbonServerShutdownPrepareService" can start doing its expected tasks
> (house keeping tasks that has to be carried out just before the server
> shutdown)
>
> Thanks
> Jayanga.
>
> *Jayanga Dissanayake*
> Senior Software Engineer
> WSO2 Inc. - http://wso2.com/
> lean . enterprise . middleware
> email: jaya...@wso2.com
> mobile: +94772207259
>
> On Sun, Sep 14, 2014 at 1:36 AM, Amila Maha Arachchi <ami...@wso2.com>
> wrote:
>
>>
>>
>> On Thu, Sep 11, 2014 at 10:47 PM, Jayanga Dissanayake <jaya...@wso2.com>
>> wrote:
>>
>>> Hi,
>>>
>>> There was a requirement to detect the server shutdown from some bundles
>>> before the OSGi framework begin to shutdown. Because there were situations
>>> where some bundle have there own  transports. If server shutdown happens
>>> while there were buffered messages, those should be processes before that
>>> particular bundle get deactivated.
>>>
>>> As the bundle stopping sequence is not guaranteed in OSGi environments,
>>> There may be some required bundles/services already being stopped when that
>>> particular bundle wants to do the finalizing tasks.
>>>
>>> So, as a solution I tried the following,
>>> Register an OSGi service "CarbonServerShutdownPrepareService" in the
>>> shutdownGracefully() before the actual server shutdown is called.  So, just
>>> before the server shutdown "CarbonServerShutdownPrepareService" get
>>> activated.
>>> Then add some dummy OSGi Declarative Service components, that is waiting
>>> for  ”CarbonServerShutdownPrepareService”,
>>> Then start the server and shutdown the server,
>>>
>>> Observations,
>>> When the server is shutting down,
>>> 1. first it registers the service “CarbonServerShutdownPrepareService”
>>> 2. then all the bundles waiting for that service get activated, (if
>>> there are listers or trackers, those get notified)
>>> 3. then actual server shutdown happens
>>>
>>
>> AFAIK, OSGi services are registered when the components startup. Here,
>> you have said that  "CarbonServerShutdownPrepareService" is registered when
>> the server is shut down. This is not clear to me.
>>
>> Did you mean the following approach:
>> 1. Register an OSGi service at the server startup.
>> 2. Add declarative service dependencies to the bundles which needs to be
>> notified about the shutdown. These bundles should implement a listener or a
>> tracker.
>> 3. When the server shutdown is called, it notifies the dependents. Is
>> this sequential?
>>
>> It seems that I don't understand something here. If it is the case,
>> please explain it to me. :)
>>
>> Thanks.
>>
>>>
>>> As the osgi framework's service registration and un-registration happens
>>> in a single thread, It is guaranteed that registration of
>>> “CarbonServerShutdownPrepareService” and notification of that registration
>>> to the other bundles happens in a sequential manner in a single thread.
>>>
>>> So, any bundle can perform there house keeping tasks that has to carry
>>> out just before the server shutdown.
>>>
>>> Suggestions, improvements and alternatives are welcome
>>>
>>> Thanks,
>>> *Jayanga Dissanayake*
>>> Senior Software Engineer
>>> WSO2 Inc. - http://wso2.com/
>>> lean . enterprise . middleware
>>> email: jaya...@wso2.com
>>> mobile: +94772207259
>>>
>>
>>
>>
>> --
>> *Amila Maharachchi*
>> Senior Technical Lead
>> WSO2, Inc.; http://wso2.com
>>
>> Blog: http://maharachchi.blogspot.com
>> Mobile: +94719371446
>>
>>
>
> _______________________________________________
> Architecture mailing list
> Architecture@wso2.org
> https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
>
>
_______________________________________________
Architecture mailing list
Architecture@wso2.org
https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture

Reply via email to