Hi,

Christopher's answer was definitely more detailed than mine (Thanks !).
In term of iPOJO, there is no handler doing that right now. However, you
may want to create one dealing with your 'Thread local' / Context service
and injecting the values inside POJO fields.

Regards,

Clement

On 25.11.10 11:00, "Christopher Brind" <[email protected]> wrote:

>The simplest way to do that is with a ThreadLocal:
>http://download.oracle.com/javase/6/docs/api/java/lang/ThreadLocal.html
>
>So you need some class that is available to all your iPojo classes.  I
>would
>put this in a separate "API" bundle, the package of which is imported by
>your other bundles.
>
>I like to keep the ThreadLocal API from being exposed by the context class
>itself by doing something like this:
>
>public class MyContext {
>
>    private static ThreadLocal<MyContext> threadLocal = new
>ThreadLocal<MyContext>() {
>
>        protected MyContext initialValue() {
>            return new MyContext();
>        }
>
>    };
>
>     public static MyContext getContext() {
>            return threadLocal.get();
>     }
>
>}
>
>Then from any of your classes that have imported the above you can just
>call:
>
>MyContext ctx = MyContext.getContext() ;
>
>When the thread dies the instance of MyContext is then available for
>garbage
>collection.
>
>There may be a more specific OSGi or iPojo friendly way of doing it
>(though
>I've used this method in the past with no problems).  I'm sure there are
>also other discussions on the use of ThreadLocal in general too, but I
>hope
>that helps.
>
>Cheers,
>Chris
>
>
>
>On 25 November 2010 09:41, Bigard Olivier <[email protected]> wrote:
>
>> Hi,
>>
>>
>>
>> I'm trying to find a way to implement following need with Felix and
>> iPojo.
>>
>>
>>
>> Imagine you have an iPojo instance of Bundle A calling an OSGi Service
>> provided by an iPojo instance of Bundle B.
>>
>> Imagine this Bundle B iPojo instance is calling an OSGi Service provided
>> by an iPojo instance of Bundle C.
>>
>>
>>
>> class A {
>>
>> @Requires
>>
>> B b;
>>
>>
>>
>> public doSomething() {
>>
>>                                ...
>>
>>                                b.doSomethingInB();
>>
>> }
>>
>> }
>>
>>
>>
>> class B {
>>
>> @Requires
>>
>> C c;
>>
>>
>>
>> public doSomethingInB() {
>>
>>                                ...
>>
>>                                c.doSomethingInC();
>>
>> }
>>
>> }
>>
>>
>>
>> class C {
>>
>> public doSomethingInC() {
>>
>>                                ...
>>
>> }
>>
>> }
>>
>>
>>
>> What I want is to be able to send some "contextual" information from
>> method "doSomething()" in class A to method "doSomethingInC()" in class
>> C without being intrusive in the method signature.
>>
>> For example, this contextual information could be created by class A
>> with the username.
>>
>> This context could be enriched by class B by adding the user email for
>> example.
>>
>> And finally the class C could get the username and user email from the
>> contextual information without adding this data as parameter of its
>> method.
>>
>>
>>
>> Do you have an idea how I can do that with iPojo?
>>
>>
>>
>> Thanks
>>
>> Olivier
>>
>>



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to