ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject ignite git commit: IGNITE-2760: Implemented.
Date Fri, 04 Mar 2016 09:17:23 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-2760 [created] 9fe4e158f


IGNITE-2760: Implemented.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9fe4e158
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9fe4e158
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9fe4e158

Branch: refs/heads/ignite-2760
Commit: 9fe4e158f01475187c3932872fb3b3935855defb
Parents: c13339f
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Mar 4 12:17:01 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Mar 4 12:17:01 2016 +0300

----------------------------------------------------------------------
 .../nio/GridAbstractCommunicationClient.java    | 60 +++++++++++---------
 .../util/nio/GridCommunicationClient.java       |  7 +--
 .../util/nio/GridShmemCommunicationClient.java  |  4 +-
 .../util/nio/GridTcpNioCommunicationClient.java |  4 +-
 .../communication/tcp/TcpCommunicationSpi.java  |  2 +-
 5 files changed, 40 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9fe4e158/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridAbstractCommunicationClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridAbstractCommunicationClient.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridAbstractCommunicationClient.java
index 9b014ec..9ac2ce6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridAbstractCommunicationClient.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridAbstractCommunicationClient.java
@@ -26,6 +26,9 @@ import org.jetbrains.annotations.Nullable;
  * Implements basic lifecycle for communication clients.
  */
 public abstract class GridAbstractCommunicationClient implements GridCommunicationClient
{
+    /** Close mask. */
+    private static int CLOSE_MASK = 1 << 30;
+
     /** Time when this client was last used. */
     private volatile long lastUsed = U.currentTimeMillis();
 
@@ -43,54 +46,54 @@ public abstract class GridAbstractCommunicationClient implements GridCommunicati
     }
 
     /** {@inheritDoc} */
-    @Override public boolean close() {
-        return reserves.compareAndSet(0, -1);
+    @Override public boolean tryClose() {
+        return reserves.compareAndSet(0, CLOSE_MASK);
     }
 
     /** {@inheritDoc} */
     @Override public void forceClose() {
-        reserves.set(-1);
+        while (true) {
+            int cur = reserves.get();
+
+            if (closed0(cur))
+                return;
+
+            if (reserves.compareAndSet(cur, cur | CLOSE_MASK))
+                return;
+        }
     }
 
     /** {@inheritDoc} */
     @Override public boolean closed() {
-        return reserves.get() == -1;
+        return closed0(reserves.get());
     }
 
     /** {@inheritDoc} */
     @Override public boolean reserve() {
-        while (true) {
-            int r = reserves.get();
+        int cur = reserves.incrementAndGet();
 
-            if (r == -1)
-                return false;
+        if (closed0(cur)) {
+            release();
 
-            if (reserves.compareAndSet(r, r + 1))
-                return true;
+            return false;
         }
+
+        return true;
     }
 
     /** {@inheritDoc} */
     @Override public void release() {
-        while (true) {
-            int r = reserves.get();
-
-            if (r == -1)
-                return;
-
-            if (reserves.compareAndSet(r, r - 1))
-                return;
-        }
+        reserves.decrementAndGet();
     }
 
     /** {@inheritDoc} */
-    @Override public boolean reserved() {
-        return reserves.get() > 0;
+    @Override public long getIdleTime() {
+        return U.currentTimeMillis() - lastUsed;
     }
 
     /** {@inheritDoc} */
-    @Override public long getIdleTime() {
-        return U.currentTimeMillis() - lastUsed;
+    @Override public boolean async() {
+        return false;
     }
 
     /**
@@ -100,9 +103,14 @@ public abstract class GridAbstractCommunicationClient implements GridCommunicati
         lastUsed = U.currentTimeMillis();
     }
 
-    /** {@inheritDoc} */
-    @Override public boolean async() {
-        return false;
+    /**
+     * Check if value represents closed client.
+     *
+     * @param val Value.
+     * @return {@code True} if closed.
+     */
+    private static boolean closed0(int val) {
+        return (val & CLOSE_MASK) == CLOSE_MASK;
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/9fe4e158/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java
index 0de54e9..74feb44 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridCommunicationClient.java
@@ -46,7 +46,7 @@ public interface GridCommunicationClient {
      * @return {@code True} if client has been closed by this call,
      *      {@code false} if failed to close client (due to concurrent reservation or concurrent
close).
      */
-    public boolean close();
+    public boolean tryClose();
 
     /**
      * Forces client close.
@@ -69,11 +69,6 @@ public interface GridCommunicationClient {
     public void release();
 
     /**
-     * @return {@code True} if client was reserved.
-     */
-    public boolean reserved();
-
-    /**
      * Gets idle time of this client.
      *
      * @return Idle time of this client.

http://git-wip-us.apache.org/repos/asf/ignite/blob/9fe4e158/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java
index ebe86fb..2b6df5d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridShmemCommunicationClient.java
@@ -84,8 +84,8 @@ public class GridShmemCommunicationClient extends GridAbstractCommunicationClien
     }
 
     /** {@inheritDoc} */
-    @Override public boolean close() {
-        boolean res = super.close();
+    @Override public boolean tryClose() {
+        boolean res = super.tryClose();
 
         if (res)
             shmem.close();

http://git-wip-us.apache.org/repos/asf/ignite/blob/9fe4e158/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
index 4022bc5..e8dabca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/nio/GridTcpNioCommunicationClient.java
@@ -71,8 +71,8 @@ public class GridTcpNioCommunicationClient extends GridAbstractCommunicationClie
     }
 
     /** {@inheritDoc} */
-    @Override public boolean close() {
-        boolean res = super.close();
+    @Override public boolean tryClose() {
+        boolean res = super.tryClose();
 
         if (res)
             ses.close();

http://git-wip-us.apache.org/repos/asf/ignite/blob/9fe4e158/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
index 2a078ee..0d6b930 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/communication/tcp/TcpCommunicationSpi.java
@@ -3110,7 +3110,7 @@ public class TcpCommunicationSpi extends IgniteSpiAdapter
                     if (log.isDebugEnabled())
                         log.debug("Closing idle node connection: " + nodeId);
 
-                    if (client.close() || client.closed())
+                    if (client.tryClose() || client.closed())
                         clients.remove(nodeId, client);
                 }
             }


Mime
View raw message