/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. 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.wso2.carbon.ml.core.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import water.H2O;
import water.H2OApp;
import water.H2OClientApp;

/**
 * H2O server for Deep Learning.
 */
public class H2OServer {

    private static final Log log = LogFactory.getLog(H2OServer.class);
    private static boolean isH2OServerStarted = false;

    /**
     * Starts H20 server in local mode
     */
    public static void startH2O(String port) {
        if (!isH2OServerStarted) {
            String[] args = new String[2];
            args[0] = "-port";
            args[1] = port;
            H2OApp.main(args);
            H2O.waitForCloudSize(1, 10 * 1000 /* ms */);
            isH2OServerStarted = true;
            log.info("H2o Server has started.");
        } else {
            log.warn("H2O Server is already Running.");
        }
    }

    /**
     * Starts instance in a remote H2O cloud
     * @param ip    IP address of the remote H2O cloud
     * @param port  Port of the remote H2O cloud
     * @param name  Name of the remote H2O cloud
     */
    public static void startH2O(String ip, String port, String name) {
        String[] args = new String[7];
        args[0] = "-port";
        args[1] = port;
        args[2] = "-ip";
        args[3] = ip;
        args[4] = "-name";
        args[5] = name;
        args[6] = "-md5skip";

        H2OClientApp.main(args);
    }

    /**
     * Stop H2O
     */
    public static void stopH2O() {
        if (isH2OServerStarted) {
            H2O.shutdown(0);
            isH2OServerStarted = false;
            log.info("H2O Server has shutdown.");
        } else {
            log.warn("H2O server is not started, hence cannot be stopped");
        }
    }

    public static boolean hasH2OServerStarted() {
        return isH2OServerStarted;
    }
}

@@ -789,16 +789,68 @@
 ctory;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import w
@@ -1247,32 +1247,36 @@
             
+List%3C
 String
-%5B%5D
+%3E
  args = new 
@@ -1279,17 +1279,21 @@
 new 
-String%5B2%5D
+ArrayList%3C%3E()
 ;%0A  
@@ -1302,37 +1302,37 @@
         args
-%5B0%5D = 
+.add(
 %22-port%22
+)
 ;%0A          
@@ -1341,48 +1341,172 @@
 args
-%5B1%5D = port;%0A            H2OApp.main(args
+.add(port);%0A            if (!log.isDebugEnabled()) %7B%0A                args.add(%22-quiet%22);%0A            %7D%0A            H2OApp.main(args.toArray(new String%5Bargs.size()%5D)
 );%0A 

Set H2O server logs to debug only