ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yzhda...@apache.org
Subject [50/50] [abbrv] ignite git commit: review
Date Wed, 18 Nov 2015 13:41:06 GMT
review


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

Branch: refs/heads/ignite-638
Commit: 580e6a4ccdc5f9be43bb7659db66abe705b9f68c
Parents: 0058465
Author: Yakov Zhdanov <yzhdanov@gridgain.com>
Authored: Wed Nov 18 16:39:43 2015 +0300
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Wed Nov 18 16:39:43 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/internal/IgniteKernal.java    | 10 +--
 .../datastructures/DataStructuresProcessor.java | 24 +++----
 .../datastructures/GridCacheSemaphoreImpl.java  | 72 +++++++++-----------
 3 files changed, 52 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/580e6a4c/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 62693db..bd984f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -2937,10 +2937,12 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public IgniteSemaphore semaphore(String name,
-       int cnt,
-       boolean fair,
-       boolean create) {
+    @Nullable @Override public IgniteSemaphore semaphore(
+        String name,
+        int cnt,
+        boolean fair,
+        boolean create
+    ) {
         guard();
 
         try {

http://git-wip-us.apache.org/repos/asf/ignite/blob/580e6a4c/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
index 847bf14..7b7f97a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
@@ -42,10 +42,10 @@ import org.apache.ignite.IgniteAtomicSequence;
 import org.apache.ignite.IgniteAtomicStamped;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCountDownLatch;
-import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteSemaphore;
 import org.apache.ignite.IgniteSet;
 import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
 import org.apache.ignite.configuration.AtomicConfiguration;
@@ -80,7 +80,6 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.GPR;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgnitePredicate;
 import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 
@@ -95,8 +94,8 @@ import static org.apache.ignite.internal.processors.datastructures.DataStructure
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.ATOMIC_STAMPED;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.COUNT_DOWN_LATCH;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.QUEUE;
-import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SET;
 import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SEMAPHORE;
+import static org.apache.ignite.internal.processors.datastructures.DataStructuresProcessor.DataStructureType.SET;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
 
@@ -140,7 +139,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
     private IgniteInternalCache<GridCacheInternalKey, GridCacheCountDownLatchValue>
cntDownLatchView;
 
     /** Cache contains only {@code GridCacheSemaphoreState}. */
-    private IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semaphoreView;
+    private IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semView;
 
     /** Cache contains only {@code GridCacheAtomicReferenceValue}. */
     private IgniteInternalCache<GridCacheInternalKey, GridCacheAtomicReferenceValue>
atomicRefView;
@@ -198,7 +197,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
 
             cntDownLatchView = atomicsCache;
 
-            semaphoreView = atomicsCache;
+            semView = atomicsCache;
 
             atomicLongView = atomicsCache;
 
@@ -1259,7 +1258,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
                     final GridCacheSemaphoreEx sem0 = new GridCacheSemaphoreImpl(
                         name,
                         key,
-                        semaphoreView,
+                        semView,
                         dsCacheCtx);
 
                     dsCacheCtx.gridEvents().addLocalEventListener(
@@ -1465,19 +1464,19 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
                         GridCacheInternalKey key = evt.getKey();
 
                         // Notify semaphore on changes.
-                        final GridCacheRemovable semaphore = dsMap.get(key);
+                        final GridCacheRemovable sem = dsMap.get(key);
 
                         GridCacheSemaphoreState val = (GridCacheSemaphoreState)val0;
 
-                        if (semaphore instanceof GridCacheSemaphoreEx) {
-                            final GridCacheSemaphoreEx semaphore0 = (GridCacheSemaphoreEx)semaphore;
+                        if (sem instanceof GridCacheSemaphoreEx) {
+                            final GridCacheSemaphoreEx semaphore0 = (GridCacheSemaphoreEx)sem;
 
                             semaphore0.onUpdate(val);
                         }
-                        else if (semaphore != null) {
+                        else if (sem != null) {
                             U.error(log, "Failed to cast object " +
                                     "[expected=" + IgniteSemaphore.class.getSimpleName()
+
-                                    ", actual=" + semaphore.getClass() + ", value=" + semaphore
+ ']');
+                                    ", actual=" + sem.getClass() + ", value=" + sem + ']');
                         }
                     }
 
@@ -1569,7 +1568,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter
{
      * @return Removed value.
      */
     @SuppressWarnings("unchecked")
-    @Nullable private <T> T retryRemove(final IgniteInternalCache cache, final Object
key) throws IgniteCheckedException {
+    @Nullable private <T> T retryRemove(final IgniteInternalCache cache, final Object
key)
+        throws IgniteCheckedException {
         return retry(log, new Callable<T>() {
             @Nullable @Override public T call() throws Exception {
                 return (T)cache.getAndRemove(key);

http://git-wip-us.apache.org/repos/asf/ignite/blob/580e6a4c/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
index b4a6b26..a62c13a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheSemaphoreImpl.java
@@ -79,7 +79,7 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
     private GridCacheInternalKey key;
 
     /** Semaphore projection. */
-    private IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semaphoreView;
+    private IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semView;
 
     /** Cache context. */
     private GridCacheContext ctx;
@@ -139,27 +139,24 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
          */
         public int getWaiters() {
             int totalWaiters = 0;
-            for(UUID id:nodeMap.keySet()){
-                if(nodeMap.get(id)>0){
+
+            for (Integer i : nodeMap.values()) {
+                if (i > 0)
                     totalWaiters++;
-                }
             }
+
             return totalWaiters;
         }
 
         /**
          * Get number of permits for node.
          *
-         * @param nodeID
+         * @param nodeID Node ID.
          * @return Number of permits node has acquired at this semaphore. Can be less than
0 if
          * more permits were released than acquired on node.
          */
         public int getPermitsForNode(UUID nodeID){
-            int ret = 0;
-            if(nodeMap.containsKey(nodeID)){
-                ret = nodeMap.get(nodeID);
-            }
-            return ret;
+            return nodeMap.containsKey(nodeID) ? nodeMap.get(nodeID) : 0;
         }
 
         /**
@@ -188,7 +185,7 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
          * @return Negative number if thread should block, positive if thread successfully
acquires permits.
          */
         final int nonfairTryAcquireShared(int acquires) {
-            for (; ; ) {
+            for (;;) {
                 int available = getState();
 
                 int remaining = available - acquires;
@@ -211,15 +208,15 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
             if (releases == 0)
                 return true;
 
-            for (; ; ) {
-                int current = getState();
+            for (;;) {
+                int cur = getState();
 
-                int next = current + releases;
+                int next = cur + releases;
 
-                if (next < current) // overflow
+                if (next < cur) // overflow
                     throw new Error("Maximum permit count exceeded");
 
-                if (compareAndSetGlobalState(current, next, false))
+                if (compareAndSetGlobalState(cur, next, false))
                     return true;
             }
         }
@@ -230,7 +227,7 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
          * @return Number of permits to drain.
          */
         final int drainPermits() {
-            for (; ; ) {
+            for (;;) {
 
                 int current = getState();
 
@@ -252,10 +249,11 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
                 return CU.outTx(
                     retryTopologySafe(new Callable<Boolean>() {
                         @Override public Boolean call() throws Exception {
-                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, semaphoreView,
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx,
+                                semView,
                                     PESSIMISTIC, REPEATABLE_READ)
                             ) {
-                                GridCacheSemaphoreState val = semaphoreView.get(key);
+                                GridCacheSemaphoreState val = semView.get(key);
 
                                 if (val == null)
                                     throw new IgniteCheckedException("Failed to find semaphore
with given name: " +
@@ -283,7 +281,7 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
 
                                     val.setCount(newVal);
 
-                                    semaphoreView.put(key, val);
+                                    semView.put(key, val);
 
                                     tx.commit();
                                 }
@@ -317,10 +315,11 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
                     retryTopologySafe(new Callable<Boolean>() {
                         @Override public Boolean call() throws Exception {
                             try (
-                                IgniteInternalTx tx = CU.txStartInternal(ctx, semaphoreView,
+                                IgniteInternalTx tx = CU.txStartInternal(ctx,
+                                    semView,
                                     PESSIMISTIC, REPEATABLE_READ)
                             ) {
-                                GridCacheSemaphoreState val = semaphoreView.get(key);
+                                GridCacheSemaphoreState val = semView.get(key);
 
                                 if (val == null)
                                     throw new IgniteCheckedException("Failed to find semaphore
with given name: " +
@@ -343,7 +342,7 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
 
                                 val.setWaiters(map);
 
-                                semaphoreView.put(key, val);
+                                semView.put(key, val);
 
                                 sync.nodeMap = map;
 
@@ -372,23 +371,23 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
      *
      * @param name Semaphore name.
      * @param key Semaphore key.
-     * @param semaphoreView Semaphore projection.
+     * @param semView Semaphore projection.
      * @param ctx Cache context.
      */
     public GridCacheSemaphoreImpl(
         String name,
         GridCacheInternalKey key,
-        IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semaphoreView,
+        IgniteInternalCache<GridCacheInternalKey, GridCacheSemaphoreState> semView,
         GridCacheContext ctx
     ) {
         assert name != null;
         assert key != null;
-        assert semaphoreView != null;
+        assert semView != null;
         assert ctx != null;
 
         this.name = name;
         this.key = key;
-        this.semaphoreView = semaphoreView;
+        this.semView = semView;
         this.ctx = ctx;
 
         log = ctx.logger(getClass());
@@ -403,8 +402,9 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
                 sync = CU.outTx(
                     retryTopologySafe(new Callable<Sync>() {
                         @Override public Sync call() throws Exception {
-                            try (IgniteInternalTx tx = CU.txStartInternal(ctx, semaphoreView,
PESSIMISTIC, REPEATABLE_READ)) {
-                                GridCacheSemaphoreState val = semaphoreView.get(key);
+                            try (IgniteInternalTx tx = CU.txStartInternal(ctx,
+                                semView, PESSIMISTIC, REPEATABLE_READ)) {
+                                GridCacheSemaphoreState val = semView.get(key);
 
                                 if (val == null) {
                                     if (log.isDebugEnabled())
@@ -482,23 +482,20 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
         int numPermits = sync.getPermitsForNode(nodeID);
 
         if (numPermits > 0) {
-            if (sync.failoverSafe) {
+            if (sync.failoverSafe)
                 // Release permits acquired by threads on failing node.
                 sync.releaseFailedNode(nodeID);
-            }
             else {
                 // Interrupt every waiting thread if this semaphore is not failover safe.
                 sync.broken = true;
 
-                for(Thread t:sync.getSharedQueuedThreads()){
+                for (Thread t : sync.getSharedQueuedThreads())
                     t.interrupt();
-                }
 
                 // Try to notify any waiting threads.
                 sync.releaseShared(0);
             }
         }
-
     }
 
     /** {@inheritDoc} */
@@ -567,9 +564,10 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
                 retryTopologySafe(new Callable<Integer>() {
                     @Override public Integer call() throws Exception {
                         try (
-                            IgniteInternalTx tx = CU.txStartInternal(ctx, semaphoreView,
PESSIMISTIC, REPEATABLE_READ)
+                            IgniteInternalTx tx = CU.txStartInternal(ctx,
+                                semView, PESSIMISTIC, REPEATABLE_READ)
                         ) {
-                            GridCacheSemaphoreState val = semaphoreView.get(key);
+                            GridCacheSemaphoreState val = semView.get(key);
 
                             if (val == null)
                                 throw new IgniteException("Failed to find semaphore with
given name: " + name);
@@ -745,6 +743,4 @@ public final class GridCacheSemaphoreImpl implements GridCacheSemaphoreEx,
Exter
     @Override public String toString() {
         return S.toString(GridCacheSemaphoreImpl.class, this);
     }
-
 }
-


Mime
View raw message