You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/06/24 14:48:38 UTC

[3/7] incubator-ignite git commit: #ignite-965: remove anonymous classes.

#ignite-965: remove anonymous classes.


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

Branch: refs/heads/ignite-965
Commit: 53e5be79236f9872e50e93899c0c58a32ca669bd
Parents: 529d2e5
Author: ivasilinets <iv...@gridgain.com>
Authored: Wed Jun 24 14:59:08 2015 +0300
Committer: ivasilinets <iv...@gridgain.com>
Committed: Wed Jun 24 14:59:08 2015 +0300

----------------------------------------------------------------------
 .../IgniteScriptingCommandHandler.java          | 112 +++++++++++++------
 1 file changed, 77 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/53e5be79/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 c43c81e..54dffe2 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
@@ -87,20 +87,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
 
                 final RestRunScriptRequest req0 = (RestRunScriptRequest) req;
 
-                GridRestResponse res = ctx.grid().compute().call(new IgniteCallable<GridRestResponse>() {
-                    @IgniteInstanceResource
-                    private Ignite ignite;
-
-                    @Override public GridRestResponse call() {
-                        try {
-                            return new GridRestResponse(((IgniteKernal)ignite).
-                                context().scripting().invokeFunction(req0.script()));
-                        }
-                        catch (IgniteCheckedException e) {
-                            return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
-                        }
-                    }
-                });
+                GridRestResponse res = ctx.grid().compute().call(new JsFunctionCallable(req0.script()));
 
                 return new GridFinishedFuture<>(res);
             }
@@ -113,10 +100,10 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
 
                 final RestMapReduceScriptRequest req0 = (RestMapReduceScriptRequest) req;
 
-                GridRestResponse execRes = ctx.grid().compute().execute(
+                GridRestResponse res = ctx.grid().compute().execute(
                     new JsTask(req0.mapFunction(), req0.argument(), req0.reduceFunction(), ctx), null);
 
-                return new GridFinishedFuture<>(execRes);
+                return new GridFinishedFuture<>(res);
             }
         }
 
@@ -166,23 +153,8 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
                 for (Object jobMapping : jsMapRes) {
                     List task = (List)jobMapping;
 
-                    final String func = (String)task.get(0);
-                    final Object argv = task.get(1);
-                    ClusterNode node = (ClusterNode)task.get(2);
-
-                    map.put(new ComputeJobAdapter() {
-                        @IgniteInstanceResource
-                        private Ignite ignite;
-
-                        @Override public Object execute() throws IgniteException {
-                            try {
-                                return ((IgniteKernal)ignite).context().scripting().invokeFunction(func, argv);
-                            }
-                            catch (IgniteCheckedException e) {
-                               throw U.convertException(e);
-                            }
-                        }
-                    }, node);
+                    map.put(new JsCallFunctionJob((String)task.get(0), task.get(1)),
+                        (ClusterNode)task.get(2));
                 }
 
                 return map;
@@ -195,7 +167,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
         /** {@inheritDoc} */
         @Nullable @Override public GridRestResponse reduce(List<ComputeJobResult> results) {
             try {
-                String[] data = new String[results.size()];
+                Object[] data = new Object[results.size()];
 
                 for (int i = 0; i < results.size(); ++i) {
                     IgniteException err = results.get(i).getException();
@@ -203,7 +175,7 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
                     if (err != null)
                         return new GridRestResponse(GridRestResponse.STATUS_FAILED, err.getMessage());
 
-                    data[i] = results.get(i).getData().toString();
+                    data[i] = results.get(i).getData();
                 }
 
                 return new GridRestResponse(ctx.scripting().invokeFunction(reduceFunc, (Object)data));
@@ -213,4 +185,74 @@ public class IgniteScriptingCommandHandler extends GridRestCommandHandlerAdapter
             }
         }
     }
+
+    /**
+     * Js call function job.
+     */
+    private static class JsCallFunctionJob extends ComputeJobAdapter {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Function to call. */
+        private String func;
+
+        /** Function argument. */
+        private Object argv;
+
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /**
+         * @param func Function to call.
+         * @param argv Function argument.
+         */
+        public JsCallFunctionJob(String func, Object argv) {
+            this.func = func;
+            this.argv = argv;
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object execute() throws IgniteException {
+            try {
+                return ((IgniteKernal)ignite).context().scripting().invokeFunction(func, argv);
+            }
+            catch (IgniteCheckedException e) {
+                throw U.convertException(e);
+            }
+        }
+    }
+
+    /**
+     * Call java script function.
+     */
+    private static class JsFunctionCallable implements IgniteCallable<GridRestResponse> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** Function to call. */
+        private String func;
+
+        /** Ignite instance. */
+        @IgniteInstanceResource
+        private Ignite ignite;
+
+        /**
+         * @param func Function to call.
+         */
+        public JsFunctionCallable(String func) {
+            this.func = func;
+        }
+
+        /** {@inheritDoc} */
+        @Override public GridRestResponse call() {
+            try {
+                return new GridRestResponse(((IgniteKernal)ignite).
+                    context().scripting().invokeFunction(func));
+            }
+            catch (IgniteCheckedException e) {
+                return new GridRestResponse(GridRestResponse.STATUS_FAILED, e.getMessage());
+            }
+        }
+    }
 }