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 Threaded View
Flume >> mail # user >> AvroClient connections


Copy link to this message
-
Re: AvroClient connections
I see in NettyAvroRPCClient flume-ng code that for every connect call it
calls newCachedThreadPool call. So it looks like I should just one instance
of this class? Trying to figure out how to effectively deal with it. For
instance when using HttpClient from http commons project it provides a
Multithreaded pool. I am wondering If I need to have one? I haven't got any
response not sure if people are using AvroClient that much?

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();
>   }
>  }
> }
>
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