@Override public void process(JCas jcas) throws AnalysisEngineProcessException { aeServiceAdapter.process(jcas); }
/** * Gets the AnalysisEngine that delivers the functionality for this service. * * @return the AnalysisEngine */ public AnalysisEngine getAnalysisEngine() { return (AnalysisEngine) getResource(); }
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try { super.collectionProcessComplete(); aeServiceAdapter.collectionProcessComplete(); } finally { aeServiceAdapter.destroy(); } }
ProcessTrace trace = aData.getProcessTrace(); if (trace == null) { trace = new ProcessTrace_impl(); String resourceName = getMetaData().getName(); trace.startEvent(resourceName, ProcessTraceEvent.SERVICE, ""); try { cas = getCasFromPool(mTimeout); aData.unmarshalCas(cas, true); getAnalysisEngine().process(cas, aResultSpec, trace); return new ServiceDataCargo(cas, trace); } catch (Exception e) { resultMessage = e.getLocalizedMessage(); getCasPool().releaseCas(cas);
@Override public void initialize(UimaContext aContext) throws ResourceInitializationException { super.initialize(aContext); String[] paraNames = aContext.getConfigParameterNames(); Parameter[] param = new Parameter[paraNames.length]; for (int i = 0; i < paraNames.length; i++) { String key = paraNames[i]; String value = (String) aContext.getConfigParameterValue(key).toString(); Parameter_impl p = new Parameter_impl(key, value); param[i] = p; } resourceSpec = createResourceSpec(); setResourceSpecParameters(param); aeServiceAdapter = createServiceAdapter(); aeServiceAdapter.initialize(resourceSpec, null); }
/** * Initialize this service. This is where the CAS pool is created. * * @see org.apache.uima.resource.service.impl.ResourceService_impl#initialize(ResourceSpecifier, Map) */ public void initialize(ResourceSpecifier aResourceSpecifier, Map<String, Object> aResourceInitParams) throws ResourceInitializationException { super.initialize(aResourceSpecifier, aResourceInitParams); Integer numInstances = (Integer) aResourceInitParams .get(AnalysisEngine.PARAM_NUM_SIMULTANEOUS_REQUESTS); if (numInstances == null) { numInstances = Integer.valueOf(1); } mCasPool = new CasPool(numInstances.intValue(), getAnalysisEngine()); // also record timeout period to use for CAS pool Integer timeoutInteger = (Integer) aResourceInitParams.get(AnalysisEngine.PARAM_TIMEOUT_PERIOD); if (timeoutInteger != null) { mTimeout = timeoutInteger.intValue(); } else { mTimeout = 0; } }
/** * Unmarshalls this <code>SerializableAnalysisProcessData</code> into an existing * <code>AnalysisProcessData</code> object. The existing CAS data in the * <code>aDataContainer</code> object will be replaced by the CAS data in this object. The * <code>ProcessTrace</code> events in this object will be appended to the * <code>ProcessTrace</code> of the <code>aDataContainer</code> object. * * @param aDataContainer * the AnalysisProcessData to unmarshal into * @param aReplaceCasTypeSystem - * @throws CASException - */ public void unmarshalInto(AnalysisProcessData aDataContainer, boolean aReplaceCasTypeSystem) throws CASException { unmarshalCas(aDataContainer.getCAS(), aReplaceCasTypeSystem); aDataContainer.getProcessTrace().addAll(mProcessTrace.getEvents()); }
/** * Gets metadata for this Resource service. * * @return metadata */ public ResourceMetaData getMetaData() throws ResourceServiceException { try { return mServiceImpl.getMetaData(); } catch (ResourceServiceException e) { UIMAFramework.getLogger().log(Level.SEVERE, e.getMessage(), e); throw e; } catch (RuntimeException e) { UIMAFramework.getLogger().log(Level.SEVERE, e.getMessage(), e); throw e; } }
/** * Gets the name of this resource, for use in logging and trace messages. * * @return the name of this resource */ protected String getResourceName() { return getMetaData().getName(); } }
/** * Gets whether socket keepAlive is enabled, by consulting the * PerformanceTuningSettings. (If no setting specified, defaults * to true.) * @return if socketKeepAlive is enabled */ private boolean isSocketKeepAliveEnabled() { Properties settings = mOwner.getPerformanceTuningSettings(); if (settings != null) { String enabledStr = (String)settings.get(UIMAFramework.SOCKET_KEEPALIVE_ENABLED); return !"false".equalsIgnoreCase(enabledStr); } return true; } }
/** * An alternative form of initialize that takes the number of simultaneous requests and timeout * period as explicit arguments. * @param aResourceSpecifier - * @param aNumSimultaneousRequests - * @param aTimeout - * @throws ResourceInitializationException - */ public void initialize(ResourceSpecifier aResourceSpecifier, int aNumSimultaneousRequests, int aTimeout) throws ResourceInitializationException { Map<String, Object> initParams = new HashMap<String, Object>(); initParams.put(AnalysisEngine.PARAM_NUM_SIMULTANEOUS_REQUESTS, Integer.valueOf( aNumSimultaneousRequests)); initParams.put(AnalysisEngine.PARAM_TIMEOUT_PERIOD, Integer.valueOf(aTimeout)); this.initialize(aResourceSpecifier, initParams); }
/** * Gets a CAS from the CAS Pool. Throws an exception if the timeout period elapses. * * @param aTimeout * maximum time to wait in milliseconds * * @return a CAS that has been checked-out of the pool * * @throws ResourceServiceException * if a CAS is not available within the timeout period. */ protected CAS getCasFromPool(int aTimeout) throws ResourceServiceException { CAS cas = getCasPool().getCas(aTimeout); if (cas == null) { throw new ResourceServiceException(ResourceServiceException.RESOURCE_UNAVAILABLE, null); } return cas; } }
/** * Processes an entity. * * @param aData * data to be processed * @param aResultSpec * specifies which results the Analysis Engine should produce * * @return the results of analysis */ public ServiceDataCargo process(ServiceDataCargo aData, ResultSpecification aResultSpec) throws ResourceServiceException { try { return mServiceImpl.process(aData, aResultSpec); } catch (ResourceServiceException e) { UIMAFramework.getLogger().log(Level.SEVERE, e.getMessage(), e); throw e; } catch (RuntimeException e) { UIMAFramework.getLogger().log(Level.SEVERE, e.getMessage(), e); throw e; } } }
/** * @see AnalysisEngineServiceStub#callProcess(CAS) */ public void callProcess(CAS aCAS) throws ResourceServiceException { try { AFrame requestFrame = new AFrame(); requestFrame.fset(Constants.VINCI_COMMAND, Constants.ANNOTATE); // serialize CAS (including type system) CASMgr cas = (CASMgr) aCAS; CASCompleteSerializer serializer = Serialization.serializeCASComplete(cas); requestFrame.fsetTrueBinary("BinaryCAS", SerializationUtils.serialize(serializer)); AFrame responseFrame = (AFrame) mVinciClient.sendAndReceive(requestFrame, mTimeout); // deserialize CAS from response frame byte[] responseCasBytes = responseFrame.fgetTrueBinary("BinaryCAS"); CASSerializer responseSerializer = (CASSerializer) SerializationUtils .deserialize(responseCasBytes); ((CASImpl) cas).reinit(responseSerializer); // also read annotation time and enter into AnalysisEngineManagementMBean int annotationTime = responseFrame.fgetInt(Constants.ANNOTATION_TIME); if (annotationTime > 0) { AnalysisEngineManagementImpl mbean = (AnalysisEngineManagementImpl) mOwner .getManagementInterface(); mbean.reportAnalysisTime(annotationTime); } } catch (Exception e) { throw new ResourceServiceException(e); } }
public void batchProcessComplete() throws AnalysisEngineProcessException { try { getStub().callBatchProcessComplete(); } catch (ResourceServiceException e) { throw new AnalysisEngineProcessException(e); } }
/** * @see org.apache.uima.resource.ConfigurableResource#getConfigParameterValue(java.lang.String) */ public Object getConfigParameterValue(String aParamName) { return getMetaData().getConfigurationParameterSettings().getParameterValue(aParamName); }
public void collectionProcessComplete() throws AnalysisEngineProcessException { try { getStub().callCollectionProcessComplete(); } catch (ResourceServiceException e) { throw new AnalysisEngineProcessException(e); } }
/** * @see org.apache.uima.resource.ConfigurableResource#getConfigParameterValue(java.lang.String, * java.lang.String) */ public Object getConfigParameterValue(String aGroupName, String aParamName) { return getMetaData().getConfigurationParameterSettings().getParameterValue(aGroupName, aParamName); }
/** * @see org.apache.uima.resource.Resource#getMetaData() */ public ResourceMetaData getMetaData() { try { if (mCachedMetaData == null && getStub() != null) { mCachedMetaData = getStub().callGetMetaData(); } return mCachedMetaData; } catch (ResourceServiceException e) { throw new UIMARuntimeException(e); } }