Fix bug where changing profile causes jsonRpcServer to become unusable.
This commit is contained in:
parent
3a9486fd26
commit
ed8a2b6f5f
|
@ -5,4 +5,5 @@ import org.ethereum.facade.Ethereum;
|
|||
public abstract class JsonRpcServer {
|
||||
public JsonRpcServer(Ethereum ethereum) {};
|
||||
public abstract void start() throws Exception;
|
||||
public abstract void stop();
|
||||
}
|
|
@ -26,6 +26,8 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
|
||||
private Ethereum ethereum;
|
||||
private Dispatcher dispatcher;
|
||||
EventLoopGroup bossGroup;
|
||||
EventLoopGroup workerGroup;
|
||||
|
||||
public JsonRpcServer(Ethereum ethereum) {
|
||||
super(ethereum);
|
||||
|
@ -105,8 +107,8 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
bossGroup = new NioEventLoopGroup(1);
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap b = new ServerBootstrap();
|
||||
b.option(ChannelOption.SO_BACKLOG, 1024);
|
||||
|
@ -125,6 +127,13 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (bossGroup != null) {
|
||||
bossGroup.shutdownGracefully();
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
class JsonRpcServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) {
|
||||
|
|
|
@ -30,6 +30,9 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
private Ethereum ethereum;
|
||||
private Dispatcher dispatcher;
|
||||
|
||||
EventLoopGroup bossGroup;
|
||||
EventLoopGroup workerGroup;
|
||||
|
||||
public JsonRpcServer(Ethereum ethereum) {
|
||||
super(ethereum);
|
||||
this.ethereum = ethereum;
|
||||
|
@ -83,8 +86,8 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
}
|
||||
|
||||
public void start() throws Exception {
|
||||
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
bossGroup = new NioEventLoopGroup(1);
|
||||
workerGroup = new NioEventLoopGroup();
|
||||
try {
|
||||
ServerBootstrap b = new ServerBootstrap();
|
||||
b.option(ChannelOption.SO_BACKLOG, 1024);
|
||||
|
@ -103,6 +106,13 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer
|
|||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (bossGroup != null) {
|
||||
bossGroup.shutdownGracefully();
|
||||
workerGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
|
||||
class JsonRpcServerInitializer extends ChannelInitializer<SocketChannel> {
|
||||
@Override
|
||||
public void initChannel(SocketChannel ch) {
|
||||
|
|
|
@ -216,6 +216,7 @@ public class EthereumRemoteService extends EthereumService {
|
|||
protected void init(Message message) {
|
||||
|
||||
if (isEthereumStarted) {
|
||||
stopJsonRpcServer();
|
||||
closeEthereum(null);
|
||||
ethereum = null;
|
||||
component = null;
|
||||
|
@ -225,6 +226,7 @@ public class EthereumRemoteService extends EthereumService {
|
|||
Bundle data = message.getData();
|
||||
List<String> privateKeys = data.getStringArrayList("privateKeys");
|
||||
ethereum.init(privateKeys);
|
||||
startJsonRpc(null);
|
||||
isEthereumStarted = true;
|
||||
}
|
||||
|
||||
|
@ -318,6 +320,17 @@ public class EthereumRemoteService extends EthereumService {
|
|||
}
|
||||
}
|
||||
|
||||
protected void stopJsonRpcServer() {
|
||||
if (jsonRpcServerThread != null) {
|
||||
jsonRpcServerThread.interrupt();
|
||||
jsonRpcServerThread = null;
|
||||
}
|
||||
if (jsonRpcServer != null) {
|
||||
jsonRpcServer.stop();
|
||||
jsonRpcServer = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the json rpc server
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue