Merge branch 'release/0.12.0.2'

This commit is contained in:
Wolf Posdorfer 2017-12-01 11:00:56 +01:00
commit 36685080ec
4 changed files with 41 additions and 20 deletions

View File

@ -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
<dependency>
<groupId>com.github.jtendermint</groupId>
<artifactId>jabci</artifactId>
<version>0.12.0.1</version>
<version>0.12.0.2</version>
</dependency>
```
@ -30,12 +30,12 @@ The current snapshot repository is: `https://oss.sonatype.org/content/repositori
</repository>
```
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
<dependency>
<groupId>com.github.jtendermint</groupId>
<artifactId>jabci</artifactId>
<version>0.12.0.1</version>
<version>0.12.0.2</version>
<scope>compile</scope>
<!-- you might want to exclude slf4j, depending on your setup -->
<exclusions>

View File

@ -5,8 +5,8 @@
<groupId>com.github.jtendermint</groupId>
<artifactId>jabci</artifactId>
<version>0.12.0.1</version>
<version>0.12.0.2</version>
<name>com.github.jtendermint:jabci</name>
<description>Java implementation for ABCI consensus protocol from tendermint.com and related tools</description>
<url>http://www.github.com/jtendermint</url>
@ -144,6 +144,7 @@
<version>1.7.25</version>
</dependency>
<dependency>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>

View File

@ -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();
}
}

View File

@ -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<SocketHandler> 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;