org.apache.uima.resource.Parameter Java Examples

The following examples show how to use org.apache.uima.resource.Parameter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CustomResourceSpecifierFactory_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testProduceResource() throws Exception {
  CustomResourceSpecifier specifier = UIMAFramework.getResourceSpecifierFactory().createCustomResourceSpecifier();
  specifier.setResourceClassName("org.apache.uima.impl.SomeCustomResource");
  Parameter[] parameters = new Parameter[2];
  parameters[0] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[0].setName("param1");
  parameters[0].setValue("val1");
  parameters[1] = UIMAFramework.getResourceSpecifierFactory().createParameter();
  parameters[1].setName("param2");
  parameters[1].setValue("val2");
  specifier.setParameters(parameters);    
  
  Resource res = crFactory.produceResource(Resource.class, specifier, Collections.EMPTY_MAP);   
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));
  
  //also UIMAFramework.produceResource should do the same thing
  res = UIMAFramework.produceResource(specifier, Collections.EMPTY_MAP);    
  assertTrue(res instanceof SomeCustomResource);
  assertEquals("val1", ((SomeCustomResource)res).paramMap.get("param1"));
  assertEquals("val2", ((SomeCustomResource)res).paramMap.get("param2"));  
}
 
Example #2
Source File: ElasticsearchHistoryTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  elasticsearch = new EmbeddedElasticsearch5();
  elasticsearchResource = new SharedElasticsearchResource();

  CustomResourceSpecifier_impl esSpecifier = new CustomResourceSpecifier_impl();
  esSpecifier.setParameters(
      new Parameter[] {
        new Parameter_impl(PARAM_CLUSTER, elasticsearch.getClusterName()),
        new Parameter_impl(PARAM_PORT, Integer.toString(elasticsearch.getTransportPort()))
      });

  elasticsearchResource.initialize(esSpecifier, Maps.newHashMap());

  history = new ElasticsearchHistory(elasticsearchResource);
  history.initialize(new CustomResourceSpecifier_impl(), Maps.newHashMap());
}
 
Example #3
Source File: SharedRabbitMQResourceSslTest.java    From baleen with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeTest() throws Exception {
  resource = new SharedRabbitMQResource();
  final CustomResourceSpecifier_impl samrSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedRabbitMQResource.PARAM_PORT, Integer.toString(port)),
        new Parameter_impl(SharedRabbitMQResource.PARAM_USER, BrokerManager.USER),
        new Parameter_impl(SharedRabbitMQResource.PARAM_PASS, BrokerManager.PASS),
        new Parameter_impl(SharedRabbitMQResource.PARAM_HTTPS, "true"),
        new Parameter_impl(SharedRabbitMQResource.PARAM_TRUSTALL, "true")
      };
  samrSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(samrSpecifier, config);
}
 
Example #4
Source File: VinciBinaryAnalysisEngineServiceStub.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the parameter value for.
 *
 * @param aKey the a key
 * @param parameters the parameters
 * @return the parameter value for
 */
public static String getParameterValueFor(String aKey, Parameter[] parameters) {
  if (aKey != null) {
    for (int i = 0; parameters != null && i < parameters.length; i++) {
      if (aKey.equals(parameters[i].getName())) {
        return parameters[i].getValue();
      }
    }
  }
  return null; // aKey not found in parameters
}
 
Example #5
Source File: SomeCustomResource.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public boolean initialize(ResourceSpecifier aSpecifier, Map aAdditionalParams) throws ResourceInitializationException {
  Assert.assertTrue(aSpecifier instanceof CustomResourceSpecifier);
  Parameter[] params = ((CustomResourceSpecifier)aSpecifier).getParameters();
  for (int i = 0; i < params.length; i++) {
    paramMap.put(params[i].getName(), params[i].getValue());
  }
  return true;
}
 
Example #6
Source File: XMLParser_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testParsePearSpecifier() throws Exception {
  XMLInputSource in = new XMLInputSource(
          JUnitExtension.getFile("XmlParserTest/TestPearSpecifier.xml"));
  PearSpecifier pearSpec = this.mXmlParser.parsePearSpecifier(in);
  assertEquals("/home/user/uimaApp/installedPears/testpear", pearSpec.getPearPath());
  
  assertThat(pearSpec.getParameters())
      .extracting(Parameter::getName, Parameter::getValue)
      .containsExactly(tuple("legacyParam1", "legacyVal1"), tuple("legacyParam2", "legacyVal2"));

  assertThat(pearSpec.getPearParameters())
      .extracting(NameValuePair::getName, NameValuePair::getValue)
      .containsExactly(tuple("param1", "stringVal1"), tuple("param2", true));
}
 
Example #7
Source File: XMLParser_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testParseCustomResourceSpecifier() throws Exception {
  XMLInputSource in = new XMLInputSource(
          JUnitExtension.getFile("XmlParserTest/TestCustomResourceSpecifier.xml"));
  CustomResourceSpecifier uriSpec = mXmlParser.parseCustomResourceSpecifier(in);
  assertEquals("foo.bar.MyResource", uriSpec.getResourceClassName());
  Parameter[] params = uriSpec.getParameters();
  assertEquals(2, params.length);
  assertEquals("param1", params[0].getName());
  assertEquals("val1", params[0].getValue());
  assertEquals("param2", params[1].getName());
  assertEquals("val2", params[1].getValue());  
}
 
Example #8
Source File: XMLParser_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testParseURISpecifier() throws Exception {
  XMLInputSource in = new XMLInputSource(
          JUnitExtension.getFile("XmlParserTest/TestUriSpecifier.xml"));
  URISpecifier uriSpec = mXmlParser.parseURISpecifier(in);
  assertEquals("AnalysisEngine", uriSpec.getResourceType());
  assertEquals("Vinci", uriSpec.getProtocol());
  assertEquals(60000, uriSpec.getTimeout().intValue());
  Parameter[] params = uriSpec.getParameters();
  assertEquals(2, params.length);
  assertEquals("VNS_HOST", params[0].getName());
  assertEquals("some.internet.ip.name-or-address", params[0].getValue());
  assertEquals("VNS_PORT", params[1].getName());
  assertEquals("9000", params[1].getValue());    
}
 
Example #9
Source File: URISpecifier_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
  uriSpec = new URISpecifier_impl();
  uriSpec.setProtocol("Vinci");
  uriSpec.setUri("foo.bar");
  uriSpec.setParameters(new Parameter[] { new Parameter_impl("VNS_HOST", "myhost"),
      new Parameter_impl("VNS_PORT", "42") });
}
 
Example #10
Source File: CustomResourceSpecifier_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void setParameters(Parameter[] aParameters) {
  if (aParameters != null) {
    mParameters = aParameters;
  } else {
    mParameters = EMPTY_PARAMETERS;
  }
  
}
 
Example #11
Source File: SharedElasticsearchResourceTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {

  try (EmbeddedElasticsearch5 elasticsearch = new EmbeddedElasticsearch5()) {
    SharedElasticsearchResource elasticsearchResource = new SharedElasticsearchResource();

    CustomResourceSpecifier_impl esSpecifier = new CustomResourceSpecifier_impl();
    esSpecifier.setParameters(
        new Parameter[] {
          new Parameter_impl(PARAM_CLUSTER, elasticsearch.getClusterName()),
          new Parameter_impl(PARAM_PORT, Integer.toString(elasticsearch.getTransportPort()))
        });

    elasticsearchResource.initialize(esSpecifier, Maps.newHashMap());

    assertNotNull(elasticsearchResource.getClient());

    // Do something simple to check we get a response we can check
    ClusterStatsResponse actionGet =
        elasticsearchResource
            .getClient()
            .admin()
            .cluster()
            .clusterStats(new ClusterStatsRequest())
            .actionGet();
    assertEquals(elasticsearch.getClusterName(), actionGet.getClusterName().value());

    elasticsearchResource.destroy();
  }
}
 
Example #12
Source File: VinciCasProcessorDeployer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a value for a named VNS parameter (either VNS_HOST or VNS_PORT). The parameter is
 * resolved with the following priority: 1) Find the parameter in the Service descriptor 2) Find
 * the parameter in the CPE descriptor 3) Find the parameter as System.property (using -D on the
 * command line) 4) Use Hardcoded default ( VNS_HOST=localhost VNS_PORT=9000)
 * 
 * 
 * @param aVNSParamKey -
 *          name of the VNS parameter for which the value is sought
 * @param aCasProcessorConfig -
 *          CPE descriptor settings
 * @param aDefault -
 *          default value for the named parameter if parameter is not defined
 * 
 * @return - value for a named VNS parameter
 * @throws ResourceConfigurationException passthru
 */
private String getVNSSettingFor(String aVNSParamKey,
        CasProcessorConfiguration aCasProcessorConfig, String aDefault)
        throws ResourceConfigurationException {
  String vnsParam = null;

  URL descriptorUrl = aCasProcessorConfig.getDescriptorUrl();
  URISpecifier uriSpecifier = getURISpecifier(descriptorUrl);
  Parameter[] params = uriSpecifier.getParameters();

  for (int i = 0; params != null && i < params.length; i++) {
    if (aVNSParamKey.equals(params[i].getName())) {
      vnsParam = params[i].getValue();
      break;
    }
  }

  if (vnsParam == null) {
    // VNS not defined in the service descriptor. Use settings from CPE descriptor, if present
    // First translate the key. Unfortunately, the key in the CPE descriptor is vnsHost instead of
    // VNS_HOST and vnsPort instead of VNS_PORT
    if (aVNSParamKey.equals("VNS_HOST")) {
      vnsParam = aCasProcessorConfig.getDeploymentParameter(Constants.VNS_HOST);
    } else if (aVNSParamKey.equals("VNS_PORT")) {
      vnsParam = aCasProcessorConfig.getDeploymentParameter(Constants.VNS_PORT);
    }

    if (vnsParam == null) // VNS not defined in the CPE descriptor. Use -D parameter first if
    // it exists. If it does not exist, used default value
    {
      if ((vnsParam = System.getProperty(aVNSParamKey)) == null) {
        vnsParam = aDefault; // default
      }
    }
  }
  return vnsParam;
}
 
Example #13
Source File: KafkaResourceTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeTest() throws Exception {

  kafkaResource = new SharedKafkaResource();
  final CustomResourceSpecifier_impl samrSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedKafkaResource.PARAM_HOST, "localhost"),
        new Parameter_impl(SharedKafkaResource.PARAM_PORT, Integer.toString(brokerPort)),
        new Parameter_impl(SharedKafkaResource.PARAM_KAFKA_CONSUMER_GROUP_ID, "1")
      };
  samrSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  kafkaResource.initialize(samrSpecifier, config);
}
 
Example #14
Source File: SharedActiveMQResourceTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeTest() throws Exception {

  samr = new SharedActiveMQResource();
  final CustomResourceSpecifier_impl samrSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedActiveMQResource.PARAM_PROTOCOL, PROTOCOL_VALUE),
        new Parameter_impl(SharedActiveMQResource.PARAM_BROKERARGS, BROKERARGS_VALUE)
      };
  samrSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  samr.initialize(samrSpecifier, config);
}
 
Example #15
Source File: SharedRabbitMQResourceTcpTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeTest() throws Exception {
  resource = new SharedRabbitMQResource();
  final CustomResourceSpecifier_impl samrSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedRabbitMQResource.PARAM_PORT, Integer.toString(port)),
        new Parameter_impl(SharedRabbitMQResource.PARAM_USER, BrokerManager.USER),
        new Parameter_impl(SharedRabbitMQResource.PARAM_PASS, BrokerManager.PASS),
        new Parameter_impl(SharedRabbitMQResource.PARAM_HTTPS, "false")
      };
  samrSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(samrSpecifier, config);
}
 
Example #16
Source File: RedisResourceIT.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Test
public void testResourceCanSendAndRecieve() throws ResourceInitializationException {

  SharedRedisResource resource = new SharedRedisResource();
  final CustomResourceSpecifier_impl resourceSpecifier = new CustomResourceSpecifier_impl();
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedRedisResource.PARAM_HOST, redis.getContainerIpAddress()),
        new Parameter_impl(
            SharedRedisResource.PARAM_PORT, Integer.toString(redis.getMappedPort(REDIS_PORT)))
      };
  resourceSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(resourceSpecifier, config);

  Jedis jedis = resource.getJedis();
  String key = "key";
  String value = "value";
  jedis.lpush(key, new String[] {value});
  String result = jedis.rpop(key);
  assertEquals(value, result);

  jedis.lpush(key, new String[] {value});
  List<String> bresult = jedis.brpop(new String[] {key, "0"});
  assertEquals(key, bresult.get(0));
  assertEquals(value, bresult.get(1));
}
 
Example #17
Source File: VinciAnalysisEngineServiceStub.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new vinci analysis engine service stub.
 *
 * @param endpointURI the endpoint URI
 * @param timeout the timeout
 * @param owner the owner
 * @param parameters the parameters
 * @throws ResourceInitializationException the resource initialization exception
 */
public VinciAnalysisEngineServiceStub(String endpointURI, Integer timeout, Resource owner,
        Parameter[] parameters) throws ResourceInitializationException {
  mOwner = owner;

  // open Vinci connection
  try {
    VinciContext vctx = new VinciContext(InetAddress.getLocalHost().getCanonicalHostName(), 0);
    // Override vinci default VNS settings
    String vnsHost = null;
    String vnsPort = null; 
    String getMetaDataTimeout = null; 
    if (parameters != null) {
       vnsHost = 
        VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("VNS_HOST", parameters); 
       vnsPort = VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("VNS_PORT",
              parameters);
       getMetaDataTimeout = VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("GetMetaDataTimeout", parameters);
    }
    if (vnsHost == null) {
      vnsHost = System.getProperty("VNS_HOST");
      if (vnsHost == null)
        vnsHost = Constants.DEFAULT_VNS_HOST;
    }
    if (vnsPort == null) {
      vnsPort = System.getProperty("VNS_PORT");
      if (vnsPort == null)
        vnsPort = "9000";
    }
    vctx.setVNSHost(vnsHost);
    vctx.setVNSPort(Integer.parseInt(vnsPort));
    
    // Override socket keepAlive setting
    vctx.setSocketKeepAliveEnabled(isSocketKeepAliveEnabled());

    if (debug) {
      System.out.println("Establishing connnection to " + endpointURI + " using VNS_HOST:"
              + vctx.getVNSHost() + " and VNS_PORT=" + vctx.getVNSPort());
    }
      
    // establish connection to service
    mVinciClient = new VinciClient(endpointURI, AFrame.getAFrameFactory(), vctx);
    
    //store timeout for use in later RPC calls
    if (timeout != null) {
      mTimeout = timeout;
    } else {
     mTimeout = mVinciClient.getSocketTimeout(); //default
    }
    if (getMetaDataTimeout != null) {
      mGetMetaDataTimeout = Integer.parseInt(getMetaDataTimeout);
    } else {
      mGetMetaDataTimeout = mVinciClient.getSocketTimeout(); //default
    }
    
    if (debug) {
      System.out.println("Success");
    }
  } catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}
 
Example #18
Source File: KafkaResourceIT.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void testResourceCanSendAndRecieve()
    throws ResourceInitializationException, IOException, InterruptedException, BaleenException {

  SharedKafkaResource resource = new SharedKafkaResource();
  final CustomResourceSpecifier_impl resourceSpecifier = new CustomResourceSpecifier_impl();
  // @formatter:off
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedKafkaResource.PARAM_HOST, container.getContainerIpAddress()),
        new Parameter_impl(SharedKafkaResource.PARAM_PORT, Integer.toString(KAFKA_PORT))
      };
  // @formatter:on

  resourceSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(resourceSpecifier, config);

  final CountDownLatch latch = new CountDownLatch(MESSAGE_COUNT);
  final Producer<String, String> producer =
      resource.createProducer(
          QUEUE,
          ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
          StringSerializer.class.getName(),
          ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
          StringSerializer.class.getName());
  // @formatter:off
  final Consumer<String, String> consumer =
      resource.createConsumer(
          QUEUE,
          ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
          StringDeserializer.class.getName(),
          ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
          StringDeserializer.class.getName(),
          ConsumerConfig.MAX_POLL_RECORDS_CONFIG,
          1,
          ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
          "earliest");
  // @formatter:on

  new Thread(
          () -> {
            int count = 0;
            while (count < MESSAGE_COUNT) {
              final ConsumerRecords<String, String> records = consumer.poll(1000);
              count += records.count();
              records.forEach(
                  (r) -> LOGGER.info("Message recieved: " + r.key() + " " + r.value()));

              records.forEach((r) -> latch.countDown());
            }
          })
      .start();

  new Thread(
          () ->
              IntStream.range(0, MESSAGE_COUNT)
                  .mapToObj(Integer::toString)
                  .map((i) -> new ProducerRecord<>(QUEUE, new Date().toString(), "test"))
                  .map(producer::send)
                  .forEach(
                      (f) -> {
                        try {
                          LOGGER.info("Message sent:" + f.get());
                        } catch (InterruptedException | ExecutionException e) {
                          fail(e.getMessage());
                        }
                      }))
      .start();

  assertTrue("Messages not recieved", latch.await(2, TimeUnit.MINUTES));
}
 
Example #19
Source File: RabbitMQResourceIT.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Test
public void testResourceCanSendAndRecieve()
    throws ResourceInitializationException, IOException, InterruptedException {

  SharedRabbitMQResource resource = new SharedRabbitMQResource();
  final CustomResourceSpecifier_impl resourceSpecifier = new CustomResourceSpecifier_impl();
  // @formatter:off
  final Parameter[] configParams =
      new Parameter[] {
        new Parameter_impl(SharedRabbitMQResource.PARAM_HOST, container.getContainerIpAddress()),
        new Parameter_impl(
            SharedRabbitMQResource.PARAM_PORT,
            Integer.toString(container.getMappedPort(AMPQ_PORT))),
        new Parameter_impl(SharedRabbitMQResource.PARAM_USER, DEFAULT_RABBIT_USER),
        new Parameter_impl(SharedRabbitMQResource.PARAM_PASS, DEFAULT_RABBIT_PASS)
      };
  // @formatter:on

  LOGGER.info("RabbitMQ management port: " + container.getMappedPort(MANAGEMENT_PORT));
  resourceSpecifier.setParameters(configParams);
  final Map<String, Object> config = Maps.newHashMap();
  resource.initialize(resourceSpecifier, config);

  final CountDownLatch latch = new CountDownLatch(10);
  final RabbitMQSupplier supplier = resource.createSupplier(EXCHANGE, ROUTE, QUEUE);
  final RabbitMQConsumer consumer = resource.createConsumer(EXCHANGE, ROUTE, QUEUE);

  new Thread(
          () ->
              IntStream.range(0, 10)
                  .forEachOrdered(
                      (i) -> {
                        byte[] bs = supplier.get();
                        LOGGER.info("Message received: " + new String(bs));
                        latch.countDown();
                      }))
      .start();

  new Thread(
          () ->
              IntStream.range(0, 10)
                  .mapToObj(Integer::toString)
                  .peek(i -> LOGGER.info("Message sent: " + i))
                  .map(String::getBytes)
                  .forEach(consumer::accept))
      .start();

  assertTrue("Messages not recieved", latch.await(1, TimeUnit.MINUTES));
}
 
Example #20
Source File: ResourceSpecifierFactory_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public Parameter createParameter() {
  return (Parameter) createObject(Parameter.class);
}
 
Example #21
Source File: URISpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @return Returns the Parameters.
 */
public Parameter[] getParameters() {
  return mParameters;
}
 
Example #22
Source File: PearSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Deprecated
public void setParameters(Parameter... parameters) {
  this.mParameters = parameters;
}
 
Example #23
Source File: PearSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Deprecated
public Parameter[] getParameters() {
  return this.mParameters;
}
 
Example #24
Source File: CustomResourceSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public Parameter[] getParameters() {
  return mParameters;
}
 
Example #25
Source File: VinciBinaryAnalysisEngineServiceStub.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Instantiates a new vinci binary analysis engine service stub.
 *
 * @param endpointURI the endpoint URI
 * @param timeout the timeout
 * @param owner the owner
 * @param parameters the parameters
 * @throws ResourceInitializationException the resource initialization exception
 */
public VinciBinaryAnalysisEngineServiceStub(String endpointURI, Integer timeout,
        AnalysisEngineServiceAdapter owner, Parameter[] parameters)
        throws ResourceInitializationException {
  mOwner = owner;

  // open Vinci connection
  try {
    VinciContext vctx = new VinciContext(InetAddress.getLocalHost().getCanonicalHostName(), 0);
    // Override vinci default VNS settings
    String vnsHost = null;
    String vnsPort = null; 
    String getMetaDataTimeout = null; 
    if (parameters != null) {
       vnsHost = 
        VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("VNS_HOST", parameters); 
       vnsPort = VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("VNS_PORT",
              parameters);
       getMetaDataTimeout = VinciBinaryAnalysisEngineServiceStub.getParameterValueFor("GetMetaDataTimeout", parameters);
    }
    if (vnsHost == null) {
      vnsHost = System.getProperty("VNS_HOST");
      if (vnsHost == null)
        vnsHost = Constants.DEFAULT_VNS_HOST;
    }
    if (vnsPort == null) {
      vnsPort = System.getProperty("VNS_PORT");
      if (vnsPort == null)
        vnsPort = "9000";
    }
    vctx.setVNSHost(vnsHost);
    vctx.setVNSPort(Integer.parseInt(vnsPort));
    
    // Override socket keepAlive setting
    vctx.setSocketKeepAliveEnabled(isSocketKeepAliveEnabled());

    if (debug) {
      System.out.println("Establishing connnection to " + endpointURI + " using VNS_HOST:"
              + vctx.getVNSHost() + " and VNS_PORT=" + vctx.getVNSPort());
    }
      
    // establish connection to service
    mVinciClient = new VinciClient(endpointURI, AFrame.getAFrameFactory(), vctx);
    
    //store timeout for use in later RPC calls
    if (timeout != null) {
      mTimeout = timeout;
    } else {
     mTimeout = mVinciClient.getSocketTimeout(); //default
    }
    if (getMetaDataTimeout != null) {
      mGetMetaDataTimeout = Integer.parseInt(getMetaDataTimeout);
    } else {
      mGetMetaDataTimeout = mVinciClient.getSocketTimeout(); //default
    }      
    
    if (debug) {
      System.out.println("Success");
    }
  } catch (Exception e) {
    throw new ResourceInitializationException(e);
  }
}
 
Example #26
Source File: ConfigurationParameterInitializer.java    From uima-uimafit with Apache License 2.0 3 votes vote down vote up
/**
 * Initialize a component from a {@link CustomResourceSpecifier}.
 *
 * @param component
 *          the component to initialize.
 * @param parameters
 *          a list of parameters.
 * @see #initialize(Object, UimaContext)
 * @throws ResourceInitializationException
 *           if a failure occurs during initialization.
 */
public static void initialize(Object component, Parameter... parameters)
        throws ResourceInitializationException {
  Map<String, Object> params = new HashMap<>();
  for (Parameter p : parameters) {
    params.put(p.getName(), p.getValue());
  }
  initialize(component, params);
}
 
Example #27
Source File: URISpecifier_impl.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * @param parameters
 *          The Parameters to set.
 */
public void setParameters(Parameter[] parameters) {
  mParameters = parameters;
}
 
Example #28
Source File: ResourceSpecifierFactory.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a <code>Parameter</code>
 * 
 * @return an instance of an object implementing <code>Parameter</code>.
 */
public Parameter createParameter();
 
Example #29
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the parameters.
 *
 * @return parameters
 */
public Parameter[] getParameters() {
  return parameters;
}
 
Example #30
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the parameters.
 *
 * @param aparameters the new parameters
 */
public void setParameters(Parameter[] aparameters) {
  parameters = aparameters;
}