Search in sources :

Example 1 with BaseUIMAAsynchronousEngine_impl

use of org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl in project dkpro-lab by dkpro.

the class SimpleClient method start.

/**
 * Initialize the UIMA-AS client.
 */
public void start() throws ResourceInitializationException {
    uimaAsEngine = new BaseUIMAAsynchronousEngine_impl();
    Map<String, Object> clientCtx = new HashMap<String, Object>();
    clientCtx.put(UimaAsynchronousEngine.ServerUri, getBrokerUrl());
    clientCtx.put(UimaAsynchronousEngine.Endpoint, endpoint);
    clientCtx.put(UimaAsynchronousEngine.Timeout, timeout * 1000);
    clientCtx.put(UimaAsynchronousEngine.GetMetaTimeout, getmeta_timeout * 1000);
    clientCtx.put(UimaAsynchronousEngine.CpcTimeout, cpc_timeout * 1000);
    clientCtx.put(UimaAsynchronousEngine.CasPoolSize, casPoolSize);
    clientCtx.put(UIMAFramework.CAS_INITIAL_HEAP_SIZE, new Integer(fsHeapSize / 4).toString());
    // Add Collection Reader
    if (collectionReaderDesc != null) {
        uimaAsEngine.setCollectionReader(UIMAFramework.produceCollectionReader(collectionReaderDesc));
    }
    // Add status listener
    // uimaAsEngine.addStatusCallbackListener(new StatusCallbackListenerImpl(ctx));
    // Initialize the client
    uimaAsEngine.initialize(clientCtx);
    log.debug("UIMA AS client started");
}
Also used : HashMap(java.util.HashMap) BaseUIMAAsynchronousEngine_impl(org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl)

Example 2 with BaseUIMAAsynchronousEngine_impl

use of org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl in project dkpro-lab by dkpro.

the class UimaAsExecutionEngine method initializeService.

protected void initializeService() throws Exception {
    // Create Asynchronous Engine API
    uimaAsEngine = new BaseUIMAAsynchronousEngine_impl();
    // Save the AED to a file because UIMA-AS cannot have an AED direclty embedded in its
    // descriptor
    AnalysisEngineDescription topDescriptor = configuration.getAnalysisEngineDescription(ctx);
    ResourceMetaData topMetaData = topDescriptor.getMetaData();
    File topDescriptorFile = File.createTempFile(getClass().getSimpleName(), ".xml");
    topDescriptorFile.deleteOnExit();
    try (OutputStream os = new FileOutputStream(topDescriptorFile)) {
        topDescriptor.toXML(os);
    }
    // Create service descriptor
    ServiceContext context = new ServiceContextImpl(topMetaData.getName(), topMetaData.getDescription(), topDescriptorFile.getAbsolutePath(), endpoint, brokerUrl);
    UimaASPrimitiveDeploymentDescriptor dd = DeploymentDescriptorFactory.createPrimitiveDeploymentDescriptor(context);
    // Store service descriptor also to a temporary file
    File deploymentDescriptionFile = File.createTempFile(getClass().getSimpleName(), ".xml");
    deploymentDescriptionFile.deleteOnExit();
    dd.save(deploymentDescriptionFile);
    Map<String, Object> serviceCtx = new HashMap<String, Object>();
    serviceCtx.put(UimaAsynchronousEngine.DD2SpringXsltFilePath, getUrlAsFile(getClass().getResource("/uima-as/dd2spring.xsl"), true).getAbsolutePath());
    serviceCtx.put(UimaAsynchronousEngine.SaxonClasspath, getClass().getResource("/uima-as/saxon8.jar").toString());
    serviceId = uimaAsEngine.deploy(deploymentDescriptionFile.getAbsolutePath(), serviceCtx);
    ctx.message("Deployed experiment as UIMA-AS service: [" + serviceId + "]");
}
Also used : HashMap(java.util.HashMap) ServiceContext(org.apache.uima.resourceSpecifier.factory.ServiceContext) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BaseUIMAAsynchronousEngine_impl(org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl) FileOutputStream(java.io.FileOutputStream) AnalysisEngineDescription(org.apache.uima.analysis_engine.AnalysisEngineDescription) UimaASPrimitiveDeploymentDescriptor(org.apache.uima.resourceSpecifier.factory.UimaASPrimitiveDeploymentDescriptor) Util.getUrlAsFile(org.dkpro.lab.Util.getUrlAsFile) File(java.io.File) ResourceMetaData(org.apache.uima.resource.metadata.ResourceMetaData) ServiceContextImpl(org.apache.uima.resourceSpecifier.factory.impl.ServiceContextImpl)

Example 3 with BaseUIMAAsynchronousEngine_impl

use of org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl in project dkpro-lab by dkpro.

the class SimpleService method start.

/**
 * Initialize the UIMA-AS client.
 */
public void start() throws ResourceInitializationException {
    uimaAsEngine = new BaseUIMAAsynchronousEngine_impl();
    Map<String, Object> serviceCtx = new HashMap<String, Object>();
    File deploymentDescriptionFile;
    try {
        // Save the AED to a file because UIMA-AS cannot have an AED direclty embedded in its
        // descriptor
        ResourceMetaData topMetaData = aeDesc.getMetaData();
        File topDescriptorFile = File.createTempFile(getClass().getSimpleName(), ".xml");
        topDescriptorFile.deleteOnExit();
        try (OutputStream os = new FileOutputStream(topDescriptorFile)) {
            aeDesc.toXML(os);
        } catch (SAXException e) {
            throw new ResourceInitializationException(e);
        }
        // Create service descriptor
        ServiceContext context = new ServiceContextImpl(topMetaData.getName(), topMetaData.getDescription(), topDescriptorFile.getAbsolutePath(), endpoint, getBrokerUrl());
        UimaASPrimitiveDeploymentDescriptor dd = DeploymentDescriptorFactory.createPrimitiveDeploymentDescriptor(context);
        deploymentDescriptionFile = File.createTempFile(getClass().getSimpleName(), ".xml");
        deploymentDescriptionFile.deleteOnExit();
        try {
            dd.save(deploymentDescriptionFile);
        } catch (Exception e) {
            throw new ResourceInitializationException(e);
        }
        serviceCtx.put(UimaAsynchronousEngine.DD2SpringXsltFilePath, getUrlAsFile(getClass().getResource("/uima-as/dd2spring.xsl"), true).getAbsolutePath());
        serviceCtx.put(UimaAsynchronousEngine.SaxonClasspath, getClass().getResource("/uima-as/saxon8.jar").toString());
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
    try {
        serviceId = uimaAsEngine.deploy(deploymentDescriptionFile.getAbsolutePath(), serviceCtx);
        log.debug("UIMA AS service deployed: [" + serviceId + "]");
    } catch (Exception e) {
        throw new ResourceInitializationException(e);
    }
}
Also used : HashMap(java.util.HashMap) ServiceContext(org.apache.uima.resourceSpecifier.factory.ServiceContext) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) IOException(java.io.IOException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) SAXException(org.xml.sax.SAXException) BaseUIMAAsynchronousEngine_impl(org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl) SAXException(org.xml.sax.SAXException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) FileOutputStream(java.io.FileOutputStream) UimaASPrimitiveDeploymentDescriptor(org.apache.uima.resourceSpecifier.factory.UimaASPrimitiveDeploymentDescriptor) Util.getUrlAsFile(org.dkpro.lab.Util.getUrlAsFile) File(java.io.File) ResourceMetaData(org.apache.uima.resource.metadata.ResourceMetaData) ServiceContextImpl(org.apache.uima.resourceSpecifier.factory.impl.ServiceContextImpl)

Aggregations

HashMap (java.util.HashMap)3 BaseUIMAAsynchronousEngine_impl (org.apache.uima.adapter.jms.client.BaseUIMAAsynchronousEngine_impl)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ResourceMetaData (org.apache.uima.resource.metadata.ResourceMetaData)2 ServiceContext (org.apache.uima.resourceSpecifier.factory.ServiceContext)2 UimaASPrimitiveDeploymentDescriptor (org.apache.uima.resourceSpecifier.factory.UimaASPrimitiveDeploymentDescriptor)2 ServiceContextImpl (org.apache.uima.resourceSpecifier.factory.impl.ServiceContextImpl)2 Util.getUrlAsFile (org.dkpro.lab.Util.getUrlAsFile)2 IOException (java.io.IOException)1 AnalysisEngineDescription (org.apache.uima.analysis_engine.AnalysisEngineDescription)1 ResourceInitializationException (org.apache.uima.resource.ResourceInitializationException)1 SAXException (org.xml.sax.SAXException)1