All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.digitaldan.harmony.shell.App Maven / Gradle / Ivy

There is a newer version: 1.1.7
Show newest version
package com.digitaldan.harmony.shell;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import org.eclipse.jetty.client.HttpClient;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.digitaldan.harmony.HarmonyClient;
import com.digitaldan.harmony.HarmonyClientListener;
import com.digitaldan.harmony.config.Activity;
import com.digitaldan.harmony.config.Activity.Status;
import com.digitaldan.harmony.config.HarmonyConfig;
import com.martiansoftware.jsap.CommandLineTokenizer;

/**
 * Sample App
 *
 */
public class App implements HarmonyClientListener {
    private final Logger logger = LoggerFactory.getLogger(App.class);
    private HarmonyClient hc;
    private ScheduledFuture ping;

    public static void main(String[] args) {
        try {
            new App(args[0]);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public App(String host) throws IOException {
        try {
            HttpClient httpClient = new HttpClient();
            hc = new HarmonyClient(httpClient);
            hc.addListener(this);
            hc.connect(host);

        } catch (Exception e) {
            logger.error("error connecting to Hub", e);
            System.exit(-1);
        }

        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while (true) {
            line = br.readLine();
            if (line == null || line.equals("q")) {
                break;
            }

            try {
                String[] lineArgs = CommandLineTokenizer.tokenize(line);
                if (lineArgs.length == 0) {
                    continue;
                }
                ShellCommandWrapper command = new ShellCommandWrapper();
                new CmdLineParser(command).parseArgument(lineArgs);
                command.execute(hc);
            } catch (CmdLineException e) {
                System.err
                        .println(e.getMessage() + "\n" + "list devices - lists the configured devices and their id's\n"
                                + "list activities - lists the configured activities and their id's\n"
                                + "show activity - shows the current activity\n"
                                + "start  - starts an activity (takes a string or id)\n"
                                + "press  




© 2015 - 2024 Weber Informatics LLC | Privacy Policy