Repository: incubator-ignite Updated Branches: refs/heads/ignite-1155_1 ae97de87e -> e3162d203
ignite-1155 Fix problems found on review. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/e3162d20 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/e3162d20 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/e3162d20 Branch: refs/heads/ignite-1155_1 Commit: e3162d203e89457f8e94658709476d5b29362990 Parents: ae97de8 Author: sevdokimov <sergey.evdoki...@jetbrains.com> Authored: Fri Jul 31 12:11:04 2015 +0300 Committer: sevdokimov <sergey.evdoki...@jetbrains.com> Committed: Fri Jul 31 12:11:04 2015 +0300 ---------------------------------------------------------------------- modules/control-center-agent/README.txt | 4 +- .../apache/ignite/agent/AgentCommandLine.java | 116 --------- .../ignite/agent/AgentCommandLineOptions.java | 116 +++++++++ .../apache/ignite/agent/AgentConfiguration.java | 2 +- .../org/apache/ignite/agent/AgentLauncher.java | 4 +- .../org/apache/ignite/agent/AgentSocket.java | 6 +- .../apache/ignite/agent/WebSocketSender.java | 39 --- .../ignite/agent/remote/RemoteCallable.java | 248 ------------------- .../ignite/agent/remote/RemoteHandler.java | 248 +++++++++++++++++++ .../ignite/agent/remote/WebSocketSender.java | 39 +++ .../apache/ignite/schema/parser/DBReader.java | 2 +- 11 files changed, 412 insertions(+), 412 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/README.txt ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/README.txt b/modules/control-center-agent/README.txt index 29abc2f..99d14a8 100644 --- a/modules/control-center-agent/README.txt +++ b/modules/control-center-agent/README.txt @@ -5,7 +5,7 @@ Control Center Agent communicates with grid nodes via REST interface and connect --------------------------- Usage example: -agent.sh -l ivan.iva...@gmail.com -p qwerty -s wss://control-center.gridgain.com +agent.sh -l john.sm...@gmail.com -p qwerty -s wss://control-center.gridgain.com Command line arguments: -l User's login (email) on web-control-center @@ -17,4 +17,4 @@ Command line arguments: --------------------------- Building module: -to build module run "mvn package" \ No newline at end of file +to build module run "mvn package" http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java deleted file mode 100644 index b9dfb76..0000000 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLine.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.agent; - -import com.beust.jcommander.*; - -/** - * Command line bean. - */ -public class AgentCommandLine { - /** */ - @Parameter(names = {"-l", "--login"}, description = "User's login (email) on web-control-center") - private String login; - - /** */ - @Parameter(names = {"-p", "--password"}, description = "User's password") - private String pwd; - - /** */ - @Parameter(names = {"-s", "--serverUri"}, - description = "Link to web-control-center web-socket server, for example: wss://control-center.gridgain.com") - private String serverUri; - - /** */ - @Parameter(names = {"-n", "--nodeUri"}, description = "ignite REST server, for example: http://localhost:8080") - private String nodeUri; - - /** */ - @Parameter(names = {"-c", "--config"}, description = "Path to configuration file") - private String cfgPath; - - /** - * @return Login. - */ - public String getLogin() { - return login; - } - - /** - * @param login Login. - */ - public void setLogin(String login) { - this.login = login; - } - - /** - * @return Password. - */ - public String getPassword() { - return pwd; - } - - /** - * @param pwd Password. - */ - public void setPassword(String pwd) { - this.pwd = pwd; - } - - /** - * @return Server URI. - */ - public String getServerUri() { - return serverUri; - } - - /** - * @param srvUri Server uri. - */ - public void setServerUri(String srvUri) { - serverUri = srvUri; - } - - /** - * @return Node URI. - */ - public String getNodeUri() { - return nodeUri; - } - - /** - * @param nodeUri Node uri. - */ - public void setNodeUri(String nodeUri) { - this.nodeUri = nodeUri; - } - - /** - * @return Config file URL. - */ - public String getConfigFile() { - return cfgPath; - } - - /** - * @param cfgPath Config path. - */ - public void setConfigPath(String cfgPath) { - this.cfgPath = cfgPath; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLineOptions.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLineOptions.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLineOptions.java new file mode 100644 index 0000000..5b45f5a --- /dev/null +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentCommandLineOptions.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.agent; + +import com.beust.jcommander.*; + +/** + * Command line bean. + */ +public class AgentCommandLineOptions { + /** */ + @Parameter(names = {"-l", "--login"}, description = "User's login (email) on web-control-center") + private String login; + + /** */ + @Parameter(names = {"-p", "--password"}, description = "User's password") + private String pwd; + + /** */ + @Parameter(names = {"-s", "--serverUri"}, + description = "Link to web-control-center web-socket server, for example: wss://control-center.gridgain.com") + private String serverUri; + + /** */ + @Parameter(names = {"-n", "--nodeUri"}, description = "ignite REST server, for example: http://localhost:8080") + private String nodeUri; + + /** */ + @Parameter(names = {"-c", "--config"}, description = "Path to configuration file") + private String cfgPath; + + /** + * @return Login. + */ + public String getLogin() { + return login; + } + + /** + * @param login Login. + */ + public void setLogin(String login) { + this.login = login; + } + + /** + * @return Password. + */ + public String getPassword() { + return pwd; + } + + /** + * @param pwd Password. + */ + public void setPassword(String pwd) { + this.pwd = pwd; + } + + /** + * @return Server URI. + */ + public String getServerUri() { + return serverUri; + } + + /** + * @param srvUri Server uri. + */ + public void setServerUri(String srvUri) { + serverUri = srvUri; + } + + /** + * @return Node URI. + */ + public String getNodeUri() { + return nodeUri; + } + + /** + * @param nodeUri Node uri. + */ + public void setNodeUri(String nodeUri) { + this.nodeUri = nodeUri; + } + + /** + * @return Config file URL. + */ + public String getConfigFile() { + return cfgPath; + } + + /** + * @param cfgPath Config path. + */ + public void setConfigPath(String cfgPath) { + this.cfgPath = cfgPath; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java index 9f01983..6b44086 100644 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentConfiguration.java @@ -127,7 +127,7 @@ public class AgentConfiguration { /** * @param cmd Command. */ - public void assign(AgentCommandLine cmd) { + public void assign(AgentCommandLineOptions cmd) { if (cmd.getLogin() != null) setLogin(cmd.getLogin()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java index c3ba096..d45be43 100644 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentLauncher.java @@ -56,7 +56,7 @@ public class AgentLauncher { cfg.load(dfltCfgUrl); - AgentCommandLine cmdCfg = new AgentCommandLine(); + AgentCommandLineOptions cmdCfg = new AgentCommandLineOptions(); new JCommander(cmdCfg, args); @@ -103,7 +103,7 @@ public class AgentLauncher { client.start(); try { - while (true) { + while (!Thread.interrupted()) { AgentSocket agentSock = new AgentSocket(cfg, restExecutor); log.log(Level.INFO, "Connecting to: " + cfg.getServerUri()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java index 95e499e..9370160 100644 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/AgentSocket.java @@ -31,7 +31,7 @@ import java.util.concurrent.*; import java.util.logging.*; /** - * + * Handler for web-socket connection. */ @WebSocket public class AgentSocket implements WebSocketSender { @@ -48,7 +48,7 @@ public class AgentSocket implements WebSocketSender { private final RestExecutor restExecutor; /** */ - private RemoteCallable remote; + private RemoteHandler remote; /** */ private Session ses; @@ -84,7 +84,7 @@ public class AgentSocket implements WebSocketSender { this.ses = ses; - remote = RemoteCallable.wrap(this, this, restExecutor); + remote = RemoteHandler.wrap(this, this, restExecutor); JsonObject authMsg = new JsonObject(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/WebSocketSender.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/WebSocketSender.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/WebSocketSender.java deleted file mode 100644 index 6d16c14..0000000 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/WebSocketSender.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.agent; - -import com.google.gson.*; - -/** - * - */ -public interface WebSocketSender { - /** - * Send message. - * @param msg Message. - * @return {@code true} if message sent successfully. - */ - public boolean send(String msg); - - /** - * Send message. - * @param msg Message. - * @return {@code true} if message sent successfully. - */ - public boolean send(JsonObject msg); -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteCallable.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteCallable.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteCallable.java deleted file mode 100644 index 6f1fb19..0000000 --- a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteCallable.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.agent.remote; - -import com.google.gson.*; -import org.apache.ignite.agent.*; - -import java.lang.reflect.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.logging.*; - -/** - * Allow to execute methods remotely from NodeJS server by web-socket command. - */ -public class RemoteCallable implements AutoCloseable { - /** */ - private static final Logger log = Logger.getLogger(RemoteCallable.class.getName()); - - /** */ - private final WebSocketSender snd; - - /** */ - private final Map<String, MethodDescriptor> methods = new HashMap<>(); - - /** */ - private final ExecutorService executorSrvc = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); - - /** - * @param snd Session. - * @param hnds Handlers. - */ - private RemoteCallable(WebSocketSender snd, Object ... hnds) { - this.snd = snd; - - for (Object hnd : hnds) { - for (Method method : hnd.getClass().getMethods()) { - Remote remoteAnn = method.getAnnotation(Remote.class); - - if (remoteAnn != null) { - MethodDescriptor old = methods.put(method.getName(), new MethodDescriptor(method, hnd, remoteAnn.async())); - - if (old != null) - throw new IllegalArgumentException("Duplicated method: " + method.getName()); - } - } - } - - } - - /** - * @param req Request. - */ - public void onMessage(JsonObject req) { - if (log.isLoggable(Level.FINE)) - log.fine("Message: " + req); - - JsonPrimitive reqIdJson = req.getAsJsonPrimitive("reqId"); - - final Long reqId = reqIdJson == null ? null : reqIdJson.getAsLong(); - - String mtdName = req.getAsJsonPrimitive("mtdName").getAsString(); - - final MethodDescriptor desc = methods.get(mtdName); - - if (desc == null) { - sendError(reqId, "Unknown method: " + mtdName); - - return; - } - - Type[] paramTypes = desc.mtd.getGenericParameterTypes(); - - JsonArray argsJson = req.getAsJsonArray("args"); - - final Object[] args; - - if (paramTypes.length > 0) { - args = new Object[paramTypes.length]; - - if (argsJson == null || argsJson.size() != paramTypes.length) { - sendError(reqId, "Inconsistent parameters"); - - return; - } - - for (int i = 0; i < paramTypes.length; i++) - args[i] = Utils.GSON.fromJson(argsJson.get(i), paramTypes[i]); - } - else { - args = Utils.EMPTY_OBJECTS; - - if (argsJson != null && argsJson.size() > 0) { - sendError(reqId, "Inconsistent parameters"); - - return; - } - } - - Runnable run = new Runnable() { - @Override public void run() { - final Object res; - - try { - res = desc.mtd.invoke(desc.hnd, args); - } catch (Exception e) { - if (reqId != null) - sendException(reqId, e); - else - log.log(Level.SEVERE, "Exception on execute remote method", e); - - return; - } - - sendResponse(reqId, res, desc.returnType); - } - }; - - if (desc.async) - executorSrvc.submit(run); - else - run.run(); - } - - /** - * @param reqId Request id. - * @param ex Exception. - */ - protected void sendException(Long reqId, Exception ex) { - if (reqId == null) - return; - - JsonObject res = new JsonObject(); - - res.addProperty("type", "CallRes"); - res.addProperty("reqId", reqId); - - JsonObject exJson = new JsonObject(); - exJson.addProperty("type", ex.getClass().getName()); - exJson.addProperty("message", ex.getMessage()); - - res.add("ex", exJson); - - snd.send(res); - } - - /** - * @param reqId Request id. - * @param err Exception. - */ - protected void sendError(Long reqId, String err) { - if (reqId == null) - return; - - JsonObject res = new JsonObject(); - - res.addProperty("type", "CallRes"); - res.addProperty("reqId", reqId); - res.addProperty("error", err); - - snd.send(res); - } - - /** - * @param reqId Request id. - * @param res Result. - * @param type Type. - */ - private void sendResponse(Long reqId, Object res, Type type) { - if (reqId == null) - return; - - JsonObject resp = new JsonObject(); - - resp.addProperty("type", "CallRes"); - - resp.addProperty("reqId", reqId); - - JsonElement resJson; - - if (type == void.class) - resJson = JsonNull.INSTANCE; - else - resJson = Utils.GSON.toJsonTree(res, type); - - resp.add("res", resJson); - - snd.send(resp); - } - - /** {@inheritDoc} */ - @Override public void close() { - executorSrvc.shutdown(); - } - - /** - * @param hnds Handler. - * @param snd Sender. - */ - public static RemoteCallable wrap(WebSocketSender snd, Object ... hnds) { - return new RemoteCallable(snd, hnds); - } - - /** - * - */ - private static class MethodDescriptor { - /** */ - private final Method mtd; - - /** */ - private final Object hnd; - - /** */ - private final Type returnType; - - /** */ - private final boolean async; - - /** - * @param mtd Method. - * @param hnd Handler. - * @param async Async. - */ - MethodDescriptor(Method mtd, Object hnd, boolean async) { - this.mtd = mtd; - this.hnd = hnd; - this.async = async; - - returnType = mtd.getGenericReturnType(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java new file mode 100644 index 0000000..fee5ba6 --- /dev/null +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/RemoteHandler.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.agent.remote; + +import com.google.gson.*; +import org.apache.ignite.agent.*; + +import java.lang.reflect.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.logging.*; + +/** + * Allow to execute methods remotely from NodeJS server by web-socket command. + */ +public class RemoteHandler implements AutoCloseable { + /** */ + private static final Logger log = Logger.getLogger(RemoteHandler.class.getName()); + + /** */ + private final WebSocketSender snd; + + /** */ + private final Map<String, MethodDescriptor> methods = new HashMap<>(); + + /** */ + private final ExecutorService executorSrvc = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + + /** + * @param snd Session. + * @param hnds Handlers. + */ + private RemoteHandler(WebSocketSender snd, Object ... hnds) { + this.snd = snd; + + for (Object hnd : hnds) { + for (Method method : hnd.getClass().getMethods()) { + Remote remoteAnn = method.getAnnotation(Remote.class); + + if (remoteAnn != null) { + MethodDescriptor old = methods.put(method.getName(), new MethodDescriptor(method, hnd, remoteAnn.async())); + + if (old != null) + throw new IllegalArgumentException("Duplicated method: " + method.getName()); + } + } + } + + } + + /** + * @param req Request. + */ + public void onMessage(JsonObject req) { + if (log.isLoggable(Level.FINE)) + log.fine("Message: " + req); + + JsonPrimitive reqIdJson = req.getAsJsonPrimitive("reqId"); + + final Long reqId = reqIdJson == null ? null : reqIdJson.getAsLong(); + + String mtdName = req.getAsJsonPrimitive("mtdName").getAsString(); + + final MethodDescriptor desc = methods.get(mtdName); + + if (desc == null) { + sendError(reqId, "Unknown method: " + mtdName); + + return; + } + + Type[] paramTypes = desc.mtd.getGenericParameterTypes(); + + JsonArray argsJson = req.getAsJsonArray("args"); + + final Object[] args; + + if (paramTypes.length > 0) { + args = new Object[paramTypes.length]; + + if (argsJson == null || argsJson.size() != paramTypes.length) { + sendError(reqId, "Inconsistent parameters"); + + return; + } + + for (int i = 0; i < paramTypes.length; i++) + args[i] = Utils.GSON.fromJson(argsJson.get(i), paramTypes[i]); + } + else { + args = Utils.EMPTY_OBJECTS; + + if (argsJson != null && argsJson.size() > 0) { + sendError(reqId, "Inconsistent parameters"); + + return; + } + } + + Runnable run = new Runnable() { + @Override public void run() { + final Object res; + + try { + res = desc.mtd.invoke(desc.hnd, args); + } catch (Exception e) { + if (reqId != null) + sendException(reqId, e); + else + log.log(Level.SEVERE, "Exception on execute remote method", e); + + return; + } + + sendResponse(reqId, res, desc.returnType); + } + }; + + if (desc.async) + executorSrvc.submit(run); + else + run.run(); + } + + /** + * @param reqId Request id. + * @param ex Exception. + */ + protected void sendException(Long reqId, Exception ex) { + if (reqId == null) + return; + + JsonObject res = new JsonObject(); + + res.addProperty("type", "CallRes"); + res.addProperty("reqId", reqId); + + JsonObject exJson = new JsonObject(); + exJson.addProperty("type", ex.getClass().getName()); + exJson.addProperty("message", ex.getMessage()); + + res.add("ex", exJson); + + snd.send(res); + } + + /** + * @param reqId Request id. + * @param err Exception. + */ + protected void sendError(Long reqId, String err) { + if (reqId == null) + return; + + JsonObject res = new JsonObject(); + + res.addProperty("type", "CallRes"); + res.addProperty("reqId", reqId); + res.addProperty("error", err); + + snd.send(res); + } + + /** + * @param reqId Request id. + * @param res Result. + * @param type Type. + */ + private void sendResponse(Long reqId, Object res, Type type) { + if (reqId == null) + return; + + JsonObject resp = new JsonObject(); + + resp.addProperty("type", "CallRes"); + + resp.addProperty("reqId", reqId); + + JsonElement resJson; + + if (type == void.class) + resJson = JsonNull.INSTANCE; + else + resJson = Utils.GSON.toJsonTree(res, type); + + resp.add("res", resJson); + + snd.send(resp); + } + + /** {@inheritDoc} */ + @Override public void close() { + executorSrvc.shutdown(); + } + + /** + * @param hnds Handler. + * @param snd Sender. + */ + public static RemoteHandler wrap(WebSocketSender snd, Object ... hnds) { + return new RemoteHandler(snd, hnds); + } + + /** + * + */ + private static class MethodDescriptor { + /** */ + private final Method mtd; + + /** */ + private final Object hnd; + + /** */ + private final Type returnType; + + /** */ + private final boolean async; + + /** + * @param mtd Method. + * @param hnd Handler. + * @param async Async. + */ + MethodDescriptor(Method mtd, Object hnd, boolean async) { + this.mtd = mtd; + this.hnd = hnd; + this.async = async; + + returnType = mtd.getGenericReturnType(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/WebSocketSender.java ---------------------------------------------------------------------- diff --git a/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/WebSocketSender.java b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/WebSocketSender.java new file mode 100644 index 0000000..44f4147 --- /dev/null +++ b/modules/control-center-agent/src/main/java/org/apache/ignite/agent/remote/WebSocketSender.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.agent.remote; + +import com.google.gson.*; + +/** + * Sender for messages to web-socket. + */ +public interface WebSocketSender { + /** + * Send message. + * @param msg Message. + * @return {@code true} if message sent successfully. + */ + public boolean send(String msg); + + /** + * Send message. + * @param msg Message. + * @return {@code true} if message sent successfully. + */ + public boolean send(JsonObject msg); +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e3162d20/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java ---------------------------------------------------------------------- diff --git a/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java b/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java index d220b14..9e8d236 100644 --- a/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java +++ b/modules/schema-import-db/src/main/java/org/apache/ignite/schema/parser/DBReader.java @@ -26,7 +26,7 @@ import java.util.*; import java.util.logging.*; /** - * + * Singleton to extract DataBase */ public class DBReader { /** Logger. */