This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 7.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 020b84938cefec71324537d52fbe6b5b2f674617 Author: Mark Thomas <ma...@apache.org> AuthorDate: Tue May 21 22:02:40 2019 +0100 Refactor to create internal lock methods. This is a step on the path to making ReplicatedMapEntry#lock() and unlock() NO-OPs. --- .../apache/catalina/ha/session/DeltaSession.java | 98 ++++++++++++---------- 1 file changed, 53 insertions(+), 45 deletions(-) diff --git a/java/org/apache/catalina/ha/session/DeltaSession.java b/java/org/apache/catalina/ha/session/DeltaSession.java index 7efafc6..08f0cd2 100644 --- a/java/org/apache/catalina/ha/session/DeltaSession.java +++ b/java/org/apache/catalina/ha/session/DeltaSession.java @@ -138,11 +138,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus */ @Override public byte[] getDiff() throws IOException { - try{ - lock(); + lockInternal(); + try { return getDeltaRequest().serialize(); - }finally{ - unlock(); + } finally { + unlockInternal(); } } @@ -168,9 +168,9 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus */ @Override public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException { + lockInternal(); try { - lock(); - ReplicationStream stream = ( (ClusterManager) getManager()).getReplicationStream(diff, offset, length); + ReplicationStream stream = ((ClusterManager) getManager()).getReplicationStream(diff, offset, length); ClassLoader contextLoader = Thread.currentThread().getContextClassLoader(); try { ClassLoader[] loaders = getClassLoaders(); @@ -182,8 +182,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } finally { Thread.currentThread().setContextClassLoader(contextLoader); } - }finally { - unlock(); + } finally { + unlockInternal(); } } @@ -195,19 +195,27 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus resetDeltaRequest(); } + @Override + public void lock() { + lockInternal(); + } + + @Override + public void unlock() { + unlockInternal(); + } + /** * Lock during serialization */ - @Override - public void lock() { + private void lockInternal() { diffLock.lock(); } /** * Unlock after serialization */ - @Override - public void unlock() { + private void unlockInternal() { diffLock.unlock(); } @@ -302,11 +310,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus public void setMaxInactiveInterval(int interval, boolean addDeltaRequest) { super.maxInactiveInterval = interval; if (addDeltaRequest) { - lock(); + lockInternal(); try { deltaRequest.setMaxInactiveInterval(interval); } finally { - unlock(); + unlockInternal(); } } } @@ -325,11 +333,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus public void setNew(boolean isNew, boolean addDeltaRequest) { super.setNew(isNew); if (addDeltaRequest){ - lock(); + lockInternal(); try { deltaRequest.setNew(isNew); - }finally{ - unlock(); + } finally { + unlockInternal(); } } } @@ -349,13 +357,13 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } public void setPrincipal(Principal principal, boolean addDeltaRequest) { + lockInternal(); try { - lock(); super.setPrincipal(principal); if (addDeltaRequest) deltaRequest.setPrincipal(principal); } finally { - unlock(); + unlockInternal(); } } @@ -371,14 +379,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } public void setAuthType(String authType, boolean addDeltaRequest) { + lockInternal(); try { - lock(); super.setAuthType(authType); if (addDeltaRequest) { deltaRequest.setAuthType(authType); } } finally { - unlock(); + unlockInternal(); } } @@ -496,12 +504,12 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus */ @Override public void recycle() { + lockInternal(); try { - lock(); super.recycle(); deltaRequest.clear(); - }finally{ - unlock(); + } finally { + unlockInternal(); } } @@ -524,14 +532,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } public void addSessionListener(SessionListener listener, boolean addDeltaRequest) { - lock(); + lockInternal(); try { super.addSessionListener(listener); if (addDeltaRequest && listener instanceof ReplicatedSessionListener) { deltaRequest.addSessionListener(listener); } } finally { - unlock(); + unlockInternal(); } } @@ -541,14 +549,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } public void removeSessionListener(SessionListener listener, boolean addDeltaRequest) { - lock(); + lockInternal(); try { super.removeSessionListener(listener); if (addDeltaRequest && listener instanceof ReplicatedSessionListener) { deltaRequest.removeSessionListener(listener); } } finally { - unlock(); + unlockInternal(); } } @@ -557,11 +565,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus @Override public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException { + lockInternal(); try { - lock(); readObjectData(in); - }finally{ - unlock(); + } finally { + unlockInternal(); } } @@ -607,12 +615,12 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus } public void resetDeltaRequest() { - lock(); + lockInternal(); try { deltaRequest.reset(); deltaRequest.setSessionId(getIdInternal()); } finally{ - unlock(); + unlockInternal(); } } @@ -629,14 +637,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus * @return The old deltaRequest */ DeltaRequest replaceDeltaRequest(DeltaRequest deltaRequest) { - lock(); + lockInternal(); try { DeltaRequest oldDeltaRequest = this.deltaRequest; this.deltaRequest = deltaRequest; this.deltaRequest.setSessionId(getIdInternal()); return oldDeltaRequest; } finally { - unlock(); + unlockInternal(); } } @@ -656,13 +664,13 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus ois.close(); DeltaRequest oldDeltaRequest = null; - lock(); + lockInternal(); try { oldDeltaRequest = replaceDeltaRequest(newDeltaRequest); newDeltaRequest.execute(this, ((ClusterManagerBase) manager).isNotifyListenersOnReplication()); setPrimarySession(false); } finally { - unlock(); + unlockInternal(); if (oldDeltaRequest != null) { oldDeltaRequest.reset(); deltaRequestPool.push(oldDeltaRequest); @@ -738,14 +746,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus return; } + lockInternal(); try { - lock(); super.setAttribute(name,value, notify); if (addDeltaRequest && !exclude(name, value)) { deltaRequest.setAttribute(name, value); } } finally { - unlock(); + unlockInternal(); } } @@ -837,11 +845,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus @Override public void writeExternal(ObjectOutput out ) throws java.io.IOException { + lockInternal(); try { - lock(); writeObject(out); - }finally { - unlock(); + } finally { + unlockInternal(); } } @@ -941,8 +949,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus protected void removeAttributeInternal(String name, boolean notify, boolean addDeltaRequest) { + lockInternal(); try { - lock(); // Remove this attribute from our collection Object value = attributes.get(name); if (value == null) return; @@ -952,8 +960,8 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus deltaRequest.removeAttribute(name); } - }finally { - unlock(); + } finally { + unlockInternal(); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org