Alex Shneyderman wrote:
> Hi, guys!
> 
> I get a request I parse it I detect what command I have to run. I
> compose it and call its run method. Now the problem is I have to pass
> paramters to some of the commands but I do not want to pass them in
> the arguments to the run method, I would like to have some context
> associated with the thread and parser would set those onto the context
> then I would retrieve those inside the particular implementation of
> the command. Does qi provide any help with this? I have a feeling it
> should be able to do something similar in other places but I can not
> find anything useful that would move me forward.

Yes, there is something like this. You can use the CompositeContext, 
which is precisely for this purpose.

To set it up you can do:
CompositeContext<MyComposite> cc = new 
CompositeContext<MyComposite>(cbf.newCompositeBuilder(MyComposite.class));

Then either use it as a ThreadLocal, or acquire the proxy and share that:
MyComposite threadComposite = cc.proxy();
...
// This will look up a MyComposite for this thread, and call it
threadComposite.doStuff();

Be careful with these kinds of things though, as they tend to make it 
harder to read the code. Only use it when necessary.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to