diff --git a/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/AbstractSession.java b/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/AbstractSession.java index 5c11ab78b..4c2278bde 100644 --- a/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/AbstractSession.java +++ b/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/AbstractSession.java @@ -49,6 +49,9 @@ public IProcess execute(Command command) throws CoreException { // public IProcess execute(final Command scriptlet, IPipe in, IPipe out) // throws CoreException public IProcess execute(Command scriptlet, IPipe in, IPipe out) throws CoreException { + if (isClosed()) { + throw new CoreException(Status.CANCEL_STATUS); + } final ICommandService svc = scriptlet instanceof ProcInstance ? new ProcInstanceService() : CorePlugin.getScriptletManager().getScriptletService(scriptlet); final IPipe tinput = in == null ? createPipe().close(Status.OK_STATUS) : in; diff --git a/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/Process.java b/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/Process.java index 7db5cf2d0..45c931d1f 100644 --- a/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/Process.java +++ b/ecl/plugins/org.eclipse.rcptt.ecl.core/src/org/eclipse/rcptt/ecl/internal/core/Process.java @@ -71,7 +71,7 @@ public synchronized IStatus waitFor(long timeout, IProgressMonitor monitor) thro } public synchronized boolean isAlive() { - return status == null; + return status == null && !session.isClosed(); } public ISession getSession() { diff --git a/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/RepeatService.java b/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/RepeatService.java index aa00381e6..c31e8b185 100644 --- a/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/RepeatService.java +++ b/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/RepeatService.java @@ -48,6 +48,9 @@ public IStatus service(Command command, IProcess process) List contentOutput = new ArrayList(); for (int i = 0; i < times; i++) { + if (!process.isAlive()) { + throw new CoreException(Status.CANCEL_STATUS); + } IPipe input = process.getSession().createPipe(); for (Object o : content) input.write(o); diff --git a/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/TryService.java b/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/TryService.java index bb8b84f48..39b117792 100644 --- a/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/TryService.java +++ b/ecl/plugins/org.eclipse.rcptt.ecl.operations/src/org/eclipse/rcptt/ecl/operations/internal/commands/TryService.java @@ -51,6 +51,9 @@ public IStatus service(Command command, IProcess process) throws InterruptedExce ISession session = process.getSession(); try { for (int i = 0; i < times; i++) { + if (!process.isAlive()) { + throw new CoreException(Status.CANCEL_STATUS); + } if (i + 1 == times && !t.isNoScreenshot()) { session.putProperty(NO_SCREENSHOT, null); } else { diff --git a/ecl/plugins/org.eclipse.rcptt.ecl.server.tcp/src/org/eclipse/rcptt/ecl/server/tcp/SessionRequestHandler.java b/ecl/plugins/org.eclipse.rcptt.ecl.server.tcp/src/org/eclipse/rcptt/ecl/server/tcp/SessionRequestHandler.java index 44ca70b89..3b06d7d73 100644 --- a/ecl/plugins/org.eclipse.rcptt.ecl.server.tcp/src/org/eclipse/rcptt/ecl/server/tcp/SessionRequestHandler.java +++ b/ecl/plugins/org.eclipse.rcptt.ecl.server.tcp/src/org/eclipse/rcptt/ecl/server/tcp/SessionRequestHandler.java @@ -10,12 +10,16 @@ *******************************************************************************/ package org.eclipse.rcptt.ecl.server.tcp; +import java.io.BufferedInputStream; import java.io.IOException; import java.net.Socket; import java.net.SocketException; +import java.net.SocketTimeoutException; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.ILog; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; import org.eclipse.rcptt.ecl.core.Command; import org.eclipse.rcptt.ecl.internal.core.CorePlugin; @@ -24,12 +28,16 @@ import org.eclipse.rcptt.ecl.runtime.IPipe; import org.eclipse.rcptt.ecl.runtime.IProcess; import org.eclipse.rcptt.ecl.runtime.ISession; +import org.osgi.framework.FrameworkUtil; final class SessionRequestHandler implements Runnable { private final Socket socket; private final ISession session; + private final BufferedInputStream inputStream; + private final int defaultTimeout; + private final static ILog LOG = Platform.getLog(FrameworkUtil.getBundle(SessionRequestHandler.class)); - SessionRequestHandler(Socket socket, boolean useJobs) { + SessionRequestHandler(Socket socket, boolean useJobs) throws IOException { // super("ECL tcp session:" + socket.getPort()); this.socket = socket; try { @@ -38,11 +46,13 @@ final class SessionRequestHandler implements Runnable { CorePlugin.log(e); } this.session = EclRuntime.createSession(useJobs); + this.inputStream = new BufferedInputStream(socket.getInputStream()); + this.defaultTimeout = socket.getSoTimeout(); } public void run() { try { - IPipe pipe = CoreUtils.createEMFPipe(socket.getInputStream(), + IPipe pipe = CoreUtils.createEMFPipe(inputStream, socket.getOutputStream()); while (!Thread.currentThread().isInterrupted() && !socket.isClosed()) { @@ -116,11 +126,15 @@ private IPipe readInput(IPipe pipe) throws CoreException { } private IStatus writeOutput(IPipe pipe, IProcess process) - throws CoreException { + throws CoreException, IOException { Object object; do { - object = process.getOutput().take(Long.MAX_VALUE); - if (object instanceof IStatus) { + object = process.getOutput().take(100); + if (object == null) { + if (!isConnected()) { + throw new CoreException(Status.CANCEL_STATUS); + } + } else if (object instanceof IStatus) { try { return process.waitFor(); } catch (InterruptedException e) { @@ -129,8 +143,22 @@ private IStatus writeOutput(IPipe pipe, IProcess process) } else { pipe.write(object); } + } while (true); } + + private boolean isConnected() throws IOException { + inputStream.mark(10); + socket.setSoTimeout(1); + try { + return inputStream.read() >= 0 && inputStream.read() >= 0; + } catch (SocketTimeoutException e) { + return true; + } finally { + socket.setSoTimeout(defaultTimeout); + inputStream.reset(); + } + } public void recover(Socket client) { } diff --git a/launching/org.eclipse.rcptt.launching/src/org/eclipse/rcptt/internal/launching/DataExecutable.java b/launching/org.eclipse.rcptt.launching/src/org/eclipse/rcptt/internal/launching/DataExecutable.java index e1faba73f..7bd7b97eb 100644 --- a/launching/org.eclipse.rcptt.launching/src/org/eclipse/rcptt/internal/launching/DataExecutable.java +++ b/launching/org.eclipse.rcptt.launching/src/org/eclipse/rcptt/internal/launching/DataExecutable.java @@ -47,6 +47,22 @@ public DataExecutable(AutLaunch launch, IQ7NamedElement element, } this.launch = launch; executionMonitor = new NullProgressMonitor(); + addListener(new Listener() { + + @Override + public void onStatusChange(Executable executable) { + if (getStatus() == State.COMPLETED) { + executionMonitor.setCanceled(true); + } + } + + @Override + public void updateSessionCounters(Executable executable, IStatus status) { + // TODO Auto-generated method stub + + } + + }); } public AutLaunch getAut() { diff --git a/runtime/ecl/org.eclipse.rcptt.tesla.ecl.impl/src/org/eclipse/rcptt/tesla/ecl/internal/impl/commands/WaitService.java b/runtime/ecl/org.eclipse.rcptt.tesla.ecl.impl/src/org/eclipse/rcptt/tesla/ecl/internal/impl/commands/WaitService.java index 24d8ff116..28a8dbd52 100644 --- a/runtime/ecl/org.eclipse.rcptt.tesla.ecl.impl/src/org/eclipse/rcptt/tesla/ecl/internal/impl/commands/WaitService.java +++ b/runtime/ecl/org.eclipse.rcptt.tesla.ecl.impl/src/org/eclipse/rcptt/tesla/ecl/internal/impl/commands/WaitService.java @@ -30,7 +30,13 @@ public IStatus service(Command command, IProcess context) int ms = wait.getMs(); if (ms < 0) return TeslaImplPlugin.err("Negative delay is not permitted"); - Thread.sleep(ms); // any exceptions will be handled by session + long stop = System.currentTimeMillis() + ms; + while (System.currentTimeMillis() < stop) { + if (!context.isAlive()) { + throw new CoreException(Status.CANCEL_STATUS); + } + Thread.sleep(100); // any exceptions will be handled by session + } return Status.OK_STATUS; } diff --git a/runtime/org.eclipse.rcptt.runtime.ui/src/org/eclipse/rcptt/runtime/ui/Q7ServerStarter.java b/runtime/org.eclipse.rcptt.runtime.ui/src/org/eclipse/rcptt/runtime/ui/Q7ServerStarter.java index 47f9ee727..e1d140f0a 100644 --- a/runtime/org.eclipse.rcptt.runtime.ui/src/org/eclipse/rcptt/runtime/ui/Q7ServerStarter.java +++ b/runtime/org.eclipse.rcptt.runtime.ui/src/org/eclipse/rcptt/runtime/ui/Q7ServerStarter.java @@ -12,7 +12,9 @@ import java.io.IOException; import java.net.InetAddress; +import java.net.UnknownHostException; +import org.eclipse.core.runtime.CoreException; import org.eclipse.rcptt.ecl.client.tcp.EclTcpSession; import org.eclipse.rcptt.ecl.debug.runtime.SuspendListener; import org.eclipse.rcptt.ecl.debug.runtime.SuspendManager; @@ -66,8 +68,12 @@ public void start() { private void testLocalEclServer() { try { - new EclTcpSession(InetAddress.getByName("localhost"), ecl); + new EclTcpSession(InetAddress.getByName("localhost"), ecl).close(); Activator.info("Verified that local ECL server is working"); + } catch ( CoreException e) { + Activator.err(e, "Error testing a local ECL server. Something is blocking connection"); + } catch (UnknownHostException e) { + Activator.err(e, "Error testing a local ECL server. Something is blocking connection"); } catch (IOException e) { Activator.err(e, "Error testing a local ECL server. Something is blocking connection"); }