Skip to content

remove solidity executorService #2485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,28 @@ private class DatabaseApi extends DatabaseImplBase {
@Override
public void getBlockReference(EmptyMessage request,
StreamObserver<BlockReference> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getDatabaseApi().getBlockReference(request, responseObserver)
);
}

@Override
public void getNowBlock(EmptyMessage request, StreamObserver<Block> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getDatabaseApi().getNowBlock(request, responseObserver));
}

@Override
public void getBlockByNum(NumberMessage request, StreamObserver<Block> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getDatabaseApi().getBlockByNum(request, responseObserver)
);
}

@Override
public void getDynamicProperties(EmptyMessage request,
StreamObserver<DynamicProperties> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getDatabaseApi().getDynamicProperties(request, responseObserver)
);
}
Expand All @@ -172,53 +172,53 @@ private class WalletSolidityApi extends WalletSolidityImplBase {

@Override
public void getAccount(Account request, StreamObserver<Account> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getAccount(request, responseObserver)
);
}

@Override
public void getAccountById(Account request, StreamObserver<Account> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getAccountById(request, responseObserver)
);
}

@Override
public void listWitnesses(EmptyMessage request, StreamObserver<WitnessList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().listWitnesses(request, responseObserver)
);
}

@Override
public void getAssetIssueById(BytesMessage request,
StreamObserver<AssetIssueContract> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getAssetIssueById(request, responseObserver)
);
}

@Override
public void getAssetIssueByName(BytesMessage request,
StreamObserver<AssetIssueContract> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getAssetIssueByName(request, responseObserver)
);
}

@Override
public void getAssetIssueList(EmptyMessage request,
StreamObserver<AssetIssueList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getAssetIssueList(request, responseObserver)
);
}

@Override
public void getAssetIssueListByName(BytesMessage request,
StreamObserver<AssetIssueList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.getAssetIssueListByName(request, responseObserver)
);
Expand All @@ -227,7 +227,7 @@ public void getAssetIssueListByName(BytesMessage request,
@Override
public void getPaginatedAssetIssueList(PaginatedMessage request,
StreamObserver<AssetIssueList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.getPaginatedAssetIssueList(request, responseObserver)
);
Expand All @@ -236,7 +236,7 @@ public void getPaginatedAssetIssueList(PaginatedMessage request,
@Override
public void getExchangeById(BytesMessage request,
StreamObserver<Exchange> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getExchangeById(
request, responseObserver
)
Expand All @@ -245,47 +245,47 @@ public void getExchangeById(BytesMessage request,

@Override
public void getNowBlock(EmptyMessage request, StreamObserver<Block> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getNowBlock(request, responseObserver)
);
}

@Override
public void getNowBlock2(EmptyMessage request,
StreamObserver<BlockExtention> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getNowBlock2(request, responseObserver)
);

}

@Override
public void getBlockByNum(NumberMessage request, StreamObserver<Block> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getBlockByNum(request, responseObserver)
);
}

@Override
public void getBlockByNum2(NumberMessage request,
StreamObserver<BlockExtention> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getBlockByNum2(request, responseObserver)
);
}

@Override
public void getDelegatedResource(DelegatedResourceMessage request,
StreamObserver<DelegatedResourceList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getDelegatedResource(request, responseObserver)
);
}

@Override
public void getDelegatedResourceAccountIndex(BytesMessage request,
StreamObserver<org.tron.protos.Protocol.DelegatedResourceAccountIndex> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.getDelegatedResourceAccountIndex(request, responseObserver)
);
Expand All @@ -294,7 +294,7 @@ public void getDelegatedResourceAccountIndex(BytesMessage request,
@Override
public void getTransactionCountByBlockNum(NumberMessage request,
StreamObserver<NumberMessage> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.getTransactionCountByBlockNum(request, responseObserver)
);
Expand All @@ -303,7 +303,7 @@ public void getTransactionCountByBlockNum(NumberMessage request,
@Override
public void getTransactionById(BytesMessage request,
StreamObserver<Transaction> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().getTransactionById(request, responseObserver)
);

Expand All @@ -312,7 +312,7 @@ public void getTransactionById(BytesMessage request,
@Override
public void getTransactionInfoById(BytesMessage request,
StreamObserver<TransactionInfo> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi()
.getTransactionInfoById(request, responseObserver)
);
Expand All @@ -322,7 +322,7 @@ public void getTransactionInfoById(BytesMessage request,
@Override
public void listExchanges(EmptyMessage request,
StreamObserver<ExchangeList> responseObserver) {
walletOnSolidity.rpcFutureGet(
walletOnSolidity.futureGet(
() -> rpcApiService.getWalletSolidityApi().listExchanges(request, responseObserver)
);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,78 +36,29 @@
@Slf4j(topic = "API")
@Component
public class WalletOnSolidity {

enum ApiType {
HTTP,
GRPC
}

private ListeningExecutorService httpExecutorService = MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(Args.getInstance().getSolidityThreads()/2,
new ThreadFactoryBuilder().setNameFormat("WalletOnSolidity-HTTP-%d").build()));
private ListeningExecutorService rpcExecutorService = MoreExecutors.listeningDecorator(
Executors.newFixedThreadPool(Args.getInstance().getSolidityThreads()/2,
new ThreadFactoryBuilder().setNameFormat("WalletOnSolidity-GRPC-%d").build()));

@Autowired
private Manager dbManager;

private <T> T futureGet(ListeningExecutorService service, ApiType type, Callable<T> callable) {
ListenableFuture<T> future = service.submit(() -> {
try {
dbManager.setMode(false);
return callable.call();
} catch (Exception e) {
logger.info(type + " futureGet " + e.getMessage());
return null;
}
});

public <T> T futureGet(TronCallable<T> callable) {
try {
return future.get(20000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException ignored) {
} catch (TimeoutException e) {
logger.info(type + " futureGet time out");
dbManager.setMode(false);
return callable.call();
} finally {
dbManager.setMode(true);
}

return null;
}

private void futureGet(ListeningExecutorService service, ApiType type, Runnable runnable) {
ListenableFuture<?> future = service.submit(() -> {
try {
dbManager.setMode(false);
runnable.run();
} catch (Exception e) {
logger.info(type + " futureGet " + e.getMessage());
}
});

public void futureGet(Runnable runnable) {
try {
future.get(20000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException ignored) {
} catch (TimeoutException e) {
logger.info(type + " futureGet time out");
dbManager.setMode(false);
runnable.run();
} finally {
dbManager.setMode(true);
}
}

public <T> T futureGet(Callable<T> callable) {
return futureGet(httpExecutorService, ApiType.HTTP, callable);
}

public void futureGet(Runnable runnable) {
futureGet(httpExecutorService, ApiType.HTTP, runnable);
}

public <T> T rpcFutureGet(Callable<T> callable) {
return futureGet(rpcExecutorService, ApiType.GRPC, callable);
}

public void rpcFutureGet(Runnable runnable) {
futureGet(rpcExecutorService, ApiType.GRPC, runnable);
public interface TronCallable<T> extends Callable<T> {
@Override
T call();
}
}
Loading