Commit 3be0243b authored by Thiago Camargo's avatar Thiago Camargo Committed by thiago

Added Lifetime to Media Proxy Sessions

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6644 b35dd754-fafc-0310-a699-88a17e54d16e
parent e286206d
...@@ -35,6 +35,9 @@ public class MediaProxy implements SessionListener { ...@@ -35,6 +35,9 @@ public class MediaProxy implements SessionListener {
private long idleTime = 90000; private long idleTime = 90000;
// Lifetime of a Channel in Seconds
private long lifetime = 9000;
/** /**
* Contruct a MediaProxy instance that will listen from every Network Interface. * Contruct a MediaProxy instance that will listen from every Network Interface.
* Recommended. * Recommended.
...@@ -126,6 +129,24 @@ public class MediaProxy implements SessionListener { ...@@ -126,6 +129,24 @@ public class MediaProxy implements SessionListener {
this.maxPort = maxPort; this.maxPort = maxPort;
} }
/**
* Get the Life Time of a channel in seconds
*
* @return Life Time in Seconds
*/
public long getLifetime() {
return lifetime;
}
/**
* Sets the Life Time of a Channel in seconds
*
* @param lifetime Life Time in Seconds
*/
public void setLifetime(long lifetime) {
this.lifetime = lifetime;
}
/** /**
* Get the agent with an especified ID * Get the agent with an especified ID
* *
...@@ -146,7 +167,7 @@ public class MediaProxy implements SessionListener { ...@@ -146,7 +167,7 @@ public class MediaProxy implements SessionListener {
* Implements Session Listener stopAgent event. * Implements Session Listener stopAgent event.
* Remove the stopped session from the sessions list. * Remove the stopped session from the sessions list.
* *
* @param session the session to * @param session the session that stopped
*/ */
public void sessionClosed(MediaProxySession session) { public void sessionClosed(MediaProxySession session) {
sessions.remove(session); sessions.remove(session);
...@@ -172,6 +193,7 @@ public class MediaProxy implements SessionListener { ...@@ -172,6 +193,7 @@ public class MediaProxy implements SessionListener {
if (session != null) { if (session != null) {
sessions.add(session); sessions.add(session);
session.addKeepAlive(idleTime); session.addKeepAlive(idleTime);
session.addLifeTime(lifetime);
session.addAgentListener(this); session.addAgentListener(this);
} }
return session; return session;
...@@ -197,14 +219,15 @@ public class MediaProxy implements SessionListener { ...@@ -197,14 +219,15 @@ public class MediaProxy implements SessionListener {
*/ */
public ProxyCandidate addSmartAgent(String id, String creator, String hostA, int portA, public ProxyCandidate addSmartAgent(String id, String creator, String hostA, int portA,
String hostB, int portB) { String hostB, int portB) {
final SmartSession agent = new SmartSession(id, creator, localhost, hostA, portA, hostB, portB, final SmartSession session = new SmartSession(id, creator, localhost, hostA, portA, hostB, portB,
minPort, maxPort); minPort, maxPort);
if (agent != null) { if (session != null) {
sessions.add(agent); sessions.add(session);
agent.addKeepAlive(idleTime); session.addKeepAlive(idleTime);
agent.addAgentListener(this); session.addLifeTime(lifetime);
session.addAgentListener(this);
} }
return agent; return session;
} }
/** /**
......
...@@ -48,6 +48,7 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -48,6 +48,7 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
protected Thread threadBtoAControl; protected Thread threadBtoAControl;
private Timer idleTimer = null; private Timer idleTimer = null;
private Timer lifeTimer = null;
private int minPort = 10000; private int minPort = 10000;
private int maxPort = 20000; private int maxPort = 20000;
...@@ -212,6 +213,16 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -212,6 +213,16 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
e.printStackTrace(); e.printStackTrace();
} }
try {
if (lifeTimer != null) {
lifeTimer.cancel();
lifeTimer.purge();
lifeTimer = null;
}
} catch (Exception e) {
e.printStackTrace();
}
channelAtoB.removeListener(); channelAtoB.removeListener();
channelAtoBControl.removeListener(); channelAtoBControl.removeListener();
channelBtoA.removeListener(); channelBtoA.removeListener();
...@@ -395,6 +406,25 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra ...@@ -395,6 +406,25 @@ public class MediaProxySession extends Thread implements ProxyCandidate, Datagra
}, delay, delay); }, delay, delay);
} }
/**
* Add a limited life time to the Session.
* The Session is stoped and remove from agents List after a certain time.
* Prevents that network cycles, refreshes a Session forever.
*
* @param lifetime time in Seconds to kill the Session
*/
void addLifeTime(long lifetime) {
lifetime *= 1000;
if (lifeTimer != null) return;
lifeTimer = new Timer();
lifeTimer.scheduleAtFixedRate(new TimerTask() {
public void run() {
stopAgent();
return;
}
}, lifetime, lifetime);
}
/** /**
* Adds a listener for Session events * Adds a listener for Session events
* *
......
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