|
|
Mohit Anchlia 2012-09-06, 17:32
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(); } } }
-
Re: AvroClient connections
Mohit Anchlia 2012-09-13, 21:34
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(); > } > } > } >
-
Re: AvroClient connections
Mohit Anchlia 2012-09-16, 15:36
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(); > } > } > } >
|
|