Bundle context - from inside POJO

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Bundle context - from inside POJO

Miroslav Beranič
Hi all,

some junior question, but would like to make it correct way.

Is it possible and if it is, how - to get access to BundleContext ( and other OSGi environment ) from some plain Java object ?

for example

there is an Activator or a Compontent ( class with annotation @Component ) that has code like:

MyClass inst = new MyClass();
inst.doSomeAction();

How would it be possible to get access to BundleContext from inside of the method doSomeAction() ?

( this is related to my Scheduler work - as I would need access to BundleContext from inside of a Quartz job, job is executed later on some day - and even Karaf restart can happen  )


Kind Regards,
Miroslav



--
Miroslav Beranič
MIBESIS
+386(0)40/814-843
[hidden email]
http://www.mibesis.si
Reply | Threaded
Open this post in threaded view
|

Re: Bundle context - from inside POJO

jbonofre
FrameworkUtil.getBundle(Foo.class).getBundleContext();

Regards
JB

On 11/09/2018 13:43, Miroslav Beranič wrote:

> Hi all,
>
> some junior question, but would like to make it correct way.
>
> Is it possible and if it is, how - to get access to BundleContext ( and
> other OSGi environment ) from some plain Java object ?
>
> for example
>
> there is an Activator or a Compontent ( class with annotation @Component
> ) that has code like:
>
> MyClass inst = new MyClass();
> inst.doSomeAction();
>
> How would it be possible to get access to BundleContext from inside of
> the method doSomeAction() ?
>
> ( this is related to my Scheduler work - as I would need access to
> BundleContext from inside of a Quartz job, job is executed later on some
> day - and even Karaf restart can happen  )
>
>
> Kind Regards,
> Miroslav
>
>
>
> --
> Miroslav Beranič
> MIBESIS
> +386(0)40/814-843
> [hidden email] <mailto:[hidden email]>
> http://www.mibesis.si

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Bundle context - from inside POJO

jbonofre
By the way, why don't you pass the bundle context to your job
implementation QuartzJob ?

Regards
JB

On 11/09/2018 13:46, Jean-Baptiste Onofré wrote:

> FrameworkUtil.getBundle(Foo.class).getBundleContext();
>
> Regards
> JB
>
> On 11/09/2018 13:43, Miroslav Beranič wrote:
>> Hi all,
>>
>> some junior question, but would like to make it correct way.
>>
>> Is it possible and if it is, how - to get access to BundleContext ( and
>> other OSGi environment ) from some plain Java object ?
>>
>> for example
>>
>> there is an Activator or a Compontent ( class with annotation @Component
>> ) that has code like:
>>
>> MyClass inst = new MyClass();
>> inst.doSomeAction();
>>
>> How would it be possible to get access to BundleContext from inside of
>> the method doSomeAction() ?
>>
>> ( this is related to my Scheduler work - as I would need access to
>> BundleContext from inside of a Quartz job, job is executed later on some
>> day - and even Karaf restart can happen  )
>>
>>
>> Kind Regards,
>> Miroslav
>>
>>
>>
>> --
>> Miroslav Beranič
>> MIBESIS
>> +386(0)40/814-843
>> [hidden email] <mailto:[hidden email]>
>> http://www.mibesis.si
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Bundle context - from inside POJO

Miroslav Beranič
In reply to this post by jbonofre
Thank you JB.


V V tor., 11. sep. 2018 ob 13:46 je oseba Jean-Baptiste Onofré <[hidden email]> napisala:
FrameworkUtil.getBundle(Foo.class).getBundleContext();

Regards
JB

On 11/09/2018 13:43, Miroslav Beranič wrote:
> Hi all,
>
> some junior question, but would like to make it correct way.
>
> Is it possible and if it is, how - to get access to BundleContext ( and
> other OSGi environment ) from some plain Java object ?
>
> for example
>
> there is an Activator or a Compontent ( class with annotation @Component
> ) that has code like:
>
> MyClass inst = new MyClass();
> inst.doSomeAction();
>
> How would it be possible to get access to BundleContext from inside of
> the method doSomeAction() ?
>
> ( this is related to my Scheduler work - as I would need access to
> BundleContext from inside of a Quartz job, job is executed later on some
> day - and even Karaf restart can happen  )
>
>
> Kind Regards,
> Miroslav
>
>
>
> --
> Miroslav Beranič
> MIBESIS
> +386(0)40/814-843
> [hidden email] <mailto:[hidden email]>
> http://www.mibesis.si

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com


--
Miroslav Beranič
MIBESIS
+386(0)40/814-843
[hidden email]
http://www.mibesis.si
Reply | Threaded
Open this post in threaded view
|

Re: Bundle context - from inside POJO

Miroslav Beranič
In reply to this post by jbonofre
JB,

for top of my head - Quartz is passed only QuartzJob class, that gets created "when needed".
Meaning - I can not pass any non-serializable data/object to the Job - as ( in my case ) Jobs are persistent in Oracle and scheduled/started at later time - in few minutes or few day, weeks, months ...
In some cases also Karaf is restarted in between ( from the time Job was created and before it job is scheduled/started )

So usecase is: Quartz Job is created and scheduled ( meaning written to Oracle ) , due to time span or SW/HW failure Karaf is restarted - when times comes to start/schedule Quartz Job -- the environment is ( in most cases ) different in a way, I can not relay on any passed in object.

I imagine also when running on distributed environment it would be a problem? ( I did not come to this at this point -- one more milestone ahead ).


Thanks for the support (y)

Kind Regards,
Miroslav



V V tor., 11. sep. 2018 ob 13:47 je oseba Jean-Baptiste Onofré <[hidden email]> napisala:
By the way, why don't you pass the bundle context to your job
implementation QuartzJob ?

Regards
JB

On 11/09/2018 13:46, Jean-Baptiste Onofré wrote:
> FrameworkUtil.getBundle(Foo.class).getBundleContext();
>
> Regards
> JB
>
> On 11/09/2018 13:43, Miroslav Beranič wrote:
>> Hi all,
>>
>> some junior question, but would like to make it correct way.
>>
>> Is it possible and if it is, how - to get access to BundleContext ( and
>> other OSGi environment ) from some plain Java object ?
>>
>> for example
>>
>> there is an Activator or a Compontent ( class with annotation @Component
>> ) that has code like:
>>
>> MyClass inst = new MyClass();
>> inst.doSomeAction();
>>
>> How would it be possible to get access to BundleContext from inside of
>> the method doSomeAction() ?
>>
>> ( this is related to my Scheduler work - as I would need access to
>> BundleContext from inside of a Quartz job, job is executed later on some
>> day - and even Karaf restart can happen  )
>>
>>
>> Kind Regards,
>> Miroslav
>>
>>
>>
>> --
>> Miroslav Beranič
>> MIBESIS
>> +386(0)40/814-843
>> [hidden email] <mailto:[hidden email]>
>> http://www.mibesis.si
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com


--
Miroslav Beranič
MIBESIS
+386(0)40/814-843
[hidden email]
http://www.mibesis.si