Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
35 lines (25 sloc) 1.23 KB

Close hooks

Close hooks is an internal feature of Vert.x useful for creating components that are notified when a Verticle or a Vertx instance is closed. It can be used for implementing automatic clean-up in verticles feature, like for a Vert.x http server.

The contract for receving a close notification is defined by the io.vertx.core.Closeable interface and its close(Handler<AsyncResult<Void>> completionHandler) method:

{@link org.vietj.vertx.closehooks.ContextCloseHook}

A Closeable instance can be registered to receive a close hook with the method The method Context#addCloseHook registers a Closeable instance to be notified when the context closes:

context.addCloseHook(closeable);

This is only valid for Verticles, when a Verticle is undeployed, its associated context is closed and the shutdown hooks are processed.

The component should still expose a close in its API to allow the user to close explicitly the resource, this method should call Context#removeCloseHook to remove the hook.

context.removeCloseHook(closeable);

Likewise VertxInternal provides the same operation to receive notifications when a Vertx instance is closed.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.