cassandra - HConnectionManager (Hector) connection state -
i'm connecting cassandra db via hector.
when given wrong socket (in purpose) connection fails message:
info cassandrahostretryservice - downed host retry service started queue size -1 , retry delay 10s error hconnectionmanager - not start connection pool host 132.202.35.14(160.202.35.14):9160 info cassandrahostretryservice - host detected down added retry queue: 132.202.35.14(160.202.35.14):9160 info jmxmonitor - registering jmx me.prettyprint.cassandra.service_rtbcluster:servicetype=hector,monitortype=hector
and keeps on trying java.net.connectexception: connection timed out: connect
every few seconds. know if connection had failed or succeeded since once succeeds take actions.
my code looks this:
cassandrahostconfigurator cassandrahostconfigurator = new cassandrahostconfigurator(this.socket); cluster = new thriftcluster(this.clustername, cassandrahostconfigurator); configurableconsistencylevel consistencylevelpolicy = new configurableconsistencylevel(); consistencylevelpolicy.setdefaultreadconsistencylevel(getconsistencylevelpolicy()); keyspace = hfactory.createkeyspace(keyspacename, cluster, consistencylevelpolicy); fireconnectionevent(true);
as can see i'm firing connection event, i'm getting there anyways - whether connection succeeded or fails , have no way distinguish between two. there event can catch or other way can informed of connection state?
i'm not sure it's optimal way, since not find better answer did:
created method:
private boolean isconnected() { list<keyspacedefinition> keyspaces = null; try { keyspaces = cluster.describekeyspaces(); } catch (hectorexception e) { return false; } return (!collectionutils.isempty(keyspaces)); }
and then:
if (isconnected()) fireconnectionevent(true); else { log.error("could not connect socket " + this.socket + ". connection cassandra down!!!"); }
Comments
Post a Comment