Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Plain View
Flume >> mail # user >> AvroClient connections


+
Mohit Anchlia 2012-09-06, 17:32
Copy link to this message
-
Re: AvroClient connections
Any suggestions would be helpful.

On Thu, Sep 6, 2012 at 10:32 AM, Mohit Anchlia <[EMAIL PROTECTED]>wrote:

> I have a below class that I use for AvroClient. My question is it ok to
> share just one connection with many threads or should one have one instance
> of this class per thread?
>
>
> public class AvroClient {
>  private static String hostName = "dslg1";
>  private static String localHostName = "unknown";
>  private static int port = 41414;
>  private RpcClient rpcClient = null;
>  public AvroClient(String hostName, int port) {
>   this.hostName = hostName;
>   this.port = port;
>  }
>  public AvroClient() { initLocalHostName();}
>
>  public AvroClient(String host) {
>   this.hostName = host;
>   initLocalHostName();
>  }
>  private void initLocalHostName() {
>   localHostName = NetworkInfo.getLocalHostName();
>  }
>  public void sendDataToFlume(String data) {
>   // Create flume event object
>   Event event = EventBuilder.withBody(data, Charset.forName("UTF-8"));
>   Map<String,String> headers = new HashMap<String,String>();
>   headers.put("host", localHostName);
>   event.setHeaders(headers);
>   try {
>    rpcClient.append(event);
>   } catch (EventDeliveryException e) {
>    connect();
>   }
>  }
>  public void connect() {
>   if (null != rpcClient) {
>    rpcClient.close();
>    rpcClient = null;
>   }
>   rpcClient = RpcClientFactory.getDefaultInstance(hostName, port);
>  }
>  public void disconnect() {
>   // close the rpc connection
>   if (null != rpcClient) {
>    rpcClient.close();
>   }
>  }
> }
>
+
Mohit Anchlia 2012-09-16, 15:36
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB