Skip to content

Commit

Permalink
add socket removal listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
pimenas committed Sep 29, 2017
1 parent 951fa7d commit b590bb1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/gov/nist/javax/sip/stack/NioTcpMessageChannel.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ protected void close(boolean removeSocket, boolean stopKeepAliveTask) {
if(stopKeepAliveTask) {
cancelPingKeepAliveTimeoutTaskIfStarted();
}

SocketRemovalListeners.send(this.getKey());
} catch (IOException e) {
logger.logError("Problem occured while closing", e);
}
Expand Down
32 changes: 32 additions & 0 deletions src/gov/nist/javax/sip/stack/SocketRemovalListeners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package gov.nist.javax.sip.stack;

import java.util.Collection;
import java.util.LinkedList;

public class SocketRemovalListeners {

private static final Collection<Listener> listeners = new LinkedList();

public static interface Listener {
void socketRemoved(String channel);
}

public static void addListener(Listener listener) {
listeners.add(listener);
}

public static void clear() {
listeners.clear();
}

public static void send(String channel) {
for (Listener listener: listeners) {
try {
listener.socketRemoved(channel);
} catch (Exception e) {
System.err.println("Exception caught with message: " + e.getMessage());
e.printStackTrace();
}
}
}
}

0 comments on commit b590bb1

Please sign in to comment.