Commit 103dd915 authored by afreyssin's avatar afreyssin

Bug fix: Adds a static collection referencing all valid client context in the server (JORAM-281).

parent 87541ec5
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2003 - 2012 ScalAgent Distributed Technologies
* Copyright (C) 2003 - 2017 ScalAgent Distributed Technologies
* Copyright (C) 2004 France Telecom R&D
* Copyright (C) 2003 - 2004 Bull SA
*
......@@ -507,5 +507,42 @@ public class ClientContext implements java.io.Serializable, Encodable {
}
}
}
class CCUID {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ctxid;
result = prime * result + ((ua == null) ? 0 : ua.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CCUID other = (CCUID) obj;
if (ctxid != other.ctxid)
return false;
if (ua == null) {
if (other.ua != null)
return false;
} else if (!ua.equals(other.ua))
return false;
return true;
}
AgentId ua = null;
int ctxid = -1;
CCUID(AgentId ua, int ctxid) {
this.ua = ua;
this.ctxid = ctxid;
}
}
......@@ -34,8 +34,10 @@ import java.io.Serializable;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
......@@ -181,7 +183,6 @@ import fr.dyade.aaa.util.management.MXWrapper;
* destinations replies to clients.
*/
public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgentItf {
/** define serialVersionUID for interoperability */
private static final long serialVersionUID = 1L;
......@@ -343,6 +344,24 @@ public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgent
*/
private Map<Integer, ClientContext> contexts;
/**
* Static collection referencing all valid context in the server.
* It allows to avoid to reply to request from closed context (JORAM-281).
*/
private static Set<CCUID> validCC = Collections.synchronizedSet(new HashSet<CCUID>());
protected static void addValidCC(ClientContext cc) {
validCC.add(new CCUID(cc.getProxyId(), cc.getId()));
}
protected static void removeValidCC(ClientContext cc) {
validCC.remove(new CCUID(cc.getProxyId(), cc.getId()));
}
public static boolean isValidCC(AgentId ua, int ctxid) {
return validCC.contains(new CCUID(ua, ctxid));
}
/**
* Table holding the <code>ClientSubscription</code> instances.
* <p>
......@@ -1154,6 +1173,7 @@ public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgent
cc.setProxyId(getId());
cc.setProxyAgent(this);
contexts.put(cc.getId(), cc);
addValidCC(cc);
} catch (Exception exc) {
logger.log(BasicLevel.ERROR,
"ClientContext named [" + persistedClientNames[i] + "] could not be loaded", exc);
......@@ -1646,6 +1666,7 @@ public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgent
activeCtx.setProxyAgent(this);
modifiedClient(activeCtx);
contexts.put(new Integer(key), activeCtx);
addValidCC(activeCtx);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "Connection " + key + " opened.");
......@@ -2630,6 +2651,7 @@ public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgent
// Finally, deleting the context:
ClientContext cc = contexts.remove(new Integer(key));
removeValidCC(cc);
cc.delete();
activeCtx = null;
......@@ -3698,7 +3720,7 @@ public final class UserAgent extends Agent implements UserAgentMBean, ProxyAgent
if(logger.isLoggable(BasicLevel.DEBUG)) {
logger.log(BasicLevel.DEBUG,"Contexts:");
for(Integer k : contexts.keySet()) {
logger.log(BasicLevel.DEBUG,k+" : "+contexts.get(k));
logger.log(BasicLevel.DEBUG, k + " : " + contexts.get(k));
}
}
......
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