uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Spico Florin <spicoflo...@gmail.com>
Subject Re: Dependency injection support in UIMA
Date Thu, 22 Nov 2012 13:06:13 GMT
Hello!
    I'm deploying my Consumer in AS environment.  My consumer is a remote
component with scaleout factor of 3. The consumer tries to get an instance
to a triplestore template that has reference to a triplestore pooled
connection. After profiling the deployed consumer with the given set up, I
found that there is *ONE* instance of SharedResourceObject and also 3
instances of consumer. Can you please have a look over the following code
snippets and check if it is UIMA AS compliant?
package com;
public class SpringResource implements SharedResourceObject {
  private AbstractApplicationContext context;
  private AtomicInteger counter = new AtomicInteger();

  public void load(DataResource aData) throws
ResourceInitializationException {
    context = new ClassPathXmlApplicationContext(aData.getUri().toString());
  }

  public AbstractApplicationContext getContext() {
    return context;
  }
  public void *registerComponent()* {
  *  counter.incrementAndGet();
  *}
  public void *unregisterComponent()* {
    if (counter.get() > 0) {
      *counter.decrementAndGet();*
    }
    if (counter.get() == 0) {
      *context.close();*
    }
  }
}//consumer

public class SpringCasConsumer extends CasConsumer_ImplBase {
  public void initialize() throws ResourceInitializationException {
* *       try {
 *     SpringResource shared = (SpringResource)
getUimaContext().getResourceObject("Resource");
      shared.getContext().getBean("myBean");
     shared.registerComponent();
 *   } catch (ResourceAccessException e) {
    }
 }
  public void destroy() {
    *   shared.unregisterComponent();
       super.destroy();
    *}
}
//deployment descriptor for UIMA AS

<analysisEngineDeploymentDescription  xmlns="
http://uima.apache.org/resourceSpecifier">

  <name>Consumer</name>
   <deployment protocol="jms" provider="activemq">
    *<casPool numberOfCASes="3"/>
    *<service>
      <inputQueue endpoint="ConsumerQueue" brokerURL="${defaultBrokerURL}"/>
      <topDescriptor>
       <import location="../../desc/cas_consumer/SpringConsumer.xml"/>
      </topDescriptor>
       <analysisEngine>
         *<scaleout numberOfInstances="3"/>*
      </analysisEngine>
    </service>
  </deployment>
</analysisEngineDeploymentDescription>

Configururation for resource manager:

 <resourceManagerConfiguration>
    <externalResources>
      <externalResource>
        <name>*springResource*</name>
        <description/>
        <fileResourceSpecifier>
          <fileUrl>file:spring_context.xml</fileUrl>
        </fileResourceSpecifier>
        <implementationName>*com.SpringResource*</implementationName>
      </externalResource>
    </externalResources>
    <externalResourceBindings>
      <externalResourceBinding>
        <key*>Resource*</key>
        <resourceName>*springResource*</resourceName>
      </externalResourceBinding>
    </externalResourceBindings>
  </resourceManagerConfiguration>

Thank you.
Regards,
 Florin




On Wed, Nov 21, 2012 at 8:25 PM, Richard Eckart de Castilho <
eckart@ukp.informatik.tu-darmstadt.de> wrote:

> Hi,
> >   Thank you for your anwers. Regarding the SharedResourceObject approach
> > in the JavaDoc I didn't find any reference about how many instances will
> be
> > created when you have many Annotators using the same resource. I would
> say
> > that that will be one SharedResouce per instance Annotator.
>
> The ResourceManager creates one instance per resource per UIMA context.
>
> >  1.So suppose that you have AnnotatorX  and AnnotatorY using the
> > SharedResourceObject collocated (same JVM) how many instances of
> > SharedResourceObject do we have?
>
> Depends how you deploy your pipelines. Assuming that run a single CPE
> (or something the likes) per JVM, there will be a single instance. Each
> CPE run creates an UIMA context internally. I don't know how UIMA-AS
> handles
> that. If you run your pipelines with uimaFIT's SimplePipeline, one instance
> per call run runPipeline() is created.
>
> >   2.Also, if the AnnotatorX is a remote EA that is using the
> > SharedResourceObject with a scale out factor of 3, how many instances of
> > SharedResourceObject  will be created?
>
> As the name says, the instance is shared - so one instance.
>
> >  What I'm afraid, that given the ApplicationContext on some point we have
> > to destroy it. As far as I know this can be achieve in the destroy method
> > of the annotator. But if we have a single SharedResourceObject shared
> among
> > annotators probably will be a mess to destroy the context from each of
> the
> > instances.
>
> It seems that UIMA does currently not support a full lifecycle management
> for external resources. It can create the, but they are not notified in
> any way
> when the UIMA context/ResourceManager goes out of business.
>
> You could implement a check-out/return mechanism: increment a counter
> variable
> in the resource every time an analysis engine calls a certain method on the
> resource. In the destroy() method of the analysis engine, call another
> method
> to decrement the counter. If the counter reaches 0 at the end of the
> decrement method, call your resource's destroy() logic.
>
> >  I would like to ask you if this code is proper solution for our case
> >
> > MyCasConsumer {
> >
> >   private ApplicationContext springContext;
> >
> >  void  initialize() {
> >   springContext = new
> ClassPathXmlApplicationContext("spring-context.xml");
> >  }
> >
> >  void destroy() {
> >   springContext.close();
> >  }
> > }
>
> I wouldn't call a shared resource "CasConsumer". Also, CasConsumer's
> normally
> don't scale because they have the MULTIPLE_DEPLOYMENT_ALLOWED_DEFAULT flag
> set
> to "false".
>
> -- 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
> -------------------------------------------------------------------
>
>
>
>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message