You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by "Kline, Larry D" <La...@USONCOLOGY.COM> on 2013/01/03 18:20:18 UTC

Sessions

I have a remotely deployed uima application (running in jboss and using
a pear file) that has a web service front end.  One of the web service
methods sets a value into the uima session.

 

recognitionAE.getUimaContext().getSession().put("g2_stemmer",
stemmerAlgorithmKey);

 

Then I would like to get that value in a user defined flow controller.
But in the flow controller I execute this:

 

                                fcContext = getContext();
// this is a FlowController method

                                String stemmer =
(String)fcContext.getSession().get(STEMMER_KEY_NAME);

 

And I get a different session object.  Is there some way to get the root
session object?

 

Thanks,

Larry

</pre>The contents of this electronic mail message and any attachments are confidential, possibly privileged and intended for the addressee(s) only.<br>Only the addressee(s) may read, disseminate, retain or otherwise use this message. If received in error, please immediately inform the sender and then delete this message without disclosing its contents to anyone.</pre>

RE: Sessions

Posted by "Kline, Larry D" <La...@USONCOLOGY.COM>.
Your suggestion to create a new type and add it to the CAS worked perfectly and was straightforward to implement.  
Thank you!

Larry

-----Original Message-----
From: Richard Eckart de Castilho [mailto:eckart@ukp.informatik.tu-darmstadt.de] 
Sent: Monday, January 07, 2013 9:29 AM
To: <us...@uima.apache.org>
Subject: Re: Sessions

Am 07.01.2013 um 14:57 schrieb "Kline, Larry D" <La...@USONCOLOGY.COM>:

> The reason I want to use a session object to store my properties is 
> that the API says these sessions are per client.  My UIMA app is 
> running in a JBoss container that is accessed by a web service call.  
> So multiple clients could be accessing it simultaneously, each one 
> passing slightly different parameters.  In the web service method I do this:
> 
> 	protected AnalysisEngine recognitionAE;
> 	...
> 	
> recognitionAE.getUimaContext().getSession().put(STEMMER_KEY_NAME,
> stemmerAlgorithmKey);
> 
> Then later in my custom flow controller I want to get this property 
> and use it to control the flow.
> 
> I'm not familiar with the external resource support.  Can I do 
> something similar using that?


The external resource mechanism allows you to share an object between UIMA components. You tell UIMA how to instantiate this object as part of your analysis engine description (or aggregate AE description). The object is instantiated once per UIMA root context, so should have the same scope as the session. I have no idea if external resources can be accessed from a FlowController. 

Your concept of "client" and that used in the documentation of the session may be slightly different. I am pretty sure the session documentation refers to a UIMA deployment which is distributed on a network. Every node (client) in that network, e.g. every UIMA-AS deployment, has its own session - they are not in any way synchronized across the network.

In your case, to make sure a session (or external resource below) is not shared between clients accessing your web application, you need to make sure that your recognitionAE instance is not shared between web clients - or put it otherwise - it is not thread-safe when you store data in the session.

I'd probably create a new UIMA type which holds such information and add it to the CAS. That way, the CAS has some metadata on how it was processed and it can be accessed by the FlowController. This also restores the thread-safety and if your annotator is programmed in a thread-safe way, you can instantiate it once and share it between all your clients. Since the instantiation of an analysis engine can be a costly process, you may want to consider that.

Cheers,

-- Richard

--
-------------------------------------------------------------------
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab (UKP-TUD) 
FB 20 Computer Science Department      
Technische Universität Darmstadt
Hochschulstr. 10, D-64289 Darmstadt, Germany phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117 eckart@ukp.informatik.tu-darmstadt.de
www.ukp.tu-darmstadt.de
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------

</pre>The contents of this electronic mail message and any attachments are confidential, possibly privileged and intended for the addressee(s) only.<br>Only the addressee(s) may read, disseminate, retain or otherwise use this message. If received in error, please immediately inform the sender and then delete this message without disclosing its contents to anyone.</pre>


Re: Sessions

Posted by Richard Eckart de Castilho <ec...@ukp.informatik.tu-darmstadt.de>.
Am 07.01.2013 um 14:57 schrieb "Kline, Larry D" <La...@USONCOLOGY.COM>:

> The reason I want to use a session object to store my properties is that
> the API says these sessions are per client.  My UIMA app is running in a
> JBoss container that is accessed by a web service call.  So multiple
> clients could be accessing it simultaneously, each one passing slightly
> different parameters.  In the web service method I do this:
> 
> 	protected AnalysisEngine recognitionAE;
> 	...
> 	
> recognitionAE.getUimaContext().getSession().put(STEMMER_KEY_NAME,
> stemmerAlgorithmKey);
> 
> Then later in my custom flow controller I want to get this property and
> use it to control the flow.
> 
> I'm not familiar with the external resource support.  Can I do something
> similar using that?


The external resource mechanism allows you to share an object between UIMA components. You tell UIMA how to instantiate this object as part of your analysis engine description (or aggregate AE description). The object is instantiated once per UIMA root context, so should have the same scope as the session. I have no idea if external resources can be accessed from a FlowController. 

Your concept of "client" and that used in the documentation of the session may be slightly different. I am pretty sure the session documentation refers to a UIMA deployment which is distributed on a network. Every node (client) in that network, e.g. every UIMA-AS deployment, has its own session - they are not in any way synchronized across the network.

In your case, to make sure a session (or external resource below) is not shared between clients accessing your web application, you need to make sure that your recognitionAE instance is not shared between web clients - or put it otherwise - it is not thread-safe when you store data in the session.

I'd probably create a new UIMA type which holds such information and add it to the CAS. That way, the CAS has some metadata on how it was processed and it can be accessed by the FlowController. This also restores the thread-safety and if your annotator is programmed in a thread-safe way, you can instantiate it once and share it between all your clients. Since the instantiation of an analysis engine can be a costly process, you may want to consider that.

Cheers,

-- Richard

-- 
------------------------------------------------------------------- 
Richard Eckart de Castilho
Technical Lead
Ubiquitous Knowledge Processing Lab (UKP-TUD) 
FB 20 Computer Science Department      
Technische Universität Darmstadt 
Hochschulstr. 10, D-64289 Darmstadt, Germany 
phone [+49] (0)6151 16-7477, fax -5455, room S2/02/B117
eckart@ukp.informatik.tu-darmstadt.de 
www.ukp.tu-darmstadt.de 
Web Research at TU Darmstadt (WeRC) www.werc.tu-darmstadt.de
-------------------------------------------------------------------


RE: Sessions

Posted by "Kline, Larry D" <La...@USONCOLOGY.COM>.
Thanks for the suggestion.  I ended up casting like this:

FlowControllerContext_impl fcContext =
(FlowControllerContext_impl)getContext();

This is in my custom flow controller, so getContext() is a superclass
(FlowController_ImplBase) method.

The reason I want to use a session object to store my properties is that
the API says these sessions are per client.  My UIMA app is running in a
JBoss container that is accessed by a web service call.  So multiple
clients could be accessing it simultaneously, each one passing slightly
different parameters.  In the web service method I do this:

	protected AnalysisEngine recognitionAE;
	...
	
recognitionAE.getUimaContext().getSession().put(STEMMER_KEY_NAME,
stemmerAlgorithmKey);

Then later in my custom flow controller I want to get this property and
use it to control the flow.

I'm not familiar with the external resource support.  Can I do something
similar using that?

Thanks,
Larry

-----Original Message-----
From: Burn Lewis [mailto:burnlewis@gmail.com] 
Sent: Friday, January 04, 2013 8:26 PM
To: user@uima.apache.org
Subject: Re: Sessions

With a cast I think you can get the root context and use its session
object.

Session rootSession =
((UimaContextAdmin)aContext).getRootContext().getSession();

Note that the the Javadocs say developers should not use this interface!
It may be preferable to use the external resource support to share a map
amongst annotators.




On Fri, Jan 4, 2013 at 11:22 AM, Eddie Epstein <ea...@gmail.com>
wrote:

> I am not 100% sure here, but think that an analytic's UimaContext is 
> fixed after the component has been instantiated. For dynamic control 
> of processing, the flow controller could use something outside of the 
> UIMA framework, or the analytic read a control key put in the CAS 
> itself.
>
> Eddie
>
> On Thu, Jan 3, 2013 at 12:20 PM, Kline, Larry D 
> <La...@usoncology.com> wrote:
> > I have a remotely deployed uima application (running in jboss and 
> > using a pear file) that has a web service front end.  One of the web

> > service methods sets a value into the uima session.
> >
> >
> >
> > recognitionAE.getUimaContext().getSession().put("g2_stemmer",
> > stemmerAlgorithmKey);
> >
> >
> >
> > Then I would like to get that value in a user defined flow
controller.
> > But in the flow controller I execute this:
> >
> >
> >
> >                                 fcContext = getContext(); // this is

> > a FlowController method
> >
> >                                 String stemmer = 
> > (String)fcContext.getSession().get(STEMMER_KEY_NAME);
> >
> >
> >
> > And I get a different session object.  Is there some way to get the 
> > root session object?
> >
> >
> >
> > Thanks,
> >
> > Larry
> >
> > </pre>The contents of this electronic mail message and any 
> > attachments
> are confidential, possibly privileged and intended for the 
> addressee(s) only.<br>Only the addressee(s) may read, disseminate, 
> retain or otherwise use this message. If received in error, please 
> immediately inform the sender and then delete this message without 
> disclosing its contents to anyone.</pre>
>
</pre>The contents of this electronic mail message and any attachments are confidential, possibly privileged and intended for the addressee(s) only.<br>Only the addressee(s) may read, disseminate, retain or otherwise use this message. If received in error, please immediately inform the sender and then delete this message without disclosing its contents to anyone.</pre>


Re: Sessions

Posted by Burn Lewis <bu...@gmail.com>.
With a cast I think you can get the root context and use its session object.

Session rootSession =
((UimaContextAdmin)aContext).getRootContext().getSession();

Note that the the Javadocs say developers should not use this interface!
It may be preferable to use the external resource support to share a map
amongst annotators.




On Fri, Jan 4, 2013 at 11:22 AM, Eddie Epstein <ea...@gmail.com> wrote:

> I am not 100% sure here, but think that an analytic's UimaContext is
> fixed after the component has been instantiated. For dynamic control
> of processing, the flow controller could use something outside of the
> UIMA framework, or the analytic read a control key put in the CAS
> itself.
>
> Eddie
>
> On Thu, Jan 3, 2013 at 12:20 PM, Kline, Larry D
> <La...@usoncology.com> wrote:
> > I have a remotely deployed uima application (running in jboss and using
> > a pear file) that has a web service front end.  One of the web service
> > methods sets a value into the uima session.
> >
> >
> >
> > recognitionAE.getUimaContext().getSession().put("g2_stemmer",
> > stemmerAlgorithmKey);
> >
> >
> >
> > Then I would like to get that value in a user defined flow controller.
> > But in the flow controller I execute this:
> >
> >
> >
> >                                 fcContext = getContext();
> > // this is a FlowController method
> >
> >                                 String stemmer =
> > (String)fcContext.getSession().get(STEMMER_KEY_NAME);
> >
> >
> >
> > And I get a different session object.  Is there some way to get the root
> > session object?
> >
> >
> >
> > Thanks,
> >
> > Larry
> >
> > </pre>The contents of this electronic mail message and any attachments
> are confidential, possibly privileged and intended for the addressee(s)
> only.<br>Only the addressee(s) may read, disseminate, retain or otherwise
> use this message. If received in error, please immediately inform the
> sender and then delete this message without disclosing its contents to
> anyone.</pre>
>

Re: Sessions

Posted by Eddie Epstein <ea...@gmail.com>.
I am not 100% sure here, but think that an analytic's UimaContext is
fixed after the component has been instantiated. For dynamic control
of processing, the flow controller could use something outside of the
UIMA framework, or the analytic read a control key put in the CAS
itself.

Eddie

On Thu, Jan 3, 2013 at 12:20 PM, Kline, Larry D
<La...@usoncology.com> wrote:
> I have a remotely deployed uima application (running in jboss and using
> a pear file) that has a web service front end.  One of the web service
> methods sets a value into the uima session.
>
>
>
> recognitionAE.getUimaContext().getSession().put("g2_stemmer",
> stemmerAlgorithmKey);
>
>
>
> Then I would like to get that value in a user defined flow controller.
> But in the flow controller I execute this:
>
>
>
>                                 fcContext = getContext();
> // this is a FlowController method
>
>                                 String stemmer =
> (String)fcContext.getSession().get(STEMMER_KEY_NAME);
>
>
>
> And I get a different session object.  Is there some way to get the root
> session object?
>
>
>
> Thanks,
>
> Larry
>
> </pre>The contents of this electronic mail message and any attachments are confidential, possibly privileged and intended for the addressee(s) only.<br>Only the addressee(s) may read, disseminate, retain or otherwise use this message. If received in error, please immediately inform the sender and then delete this message without disclosing its contents to anyone.</pre>