|
@@ -11,12 +11,12 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
/** |
|
|
/** |
|
|
* The string manager for this package. |
|
|
* The string manager for this package. |
|
|
*/ |
|
|
*/ |
|
|
protected static final StringManager sm = |
|
|
|
|
|
StringManager.getManager(Constants.Package); |
|
|
|
|
|
|
|
|
protected static final StringManager sm = StringManager.getManager(Constants.Package); |
|
|
/** |
|
|
/** |
|
|
* Type array. |
|
|
* Type array. |
|
|
*/ |
|
|
*/ |
|
|
protected static final String EMPTY_ARRAY[] = new String[0]; |
|
|
|
|
|
|
|
|
private static final String[] EMPTY_ARRAY = new String[0]; |
|
|
|
|
|
|
|
|
// ------------------------------ WxSession |
|
|
// ------------------------------ WxSession |
|
|
protected Map<String, Object> attributes = new ConcurrentHashMap<>(); |
|
|
protected Map<String, Object> attributes = new ConcurrentHashMap<>(); |
|
|
/** |
|
|
/** |
|
@@ -71,20 +71,23 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
@Override |
|
|
@Override |
|
|
public Object getAttribute(String name) { |
|
|
public Object getAttribute(String name) { |
|
|
|
|
|
|
|
|
if (!isValidInternal()) |
|
|
|
|
|
|
|
|
if (!isValidInternal()) { |
|
|
throw new IllegalStateException |
|
|
throw new IllegalStateException |
|
|
(sm.getString("sessionImpl.getAttribute.ise")); |
|
|
(sm.getString("sessionImpl.getAttribute.ise")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (name == null) return null; |
|
|
|
|
|
|
|
|
if (name == null) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return (this.attributes.get(name)); |
|
|
|
|
|
|
|
|
return this.attributes.get(name); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Enumeration<String> getAttributeNames() { |
|
|
public Enumeration<String> getAttributeNames() { |
|
|
if (!isValidInternal()) |
|
|
|
|
|
throw new IllegalStateException |
|
|
|
|
|
(sm.getString("sessionImpl.getAttributeNames.ise")); |
|
|
|
|
|
|
|
|
if (!isValidInternal()) { |
|
|
|
|
|
throw new IllegalStateException(sm.getString("sessionImpl.getAttributeNames.ise")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Set<String> names = new HashSet<>(); |
|
|
Set<String> names = new HashSet<>(); |
|
|
names.addAll(this.attributes.keySet()); |
|
|
names.addAll(this.attributes.keySet()); |
|
@@ -94,9 +97,9 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
@Override |
|
|
@Override |
|
|
public void setAttribute(String name, Object value) { |
|
|
public void setAttribute(String name, Object value) { |
|
|
// Name cannot be null |
|
|
// Name cannot be null |
|
|
if (name == null) |
|
|
|
|
|
throw new IllegalArgumentException |
|
|
|
|
|
(sm.getString("sessionImpl.setAttribute.namenull")); |
|
|
|
|
|
|
|
|
if (name == null) { |
|
|
|
|
|
throw new IllegalArgumentException(sm.getString("sessionImpl.setAttribute.namenull")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Null value is the same as removeAttribute() |
|
|
// Null value is the same as removeAttribute() |
|
|
if (value == null) { |
|
|
if (value == null) { |
|
@@ -105,9 +108,9 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Validate our current state |
|
|
// Validate our current state |
|
|
if (!isValidInternal()) |
|
|
|
|
|
throw new IllegalStateException(sm.getString( |
|
|
|
|
|
"sessionImpl.setAttribute.ise", getIdInternal())); |
|
|
|
|
|
|
|
|
if (!isValidInternal()) { |
|
|
|
|
|
throw new IllegalStateException(sm.getString("sessionImpl.setAttribute.ise", getIdInternal())); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.attributes.put(name, value); |
|
|
this.attributes.put(name, value); |
|
|
|
|
|
|
|
@@ -121,8 +124,7 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
@Override |
|
|
@Override |
|
|
public void invalidate() { |
|
|
public void invalidate() { |
|
|
if (!isValidInternal()) |
|
|
if (!isValidInternal()) |
|
|
throw new IllegalStateException |
|
|
|
|
|
(sm.getString("sessionImpl.invalidate.ise")); |
|
|
|
|
|
|
|
|
throw new IllegalStateException(sm.getString("sessionImpl.invalidate.ise")); |
|
|
|
|
|
|
|
|
// Cause this session to expire |
|
|
// Cause this session to expire |
|
|
expire(); |
|
|
expire(); |
|
@@ -131,12 +133,11 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public WxSession getSession() { |
|
|
public WxSession getSession() { |
|
|
|
|
|
|
|
|
if (this.facade == null) { |
|
|
if (this.facade == null) { |
|
|
this.facade = new StandardSessionFacade(this); |
|
|
this.facade = new StandardSessionFacade(this); |
|
|
} |
|
|
} |
|
|
return (this.facade); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.facade; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -185,12 +186,14 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public String getIdInternal() { |
|
|
public String getIdInternal() { |
|
|
return (this.id); |
|
|
|
|
|
|
|
|
return this.id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected void removeAttributeInternal(String name) { |
|
|
protected void removeAttributeInternal(String name) { |
|
|
// Avoid NPE |
|
|
// Avoid NPE |
|
|
if (name == null) return; |
|
|
|
|
|
|
|
|
if (name == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Remove this attribute from our collection |
|
|
// Remove this attribute from our collection |
|
|
this.attributes.remove(name); |
|
|
this.attributes.remove(name); |
|
@@ -202,19 +205,22 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
// Check to see if session has already been invalidated. |
|
|
// Check to see if session has already been invalidated. |
|
|
// Do not check expiring at this point as expire should not return until |
|
|
// Do not check expiring at this point as expire should not return until |
|
|
// isValid is false |
|
|
// isValid is false |
|
|
if (!this.isValid) |
|
|
|
|
|
|
|
|
if (!this.isValid) { |
|
|
return; |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
synchronized (this) { |
|
|
synchronized (this) { |
|
|
// Check again, now we are inside the sync so this code only runs once |
|
|
// Check again, now we are inside the sync so this code only runs once |
|
|
// Double check locking - isValid needs to be volatile |
|
|
// Double check locking - isValid needs to be volatile |
|
|
// The check of expiring is to ensure that an infinite loop is not |
|
|
// The check of expiring is to ensure that an infinite loop is not |
|
|
// entered as per bug 56339 |
|
|
// entered as per bug 56339 |
|
|
if (this.expiring || !this.isValid) |
|
|
|
|
|
|
|
|
if (this.expiring || !this.isValid) { |
|
|
return; |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (this.manager == null) |
|
|
|
|
|
|
|
|
if (this.manager == null) { |
|
|
return; |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Mark this session as "being expired" |
|
|
// Mark this session as "being expired" |
|
|
this.expiring = true; |
|
|
this.expiring = true; |
|
@@ -230,9 +236,9 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
this.expiring = false; |
|
|
this.expiring = false; |
|
|
|
|
|
|
|
|
// Unbind any objects associated with this session |
|
|
// Unbind any objects associated with this session |
|
|
String keys[] = keys(); |
|
|
|
|
|
for (int i = 0; i < keys.length; i++) { |
|
|
|
|
|
removeAttributeInternal(keys[i]); |
|
|
|
|
|
|
|
|
String[] keys = keys(); |
|
|
|
|
|
for (String key : keys) { |
|
|
|
|
|
removeAttributeInternal(key); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -273,13 +279,15 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void setId(String id) { |
|
|
public void setId(String id) { |
|
|
if ((this.id != null) && (this.manager != null)) |
|
|
|
|
|
|
|
|
if ((this.id != null) && (this.manager != null)) { |
|
|
this.manager.remove(this); |
|
|
this.manager.remove(this); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
this.id = id; |
|
|
this.id = id; |
|
|
|
|
|
|
|
|
if (this.manager != null) |
|
|
|
|
|
|
|
|
if (this.manager != null) { |
|
|
this.manager.add(this); |
|
|
this.manager.add(this); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@@ -295,21 +303,41 @@ public class StandardSession implements WxSession, InternalSession { |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public boolean equals(Object o) { |
|
|
public boolean equals(Object o) { |
|
|
if (this == o) return true; |
|
|
|
|
|
if (!(o instanceof StandardSession)) return false; |
|
|
|
|
|
|
|
|
if (this == o) { |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
if (!(o instanceof StandardSession)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
StandardSession session = (StandardSession) o; |
|
|
StandardSession session = (StandardSession) o; |
|
|
|
|
|
|
|
|
if (this.creationTime != session.creationTime) return false; |
|
|
|
|
|
if (this.expiring != session.expiring) return false; |
|
|
|
|
|
if (this.isValid != session.isValid) return false; |
|
|
|
|
|
if (this.maxInactiveInterval != session.maxInactiveInterval) return false; |
|
|
|
|
|
if (this.thisAccessedTime != session.thisAccessedTime) return false; |
|
|
|
|
|
if (this.accessCount.get() != session.accessCount.get()) return false; |
|
|
|
|
|
if (!this.attributes.equals(session.attributes)) return false; |
|
|
|
|
|
if (!this.facade.equals(session.facade)) return false; |
|
|
|
|
|
if (!this.id.equals(session.id)) return false; |
|
|
|
|
|
return this.manager.equals(session.manager); |
|
|
|
|
|
|
|
|
if (this.creationTime != session.creationTime) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.expiring != session.expiring) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.isValid != session.isValid) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.maxInactiveInterval != session.maxInactiveInterval) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.thisAccessedTime != session.thisAccessedTime) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (this.accessCount.get() != session.accessCount.get()) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (!this.attributes.equals(session.attributes)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
if (!this.facade.equals(session.facade)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this.id.equals(session.id) && this.manager.equals(session.manager); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|