Search in sources :

Example 1 with RuntimeClient

use of org.talend.designer.esb.runcontainer.ui.console.RuntimeClient in project tesb-studio-se by Talend.

the class RuntimeConsoleUtil method loadConsole.

public static void loadConsole() {
    clearConsole();
    RuntimeClient client = new RuntimeClient();
    PipedInputStream pis = new PipedInputStream();
    PipedOutputStream pos = new PipedOutputStream();
    try {
        pos.connect(pis);
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    client.setInputStream(pis);
    Thread consoleThread = new Thread("Runtime Console Input") {

        @Override
        public void run() {
            InputStream is = findConsole().getInputStream();
            int count = 0;
            byte[] bs = new byte[1024];
            try {
                while ((count = is.read(bs)) > 0) {
                    // remore duplicate \r\n for Windows
                    if (count > 1 && bs[count - 1] == 10 && bs[count - 2] == 13) {
                        count--;
                    }
                    pos.write(Arrays.copyOf(bs, count));
                }
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    pos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    };
    consoleThread.start();
    Thread connectThread = new Thread("Runtime Console Connector") {

        @Override
        public void run() {
            IPreferenceStore store = ESBRunContainerPlugin.getDefault().getPreferenceStore();
            String etcLocation = store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_LOCATION);
            String host = store.getString(RunContainerPreferenceInitializer.P_ESB_RUNTIME_HOST);
            System.setProperty("karaf.etc", etcLocation + "/etc");
            String[] karafArgs = new String[] { "-h", host };
            try {
                client.connect(karafArgs);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    };
    connectThread.start();
}
Also used : RuntimeClient(org.talend.designer.esb.runcontainer.ui.console.RuntimeClient) PipedInputStream(java.io.PipedInputStream) InputStream(java.io.InputStream) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 RuntimeClient (org.talend.designer.esb.runcontainer.ui.console.RuntimeClient)1