本文整理汇总了Java中org.apache.flume.api.RpcClientFactory.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java RpcClientFactory.getInstance方法的具体用法?Java RpcClientFactory.getInstance怎么用?Java RpcClientFactory.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flume.api.RpcClientFactory
的用法示例。
在下文中一共展示了RpcClientFactory.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeRpcClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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);
}
}
示例2: activateOptions
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
* Activate the options set using <tt>setHosts()</tt>, <tt>setSelector</tt>
* and <tt>setMaxBackoff</tt>
*
* @throws FlumeException
* if the LoadBalancingRpcClient cannot be instantiated.
*/
@Override
public void activateOptions() throws FlumeException {
try {
final Properties properties = getProperties(hosts, selector, maxBackoff, getTimeout());
rpcClient = RpcClientFactory.getInstance(properties);
if (layout != null) {
layout.activateOptions();
}
configured = true;
} catch (Exception e) {
String errormsg = "RPC client creation failed! " + e.getMessage();
LogLog.error(errormsg);
if (getUnsafeMode()) {
return;
}
throw new FlumeException(e);
}
}
示例3: activateOptions
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
* Activate the options set using <tt>setPort()</tt>
* and <tt>setHostname()</tt>
*
* @throws FlumeException if the <tt>hostname</tt> and
* <tt>port</tt> combination is invalid.
*/
@Override
public void activateOptions() throws FlumeException {
Properties props = new Properties();
props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, "h1");
props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + "h1",
hostname + ":" + port);
props.setProperty(RpcClientConfigurationConstants.CONFIG_CONNECT_TIMEOUT,
String.valueOf(timeout));
props.setProperty(RpcClientConfigurationConstants.CONFIG_REQUEST_TIMEOUT,
String.valueOf(timeout));
try {
rpcClient = RpcClientFactory.getInstance(props);
if (layout != null) {
layout.activateOptions();
}
} catch (FlumeException e) {
String errormsg = "RPC client creation failed! " + e.getMessage();
LogLog.error(errormsg);
if (unsafeMode) {
return;
}
throw e;
}
}
示例4: 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");
}
}
示例5: createClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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;
}
示例6: main
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException,
IOException, EventDeliveryException {
if (args.length == 0) {
System.out
.println("AvroClient {host} {port} {numOfEvents}");
return;
}
String host = args[0];
int port = Integer.parseInt(args[1]);
int numberOfEvents = Integer.parseInt(args[2]);
Properties starterProp = new Properties();
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, "h1");
starterProp.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + "h1", host + ":" + port);
NettyAvroRpcClient client = (NettyAvroRpcClient) RpcClientFactory
.getInstance(starterProp);
System.out.println("Starting");
for (int i = 0; i < numberOfEvents; i++) {
if (i%100 == 0) {
System.out.print(".");
}
SimpleEvent event = generateEvent(i);
client.append(event);
}
System.out.println();
System.out.println("Done");
}
示例7: createClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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;
}
示例8: AvroAsyncRpcClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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));
}
示例9: connect
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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;
}
}
示例10: activateOptions
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
* Activate the options set using <tt>setHosts()</tt>, <tt>setSelector</tt>
* and <tt>setMaxBackoff</tt>
*
* @throws FlumeException
* if the LoadBalancingRpcClient cannot be instantiated.
*/
@Override
public void activateOptions() throws FlumeException {
try {
final Properties properties = getProperties(hosts, selector, maxBackoff);
rpcClient = RpcClientFactory.getInstance(properties);
} catch (FlumeException e) {
String errormsg = "RPC client creation failed! " + e.getMessage();
LogLog.error(errormsg);
throw e;
}
}
示例11: NettyAvroAsyncRpcClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public NettyAvroAsyncRpcClient(Properties starterProp) {
int numberOfClientThreads = Integer.parseInt(starterProp.getProperty(ASYNC_MAX_THREADS));
clientQueue = new ArrayBlockingQueue<NettyAvroRpcClient>(numberOfClientThreads);
for (int i = 0 ; i < numberOfClientThreads; i++) {
NettyAvroRpcClient client = (NettyAvroRpcClient)RpcClientFactory.getInstance(starterProp);
clientQueue.add(client);
}
logger.info("Number of Threads:" + numberOfClientThreads);
executorService = Executors.newFixedThreadPool(numberOfClientThreads);
}
示例12: connect
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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;
}
}
示例13: initializeRpcClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
@Override
protected RpcClient initializeRpcClient(Properties props) {
logger.info("Attempting to create Avro Rpc client.");
return RpcClientFactory.getInstance(props);
}
示例14: run
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的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();
}
}
示例15: 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;
}
}
}
}