ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sevdoki...@apache.org
Subject incubator-ignite git commit: IGNITE-137 IgniteCache.enableAsync() should return same instance for different call.
Date Tue, 27 Jan 2015 12:02:28 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-137 [created] f46ccf831


IGNITE-137 IgniteCache.enableAsync() should return same instance for different call.


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

Branch: refs/heads/ignite-137
Commit: f46ccf83181c4ba9f76f3dbd9ae87dc247bb94d0
Parents: 17d1b5f
Author: sevdokimov <sevdokimov@gridgain.com>
Authored: Tue Jan 27 15:01:48 2015 +0300
Committer: sevdokimov <sevdokimov@gridgain.com>
Committed: Tue Jan 27 15:01:48 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/IgniteClusterAsyncImpl.java | 10 ++------
 .../ignite/internal/IgniteComputeImpl.java      |  2 +-
 .../ignite/internal/IgniteEventsImpl.java       |  7 ++---
 .../ignite/internal/IgniteMessagingImpl.java    |  6 ++---
 .../processors/cache/IgniteCacheProxy.java      |  7 ++---
 .../processors/fs/GridGgfsAsyncImpl.java        |  7 +----
 .../ignite/lang/IgniteAsyncSupportAdapter.java  | 27 +++++++++++++++++---
 7 files changed, 35 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/IgniteClusterAsyncImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteClusterAsyncImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteClusterAsyncImpl.java
index cbcc126..a02c931 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteClusterAsyncImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteClusterAsyncImpl.java
@@ -19,9 +19,8 @@ package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
-import org.apache.ignite.internal.*;
-import org.apache.ignite.lang.*;
 import org.apache.ignite.internal.util.lang.*;
+import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
 
 import java.io.*;
@@ -30,7 +29,7 @@ import java.util.*;
 /**
  *
  */
-public class IgniteClusterAsyncImpl extends IgniteAsyncSupportAdapter implements IgniteCluster
{
+public class IgniteClusterAsyncImpl extends IgniteAsyncSupportAdapter<IgniteCluster>
implements IgniteCluster {
     /** */
     private final GridKernal grid;
 
@@ -123,11 +122,6 @@ public class IgniteClusterAsyncImpl extends IgniteAsyncSupportAdapter
implements
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteCluster enableAsync() {
-        return this;
-    }
-
-    /** {@inheritDoc} */
     @Override public Ignite ignite() {
         return grid.ignite();
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java
index 84dc748..afd2b54 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComputeImpl.java
@@ -49,7 +49,7 @@ public class IgniteComputeImpl implements IgniteCompute, Externalizable
{
     private UUID subjId;
 
     /** */
-    private IgniteAsyncSupportAdapter asyncSup;
+    private IgniteAsyncSupportAdapter<IgniteAsyncSupport> asyncSup;
 
     /**
      * Required by {@link Externalizable}.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
index 126b8de..579f1f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteEventsImpl.java
@@ -31,7 +31,7 @@ import java.util.*;
 /**
  * {@link org.apache.ignite.IgniteEvents} implementation.
  */
-public class IgniteEventsImpl extends IgniteAsyncSupportAdapter implements IgniteEvents,
Externalizable {
+public class IgniteEventsImpl extends IgniteAsyncSupportAdapter<IgniteEvents> implements
IgniteEvents, Externalizable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -270,10 +270,7 @@ public class IgniteEventsImpl extends IgniteAsyncSupportAdapter implements
Ignit
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteEvents enableAsync() {
-        if (isAsync())
-            return this;
-
+    @Override protected IgniteEvents createAsyncInstance() {
         return new IgniteEventsImpl(ctx, prj, true);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
index fe82ac5..3784799 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteMessagingImpl.java
@@ -19,10 +19,10 @@ package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
 import org.apache.ignite.cluster.*;
-import org.apache.ignite.lang.*;
 import org.apache.ignite.internal.processors.continuous.*;
 import org.apache.ignite.internal.util.typedef.*;
 import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.lang.*;
 import org.jetbrains.annotations.*;
 
 import java.io.*;
@@ -31,7 +31,7 @@ import java.util.*;
 /**
  * {@link org.apache.ignite.IgniteMessaging} implementation.
  */
-public class IgniteMessagingImpl extends IgniteAsyncSupportAdapter implements IgniteMessaging,
Externalizable {
+public class IgniteMessagingImpl extends IgniteAsyncSupportAdapter<IgniteMessaging>
implements IgniteMessaging, Externalizable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -195,7 +195,7 @@ public class IgniteMessagingImpl extends IgniteAsyncSupportAdapter implements
Ig
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteMessaging enableAsync() {
+    @Override protected IgniteMessaging createAsyncInstance() {
         return new IgniteMessagingImpl(ctx, prj, true);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 63c1f65..b4d6fdc 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -41,7 +41,7 @@ import java.util.concurrent.locks.*;
 /**
  * Cache proxy.
  */
-public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter implements IgniteCache<K,
V>, Externalizable {
+public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter<IgniteCache<K,
V>> implements IgniteCache<K, V>, Externalizable {
     /** */
     private static final long serialVersionUID = 0L;
 
@@ -963,10 +963,7 @@ public class IgniteCacheProxy<K, V> extends IgniteAsyncSupportAdapter
implements
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteCache<K, V> enableAsync() {
-        if (isAsync())
-            return this;
-
+    @Override protected IgniteCache<K, V> createAsyncInstance() {
         return new IgniteCacheProxy<>(ctx, delegate, prj, true);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAsyncImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAsyncImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAsyncImpl.java
index 80154c0..58de369 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAsyncImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/fs/GridGgfsAsyncImpl.java
@@ -29,7 +29,7 @@ import java.util.*;
 /**
  * Ggfs supporting asynchronous operations.
  */
-public class GridGgfsAsyncImpl extends IgniteAsyncSupportAdapter implements GridGgfsEx {
+public class GridGgfsAsyncImpl extends IgniteAsyncSupportAdapter<IgniteFs> implements
GridGgfsEx {
     /** */
     private final GridGgfsImpl ggfs;
 
@@ -43,11 +43,6 @@ public class GridGgfsAsyncImpl extends IgniteAsyncSupportAdapter implements
Grid
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteFs enableAsync() {
-        return this;
-    }
-
-    /** {@inheritDoc} */
     @Override public void format() throws IgniteCheckedException {
         saveOrGet(ggfs.formatAsync());
     }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/f46ccf83/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupportAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupportAdapter.java
b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupportAdapter.java
index f23abaf..40c0297 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupportAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteAsyncSupportAdapter.java
@@ -22,10 +22,13 @@ import org.apache.ignite.*;
 /**
  * Adapter for {@link IgniteAsyncSupport}.
  */
-public class IgniteAsyncSupportAdapter implements IgniteAsyncSupport {
+public class IgniteAsyncSupportAdapter<T extends IgniteAsyncSupport> implements IgniteAsyncSupport
{
     /** Future for previous asynchronous operation. */
     protected ThreadLocal<IgniteFuture<?>> curFut;
 
+    /** */
+    protected volatile T asyncInstance;
+
     /**
      * Default constructor.
      */
@@ -37,12 +40,30 @@ public class IgniteAsyncSupportAdapter implements IgniteAsyncSupport {
      * @param async Async enabled flag.
      */
     public IgniteAsyncSupportAdapter(boolean async) {
-        if (async)
+        if (async) {
             curFut = new ThreadLocal<>();
+
+            asyncInstance = (T)this;
+        }
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteAsyncSupport enableAsync() {
+    @Override public T enableAsync() {
+        T res = asyncInstance;
+
+        if (res == null) {
+            res = createAsyncInstance();
+
+            asyncInstance = res;
+        }
+
+        return res;
+    }
+
+    /**
+     * Creates component with asynchronous mode enabled.
+     */
+    protected T createAsyncInstance() {
         throw new UnsupportedOperationException();
     }
 


Mime
View raw message