Skip to content

Commit

Permalink
Do not expose RemovalListener in public interface
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Dec 18, 2020
1 parent f4ecd18 commit aa382b2
Showing 1 changed file with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
import com.redhat.rhjmc.containerjfr.core.net.JFRConnectionToolkit;
import dagger.Lazy;

public class TargetConnectionManager
implements RemovalListener<ConnectionDescriptor, JFRConnection> {
public class TargetConnectionManager {

public static final Pattern HOST_PORT_PAIR_PATTERN =
Pattern.compile("^([^:\\s]+)(?::(\\d{1,5}))?$");
Expand All @@ -83,25 +82,25 @@ public class TargetConnectionManager
Caffeine.newBuilder()
.scheduler(Scheduler.systemScheduler())
.expireAfterAccess(ttl)
.removalListener(this)
.removalListener(new RemovalListener<ConnectionDescriptor, JFRConnection>() {
@Override
public void onRemoval(
ConnectionDescriptor descriptor, JFRConnection connection, RemovalCause cause) {
if (descriptor == null) {
logger.warn("Connection eviction triggered with null descriptor");
return;
}
if (connection == null) {
logger.warn("Connection eviction triggered with null connection");
return;
}
logger.info(String.format("Removing cached connection for %s", descriptor.getTargetId()));
connection.close();
}
})
.build(this::connect);
}

@Override
public void onRemoval(
ConnectionDescriptor descriptor, JFRConnection connection, RemovalCause cause) {
if (descriptor == null) {
logger.warn("Connection eviction triggered with null descriptor");
return;
}
if (connection == null) {
logger.warn("Connection eviction triggered with null connection");
return;
}
logger.info(String.format("Removing cached connection for %s", descriptor.getTargetId()));
connection.close();
}

public <T> T executeConnectedTask(
ConnectionDescriptor connectionDescriptor, ConnectedTask<T> task) throws Exception {
return task.execute(connections.get(connectionDescriptor));
Expand Down

0 comments on commit aa382b2

Please sign in to comment.