[ 
https://issues.apache.org/jira/browse/AVRO-1808?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16678875#comment-16678875
 ] 

ASF GitHub Bot commented on AVRO-1808:
--------------------------------------

Fokko closed pull request #75: AVRO-1808. Added possibility of overriding lock 
mechanics for Requestor.handshakeLock
URL: https://github.com/apache/avro/pull/75
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java 
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
index 53799451d..225a916ed 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
@@ -128,7 +128,16 @@ public Object request(String messageName, Object request)
     throws Exception {
     request(new Request(messageName, request, new RPCContext()), callback);
   }
-  
+
+  protected void lockHandshake() {
+    handshakeLock.lock();
+  }
+
+  protected void unlockHandshake() {
+    if (handshakeLock.isHeldByCurrentThread())
+      handshakeLock.unlock();
+  }
+
   /** Writes a request message and returns the result through a Callback. */
   <T> void request(Request request, Callback<T> callback)
     throws Exception {
@@ -136,12 +145,12 @@ public Object request(String messageName, Object request)
     if (!t.isConnected()) {
       // Acquire handshake lock so that only one thread is performing the
       // handshake and other threads block until the handshake is completed
-      handshakeLock.lock();
+      lockHandshake();
       try {
         if (t.isConnected()) {
           // Another thread already completed the handshake; no need to hold
           // the write lock
-          handshakeLock.unlock();
+          unlockHandshake();
         } else {
           CallFuture<T> callFuture = new CallFuture<T>(callback);
           t.transceive(request.getBytes(),
@@ -161,9 +170,7 @@ public Object request(String messageName, Object request)
           return;
         }
       } finally{
-        if (handshakeLock.isHeldByCurrentThread()) {
-          handshakeLock.unlock();
-        }
+        unlockHandshake();
       }
     }
     
@@ -272,7 +279,7 @@ public Protocol getRemote() throws IOException {
       remote = REMOTE_PROTOCOLS.get(remoteHash);
       if (remote != null) return remote;            // already cached
     }
-    handshakeLock.lock();
+    lockHandshake();
     try {
       // force handshake
       ByteBufferOutputStream bbo = new ByteBufferOutputStream();
@@ -289,7 +296,7 @@ public Protocol getRemote() throws IOException {
       readHandshake(in);
       return this.remote;
     } finally {
-      handshakeLock.unlock();
+      unlockHandshake();
     }
   }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> It would be useful to be able to change lock mechanics for handshake at 
> Requestor 
> ----------------------------------------------------------------------------------
>
>                 Key: AVRO-1808
>                 URL: https://issues.apache.org/jira/browse/AVRO-1808
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>            Reporter: Konstantin Usachev
>            Assignee: Konstantin Usachev
>            Priority: Minor
>
> For now there is no option to change lock mechanics for handshake at 
> org.apache.avro.ipc.Requestor - it uses ReentrantLock. We can't use this type 
> of lock in our system, so we need some way to override it, like the way you 
> have already done for org.apache.avro.ipc.Transceiver.channelLock.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to