Apache Solr open-source search software
SOLR-3733: Fix crazy zookeeper test-only stuff by reflection.
Uwe Schindler39757948fe74
diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.javaindex 0b3c8f56c42..c4212ef09ea 100644--- a/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java@@ -18,11 +18,10 @@ package org.apache.solr.common.cloud;*/import java.io.IOException;-import java.nio.channels.SocketChannel;-import java.util.Iterator;+import java.lang.reflect.Field;+import java.nio.channels.SelectableChannel;+import java.nio.channels.SelectionKey;import java.util.List;-import java.util.Map;-import java.util.concurrent.ConcurrentHashMap;import java.util.concurrent.CopyOnWriteArrayList;import org.apache.zookeeper.ClientCnxn;@@ -46,6 +45,16 @@ public class SolrZooKeeper extends ZooKeeper {return cnxn;}+ SelectableChannel getSendThreadChannel() throws Exception {+ final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread");+ sendThreadFld.setAccessible(true);+ Object sendThread = sendThreadFld.get(cnxn);+ final Field sockKeyFld = sendThread.getClass().getDeclaredField("sockKey");+ sockKeyFld.setAccessible(true);+ final SelectionKey sockKey = (SelectionKey) sockKeyFld.get(sendThread);+ return sockKey.channel();+ }+/*** Cause this ZooKeeper object to stop receiving from the ZooKeeperServer* for the given number of milliseconds.@@ -57,17 +66,12 @@ public class SolrZooKeeper extends ZooKeeper {try {synchronized (cnxn) {try {- // nocommit: reflect me, move me somewehre else as static method,- // something. i am only used by tests! the rest of this file is clean.- ((SocketChannel) cnxn.sendThread.sockKey.channel()).socket()- .close();+ getSendThreadChannel().close();} catch (Exception e) {+ throw new RuntimeException("Closing zookeper send channel failed.", e);}Thread.sleep(ms);}-- // Wait a long while to make sure we properly clean up these threads.- Thread.sleep(500000);} catch (InterruptedException e) {}}};@@ -77,9 +81,8 @@ public class SolrZooKeeper extends ZooKeeper {@Overridepublic synchronized void close() throws InterruptedException {- //clients.remove(this);for (Thread t : spawnedThreads) {- t.interrupt();+ if (t.isAlive()) t.interrupt();}super.close();}