Commit c9d04464 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-16] Added timer to routinely check for orphaned transport sessions.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5136 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4cd21f8e
...@@ -74,7 +74,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -74,7 +74,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
* Manages all active sessions. * Manages all active sessions.
* @see org.jivesoftware.wildfire.gateway.TransportSessionManager * @see org.jivesoftware.wildfire.gateway.TransportSessionManager
*/ */
public final TransportSessionManager sessionManager = new TransportSessionManager(); public final TransportSessionManager sessionManager = new TransportSessionManager(this);
/** /**
* Manages registration information. * Manages registration information.
...@@ -706,6 +706,7 @@ public abstract class BaseTransport implements Component, RosterEventListener { ...@@ -706,6 +706,7 @@ public abstract class BaseTransport implements Component, RosterEventListener {
for (TransportSession session : sessionManager.getSessions()) { for (TransportSession session : sessionManager.getSessions()) {
registrationLoggedOut(session); registrationLoggedOut(session);
} }
sessionManager.shutdown();
} }
/** /**
......
...@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.gateway; ...@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.gateway;
import java.util.*; import java.util.*;
import org.jivesoftware.util.NotFoundException; import org.jivesoftware.util.NotFoundException;
import org.jivesoftware.wildfire.SessionManager;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/** /**
...@@ -30,6 +31,43 @@ public class TransportSessionManager { ...@@ -30,6 +31,43 @@ public class TransportSessionManager {
*/ */
private Map<JID,TransportSession> activeSessions = new HashMap<JID,TransportSession>(); private Map<JID,TransportSession> activeSessions = new HashMap<JID,TransportSession>();
/**
* Timer to check for orphaned sessions.
*/
private Timer timer = new Timer();
/**
* Interval at which sessions are reaped.
*/
private int reaperInterval = 300000; // 5 minutes
/**
* The actual repear task.
*/
@SuppressWarnings({"FieldCanBeLocal"}) private SessionReaper sessionReaper;
/**
* The transport we are associated with.
*/
BaseTransport transport;
/**
* Creates the transport session manager instance and initializes.
*/
TransportSessionManager(BaseTransport transport) {
this.transport = transport;
sessionReaper = new SessionReaper();
timer.schedule(sessionReaper, reaperInterval, reaperInterval);
}
/**
* Shuts down the session manager.
*/
public void shutdown() {
sessionReaper.cancel();
timer.cancel();
}
/** /**
* Retrieve the session instance for a given JID. * Retrieve the session instance for a given JID.
* *
...@@ -81,4 +119,28 @@ public class TransportSessionManager { ...@@ -81,4 +119,28 @@ public class TransportSessionManager {
return activeSessions.values(); return activeSessions.values();
} }
/**
* Bury any transport sessions that no longer have an associated xmpp session.
*/
private class SessionReaper extends TimerTask {
/**
* Kill any session that has been orphaned.
*/
public void run() {
cleanupOrphanedSessions();
}
}
/**
* Compares active xmpp sessions with active transport sessions and buries the orphaned.
*/
private void cleanupOrphanedSessions() {
SessionManager sessionManager = SessionManager.getInstance();
for (TransportSession session : getSessions()) {
if (sessionManager.getSessionCount(session.getJID().getNode()) == 0) {
transport.registrationLoggedOut(session);
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment