Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshadr committed Nov 6, 2016
1 parent bcb07a0 commit 401ce15
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/java/main/org/apache/zookeeper/server/NIOServerCnxn.java
Expand Up @@ -426,7 +426,7 @@ public void enableRecv() {
}

private void readConnectRequest() throws IOException, InterruptedException {
if (zkServer == null) {
if (isZKServerRunning()) {
throw new IOException("ZooKeeperServer not running");
}
zkServer.processConnectRequest(this, incomingBuffer);
Expand Down Expand Up @@ -539,13 +539,17 @@ private boolean readLength(SelectionKey k) throws IOException {
if (len < 0 || len > BinaryInputArchive.maxBuffer) {
throw new IOException("Len error " + len);
}
if (zkServer == null) {
if (isZKServerRunning()) {
throw new IOException("ZooKeeperServer not running");
}
incomingBuffer = ByteBuffer.allocate(len);
return true;
}

boolean isZKServerRunning() {
return zkServer == null || !zkServer.isRunning();
}

public long getOutstandingRequests() {
return outstandingRequests.get();
}
Expand Down
Expand Up @@ -332,7 +332,7 @@ public void receiveMessage(ChannelBuffer message) {
bb.flip();

ZooKeeperServer zks = this.zkServer;
if (zks == null) {
if (zks == null || !zks.isRunning()) {
throw new IOException("ZK down");
}
if (initialized) {
Expand Down
Expand Up @@ -86,7 +86,7 @@ public static CommandResponse runCommand(String cmdName, ZooKeeperServer zkServe
if (!commands.containsKey(cmdName)) {
return new CommandResponse(cmdName, "Unknown command: " + cmdName);
}
if (zkServer == null) {
if (zkServer == null || !zkServer.isRunning()) {
return new CommandResponse(cmdName, "This ZooKeeper instance is not currently serving requests");
}
return commands.get(cmdName).run(zkServer, kwargs);
Expand Down
Expand Up @@ -64,6 +64,10 @@ public void setZkServer(ZooKeeperServer zkServer) {
this.zkServer = zkServer;
}

boolean isZKServerRunning() {
return zkServer == null || !zkServer.isRunning();
}

public void setFactory(ServerCnxnFactory factory) {
this.factory = factory;
}
Expand Down
Expand Up @@ -29,7 +29,7 @@ public CnxnStatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
factory.resetAllConnectionStats();
Expand Down
Expand Up @@ -29,7 +29,7 @@ public class ConfCommand extends AbstractFourLetterCommand {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
zkServer.dumpConf(pw);
Expand Down
Expand Up @@ -29,7 +29,7 @@ public ConsCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
for (ServerCnxn c : factory.getConnections()) {
Expand Down
Expand Up @@ -31,7 +31,7 @@ public DirsCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() throws IOException {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
return;
}
Expand Down
Expand Up @@ -30,7 +30,7 @@ public DumpCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
pw.println("SessionTracker dump:");
Expand Down
Expand Up @@ -31,7 +31,7 @@ public IsroCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.print("null");
} else if (zkServer instanceof ReadOnlyZooKeeperServer) {
pw.print("ro");
Expand Down
Expand Up @@ -36,7 +36,7 @@ public class MonitorCommand extends AbstractFourLetterCommand {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
return;
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public StatCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
pw.print("Zookeeper version: ");
Expand Down
Expand Up @@ -29,7 +29,7 @@ public StatResetCommand(PrintWriter pw, ServerCnxn serverCnxn) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
zkServer.serverStats().reset();
Expand Down
Expand Up @@ -32,7 +32,7 @@ public WatchCommand(PrintWriter pw, ServerCnxn serverCnxn, int len) {

@Override
public void commandRun() {
if (zkServer == null) {
if (isZKServerRunning()) {
pw.println(ZK_NOT_SERVING);
} else {
DataTree dt = zkServer.getZKDatabase().getDataTree();
Expand Down

0 comments on commit 401ce15

Please sign in to comment.