* @throws IOException
*/
protected DeltaRequest deserializeDeltaRequest(DeltaSession session, byte[] data) throws ClassNotFoundException, IOException {
- ReplicationStream ois = getReplicationStream(data);
- session.getDeltaRequest().readExternal(ois);
- ois.close();
- return session.getDeltaRequest();
+ try {
+ session.lock();
+ ReplicationStream ois = getReplicationStream(data);
+ session.getDeltaRequest().readExternal(ois);
+ ois.close();
+ return session.getDeltaRequest();
+ }finally {
+ session.unlock();
+ }
}
/**
* @return serialized delta request
* @throws IOException
*/
- protected byte[] serializeDeltaRequest(DeltaRequest deltaRequest) throws IOException {
- return deltaRequest.serialize();
+ protected byte[] serializeDeltaRequest(DeltaSession session, DeltaRequest deltaRequest) throws IOException {
+ try {
+ session.lock();
+ return deltaRequest.serialize();
+ }finally {
+ session.unlock();
+ }
}
/**
* @return a SessionMessage to be sent,
*/
public ClusterMessage requestCompleted(String sessionId) {
+ DeltaSession session = null;
try {
- DeltaSession session = (DeltaSession) findSession(sessionId);
+ session = (DeltaSession) findSession(sessionId);
DeltaRequest deltaRequest = session.getDeltaRequest();
+ session.lock();
SessionMessage msg = null;
boolean isDeltaRequest = false ;
synchronized(deltaRequest) {
isDeltaRequest = deltaRequest.getSize() > 0 ;
if (isDeltaRequest) {
counterSend_EVT_SESSION_DELTA++;
- byte[] data = serializeDeltaRequest(deltaRequest);
+ byte[] data = serializeDeltaRequest(session,deltaRequest);
msg = new SessionMessageImpl(getName(),
SessionMessage.EVT_SESSION_DELTA,
data,
} catch (IOException x) {
log.error(sm.getString("deltaManager.createMessage.unableCreateDeltaRequest",sessionId), x);
return null;
+ }finally {
+ if (session!=null) session.unlock();
}
}
DeltaSession session = (DeltaSession) findSession(msg.getSessionID());
if (session != null) {
if (log.isDebugEnabled()) log.debug(sm.getString("deltaManager.receiveMessage.delta",getName(), msg.getSessionID()));
- DeltaRequest dreq = deserializeDeltaRequest(session, delta);
- dreq.execute(session, notifyListenersOnReplication);
- session.setPrimarySession(false);
+ try {
+ session.lock();
+ DeltaRequest dreq = deserializeDeltaRequest(session, delta);
+ dreq.execute(session, notifyListenersOnReplication);
+ session.setPrimarySession(false);
+ }finally {
+ session.unlock();
+ }
}
}
addAction(TYPE_ISNEW,action,NAME_ISNEW,new Boolean(n));
}
- protected synchronized void addAction(int type,
+ protected void addAction(int type,
int action,
String name,
Object value) {
execute(session,true);
}
- public synchronized void execute(DeltaSession session, boolean notifyListeners) {
+ public 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();
reset();
}
- public synchronized void reset() {
+ public void reset() {
while ( actions.size() > 0 ) {
try {
AttributeInfo info = (AttributeInfo) actions.removeFirst();
return actions.size();
}
- public synchronized void clear() {
+ public void clear() {
actions.clear();
actionPool.clear();
}
- public synchronized void readExternal(java.io.ObjectInput in) throws IOException,ClassNotFoundException {
+ public void readExternal(java.io.ObjectInput in) throws IOException,ClassNotFoundException {
//sessionId - String
//recordAll - boolean
//size - int
- public synchronized void writeExternal(java.io.ObjectOutput out ) throws java.io.IOException {
+ public void writeExternal(java.io.ObjectOutput out ) throws java.io.IOException {
//sessionId - String
//recordAll - boolean
//size - int
return other.getName().equals(this.getName());
}
- public synchronized void readExternal(java.io.ObjectInput in ) throws IOException,ClassNotFoundException {
+ public void readExternal(java.io.ObjectInput in ) throws IOException,ClassNotFoundException {
//type - int
//action - int
//name - String
if ( hasValue ) value = in.readObject();
}
- public synchronized void writeExternal(java.io.ObjectOutput out) throws IOException {
+ public void writeExternal(java.io.ObjectOutput out) throws IOException {
//type - int
//action - int
//name - String
* @throws IOException
*/
public byte[] getDiff() throws IOException {
- return getDeltaRequest().serialize();
+ try{
+ lock();
+ return getDeltaRequest().serialize();
+ }finally{
+ unlock();
+ }
}
public ClassLoader[] getClassLoaders() {
* @throws IOException
*/
public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException {
- ReplicationStream stream = ((ClusterManager)getManager()).getReplicationStream(diff,offset,length);
- getDeltaRequest().readExternal(stream);
- ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
try {
- ClassLoader[] loaders = getClassLoaders();
- if ( loaders != null && loaders.length >0 ) Thread.currentThread().setContextClassLoader(loaders[0]);
- getDeltaRequest().execute(this);
+ lock();
+ ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length);
+ getDeltaRequest().readExternal(stream);
+ ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ ClassLoader[] loaders = getClassLoaders();
+ if (loaders != null && loaders.length > 0)
+ Thread.currentThread().setContextClassLoader(loaders[0]);
+ getDeltaRequest().execute(this);
+ } finally {
+ Thread.currentThread().setContextClassLoader(contextLoader);
+ }
}finally {
- Thread.currentThread().setContextClassLoader(contextLoader);
+ unlock();
}
}
if (isValid && interval == 0) {
expire();
} else {
- if (addDeltaRequest && (deltaRequest != null))
- deltaRequest.setMaxInactiveInterval(interval);
+ if (addDeltaRequest && (deltaRequest != null)) {
+ try {
+ lock();
+ deltaRequest.setMaxInactiveInterval(interval);
+ }finally{
+ unlock();
+ }
+ }
+
}
}
public void setNew(boolean isNew, boolean addDeltaRequest) {
super.setNew(isNew);
- if (addDeltaRequest && (deltaRequest != null))
- deltaRequest.setNew(isNew);
+ if (addDeltaRequest && (deltaRequest != null)){
+ try {
+ lock();
+ deltaRequest.setNew(isNew);
+ }finally{
+ unlock();
+ }
+ }
}
/**
* preparation for reuse of this object.
*/
public void recycle() {
- super.recycle();
- deltaRequest.clear();
+ try {
+ lock();
+ super.recycle();
+ deltaRequest.clear();
+ }finally{
+ unlock();
+ }
}
// ------------------------------------------------ Session Package Methods
- public synchronized void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
- readObjectData(in);
+ public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
+ try {
+ lock();
+ readObjectData(in);
+ }finally{
+ unlock();
+ }
}
}
public void resetDeltaRequest() {
- if (deltaRequest == null) {
- deltaRequest = new DeltaRequest(getIdInternal(), false);
- } else {
- deltaRequest.reset();
- deltaRequest.setSessionId(getIdInternal());
+ try {
+ lock();
+ if (deltaRequest == null) {
+ deltaRequest = new DeltaRequest(getIdInternal(), false);
+ } else {
+ deltaRequest.reset();
+ deltaRequest.setSessionId(getIdInternal());
+ }
+ }finally{
+ unlock();
}
}
activate();
}
- public synchronized void writeExternal(ObjectOutput out ) throws java.io.IOException {
- writeObject(out);
+ public void writeExternal(ObjectOutput out ) throws java.io.IOException {
+ try {
+ lock();
+ writeObject(out);
+ }finally {
+ unlock();
+ }
}