本文整理了Java中io.grpc.Server.shutdownNow()
方法的一些代码示例,展示了Server.shutdownNow()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Server.shutdownNow()
方法的具体详情如下:
包路径:io.grpc.Server
类名称:Server
方法名:shutdownNow
[英]Initiates a forceful shutdown in which preexisting and new calls are rejected. Although forceful, the shutdown process is still not instantaneous; #isTerminated() will likely return false immediately after this method returns.
[中]启动强制关机,拒绝之前存在的来电和新来电。尽管关闭过程很有力,但仍然不是瞬间的#isTerminated()可能会在该方法返回后立即返回false。
代码示例来源:origin: googleapis/google-cloud-java
/** Shuts down the in-memory service. */
public void shutdownNow() {
server.shutdownNow();
}
}
代码示例来源:origin: Alluxio/alluxio
/**
* Shuts down the server.
*
* @return {@code true} if the server was successfully terminated.
* @throws InterruptedException
*/
public boolean shutdown() {
mServer.shutdown();
try {
return mServer.awaitTermination(mServerShutdownTimeoutMs, TimeUnit.MILLISECONDS);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
return false;
} finally {
mServer.shutdownNow();
}
}
代码示例来源:origin: googleapis/google-cloud-java
@After
public void tearDown() throws Exception {
testServer.shutdownNow().awaitTermination();
}
代码示例来源:origin: googleapis/google-cloud-java
@After
public void tearDown() throws Exception {
testServer.shutdownNow().awaitTermination();
testChannel.shutdown();
}
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
private void stop() throws Exception {
server.shutdownNow();
if (!server.awaitTermination(5, TimeUnit.SECONDS)) {
System.err.println("Timed out waiting for server shutdown");
}
}
代码示例来源:origin: glowroot/glowroot
void close() throws InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
while (stopwatch.elapsed(SECONDS) < 10 && !downstreamService.closedByAgent) {
MILLISECONDS.sleep(10);
}
checkState(downstreamService.closedByAgent);
// TODO shutdownNow() has been needed to interrupt grpc threads since grpc-java 1.7.0
server.shutdownNow();
if (!server.awaitTermination(10, SECONDS)) {
throw new IllegalStateException("Could not terminate channel");
}
// not sure why, but server needs a little extra time to shut down properly
// without this sleep, this warning is logged (but tests still pass):
// io.grpc.netty.NettyServerHandler - Connection Error: RejectedExecutionException
MILLISECONDS.sleep(100);
executor.shutdown();
if (!executor.awaitTermination(10, SECONDS)) {
throw new IllegalStateException("Could not terminate executor");
}
if (!bossEventLoopGroup.shutdownGracefully(0, 0, SECONDS).await(10, SECONDS)) {
throw new IllegalStateException("Could not terminate event loop group");
}
if (!workerEventLoopGroup.shutdownGracefully(0, 0, SECONDS).await(10, SECONDS)) {
throw new IllegalStateException("Could not terminate event loop group");
}
}
代码示例来源:origin: salesforce/reactive-grpc
public void stopServer() {
if (server != null) {
server.shutdownNow();
}
}
代码示例来源:origin: net.spals.appbuilder.plugins/spals-appbuilder-app-grpc
@VisibleForTesting
synchronized final void shutdownNow() {
if (isRunning.getAndSet(false)) {
isStarted.set(false);
restServerRef.get().ifPresent(restServer -> restServer.close());
grpcInternalServerRef.get().ifPresent(grpcInternalServer -> grpcInternalServer.shutdownNow());
runConfigure().grpcExternalServerRef.get().shutdownNow();
}
}
代码示例来源:origin: googleapis/gax-java
/** Stops the local server. */
public void stop() {
server.shutdownNow();
}
代码示例来源:origin: getgauge/gauge-java
@Override
public void killProcess(Messages.KillProcessRequest request, StreamObserver<Lsp.Empty> responseObserver) {
server.shutdownNow();
responseObserver.onNext(Lsp.Empty.newBuilder().build());
responseObserver.onCompleted();
}
}
代码示例来源:origin: pravega/pravega
@After
public void tearDown() throws IOException {
testRPCServer1.shutdownNow();
testRPCServer2.shutdownNow();
testRPCServer3.shutdownNow();
}
代码示例来源:origin: com.thoughtworks.gauge/gauge-java
@Override
public void killProcess(Messages.KillProcessRequest request, StreamObserver<Lsp.Empty> responseObserver) {
server.shutdownNow();
responseObserver.onNext(Lsp.Empty.newBuilder().build());
responseObserver.onCompleted();
}
}
代码示例来源:origin: com.salesforce.servicelibs/grpc-contrib
/**
* Attempt to {@link Server#shutdown()} the {@link Server} gracefully. If the max wait time is exceeded, give up and
* perform a hard {@link Server#shutdownNow()}.
*
* @param server the server to be shutdown
* @param timeout the max amount of time to wait for graceful shutdown to occur
* @param unit the time unit denominating the shutdown timeout
* @return the given server
* @throws InterruptedException if waiting for termination is interrupted
*/
public static Server shutdownGracefully(Server server, long timeout, TimeUnit unit) throws InterruptedException {
Preconditions.checkNotNull(server, "server");
Preconditions.checkArgument(timeout > 0, "timeout must be greater than 0");
Preconditions.checkNotNull(unit, "unit");
server.shutdown();
try {
server.awaitTermination(timeout, unit);
} finally {
server.shutdownNow();
}
return server;
}
代码示例来源:origin: salesforce/grpc-java-contrib
/**
* Attempt to {@link Server#shutdown()} the {@link Server} gracefully. If the max wait time is exceeded, give up and
* perform a hard {@link Server#shutdownNow()}.
*
* @param server the server to be shutdown
* @param timeout the max amount of time to wait for graceful shutdown to occur
* @param unit the time unit denominating the shutdown timeout
* @return the given server
* @throws InterruptedException if waiting for termination is interrupted
*/
public static Server shutdownGracefully(Server server, long timeout, TimeUnit unit) throws InterruptedException {
Preconditions.checkNotNull(server, "server");
Preconditions.checkArgument(timeout > 0, "timeout must be greater than 0");
Preconditions.checkNotNull(unit, "unit");
server.shutdown();
try {
server.awaitTermination(timeout, unit);
} finally {
server.shutdownNow();
}
return server;
}
代码示例来源:origin: carl-mastrangelo/kvstore
private void stopServer() throws InterruptedException {
Server s = server;
if (s == null) {
throw new IllegalStateException("Already stopped");
}
server = null;
s.shutdown();
if (s.awaitTermination(1, TimeUnit.SECONDS)) {
return;
}
s.shutdownNow();
if (s.awaitTermination(1, TimeUnit.SECONDS)) {
return;
}
throw new RuntimeException("Unable to shutdown server");
}
}
代码示例来源:origin: hyperledger/fabric-chaincode-java
/**
* Stop serving requests and shutdown resources.
*/
public void stop() {
if (server != null) {
server.shutdownNow();
try {
server.awaitTermination();
} catch (InterruptedException e) {
}
}
}
代码示例来源:origin: com.srotya.minuteman/minuteman-core
@Override
public void stop() throws InterruptedException {
for (Entry<String, Replica> entry : localReplicaTable.entrySet()) {
try {
logger.info("Attempting to stop replica:" + entry.getKey() + " on node:" + getThisNodeKey());
entry.getValue().getLocal().stop();
if (entry.getValue().getClient() != null) {
entry.getValue().getClient().stop();
}
entry.getValue().getWal().close();
logger.info("Stopped replica:" + entry.getKey() + " on node:" + getThisNodeKey());
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed to stop wal:" + entry.getKey() + "\t on replica:"
+ entry.getValue().getReplicaNodeKey() + "\tleader:" + entry.getValue().getLeaderNodeKey(), e);
}
}
server.shutdownNow().awaitTermination(5, TimeUnit.SECONDS);
}
代码示例来源:origin: salesforce/grpc-java-contrib
/**
* Shutdown the gRPC {@link Server} when this object is closed.
*/
@Override
public void close() throws Exception {
final Server server = server();
if (server != null) {
server.shutdown();
try {
// TODO: Maybe we should catch the InterruptedException from this?
server.awaitTermination(shutdownWaitTimeInMillis, TimeUnit.MILLISECONDS);
} finally {
server.shutdownNow();
this.server = null;
}
}
}
代码示例来源:origin: com.salesforce.servicelibs/grpc-spring
/**
* Shutdown the gRPC {@link Server} when this object is closed.
*/
@Override
public void close() throws Exception {
final Server server = server();
if (server != null) {
server.shutdown();
try {
// TODO: Maybe we should catch the InterruptedException from this?
server.awaitTermination(shutdownWaitTimeInMillis, TimeUnit.MILLISECONDS);
} finally {
server.shutdownNow();
this.server = null;
}
}
}
代码示例来源:origin: pravega/pravega
@After
public void tearDown() {
ExecutorServiceHelpers.shutdown(executor);
testGRPCServer.shutdownNow();
}
内容来源于网络,如有侵权,请联系作者删除!