当前位置: 首页>>代码示例>>Java>>正文


Java RpcClientFactory.getThriftInstance方法代码示例

本文整理汇总了Java中org.apache.flume.api.RpcClientFactory.getThriftInstance方法的典型用法代码示例。如果您正苦于以下问题:Java RpcClientFactory.getThriftInstance方法的具体用法?Java RpcClientFactory.getThriftInstance怎么用?Java RpcClientFactory.getThriftInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.flume.api.RpcClientFactory的用法示例。


在下文中一共展示了RpcClientFactory.getThriftInstance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAppend

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@Test
public void testAppend() throws Exception {
  client = RpcClientFactory.getThriftInstance(props);
  Context context = new Context();
  channel.configure(context);
  configureSource();
  context.put(ThriftSource.CONFIG_BIND, "0.0.0.0");
  context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
  Configurables.configure(source, context);
  source.start();
  for (int i = 0; i < 30; i++) {
    client.append(EventBuilder.withBody(String.valueOf(i).getBytes()));
  }
  Transaction transaction = channel.getTransaction();
  transaction.begin();

  for (int i = 0; i < 30; i++) {
    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals(String.valueOf(i), new String(event.getBody()));
  }
  transaction.commit();
  transaction.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:TestThriftSource.java

示例2: testAppendSSL

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@Test
public void testAppendSSL() throws Exception {
  Properties sslprops = (Properties)props.clone();
  sslprops.put("ssl", "true");
  sslprops.put("truststore", "src/test/resources/truststorefile.jks");
  sslprops.put("truststore-password", "password");
  sslprops.put("trustmanager-type", TrustManagerFactory.getDefaultAlgorithm());
  client = RpcClientFactory.getThriftInstance(sslprops);

  Context context = new Context();
  channel.configure(context);
  configureSource();
  context.put(ThriftSource.CONFIG_BIND, "0.0.0.0");
  context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
  context.put("ssl", "true");
  context.put("keystore", "src/test/resources/keystorefile.jks");
  context.put("keystore-password", "password");
  context.put("keymanager-type", KeyManagerFactory.getDefaultAlgorithm());
  Configurables.configure(source, context);
  source.start();
  for (int i = 0; i < 30; i++) {
    client.append(EventBuilder.withBody(String.valueOf(i).getBytes()));
  }
  Transaction transaction = channel.getTransaction();
  transaction.begin();

  for (int i = 0; i < 30; i++) {
    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertEquals(String.valueOf(i), new String(event.getBody()));
  }
  transaction.commit();
  transaction.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:35,代码来源:TestThriftSource.java

示例3: connect

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public void connect() {
  Properties props = new Properties();
  StringBuilder hosts = new StringBuilder();
  int numFlumeHosts = 0;
  for(Map.Entry<String, String> e : flumeHostsConfig.entrySet()) {
    hosts.append(e.getKey()).append(" ");
    props.setProperty(HOSTS_KEY + "." + e.getKey(), e.getValue());
    numFlumeHosts++;
  }
  props.setProperty(HOSTS_KEY, hosts.toString().trim());
  props.setProperty(BATCH_SIZE_KEY, String.valueOf(batchSize));
  props.setProperty(CONNECTION_TIMEOUT_KEY, String.valueOf(connectionTimeout));
  props.setProperty(REQUEST_TIMEOUT_KEY, String.valueOf(requestTimeout));

  switch(clientType) {
    case THRIFT:
      this.client = RpcClientFactory.getThriftInstance(props);
      break;
    case AVRO_FAILOVER:
      props.put(CLIENT_TYPE_KEY, CLIENT_TYPE_DEFAULT_FAILOVER);
      props.setProperty(MAX_ATTEMPTS_KEY, String.valueOf(numFlumeHosts));
      this.client = RpcClientFactory.getInstance(props);
      break;
    case AVRO_LOAD_BALANCING:
      props.put(CLIENT_TYPE_KEY, CLIENT_TYPE_DEFAULT_LOADBALANCING);
      props.setProperty(BACKOFF_KEY, String.valueOf(backOff));
      props.setProperty(MAX_BACKOFF_KEY, String.valueOf(maxBackOff));
      props.setProperty(HOST_SELECTOR_KEY, getHostSelector(hostSelectionStrategy));
      this.client = RpcClientFactory.getInstance(props);
      break;
    default:
      throw new IllegalStateException("Unsupported client type - cannot happen");
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:35,代码来源:FlumeConfig.java

示例4: testMultipleClients

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@Test
public void testMultipleClients() throws Exception {
  ExecutorService submitter = Executors.newCachedThreadPool();
  client = RpcClientFactory.getThriftInstance(props);
  Context context = new Context();
  context.put("capacity", "1000");
  context.put("transactionCapacity", "1000");
  channel.configure(context);
  configureSource();
  context.put(ThriftSource.CONFIG_BIND, "0.0.0.0");
  context.put(ThriftSource.CONFIG_PORT, String.valueOf(port));
  Configurables.configure(source, context);
  source.start();
  ExecutorCompletionService<Void> completionService = new ExecutorCompletionService(submitter);
  for (int i = 0; i < 30; i++) {
    completionService.submit(new SubmitHelper(i), null);
  }
  //wait for all threads to be done


  for (int i = 0; i < 30; i++) {
    completionService.take();
  }

  Transaction transaction = channel.getTransaction();
  transaction.begin();
  long after = System.currentTimeMillis();
  List<Integer> events = Lists.newArrayList();
  for (int i = 0; i < 300; i++) {
    Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue(Long.valueOf(event.getHeaders().get("time")) < after);
    events.add(Integer.parseInt(new String(event.getBody())));
  }
  transaction.commit();
  transaction.close();

  Collections.sort(events);

  int index = 0;
  //30 batches of 10
  for (int i = 0; i < 30; i++) {
    for (int j = 0; j < 10; j++) {
      Assert.assertEquals(i, events.get(index++).intValue());
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:48,代码来源:TestThriftSource.java

示例5: getNewClient

import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
 * get a new RPC client
 */
private void getNewClient() {
    boolean retry = true;
    int retryCount = 0;
    cleanup();
    
    LOG.info("getNewClient(): establishing RPC connection");

    while (retry) {

        try {
            switch (rpcType) {
            case THRIFT_RPC:
                client = RpcClientFactory.getThriftInstance(hostname, 
                                                            port, rpcBatchSize);
                LOG.info("getNewClient(): Thrift RPC client connection succeeded");

                break;
            case AVRO_RPC:
            default:
                // note: we could also set properties and call
                // RpcClientFactory.getInstance(Properties props);
                //client = RpcClientFactory.getDefaultInstance(hostname, 
                //                                             port, rpcBatchSize);
                client = RpcClientFactory.getInstance(rpcProperties);
                LOG.info("getNewClient(): Avro RPC client connection succeeded");
                retry = false;
                break;
            }
        } catch (FlumeException fe) {
            LOG.warn("getNewClient(): FlumeException encountered: {}", 
                     fe.getMessage());
            LOG.info("*** Retrying connection ...");
            retryCount++;
            if (retryCount < rpcMaxRetries) {
                try {
                    Thread.sleep(rpcRetryDelaySecs * 1000);
                } catch (InterruptedException e) {
                    // in theory we should never be interrupted
                    // so we will just contine
                    retry = true;
                }
            } else {
                LOG.error("*** Max retries exceeded. Giving up.");
                retry = false;
                throw fe;
            }
        }
    }
}
 
开发者ID:oracle,项目名称:bdglue,代码行数:53,代码来源:FlumePublisher.java


注:本文中的org.apache.flume.api.RpcClientFactory.getThriftInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。