Path: blob/master/test/hotspot/jtreg/vmTestbase/vm/share/process/ProcessHandler.java
41159 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package vm.share.process;2324import java.util.List;2526public class ProcessHandler implements MessageInput, MessageOutput {27private StreamMessageInput stdout = new StreamMessageInput();28private StreamMessageInput stderr = new StreamMessageInput();29private StreamMessageOutput stdin = new StreamMessageOutput();3031public ProcessHandler() {32}3334public ProcessHandler(ProcessExecutor exec) {35bind(exec);36}3738public void bind(ProcessExecutor exec) {39exec.addStdOutListener(stdout.createListener());40exec.addStdErrListener(stderr.createListener());41exec.start();42stdin.bind(exec.getStdIn());43}4445public boolean waitForStart(long timeout) throws InterruptedException {46return stdout.waitForStart(timeout) && stderr.waitForStart(timeout);47}4849public boolean waitForMessage(long timeout) throws InterruptedException {50return stdout.waitForMessage(timeout);51}5253public boolean waitForMessage(String msg, long timeout) throws InterruptedException {54return stdout.waitForMessage(msg, timeout);55}5657public String getMessage() {58return stdout.getMessage();59}6061public List<String> getMessages() {62return stdout.getMessages();63}6465public List<String> getMessages(int to) {66return stdout.getMessages(to);67}6869public List<String> getMessages(int from, int to) {70return stdout.getMessages(from, to);71}7273public boolean waitForStdErrMessage(String msg, long timeout) throws InterruptedException {74return stderr.waitForMessage(msg, timeout);75}7677public String getStdErrMessage() {78return stderr.getMessage();79}8081public boolean waitForFinish(long timeout) throws InterruptedException {82return stdout.waitForFinish(timeout) && stderr.waitForFinish(timeout);83}8485public void start() {86stdin.start();87}8889public void send(String msg) {90stdin.send(msg);91}9293public void finish() {94stdin.finish();95}9697public void reset() {98stdout.reset();99stderr.reset();100}101}102103104