public void setAttribute(String name, Object value) { int action = (value==null)?ACTION_REMOVE:ACTION_SET; addAction(TYPE_ATTRIBUTE,action,name,value); }
@Override public void writeExternal(java.io.ObjectOutput out ) throws java.io.IOException { //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 = actions.get(i); info.writeExternal(out); } }
public void resetDeltaRequest() { try { lock(); if (deltaRequest == null) { deltaRequest = new DeltaRequest(getIdInternal(), false); } else { deltaRequest.reset(); deltaRequest.setSessionId(getIdInternal()); } }finally{ unlock(); } }
/** * Only support principals from type {@link GenericPrincipal GenericPrincipal} * @param p Session principal * @see GenericPrincipal */ public void setPrincipal(Principal p) { int action = (p==null)?ACTION_REMOVE:ACTION_SET; GenericPrincipal gp = null; if (p != null) { if (p instanceof GenericPrincipal) { gp = (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, gp); }
/** * Applies a diff to an existing object. * @param diff byte[] * @param offset int * @param length int * @throws IOException */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { try { lock(); ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } }finally { unlock(); } }
/** * Has the object changed since last replication * and is not in a locked state * @return boolean */ @Override public boolean isDirty() { return getDeltaRequest().getSize()>0; }
/** * serialize DeltaRequest * @see DeltaRequest#writeExternal(java.io.ObjectOutput) * * @param deltaRequest * @return serialized delta request * @throws IOException */ protected byte[] serializeDeltaRequest(DeltaSession session, DeltaRequest deltaRequest) throws IOException { try { session.lock(); return deltaRequest.serialize(); }finally { session.unlock(); } }
reset(); sessionId = in.readUTF(); recordAllActions = in.readBoolean();
/** * Release all object references, and initialize instance variables, in * preparation for reuse of this object. */ @Override public void recycle() { lock(); try { super.recycle(); deltaRequest.clear(); } finally{ unlock(); } }
protected void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest) { try { lock(); // Remove this attribute from our collection Object value = attributes.get(name); if (value == null) return; super.removeAttributeInternal(name,notify); if (addDeltaRequest && deltaRequest != null && !exclude(name)) { deltaRequest.removeAttribute(name); } }finally { unlock(); } }
/** * Load Deltarequest from external node * Load the Class at container classloader * @see DeltaRequest#readExternal(java.io.ObjectInput) * @param session Corresponding session * @param data message data * @return The request * @throws ClassNotFoundException Serialization error * @throws IOException IO error with serialization */ protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data) throws ClassNotFoundException, IOException { session.lock(); try { ReplicationStream ois = getReplicationStream(data); session.getDeltaRequest().readExternal(ois); ois.close(); return session.getDeltaRequest(); } finally { session.unlock(); } }
/** * handle receive session delta * @param msg * @param sender * @throws IOException * @throws ClassNotFoundException */ protected void handleSESSION_DELTA(SessionMessage msg, Member sender) throws IOException, ClassNotFoundException { counterReceive_EVT_SESSION_DELTA++; byte[] delta = msg.getSession(); DeltaSession session = (DeltaSession) findSession(msg.getSessionID()); if (session != null) { if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.delta",getName(), msg.getSessionID())); try { session.lock(); DeltaRequest dreq = deserializeDeltaRequest(session, delta); dreq.execute(session, isNotifyListenersOnReplication()); session.setPrimarySession(false); }finally { session.unlock(); } } }
public void resetDeltaRequest() { try { lock(); if (deltaRequest == null) { deltaRequest = new DeltaRequest(getIdInternal(), false); } else { deltaRequest.reset(); deltaRequest.setSessionId(getIdInternal()); } }finally{ unlock(); } }
/** * convert principal at SerializablePrincipal for backup nodes. * Only support principals from type {@link GenericPrincipal GenericPrincipal} * @param p Session principal * @see GenericPrincipal */ public void setPrincipal(Principal p) { 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); }
/** * Applies a diff to an existing object. * @param diff byte[] * @param offset int * @param length int * @throws IOException */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { try { lock(); ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); if (loaders != null && loaders.length > 0) Thread.currentThread().setContextClassLoader(loaders[0]); getDeltaRequest().readExternal(stream); getDeltaRequest().execute(this, ((ClusterManager)getManager()).isNotifyListenersOnReplication()); } finally { Thread.currentThread().setContextClassLoader(contextLoader); } }finally { unlock(); } }
/** * Has the object changed since last replication * and is not in a locked state * @return boolean */ @Override public boolean isDirty() { return getDeltaRequest().getSize()>0; }
/** * serialize DeltaRequest * @see DeltaRequest#writeExternal(java.io.ObjectOutput) * * @param deltaRequest * @return serialized delta request * @throws IOException */ protected byte[] serializeDeltaRequest(DeltaSession session, DeltaRequest deltaRequest) throws IOException { try { session.lock(); return deltaRequest.serialize(); }finally { session.unlock(); } }
reset(); sessionId = in.readUTF(); recordAllActions = in.readBoolean();
/** * Release all object references, and initialize instance variables, in * preparation for reuse of this object. */ @Override public void recycle() { try { lock(); super.recycle(); deltaRequest.clear(); }finally{ unlock(); } }
protected void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest) { lock(); try { // Remove this attribute from our collection Object value = attributes.get(name); if (value == null) return; super.removeAttributeInternal(name,notify); if (addDeltaRequest && deltaRequest != null && !exclude(name, null)) { deltaRequest.removeAttribute(name); } } finally { unlock(); } }