|
|
|
@ -33,18 +33,16 @@ import java.util.Map; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SimpAttributes { |
|
|
|
public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
private static Log logger = LogFactory.getLog(SimpAttributes.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String className = SimpAttributes.class.getName(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Key for the mutex session attribute */ |
|
|
|
/** Key for the mutex session attribute */ |
|
|
|
public static final String SESSION_MUTEX_NAME = className + ".MUTEX"; |
|
|
|
public static final String SESSION_MUTEX_NAME = SimpAttributes.class.getName() + ".MUTEX"; |
|
|
|
|
|
|
|
|
|
|
|
/** Key set after the session is completed */ |
|
|
|
/** Key set after the session is completed */ |
|
|
|
public static final String SESSION_COMPLETED_NAME = className + ".COMPLETED"; |
|
|
|
public static final String SESSION_COMPLETED_NAME = SimpAttributes.class.getName() + ".COMPLETED"; |
|
|
|
|
|
|
|
|
|
|
|
/** Prefix for the name of session attributes used to store destruction callbacks. */ |
|
|
|
/** Prefix for the name of session attributes used to store destruction callbacks. */ |
|
|
|
public static final String DESTRUCTION_CALLBACK_NAME_PREFIX = className + ".DESTRUCTION_CALLBACK."; |
|
|
|
public static final String DESTRUCTION_CALLBACK_NAME_PREFIX = SimpAttributes.class.getName() + ".DESTRUCTION_CALLBACK."; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log logger = LogFactory.getLog(SimpAttributes.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String sessionId; |
|
|
|
private final String sessionId; |
|
|
|
@ -54,7 +52,6 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Constructor wrapping the given session attributes map. |
|
|
|
* Constructor wrapping the given session attributes map. |
|
|
|
* |
|
|
|
|
|
|
|
* @param sessionId the id of the associated session |
|
|
|
* @param sessionId the id of the associated session |
|
|
|
* @param attributes the attributes |
|
|
|
* @param attributes the attributes |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -66,27 +63,8 @@ public class SimpAttributes { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Extract the SiMP session attributes from the given message, wrap them in |
|
|
|
|
|
|
|
* a {@link SimpAttributes} instance. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param message the message to extract session attributes from |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static SimpAttributes fromMessage(Message<?> message) { |
|
|
|
|
|
|
|
Assert.notNull(message); |
|
|
|
|
|
|
|
MessageHeaders headers = message.getHeaders(); |
|
|
|
|
|
|
|
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); |
|
|
|
|
|
|
|
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(headers); |
|
|
|
|
|
|
|
if (sessionId == null || sessionAttributes == null) { |
|
|
|
|
|
|
|
throw new IllegalStateException( |
|
|
|
|
|
|
|
"Message does not contain SiMP session id or attributes: " + message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new SimpAttributes(sessionId, sessionAttributes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the value for the attribute of the given name, if any. |
|
|
|
* Return the value for the attribute of the given name, if any. |
|
|
|
* |
|
|
|
|
|
|
|
* @param name the name of the attribute |
|
|
|
* @param name the name of the attribute |
|
|
|
* @return the current attribute value, or {@code null} if not found |
|
|
|
* @return the current attribute value, or {@code null} if not found |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -96,7 +74,6 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Set the value with the given name replacing an existing value (if any). |
|
|
|
* Set the value with the given name replacing an existing value (if any). |
|
|
|
* |
|
|
|
|
|
|
|
* @param name the name of the attribute |
|
|
|
* @param name the name of the attribute |
|
|
|
* @param value the value for the attribute |
|
|
|
* @param value the value for the attribute |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -106,12 +83,10 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Remove the attribute of the given name, if it exists. |
|
|
|
* Remove the attribute of the given name, if it exists. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Also removes the registered destruction callback for the specified |
|
|
|
* <p>Also removes the registered destruction callback for the specified |
|
|
|
* attribute, if any. However it <i>does not</i> execute</i> the callback. |
|
|
|
* attribute, if any. However it <i>does not</i> execute</i> the callback. |
|
|
|
* It is assumed the removed object will continue to be used and destroyed |
|
|
|
* It is assumed the removed object will continue to be used and destroyed |
|
|
|
* independently at the appropriate time. |
|
|
|
* independently at the appropriate time. |
|
|
|
* |
|
|
|
|
|
|
|
* @param name the name of the attribute |
|
|
|
* @param name the name of the attribute |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void removeAttribute(String name) { |
|
|
|
public void removeAttribute(String name) { |
|
|
|
@ -121,7 +96,6 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Retrieve the names of all attributes. |
|
|
|
* Retrieve the names of all attributes. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the attribute names as String array, never {@code null} |
|
|
|
* @return the attribute names as String array, never {@code null} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String[] getAttributeNames() { |
|
|
|
public String[] getAttributeNames() { |
|
|
|
@ -131,7 +105,6 @@ public class SimpAttributes { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Register a callback to execute on destruction of the specified attribute. |
|
|
|
* Register a callback to execute on destruction of the specified attribute. |
|
|
|
* The callback is executed when the session is closed. |
|
|
|
* The callback is executed when the session is closed. |
|
|
|
* |
|
|
|
|
|
|
|
* @param name the name of the attribute to register the callback for |
|
|
|
* @param name the name of the attribute to register the callback for |
|
|
|
* @param callback the destruction callback to be executed |
|
|
|
* @param callback the destruction callback to be executed |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -152,7 +125,6 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return an id for the associated session. |
|
|
|
* Return an id for the associated session. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the session id as String (never {@code null}) |
|
|
|
* @return the session id as String (never {@code null}) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public String getSessionId() { |
|
|
|
public String getSessionId() { |
|
|
|
@ -161,7 +133,6 @@ public class SimpAttributes { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Expose the object to synchronize on for the underlying session. |
|
|
|
* Expose the object to synchronize on for the underlying session. |
|
|
|
* |
|
|
|
|
|
|
|
* @return the session mutex to use (never {@code null}) |
|
|
|
* @return the session mutex to use (never {@code null}) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Object getSessionMutex() { |
|
|
|
public Object getSessionMutex() { |
|
|
|
@ -197,13 +168,29 @@ public class SimpAttributes { |
|
|
|
try { |
|
|
|
try { |
|
|
|
((Runnable) entry.getValue()).run(); |
|
|
|
((Runnable) entry.getValue()).run(); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Throwable t) { |
|
|
|
catch (Throwable ex) { |
|
|
|
if (logger.isErrorEnabled()) { |
|
|
|
logger.error("Uncaught error in session attribute destruction callback", ex); |
|
|
|
logger.error("Uncaught error in session attribute destruction callback", t); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Extract the SiMP session attributes from the given message, wrap them in |
|
|
|
|
|
|
|
* a {@link SimpAttributes} instance. |
|
|
|
|
|
|
|
* @param message the message to extract session attributes from |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public static SimpAttributes fromMessage(Message<?> message) { |
|
|
|
|
|
|
|
Assert.notNull(message); |
|
|
|
|
|
|
|
MessageHeaders headers = message.getHeaders(); |
|
|
|
|
|
|
|
String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); |
|
|
|
|
|
|
|
Map<String, Object> sessionAttributes = SimpMessageHeaderAccessor.getSessionAttributes(headers); |
|
|
|
|
|
|
|
if (sessionId == null || sessionAttributes == null) { |
|
|
|
|
|
|
|
throw new IllegalStateException( |
|
|
|
|
|
|
|
"Message does not contain SiMP session id or attributes: " + message); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new SimpAttributes(sessionId, sessionAttributes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|