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

net.scattersphere.client.handler.StreamCommandHandler Maven / Gradle / Ivy

package net.scattersphere.client.handler;

import net.scattersphere.api.Client;
import net.scattersphere.client.StreamClientCache;

import java.io.PrintWriter;

/**
 * This class handles the "stream" command from the CLI.
 *
 * Created by kenji on 2/2/15.
 */
public class StreamCommandHandler extends AbstractCommandHandler {

    public StreamCommandHandler(PrintWriter out, Client client) {
        super(out, client);
    }

    @Override
    public void handle(String[] args) {
        if (getClient().getClientConnection("Main").isConnected()) {
            if (args.length > 2) {
                String streamCommand = args[1];
                String streamId = args[2];

                switch(streamCommand.toLowerCase()) {
                    case "status":
                    case "size":
                        getClient().streamJob("Main", streamCommand, streamId);
                        break;

                    case "open":
                        StreamClientCache.instance().openStream(streamId, getPrintWriter());
                        break;

                    case "close":
                        StreamClientCache.instance().closeStream(streamId, getPrintWriter());
                        break;
                }
            } else {
                getPrintWriter().println("Stream: requires a command and stream ID.");
            }
        } else {
            getPrintWriter().println("Not connected.\n");
        }
    }

    public String getCommandString() {
        return "STREAM";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy