-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close GRPC server during CRaC snapshotting
Signed-off-by: Radim Vansa <[email protected]>
- Loading branch information
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ | |
import io.vertx.core.net.impl.SslContextProvider; | ||
import io.vertx.core.net.impl.VertxEventLoopGroup; | ||
import io.vertx.core.spi.transport.Transport; | ||
import org.crac.Context; | ||
import org.crac.Core; | ||
import org.crac.Resource; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
@@ -51,7 +54,7 @@ | |
/** | ||
* @author <a href="mailto:[email protected]">Julien Viet</a> | ||
*/ | ||
public class VertxServer extends Server { | ||
public class VertxServer extends Server implements Resource { | ||
|
||
private static final ConcurrentMap<ServerID, ActualServer> map = new ConcurrentHashMap<>(); | ||
|
||
|
@@ -166,6 +169,7 @@ void stop(ContextInternal context, Promise<Void> promise) { | |
this.builder = builder; | ||
this.context = context; | ||
this.commandDecorator = commandDecorator; | ||
Core.getGlobalContext().register(this); | ||
} | ||
|
||
@Override | ||
|
@@ -236,4 +240,26 @@ public void awaitTermination() throws InterruptedException { | |
public Server getRawServer() { | ||
return actual.server; | ||
} | ||
|
||
@Override | ||
public void beforeCheckpoint(Context<? extends Resource> context) throws Exception { | ||
Promise<Void> promise = Promise.promise(); | ||
this.context.runOnContext(ignored -> { | ||
if (actual != null) { | ||
shutdown(promise); | ||
} | ||
}); | ||
promise.future().toCompletionStage().toCompletableFuture().get(); | ||
} | ||
|
||
@Override | ||
public void afterRestore(Context<? extends Resource> context) throws Exception { | ||
Promise<Void> promise = Promise.promise(); | ||
this.context.runOnContext(ignored -> { | ||
if (actual != null) { | ||
start(promise); | ||
} | ||
}); | ||
promise.future().toCompletionStage().toCompletableFuture().get(); | ||
} | ||
} |