[Esbox-commits] r2243 - trunk/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core
eswartz at garage.maemo.org
eswartz at garage.maemo.org
Mon Sep 28 22:59:15 EEST 2009
Author: eswartz
Date: 2009-09-28 22:59:14 +0300 (Mon, 28 Sep 2009)
New Revision: 2243
Added:
trunk/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java
Log:
Add missing file
Added: trunk/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java
===================================================================
--- trunk/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java (rev 0)
+++ trunk/org.maemo.esbox.vm/src/org/maemo/esbox/internal/api/vm/core/LaunchedMachineInfo.java 2009-09-28 19:59:14 UTC (rev 2243)
@@ -0,0 +1,102 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Nokia Corporation
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Ed Swartz (Nokia) - initial API and implementation
+ *******************************************************************************/
+
+package org.maemo.esbox.internal.api.vm.core;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.maemo.esbox.internal.vm.Activator;
+import org.maemo.esbox.vm.core.IVirtualMachineConfiguration;
+import org.maemo.mica.common.core.process.IProcessLauncher;
+import org.maemo.mica.common.core.process.IProcessMonitor;
+import org.maemo.mica.common.core.process.StringBuilderStreamTextMonitor;
+import org.maemo.mica.common.core.process.ProcessLauncherUtils.LaunchResults;
+
+public class LaunchedMachineInfo {
+ public LaunchedMachineInfo(
+ IVirtualMachineConfiguration configuration,
+ IProcessLauncher processLauncher) {
+ this.configuration = configuration;
+ this.launcher = processLauncher;
+ this.monitor = processLauncher.createProcessMonitor();
+ this.streamGrabber = new StringBuilderStreamTextMonitor(false);
+ this.monitor.addMonitor(streamGrabber);
+ }
+ public LaunchedMachineInfo(IStatus failedStatus) {
+ this.failedStatus = failedStatus;
+ }
+
+ public IProcessLauncher launcher;
+ public IProcessMonitor monitor;
+ public StringBuilderStreamTextMonitor streamGrabber;
+ public IVirtualMachineConfiguration configuration;
+ private IStatus failedStatus;
+
+ public boolean isAlive() {
+ if (monitor == null)
+ return false;
+
+ return !monitor.isCompleted();
+ }
+
+ /**
+ * Return an status describing the output if the machine died.
+ * @return IStatus
+ */
+ public IStatus checkAlive() {
+ if (isAlive())
+ return Status.OK_STATUS;
+
+ String msg;
+ if (launcher != null) {
+ LaunchResults results = new LaunchResults(launcher.getLastCreatedProcess().exitValue(),
+ streamGrabber.stdout.toString(),
+ streamGrabber.stderr.toString());
+ msg = results.reportResults("Virtual machine died unexpectedly");
+ return Activator.createErrorStatus(msg, null);
+ } else {
+ return failedStatus != null ? failedStatus :
+ Activator.createErrorStatus("The machine was never launched", null);
+ }
+ }
+
+ /**
+ * @return the failed
+ */
+ public boolean isFailed() {
+ return failedStatus != null;
+ }
+
+ /**
+ * Indicate that this launch failed
+ * @param status
+ */
+ public void setFailed(IStatus status) {
+ if (this.failedStatus == null)
+ this.failedStatus = status;
+ }
+ /**
+ * @return the failedStatus
+ */
+ public IStatus getFailedStatus() {
+ return failedStatus;
+ }
+ /**
+ *
+ */
+ public void cancel() {
+ setFailed(BaseLaunchableVirtualMachineController.CANCEL_STATUS);
+
+ // don't cancel anything else here... we can't distinguish explicit user cancel from
+ // a nested cancellation (e.g. refresh SDKs launches machine, then the refresh is canceled).
+ // This can result in killing a perfectly fine machine
+ }
+}
\ No newline at end of file
More information about the Esbox-commits
mailing list