diff --git a/Readme.md b/Readme.md
index fa3a4c2..44245c8 100644
--- a/Readme.md
+++ b/Readme.md
@@ -9,12 +9,12 @@ A Java implementation of the Tendermint Application BlockChain Interface ([ABCI]
Check out [StartupExampleDummy.java](https://github.com/jTendermint/jabci/blob/master/src/main/java/com/github/jtendermint/jabci/StartupExampleDummy.java) or [JavaCounter.java](https://github.com/jTendermint/jabci/blob/master/src/main/java/com/github/jtendermint/jabci/JavaCounter.java) for examples.
#### Maven integration
-jABCI v0.12.0.1 Release is now available via maven central. Use the following dependency to include the latest release:
+jABCI v0.12.0.2 Release is now available via maven central. Use the following dependency to include the latest release:
```xml
com.github.jtendermint
jabci
- 0.12.0.1
+ 0.12.0.2
```
@@ -30,12 +30,12 @@ The current snapshot repository is: `https://oss.sonatype.org/content/repositori
```
-Use the following dependency to include current snapshot of jABCI in your project:
+Use the following dependency to include current version of jABCI in your project:
```xml
com.github.jtendermint
jabci
- 0.12.0.1
+ 0.12.0.2
compile
diff --git a/pom.xml b/pom.xml
index 8cf7df2..1c96e76 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,8 +5,8 @@
com.github.jtendermint
jabci
- 0.12.0.1
-
+ 0.12.0.2
+
com.github.jtendermint:jabci
Java implementation for ABCI consensus protocol from tendermint.com and related tools
http://www.github.com/jtendermint
@@ -144,6 +144,7 @@
1.7.25
+ test
junit
junit
4.12
diff --git a/src/main/java/com/github/jtendermint/jabci/JavaCounter.java b/src/main/java/com/github/jtendermint/jabci/JavaCounter.java
index 44855ea..2acf870 100644
--- a/src/main/java/com/github/jtendermint/jabci/JavaCounter.java
+++ b/src/main/java/com/github/jtendermint/jabci/JavaCounter.java
@@ -132,8 +132,9 @@ public final class JavaCounter implements IDeliverTx, ICheckTx, ICommit, IQuery
if (txCount == 0) {
return ResponseCommit.newBuilder().setCode(CodeType.OK).build();
} else {
- ByteBuffer buf = ByteBuffer.allocate(Integer.SIZE);
+ ByteBuffer buf = ByteBuffer.allocate(Integer.BYTES);
buf.putInt(txCount);
+ buf.rewind();
return ResponseCommit.newBuilder().setCode(CodeType.OK).setData(ByteString.copyFrom(buf)).build();
}
}
diff --git a/src/main/java/com/github/jtendermint/jabci/socket/TSocket.java b/src/main/java/com/github/jtendermint/jabci/socket/TSocket.java
index 4ae52e8..f270d2a 100644
--- a/src/main/java/com/github/jtendermint/jabci/socket/TSocket.java
+++ b/src/main/java/com/github/jtendermint/jabci/socket/TSocket.java
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.math.BigInteger;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.SocketTimeoutException;
import java.util.HashSet;
import org.slf4j.Logger;
@@ -48,6 +49,7 @@ import com.google.protobuf.GeneratedMessageV3;
public class TSocket extends ASocket {
public static final int DEFAULT_LISTEN_SOCKET_PORT = 46658;
+ private static final int DEFAULT_LISTEN_SOCKET_TIMEOUT = 1000;
private static final Logger TSOCKET_LOG = LoggerFactory.getLogger(TSocket.class);
private static final Logger HANDLER_LOG = LoggerFactory.getLogger(SocketHandler.class);
@@ -56,7 +58,7 @@ public class TSocket extends ASocket {
public static final String CONSENSUS_SOCKET = "-Consensus";
private final HashSet runningThreads = new HashSet<>();
-
+
private long lastConnectedSocketTime = -1;
private boolean continueRunning = true;
@@ -65,7 +67,7 @@ public class TSocket extends ASocket {
* Start listening on the default ABCI port 46658
*/
public void start() {
- this.start(DEFAULT_LISTEN_SOCKET_PORT);
+ this.start(DEFAULT_LISTEN_SOCKET_PORT, DEFAULT_LISTEN_SOCKET_TIMEOUT);
}
/**
@@ -73,25 +75,41 @@ public class TSocket extends ASocket {
*
* @param portNumber
*/
- public void start(int portNumber) {
+ public void start(final int portNumber) {
+ this.start(portNumber, DEFAULT_LISTEN_SOCKET_TIMEOUT);
+ }
+
+ /**
+ * Start listening on the specified port
+ *
+ * @param portNumber
+ * @param socketTimeout
+ */
+ public void start(final int portNumber,final int socketTimeout) {
TSOCKET_LOG.debug("starting serversocket");
continueRunning = true;
int socketcount = 0;
try (ServerSocket serverSocket = new ServerSocket(portNumber)) {
+ serverSocket.setSoTimeout(socketTimeout);
while (continueRunning) {
- Socket clientSocket = serverSocket.accept();
- lastConnectedSocketTime = System.currentTimeMillis();
- String socketName = socketNameForCount(++socketcount);
- TSOCKET_LOG.debug("starting socket with: {}", socketName);
- SocketHandler t = (socketName != null) ? new SocketHandler(clientSocket, socketName) : new SocketHandler(clientSocket);
- t.start();
- runningThreads.add(t);
- TSOCKET_LOG.debug("Started thread for sockethandling...");
+ try {
+ Socket clientSocket = serverSocket.accept();
+ lastConnectedSocketTime = System.currentTimeMillis();
+ String socketName = socketNameForCount(++socketcount);
+ TSOCKET_LOG.debug("starting socket with: {}", socketName);
+ SocketHandler t = (socketName != null) ? new SocketHandler(clientSocket, socketName) : new SocketHandler(clientSocket);
+ t.start();
+ runningThreads.add(t);
+ TSOCKET_LOG.debug("Started thread for sockethandling...");
+ } catch (SocketTimeoutException ste) {
+ // this is triggered by accept()
+ }
}
TSOCKET_LOG.debug("TSocket Stopped Running");
} catch (IOException e) {
TSOCKET_LOG.error("Exception caught when trying to listen on port " + portNumber + " or listening for a connection", e);
}
+ TSOCKET_LOG.debug("Exited main-run-while loop");
}
private String socketNameForCount(int c) {
@@ -124,6 +142,7 @@ public class TSocket extends ASocket {
runningThreads.clear();
Thread.currentThread().interrupt();
+ TSOCKET_LOG.debug("Finished calling stop on members.");
}
/**
* @return the amount of connected sockets, this should usually be 3: info,mempool and consensus
@@ -131,11 +150,11 @@ public class TSocket extends ASocket {
public int sizeOfConnectedABCISockets() {
return runningThreads.size();
}
-
+
public long getLastConnectedTime() {
return lastConnectedSocketTime;
}
-
+
class SocketHandler extends Thread {
private final Socket socket;