将Cassandra客户端Hector迁移到java驱动程序 - 替换ConnectionListener

时间:2016-04-13 07:43:23

标签: java cassandra datastax-java-driver hector

目前我们正在将Cassandra客户端从Hector迁移到Java驱动程序,但无法找到ConnectionListener的替代品,因为这用于避免重复的客户端请求到同一DC已因某种原因已经关闭。

代码:

         if(getClusterConnectionListenerForDCId(dcId).isAllHostsInThisDCClusterDown())
             {
            /* directly return failure w/o even trying: this is vital, because if we keep trying to write to a all-downed cluster again and again,and since hector is stupid enough not to skip writing to cluster given that it already knew the cluster is all down, every single remote local-quorum call will need to wait until timeout (10 second) again and again, when cross-DC channel has hiccup.
*/
                            return false;
                }

        //overridden function of ConnectionManagerListener

        @Override
            public void onAllHostsDown() {
                //when all hosts are down for a particular cluster, we want to disable writing to that particular cluser
                //until at least one host of the cluster recovers
                mIsAllHostsInThisDCClusterDown = true;
                smIsAnyDCClusterAllHostsDown = true;
                logger.warn("all hosts are down for DC: " + mDcId);
            } 

1 个答案:

答案 0 :(得分:0)

  

但无法找到ConnectionListener的替代品,因为这用于避免重复的客户端请求到同一个已因某种原因已经关闭的DC。

你不再需要它了。使用Java驱动程序,您可以DCAwareLoadBalancingStrategy自动处理节点/ DC停机时间