DeltaRequestpublic class DeltaRequest extends Object implements ExternalizableThis class is used to track the series of actions that happens when
a request is executed. These actions will then translate into invokations of methods
on the actual session.
This class is NOT thread safe. One DeltaRequest per session |
Fields Summary |
---|
public static org.apache.juli.logging.Log | log | protected static org.apache.catalina.util.StringManager | smThe string manager for this package. | public static final int | TYPE_ATTRIBUTE | public static final int | TYPE_PRINCIPAL | public static final int | TYPE_ISNEW | public static final int | TYPE_MAXINTERVAL | public static final int | ACTION_SET | public static final int | ACTION_REMOVE | public static final String | NAME_PRINCIPAL | public static final String | NAME_MAXINTERVAL | public static final String | NAME_ISNEW | private String | sessionId | private LinkedList | actions | private LinkedList | actionPool | private boolean | recordAllActions |
Constructors Summary |
---|
public DeltaRequest()
| public DeltaRequest(String sessionId, boolean recordAllActions)
this.recordAllActions=recordAllActions;
if(sessionId != null)
setSessionId(sessionId);
|
Methods Summary |
---|
protected synchronized void | addAction(int type, int action, java.lang.String name, java.lang.Object value)
AttributeInfo info = null;
if ( this.actionPool.size() > 0 ) {
try {
info = (AttributeInfo) actionPool.removeFirst();
}catch ( Exception x ) {
log.error("Unable to remove element:",x);
info = new AttributeInfo(type, action, name, value);
}
info.init(type,action,name,value);
} else {
info = new AttributeInfo(type, action, name, value);
}
//if we have already done something to this attribute, make sure
//we don't send multiple actions across the wire
if ( !recordAllActions) {
try {
actions.remove(info);
} catch (java.util.NoSuchElementException x) {
//do nothing, we wanted to remove it anyway
}
}
//add the action
actions.addLast(info);
| public synchronized void | clear()
actions.clear();
actionPool.clear();
| public synchronized void | execute(DeltaSession session, boolean notifyListeners)
if ( !this.sessionId.equals( session.getId() ) )
throw new java.lang.IllegalArgumentException("Session id mismatch, not executing the delta request");
session.access();
for ( int i=0; i<actions.size(); i++ ) {
AttributeInfo info = (AttributeInfo)actions.get(i);
switch ( info.getType() ) {
case TYPE_ATTRIBUTE: {
if ( info.getAction() == ACTION_SET ) {
if ( log.isTraceEnabled() ) log.trace("Session.setAttribute('"+info.getName()+"', '"+info.getValue()+"')");
session.setAttribute(info.getName(), info.getValue(),notifyListeners,false);
} else {
if ( log.isTraceEnabled() ) log.trace("Session.removeAttribute('"+info.getName()+"')");
session.removeAttribute(info.getName(),notifyListeners,false);
}
break;
}//case
case TYPE_ISNEW: {
if ( log.isTraceEnabled() ) log.trace("Session.setNew('"+info.getValue()+"')");
session.setNew(((Boolean)info.getValue()).booleanValue(),false);
break;
}//case
case TYPE_MAXINTERVAL: {
if ( log.isTraceEnabled() ) log.trace("Session.setMaxInactiveInterval('"+info.getValue()+"')");
session.setMaxInactiveInterval(((Integer)info.getValue()).intValue(),false);
break;
}//case
case TYPE_PRINCIPAL: {
Principal p = null;
if ( info.getAction() == ACTION_SET ) {
SerializablePrincipal sp = (SerializablePrincipal)info.getValue();
p = (Principal)sp.getPrincipal(session.getManager().getContainer().getRealm());
}
session.setPrincipal(p,false);
break;
}//case
default : throw new java.lang.IllegalArgumentException("Invalid attribute info type="+info);
}//switch
}//for
session.endAccess();
reset();
| public void | execute(DeltaSession session)
execute(session,true);
| public java.lang.String | getSessionId()
return sessionId;
| public int | getSize()
return actions.size();
| public synchronized void | readExternal(java.io.ObjectInput in)
//sessionId - String
//recordAll - boolean
//size - int
//AttributeInfo - in an array
reset();
sessionId = in.readUTF();
recordAllActions = in.readBoolean();
int cnt = in.readInt();
if (actions == null)
actions = new LinkedList();
else
actions.clear();
for (int i = 0; i < cnt; i++) {
AttributeInfo info = null;
if (this.actionPool.size() > 0) {
try {
info = (AttributeInfo) actionPool.removeFirst();
} catch ( Exception x ) {
log.error("Unable to remove element",x);
info = new AttributeInfo(-1,-1,null,null);
}
}
else {
info = new AttributeInfo(-1,-1,null,null);
}
info.readExternal(in);
actions.addLast(info);
}//for
| public void | removeAttribute(java.lang.String name)
int action = ACTION_REMOVE;
addAction(TYPE_ATTRIBUTE,action,name,null);
| public synchronized void | reset()
while ( actions.size() > 0 ) {
try {
AttributeInfo info = (AttributeInfo) actions.removeFirst();
info.recycle();
actionPool.addLast(info);
}catch ( Exception x ) {
log.error("Unable to remove element",x);
}
}
actions.clear();
| protected byte[] | serialize()serialize DeltaRequest
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
writeExternal(oos);
oos.flush();
oos.close();
return bos.toByteArray();
| public void | setAttribute(java.lang.String name, java.lang.Object value)
int action = (value==null)?ACTION_REMOVE:ACTION_SET;
addAction(TYPE_ATTRIBUTE,action,name,value);
| public void | setMaxInactiveInterval(int interval)
int action = ACTION_SET;
addAction(TYPE_MAXINTERVAL,action,NAME_MAXINTERVAL,new Integer(interval));
| public void | setNew(boolean n)
int action = ACTION_SET;
addAction(TYPE_ISNEW,action,NAME_ISNEW,new Boolean(n));
| public void | setPrincipal(java.security.Principal p)convert principal at SerializablePrincipal for backup nodes.
Only support principals from type {@link GenericPrincipal GenericPrincipal}
int action = (p==null)?ACTION_REMOVE:ACTION_SET;
SerializablePrincipal sp = null;
if ( p != null ) {
if(p instanceof GenericPrincipal) {
sp = SerializablePrincipal.createPrincipal((GenericPrincipal)p);
if(log.isDebugEnabled())
log.debug(sm.getString("deltaRequest.showPrincipal", p.getName() , getSessionId()));
} else
log.error(sm.getString("deltaRequest.wrongPrincipalClass",p.getClass().getName()));
}
addAction(TYPE_PRINCIPAL,action,NAME_PRINCIPAL,sp);
| public void | setSessionId(java.lang.String sessionId)
this.sessionId = sessionId;
if ( sessionId == null ) {
new Exception("Session Id is null for setSessionId").fillInStackTrace().printStackTrace();
}
| public synchronized void | writeExternal(java.io.ObjectOutput out)
//sessionId - String
//recordAll - boolean
//size - int
//AttributeInfo - in an array
out.writeUTF(getSessionId());
out.writeBoolean(recordAllActions);
out.writeInt(getSize());
for ( int i=0; i<getSize(); i++ ) {
AttributeInfo info = (AttributeInfo)actions.get(i);
info.writeExternal(out);
}
|
|