You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2019/05/23 10:31:49 UTC

[tomcat] 03/06: Refactor to create internal lock methods.

This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 658444244cbe01df02bdd10f4856a79fc5a84f77
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   | 80 ++++++++++++----------
 1 file changed, 44 insertions(+), 36 deletions(-)

diff --git a/java/org/apache/catalina/ha/session/DeltaSession.java b/java/org/apache/catalina/ha/session/DeltaSession.java
index 898d1a9..9609e24 100644
--- a/java/org/apache/catalina/ha/session/DeltaSession.java
+++ b/java/org/apache/catalina/ha/session/DeltaSession.java
@@ -137,11 +137,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
      */
     @Override
     public byte[] getDiff() throws IOException {
-        lock();
+        lockInternal();
         try {
             return getDeltaRequest().serialize();
         } finally{
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -164,7 +164,7 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
      */
     @Override
     public void applyDiff(byte[] diff, int offset, int length) throws IOException, ClassNotFoundException {
-        lock();
+        lockInternal();
         try (ObjectInputStream stream = ((ClusterManager) getManager()).getReplicationStream(diff, offset, length)) {
             ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
             try {
@@ -177,7 +177,7 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
                 Thread.currentThread().setContextClassLoader(contextLoader);
             }
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -189,19 +189,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();
     }
 
@@ -296,11 +304,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();
             }
         }
     }
@@ -319,11 +327,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();
+                unlockInternal();
             }
         }
     }
@@ -343,13 +351,13 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
     }
 
     public void setPrincipal(Principal principal, boolean addDeltaRequest) {
-        lock();
+        lockInternal();
         try {
             super.setPrincipal(principal);
             if (addDeltaRequest)
                 deltaRequest.setPrincipal(principal);
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -365,14 +373,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
     }
 
     public void setAuthType(String authType, boolean addDeltaRequest) {
-        lock();
+        lockInternal();
         try {
             super.setAuthType(authType);
             if (addDeltaRequest) {
                 deltaRequest.setAuthType(authType);
             }
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -484,12 +492,12 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
      */
     @Override
     public void recycle() {
-        lock();
+        lockInternal();
         try {
             super.recycle();
             deltaRequest.clear();
         } finally{
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -512,14 +520,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();
         }
     }
 
@@ -529,14 +537,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();
         }
     }
 
@@ -545,11 +553,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
 
     @Override
     public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
-        lock();
+        lockInternal();
         try {
             readObjectData(in);
         } finally{
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -595,12 +603,12 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
     }
 
     public void resetDeltaRequest() {
-        lock();
+        lockInternal();
         try {
             deltaRequest.reset();
             deltaRequest.setSessionId(getIdInternal());
         } finally{
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -617,14 +625,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();
         }
     }
 
@@ -644,13 +652,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);
@@ -726,14 +734,14 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
             return;
         }
 
-        lock();
+        lockInternal();
         try {
             super.setAttribute(name,value, notify);
             if (addDeltaRequest && !exclude(name, value)) {
                 deltaRequest.setAttribute(name, value);
             }
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -825,11 +833,11 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
 
     @Override
     public void writeExternal(ObjectOutput out ) throws java.io.IOException {
-        lock();
+        lockInternal();
         try {
             doWriteObject(out);
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 
@@ -921,7 +929,7 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
 
     protected void removeAttributeInternal(String name, boolean notify,
                                            boolean addDeltaRequest) {
-        lock();
+        lockInternal();
         try {
             // Remove this attribute from our collection
             Object value = attributes.get(name);
@@ -933,7 +941,7 @@ public class DeltaSession extends StandardSession implements Externalizable,Clus
             }
 
         } finally {
-            unlock();
+            unlockInternal();
         }
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org