-
Notifications
You must be signed in to change notification settings - Fork 991
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjusted resource cleanup to prevent memory leaks
- Loading branch information
Showing
4 changed files
with
27 additions
and
16 deletions.
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.lambdaworks.redis; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -20,7 +21,7 @@ | |
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
* @since 15.05.14 16:09 | ||
*/ | ||
public abstract class RedisChannelHandler<K, V> extends ChannelInboundHandlerAdapter { | ||
public abstract class RedisChannelHandler<K, V> extends ChannelInboundHandlerAdapter implements Closeable { | ||
|
||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(RedisChannelHandler.class); | ||
|
||
|
@@ -65,7 +66,6 @@ public synchronized void close() { | |
if (!closed) { | ||
active = false; | ||
closed = true; | ||
channelWriter.close(); | ||
closeEvents.fireEventClosed(this); | ||
closeEvents = null; | ||
} | ||
|
@@ -92,8 +92,19 @@ public void registerCloseables(final Collection<Closeable> registry, final Close | |
addListener(new CloseEvents.CloseListener() { | ||
@Override | ||
public void resourceClosed(Object resource) { | ||
registry.removeAll(Arrays.asList(closeables)); | ||
for (Closeable closeable : closeables) { | ||
if (closeable == RedisChannelHandler.this) { | ||
continue; | ||
} | ||
|
||
try { | ||
closeable.close(); | ||
} catch (IOException e) { | ||
logger.debug(e.toString(), e); | ||
} | ||
} | ||
|
||
registry.removeAll(Arrays.asList(closeables)); | ||
} | ||
}); | ||
} | ||
|
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