本文整理汇总了Java中org.apache.flume.api.RpcClientFactory类的典型用法代码示例。如果您正苦于以下问题:Java RpcClientFactory类的具体用法?Java RpcClientFactory怎么用?Java RpcClientFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RpcClientFactory类属于org.apache.flume.api包,在下文中一共展示了RpcClientFactory类的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: 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();
}
示例3: 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);
}
}
示例4: 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;
}
}
示例5: startClient
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
/**
* Create / reconnect Flume RPC client
*/
private void startClient() {
// If current client is inactive, close it
if (flumeClient != null && !flumeClient.isActive()) {
flumeClient.close();
flumeClient = null;
}
// Create client if needed
if (flumeClient == null) {
try {
flumeClient = RpcClientFactory.getDefaultInstance(flumeHostName, flumePort, maxSpanBatchSize);
} catch (FlumeException e) {
LOG.warn("Failed to create Flume RPC Client. " + e.getMessage());
}
}
}
示例6: 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();
}
示例7: testFailure
import org.apache.flume.api.RpcClientFactory; //导入依赖的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();
}
}
}
示例8: testRpcClient
import org.apache.flume.api.RpcClientFactory; //导入依赖的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()));
}
}
示例9: init
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
/**
* Initializes the connection to Apache Flume.
*
* @param hostname
* The host
* @param port
* The port.
*/
public void init(String hostname, int port) {
// Setup the RPC connection
this.hostname = hostname;
this.port = port;
int initCounter = 0;
while (true) {
if (initCounter >= 90) {
throw new RuntimeException("Cannot establish connection with" + port + " at "
+ host);
}
try {
this.client = RpcClientFactory.getDefaultInstance(hostname, port);
} catch (FlumeException e) {
// Wait one second if the connection failed before the next
// try
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
if (LOG.isErrorEnabled()) {
LOG.error("Interrupted while trying to connect {} at {}", port, host);
}
}
}
if (client != null) {
break;
}
initCounter++;
}
initDone = true;
}
示例10: sendDataToFlume
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
/**
* Sends byte arrays as {@link Event} series to Apache Flume.
*
* @param data
* The byte array to send to Apache FLume
*/
public void sendDataToFlume(byte[] data) {
Event event = EventBuilder.withBody(data);
try {
client.append(event);
} catch (EventDeliveryException e) {
// clean up and recreate the client
client.close();
client = null;
client = RpcClientFactory.getDefaultInstance(hostname, port);
}
}
示例11: init
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
/**
* Initializes the connection to Apache Flume.
*
* @param hostname
* The host
* @param port
* The port.
*/
public void init(String hostname, int port) {
// Setup the RPC connection
this.hostname = hostname;
this.port = port;
int initCounter = 0;
while (true) {
if (initCounter >= 90) {
throw new RuntimeException("Cannot establish connection with" + port + " at "
+ host);
}
try {
this.client = RpcClientFactory.getDefaultInstance(hostname, port);
} catch (FlumeException e) {
// Wait one second if the connection failed before the next
// try
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
if (LOG.isErrorEnabled()) {
LOG.error("Interrupted while trying to connect {} at {}", port, host);
}
}
}
if (client != null) {
break;
}
initCounter++;
}
initDone = true;
}
示例12: sendDataToFlume
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
/**
* Sends byte arrays as {@link Event} series to Apache Flume.
*
* @param data
* The byte array to send to Apache FLume
*/
public void sendDataToFlume(byte[] data) {
Event event = EventBuilder.withBody(data);
try {
client.append(event);
} catch (EventDeliveryException e) {
// clean up and recreate the client
client.close();
client = null;
client = RpcClientFactory.getDefaultInstance(hostname, port);
}
}
示例13: sendData
import org.apache.flume.api.RpcClientFactory; //导入依赖的package包/类
public void sendData(String data){
Event event = EventBuilder.withBody(data.getBytes());
try {
rpcClient.append(event);
} catch (EventDeliveryException e) {
e.printStackTrace();
rpcClient.close();
rpcClient = RpcClientFactory.getDefaultInstance(this.hostName, this.port);
}
}
示例14: 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");
}
}
示例15: 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;
}