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


Java RpcClient类代码示例

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


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

示例1: initializeRpcClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@Override
protected RpcClient initializeRpcClient(Properties props) {
  // Only one thread is enough, since only one sink thread processes
  // transactions at any given time. Each sink owns its own Rpc client.
  props.setProperty(RpcClientConfigurationConstants.CONFIG_CONNECTION_POOL_SIZE,
                    String.valueOf(1));
  boolean enableKerberos = Boolean.parseBoolean(
      props.getProperty(RpcClientConfigurationConstants.KERBEROS_KEY, "false"));
  if (enableKerberos) {
    return SecureRpcClientFactory.getThriftInstance(props);
  } else {
    props.setProperty(RpcClientConfigurationConstants.CONFIG_CLIENT_TYPE,
                      RpcClientFactory.ClientType.THRIFT.name());
    return RpcClientFactory.getInstance(props);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:ThriftSink.java

示例2: testFailure

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@Test
public void testFailure() throws Exception {
  try {

    StagedInstall.getInstance().startAgent(
        "rpccagent", CONFIG_FILE_PRCCLIENT_TEST);
    StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
    RpcClient client = RpcClientFactory.getDefaultInstance(
        "localhost", 12121);
    String[] text = {"foo", "bar", "xyz", "abc"};
    for (String str : text) {
      client.append(EventBuilder.withBody(str.getBytes()));
    }

    // Stop the agent
    StagedInstall.getInstance().stopAgent();

    // Try sending the event which should fail
    try {
      client.append(EventBuilder.withBody("test".getBytes()));
      Assert.fail("EventDeliveryException expected but not raised");
    } catch (EventDeliveryException ex) {
      System.out.println("Attempting to close client");
      client.close();
    }
  } finally {
    if (StagedInstall.getInstance().isRunning()) {
      StagedInstall.getInstance().stopAgent();
    }
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:32,代码来源:TestRpcClientCommunicationFailure.java

示例3: testRpcClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@Test
public void testRpcClient() throws Exception {
  StagedInstall.waitUntilPortOpens("localhost", 12121, 20000);
  RpcClient client = RpcClientFactory.getDefaultInstance("localhost", 12121);
  String[] text = {"foo", "bar", "xyz", "abc"};
  for (String str : text) {
    client.append(EventBuilder.withBody(str.getBytes()));
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:10,代码来源:TestRpcClient.java

示例4: createClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
private synchronized RpcClient createClient() {
  if (client == null) {
    loggingContext.addInfo("Creating a new Flume Client with properties: " + connectionProps);
    try {
      client = RpcClientFactory.getInstance(connectionProps);
    } catch ( Exception e ) {
      loggingContext.addError(e.getLocalizedMessage(), e);
    }
  }

  return client;
}
 
开发者ID:gilt,项目名称:logback-flume-appender,代码行数:13,代码来源:EventReporter.java

示例5: createClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
private synchronized RpcClient createClient() {
  if (client == null) {
    logger.info("Creating a new Flume Client with properties: " + connectionProps);
    try {
      client = RpcClientFactory.getInstance(connectionProps);
    } catch ( Exception e ) {
      logger.error(e.getLocalizedMessage(), e);
    }
  }

  return client;
}
 
开发者ID:gilt,项目名称:flume-appenders,代码行数:13,代码来源:EventReporter.java

示例6: AvroAsyncRpcClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
/**
 * Create new instance of <code>AvroAsyncRpcClient</code>.
 *
 * @param starterProp the properties of starter
 * @param numberOfClientThreads is number of client's threads
 */
public AvroAsyncRpcClient(Properties starterProp, int numberOfClientThreads) {
  clientQueue = new ArrayBlockingQueue<RpcClient>(numberOfClientThreads);

  for (int i = 0; i < numberOfClientThreads; i++) {
    RpcClient client = RpcClientFactory.getInstance(starterProp);
    clientQueue.add(client);
  }

  LOG.info("Number of Threads:" + numberOfClientThreads);
  executorService = MoreExecutors
      .listeningDecorator(Executors.newFixedThreadPool(numberOfClientThreads));
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:19,代码来源:AvroAsyncRpcClient.java

示例7: appendAsync

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
/**
 * Async append event to RPC client, return listenable future.
 *
 * @param event to adding by RPC
 * @return listenable future
 */
public ListenableFuture<AppendAsyncResultPojo> appendAsync(final Event event)
    throws EventDeliveryException {
  ListenableFuture<AppendAsyncResultPojo> future = executorService.submit(
      new Callable<AppendAsyncResultPojo>() {
        public AppendAsyncResultPojo call() throws Exception {
          RpcClient client = clientQueue.poll();
          client.append(event);
          clientQueue.add(client);
          return new AppendAsyncResultPojo(true, event);
        }
      });
  return future;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:20,代码来源:AvroAsyncRpcClient.java

示例8: appendBatchAsync

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
/**
 * Async append some events to RPC client, return listenable future.
 *
 * @param events to adding by RPC
 * @return listenable future
 */
public ListenableFuture<AppendBatchAsyncResultPojo> appendBatchAsync(final List<Event> events)
    throws EventDeliveryException {
  ListenableFuture<AppendBatchAsyncResultPojo> future = executorService
      .submit(new Callable<AppendBatchAsyncResultPojo>() {
        public AppendBatchAsyncResultPojo call() throws Exception {
          RpcClient client = clientQueue.poll();
          client.appendBatch(events);
          clientQueue.add(client);
          return new AppendBatchAsyncResultPojo(true, events);
        }
      });

  return future;
}
 
开发者ID:kaaproject,项目名称:kaa,代码行数:21,代码来源:AvroAsyncRpcClient.java

示例9: connect

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
/**
 * There is a very good chance that this will always return the first agent even if it isn't available.
 * @param agents The list of agents to choose from
 * @return The FlumeEventAvroServer.
 */

private RpcClient connect(final Agent[] agents, int retries, final int connectTimeout, final int requestTimeout) {
    try {
        final Properties props = new Properties();

        props.put("client.type", agents.length > 1 ? "default_failover" : "default");

        int count = 1;
        final StringBuilder sb = new StringBuilder();
        for (final Agent agent : agents) {
            if (sb.length() > 0) {
                sb.append(" ");
            }
            final String hostName = "host" + count++;
            props.put("hosts." + hostName, agent.getHost() + ":" + agent.getPort());
            sb.append(hostName);
        }
        props.put("hosts", sb.toString());
        if (batchSize > 0) {
            props.put("batch-size", Integer.toString(batchSize));
        }
        if (retries > 1) {
            if (retries > MAX_RECONNECTS) {
                retries = MAX_RECONNECTS;
            }
            props.put("max-attempts", Integer.toString(retries * agents.length));
        }
        if (requestTimeout >= MINIMUM_TIMEOUT) {
            props.put("request-timeout", Integer.toString(requestTimeout));
        }
        if (connectTimeout >= MINIMUM_TIMEOUT) {
            props.put("connect-timeout", Integer.toString(connectTimeout));
        }
        return RpcClientFactory.getInstance(props);
    } catch (final Exception ex) {
        LOGGER.error("Unable to create Flume RPCClient: {}", ex.getMessage());
        return null;
    }
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:45,代码来源:FlumeAvroManager.java

示例10: connect

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
/**
 * There is a very good chance that this will always return the first agent even if it isn't available.
 * @param agents The list of agents to choose from
 * @return The FlumeEventAvroServer.
 */
private RpcClient connect(final Agent[] agents, int retries, final int connectTimeoutMillis, final int requestTimeoutMillis) {
    try {
        final Properties props = new Properties();

        props.put("client.type", "default_failover");

        int agentCount = 1;
        final StringBuilder sb = new StringBuilder();
        for (final Agent agent : agents) {
            if (sb.length() > 0) {
                sb.append(' ');
            }
            final String hostName = "host" + agentCount++;
            props.put("hosts." + hostName, agent.getHost() + ':' + agent.getPort());
            sb.append(hostName);
        }
        props.put("hosts", sb.toString());
        if (batchSize > 0) {
            props.put("batch-size", Integer.toString(batchSize));
        }
        if (retries > 1) {
            if (retries > MAX_RECONNECTS) {
                retries = MAX_RECONNECTS;
            }
            props.put("max-attempts", Integer.toString(retries * agents.length));
        }
        if (requestTimeoutMillis >= MINIMUM_TIMEOUT) {
            props.put("request-timeout", Integer.toString(requestTimeoutMillis));
        }
        if (connectTimeoutMillis >= MINIMUM_TIMEOUT) {
            props.put("connect-timeout", Integer.toString(connectTimeoutMillis));
        }
        return RpcClientFactory.getInstance(props);
    } catch (final Exception ex) {
        LOGGER.error("Unable to create Flume RPCClient: {}", ex.getMessage());
        return null;
    }
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:44,代码来源:FlumeAvroManager.java

示例11: getUnderlyingClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@VisibleForTesting
RpcClient getUnderlyingClient() {
  return client;
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:5,代码来源:AbstractRpcSink.java

示例12: initializeRpcClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@Override
protected RpcClient initializeRpcClient(Properties props) {
  logger.info("Attempting to create Avro Rpc client.");
  return RpcClientFactory.getInstance(props);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:6,代码来源:AvroSink.java

示例13: run

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
private void run() throws IOException, FlumeException,
    EventDeliveryException {

  EventReader reader = null;

  RpcClient rpcClient;
  if (rpcClientPropsFile != null) {
    rpcClient = RpcClientFactory.getInstance(new File(rpcClientPropsFile));
  } else {
    rpcClient = RpcClientFactory.getDefaultInstance(hostname, port,
        BATCH_SIZE);
  }

  try {
    if (fileName != null) {
      reader = new SimpleTextLineEventReader(new FileReader(new File(fileName)));
    } else if (dirName != null) {
      reader = new ReliableSpoolingFileEventReader.Builder()
          .spoolDirectory(new File(dirName)).build();
    } else {
      reader = new SimpleTextLineEventReader(new InputStreamReader(System.in));
    }

    long lastCheck = System.currentTimeMillis();
    long sentBytes = 0;

    int batchSize = rpcClient.getBatchSize();
    List<Event> events;
    while (!(events = reader.readEvents(batchSize)).isEmpty()) {
      for (Event event : events) {
        event.setHeaders(headers);
        sentBytes += event.getBody().length;
        sent++;

        long now = System.currentTimeMillis();
        if (now >= lastCheck + 5000) {
          logger.debug("Packed {} bytes, {} events", sentBytes, sent);
          lastCheck = now;
        }
      }
      rpcClient.appendBatch(events);
      if (reader instanceof ReliableEventReader) {
        ((ReliableEventReader) reader).commit();
      }
    }
    logger.debug("Finished");
  } finally {
    if (reader != null) {
      logger.debug("Closing reader");
      reader.close();
    }

    logger.debug("Closing RPC client");
    rpcClient.close();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:57,代码来源:AvroCLIClient.java

示例14: testReset

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
@Test
public void testReset() throws Exception {

  setUp();
  Server server = createServer(new MockAvroServer());

  server.start();

  Context context = new Context();

  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));
  context.put("reset-connection-interval", String.valueOf("5"));

  sink.setChannel(channel);
  Configurables.configure(sink, context);
  sink.start();
  RpcClient firstClient = sink.getUnderlyingClient();
  Thread.sleep(6000);
  Transaction t = channel.getTransaction();
  t.begin();
  channel.put(EventBuilder.withBody("This is a test", Charset.defaultCharset()));
  t.commit();
  t.close();
  sink.process();
  // Make sure they are not the same object, connection should be reset
  Assert.assertFalse(firstClient == sink.getUnderlyingClient());
  sink.stop();

  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));
  context.put("reset-connection-interval", String.valueOf("0"));

  sink.setChannel(channel);
  Configurables.configure(sink, context);
  sink.start();
  firstClient = sink.getUnderlyingClient();
  Thread.sleep(6000);
  // Make sure they are the same object, since connection should not be reset
  Assert.assertTrue(firstClient == sink.getUnderlyingClient());
  sink.stop();

  context.clear();
  context.put("hostname", hostname);
  context.put("port", String.valueOf(port));
  context.put("batch-size", String.valueOf(2));
  context.put("connect-timeout", String.valueOf(2000L));
  context.put("request-timeout", String.valueOf(3000L));

  sink.setChannel(channel);
  Configurables.configure(sink, context);
  sink.start();
  firstClient = sink.getUnderlyingClient();
  Thread.sleep(6000);
  // Make sure they are the same object, since connection should not be reset
  Assert.assertTrue(firstClient == sink.getUnderlyingClient());
  sink.stop();
  server.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:66,代码来源:TestAvroSink.java

示例15: getRpcClient

import org.apache.flume.api.RpcClient; //导入依赖的package包/类
public RpcClient getRpcClient() {
  return client;
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:4,代码来源:FlumeConfig.java


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