You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/09/20 20:13:29 UTC

svn commit: r1388150 - /lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java

Author: uschindler
Date: Thu Sep 20 18:13:28 2012
New Revision: 1388150

URL: http://svn.apache.org/viewvc?rev=1388150&view=rev
Log:
SOLR-3733: Fix NPE, now it seems to work - sorry

Modified:
    lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java

Modified: lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java?rev=1388150&r1=1388149&r2=1388150&view=diff
==============================================================================
--- lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java (original)
+++ lucene/dev/branches/solr3733/solr/solrj/src/java/org/apache/solr/common/cloud/SolrZooKeeper.java Thu Sep 20 18:13:28 2012
@@ -19,7 +19,6 @@ package org.apache.solr.common.cloud;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
-import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArraySet;
@@ -45,16 +44,6 @@ public class SolrZooKeeper extends ZooKe
     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.
@@ -64,9 +53,20 @@ public class SolrZooKeeper extends ZooKe
     final Thread t = new Thread() {
       public void run() {
         try {
+          final ClientCnxn cnxn = getConnection();
           synchronized (cnxn) {
             try {
-              getSendThreadChannel().close();
+              final Field sendThreadFld = cnxn.getClass().getDeclaredField("sendThread");
+              sendThreadFld.setAccessible(true);
+              Object sendThread = sendThreadFld.get(cnxn);
+              if (sendThread != null) {
+                final Field sockKeyFld = sendThread.getClass().getDeclaredField("sockKey");
+                sockKeyFld.setAccessible(true);
+                final SelectionKey sockKey = (SelectionKey) sockKeyFld.get(sendThread);
+                if (sockKey != null) {
+                  sockKey.channel().close();
+                }
+              }
             } catch (Exception e) {
               throw new RuntimeException("Closing Zookeeper send channel failed.", e);
             }