ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject incubator-ignite git commit: #ignite-961: fix handleAsync in IgniteScriptingCommandHandler.
Date Fri, 26 Jun 2015 15:19:18 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-961 04459d27e -> 8379cd755


#ignite-961: fix handleAsync in IgniteScriptingCommandHandler.


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

Branch: refs/heads/ignite-961
Commit: 8379cd755aebf3aee98a2a9cf74e4fdca0829eaa
Parents: 04459d2
Author: ivasilinets <ivasilinets@gridgain.com>
Authored: Fri Jun 26 18:19:07 2015 +0300
Committer: ivasilinets <ivasilinets@gridgain.com>
Committed: Fri Jun 26 18:19:07 2015 +0300

----------------------------------------------------------------------
 .../IgniteScriptingCommandHandler.java          | 97 +++++++++++++++-----
 1 file changed, 72 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8379cd75/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
index 98ca7b1..2d65016 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/scripting/IgniteScriptingCommandHandler.java
@@ -33,6 +33,7 @@ import org.apache.ignite.resources.*;
 import org.jetbrains.annotations.*;
 
 import java.util.*;
+import java.util.concurrent.*;
 
 import static org.apache.ignite.internal.processors.rest.GridRestCommand.*;
 
@@ -86,37 +87,15 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             case RUN_SCRIPT: {
                 assert req instanceof RestRunScriptRequest : "Invalid type of run script
request.";
 
-                return ctx.closure().callAsync(new IgniteClosure<RestRunScriptRequest,
GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestRunScriptRequest req) {
-                        try {
-                            return new GridRestResponse(ctx.grid().compute().call(
-                                new JsFunctionCallable(req.script(), req.argument())));
-                        }
-                        catch (Exception e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                    }
-                }, (RestRunScriptRequest)req, Collections.singleton(ctx.grid().localNode()));
+                return ctx.closure().callLocalSafe(new RunScriptCallable(ctx, (RestRunScriptRequest)
req), false);
             }
 
             case EXECUTE_MAP_REDUCE_SCRIPT: {
                 assert req instanceof RestMapReduceScriptRequest :
                     "Invalid type of execute map reduce script request.";
 
-                assert SUPPORTED_COMMANDS.contains(req.command());
-
-                return ctx.closure().callAsync(new IgniteClosure<RestMapReduceScriptRequest,
GridRestResponse>() {
-                    @Override public GridRestResponse apply(RestMapReduceScriptRequest req0)
{
-                        try {
-                            return new GridRestResponse(ctx.grid().compute().execute(
-                                new JsTask(req0.mapFunction(), req0.argument(), req0.reduceFunction(),
ctx, emitRes),
-                                null));
-                        }
-                        catch (Exception e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                }
-                }, (RestMapReduceScriptRequest)req, Collections.singleton(ctx.grid().localNode()));
+                return ctx.closure().callLocalSafe(
+                    new MapReduceCallable(ctx, (RestMapReduceScriptRequest)req, emitRes));
             }
         }
 
@@ -276,4 +255,72 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             }
         }
     }
+
+    /**
+     * Run script callable.
+     */
+    private static class RunScriptCallable implements Callable<GridRestResponse> {
+        /** Kernal context. */
+        private GridKernalContext ctx;
+
+        /** Run script request. */
+        private RestRunScriptRequest req;
+
+        /**
+         * @param ctx Kernal context.
+         * @param req Run script request.
+         */
+        public RunScriptCallable(GridKernalContext ctx, RestRunScriptRequest req) {
+            this.ctx = ctx;
+            this.req = req;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                return new GridRestResponse(ctx.grid().compute().call(
+                    new JsFunctionCallable(req.script(), req.argument())));
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
+
+    /**
+     * Map reduce callable.
+     */
+    private static class MapReduceCallable implements Callable<GridRestResponse> {
+        /** Kernal context. */
+        private GridKernalContext ctx;
+
+        /** Run script request. */
+        private RestMapReduceScriptRequest req;
+
+        /** Emit results. */
+        IgniteJsEmitResult emitRes;
+
+        /**
+         * @param ctx Kernal context.
+         * @param req Run script request.
+         * @param emitRes Emit function results.
+         */
+        public MapReduceCallable(GridKernalContext ctx, RestMapReduceScriptRequest req,IgniteJsEmitResult
emitRes) {
+            this.ctx = ctx;
+            this.req = req;
+            this.emitRes = emitRes;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() throws Exception {
+            try {
+                return new GridRestResponse(ctx.grid().compute().execute(
+                    new JsTask(req.mapFunction(), req.argument(), req.reduceFunction(), ctx,
emitRes),
+                    null));
+            }
+            catch (Exception e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
 }


Mime
View raw message