本文整理汇总了Java中org.apache.flume.api.RpcClientFactory.getDefaultInstance方法的典型用法代码示例。如果您正苦于以下问题:Java RpcClientFactory.getDefaultInstance方法的具体用法?Java RpcClientFactory.getDefaultInstance怎么用?Java RpcClientFactory.getDefaultInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.flume.api.RpcClientFactory
的用法示例。
在下文中一共展示了RpcClientFactory.getDefaultInstance方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
}
示例2: 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();
}
}
}
示例3: 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()));
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: 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;
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: AvroAsyncRpcClient
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
/**
* Create new instance of <code>AvroAsyncRpcClient</code>.
*
* @param hostname the RPC hostname, use it to create RPC client
* @param port the RPC port, use it to create RPC client
* @param numberOfThreads is number of client's threads
*/
public AvroAsyncRpcClient(String hostname, Integer port, int numberOfThreads) {
int numberOfClientThreads = numberOfThreads;
clientQueue = new ArrayBlockingQueue<RpcClient>(numberOfClientThreads);
for (int i = 0; i < numberOfClientThreads; i++) {
RpcClient client = RpcClientFactory.getDefaultInstance(hostname, port);
clientQueue.add(client);
}
LOG.info("Number of Threads:" + numberOfClientThreads);
executorService = MoreExecutors
.listeningDecorator(Executors.newFixedThreadPool(numberOfClientThreads));
}
示例10: 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;
}
示例11: 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{
try {
rpcClient = RpcClientFactory.getDefaultInstance(hostname, port);
} catch (FlumeException e) {
String errormsg = "RPC client creation failed! " +
e.getMessage();
LogLog.error(errormsg);
throw e;
}
if(layout != null) {
layout.activateOptions();
}
}
示例12: 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();
}
}
示例13: init
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public void init(String hostname, int port) {
// Setup the RPC connection
this.client = RpcClientFactory.getDefaultInstance(hostname, port);
}
示例14: RpcEventGenerator
import org.apache.flume.api.RpcClientFactory; //导入方法依赖的package包/类
public RpcEventGenerator(String hostName, int port) {
this.hostName = hostName;
this.port = port;
this.rpcClient = RpcClientFactory.getDefaultInstance(hostName, port);
}