Review Board 1.7.22


Added option to not do JMX registrations

Review Request #3410 - Created Jan. 6, 2012 and updated

Jordan Zimmerman
ZOOKEEPER-1350
Reviewers
zookeeper
zookeeper
LearnerZooKeeperServer has no option to disable JMX registrations. Curator has a test ZK server cluster. Due to the intricacies of JMX, the registrations cannot be easily undone. In order for the Curator Test cluster to be re-usable in a testing session, JavaAssist ugliness was necessary to make LearnerZooKeeperServer.registerJMX() and LearnerZooKeeperServer.unregisterJMX() NOPs. 

 
/src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java
Revision 1227917 New Change
[20] 110 lines
[+20] [+] static public ServerCnxnFactory createFactory(InetSocketAddress addr,
111
        ServerCnxnFactory factory = createFactory();
111
        ServerCnxnFactory factory = createFactory();
112
        factory.configure(addr, maxClientCnxns);
112
        factory.configure(addr, maxClientCnxns);
113
        return factory;
113
        return factory;
114
    }
114
    }
115

    
   
115

   

    
   
116
    static public boolean jmxIsEnabled() {

    
   
117
        return !Boolean.getBoolean("zookeeper.server.jmx.disable");

    
   
118
    }

    
   
119

   
116
    public abstract InetSocketAddress getLocalAddress();
120
    public abstract InetSocketAddress getLocalAddress();
117

    
   
121

   
118
    private HashMap<ServerCnxn, ConnectionBean> connectionBeans = new HashMap<ServerCnxn, ConnectionBean>();
122
    private HashMap<ServerCnxn, ConnectionBean> connectionBeans = new HashMap<ServerCnxn, ConnectionBean>();
119
    public void unregisterConnection(ServerCnxn serverCnxn) {
123
    public void unregisterConnection(ServerCnxn serverCnxn) {
120
        ConnectionBean jmxConnectionBean = connectionBeans.remove(serverCnxn);
124
        ConnectionBean jmxConnectionBean = connectionBeans.remove(serverCnxn);
121
        if (jmxConnectionBean != null){
125
        if (jmxConnectionBean != null){
122
            MBeanRegistry.getInstance().unregister(jmxConnectionBean);
126
            MBeanRegistry.getInstance().unregister(jmxConnectionBean);
123
        }
127
        }
124
    }
128
    }
125
    
129
    
126
    public void registerConnection(ServerCnxn serverCnxn) {
130
    public void registerConnection(ServerCnxn serverCnxn) {
127
        if (zkServer != null) {
131
        if ((zkServer != null) && jmxIsEnabled()) {
128
            ConnectionBean jmxConnectionBean = new ConnectionBean(serverCnxn, zkServer);
132
            ConnectionBean jmxConnectionBean = new ConnectionBean(serverCnxn, zkServer);
129
            try {
133
            try {
130
                MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean);
134
                MBeanRegistry.getInstance().register(jmxConnectionBean, zkServer.jmxServerBean);
131
                connectionBeans.put(serverCnxn, jmxConnectionBean);
135
                connectionBeans.put(serverCnxn, jmxConnectionBean);
132
            } catch (JMException e) {
136
            } catch (JMException e) {
133
                LOG.warn("Could not register connection", e);
137
                LOG.warn("Could not register connection", e);
134
            }
138
            }
135
        }
139
        }
136

    
   
140

   
137
    }
141
    }
138

    
   
142

   
139
}
143
}
/src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java
Revision 1227917 New Change
 
/src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java
Revision 1227917 New Change
 
/src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java
Revision 1227917 New Change
 
  1. /src/java/main/org/apache/zookeeper/server/ServerCnxnFactory.java: Loading...
  2. /src/java/main/org/apache/zookeeper/server/ZooKeeperServer.java: Loading...
  3. /src/java/main/org/apache/zookeeper/server/quorum/AuthFastLeaderElection.java: Loading...
  4. /src/java/main/org/apache/zookeeper/server/quorum/FastLeaderElection.java: Loading...
  5. /src/java/main/org/apache/zookeeper/server/quorum/LeaderElection.java: Loading...
  6. /src/java/main/org/apache/zookeeper/server/quorum/LeaderZooKeeperServer.java: Loading...
  7. /src/java/main/org/apache/zookeeper/server/quorum/LearnerZooKeeperServer.java: Loading...
  8. /src/java/main/org/apache/zookeeper/server/quorum/QuorumPeer.java: Loading...
  9. /src/java/main/org/apache/zookeeper/server/quorum/ReadOnlyZooKeeperServer.java: Loading...
  10. /src/java/test/org/apache/zookeeper/server/quorum/LearnerTest.java: Loading...