Search in sources :

Example 1 with AsyncCloseable

use of io.lettuce.core.api.AsyncCloseable in project lettuce-core by lettuce-io.

the class RedisChannelHandler method registerCloseables.

/**
 * Register Closeable resources. Internal access only.
 *
 * @param registry registry of closeables
 * @param closeables closeables to register
 */
public void registerCloseables(final Collection<Closeable> registry, Closeable... closeables) {
    registry.addAll(Arrays.asList(closeables));
    addListener(resource -> {
        for (Closeable closeable : closeables) {
            if (closeable == RedisChannelHandler.this) {
                continue;
            }
            try {
                if (closeable instanceof AsyncCloseable) {
                    ((AsyncCloseable) closeable).closeAsync();
                } else {
                    closeable.close();
                }
            } catch (IOException e) {
                if (debugEnabled) {
                    logger.debug(e.toString(), e);
                }
            }
        }
        registry.removeAll(Arrays.asList(closeables));
    });
}
Also used : AsyncCloseable(io.lettuce.core.api.AsyncCloseable) AsyncCloseable(io.lettuce.core.api.AsyncCloseable) Closeable(java.io.Closeable) IOException(java.io.IOException)

Aggregations

AsyncCloseable (io.lettuce.core.api.AsyncCloseable)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1