Author: jjohnstn
Date: 2010-09-29 17:30:58 -0400 (Wed, 29 Sep 2010)
New Revision: 25313
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
Log:
2010-09-29 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java: New
file.
* src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java: New file.
* src/org/jboss/tools/deltacloud/ui/views/InstanceView.java: Remove action thread classes
as they
are now external so they can be used from the Cloud Viewer as well.
(refreshInstance): Removed.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-09-29 20:44:52
UTC (rev 25312)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-09-29 21:30:58
UTC (rev 25313)
@@ -1,5 +1,13 @@
2010-09-29 Jeff Johnston <jjohnstn(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java: New
file.
+ * src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java: New file.
+ * src/org/jboss/tools/deltacloud/ui/views/InstanceView.java: Remove action thread
classes as they
+ are now external so they can be used from the Cloud Viewer as well.
+ (refreshInstance): Removed.
+
+2010-09-29 Jeff Johnston <jjohnstn(a)redhat.com>
+
* icons/reboot.gif: New file.
* icons/rebootd.gif: New file.
* icons/runningd.gif: New file.
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-09-29
20:44:52 UTC (rev 25312)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/InstanceView.java 2010-09-29
21:30:58 UTC (rev 25313)
@@ -64,7 +64,6 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
import org.jboss.tools.deltacloud.core.ICloudManagerListener;
@@ -112,7 +111,6 @@
private Action rseAction;
private Map<String, Action> instanceActions;
- private Map<String, Job> currentPerformingActions = new HashMap<String,
Job>();
private InstanceView parentView;
@@ -349,106 +347,6 @@
manager.add(instanceActions.get(DeltaCloudInstance.DESTROY));
}
- private class PerformInstanceActionThread extends Job {
- private DeltaCloud cloud;
- private DeltaCloudInstance instance;
- private String action;
- private String taskName;
- private String expectedState;
-
- public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
- String action, String title, String taskName, String expectedState) {
- super(title);
- this.cloud = cloud;
- this.instance = instance;
- this.action = action;
- this.taskName = taskName;
- this.expectedState = expectedState;
- }
-
- @Override
- public IStatus run(IProgressMonitor pm) {
- String id = instance.getId();
- try {
- pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
- pm.worked(1);
- // To handle the user starting a new action when we haven't confirmed the last
one yet,
- // cancel the previous job and then go on performing this action
- Job job = cloud.getActionJob(id);
- if (job != null) {
- job.cancel();
- try {
- job.join();
- } catch (InterruptedException e) {
- // do nothing, this is ok
- }
- }
- currentPerformingActions.put(id, this);
- cloud.performInstanceAction(id, action);
- while (instance != null && !(instance.getState().equals(expectedState))
- && !(instance.getState().equals(DeltaCloudInstance.TERMINATED))) {
- instance = refreshInstance(instance);
- try {
- Thread.sleep(300);
- } catch (InterruptedException e) {
- break;
- }
- }
- } catch (DeltaCloudException e) {
- // do nothing..action had problem executing..perhaps illegal
- } finally {
- cloud.removeActionJob(id, this);
- pm.done();
- }
- return Status.OK_STATUS;
- }
- }
-
- private class PerformDestroyInstanceActionThread extends Job {
- private DeltaCloud cloud;
- private DeltaCloudInstance instance;
- private String taskName;
-
- public PerformDestroyInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance
instance,
- String title, String taskName) {
- super(title);
- this.cloud = cloud;
- this.instance = instance;
- this.taskName = taskName;
- }
-
- @Override
- public IStatus run(IProgressMonitor pm) {
- String id = instance.getId();
- try {
- pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
- pm.worked(1);
- // To handle the user starting a new action when we haven't confirmed the last
one yet,
- // cancel the previous job and then go on performing this action
- Job job = cloud.getActionJob(id);
- if (job != null) {
- job.cancel();
- try {
- job.join();
- } catch (InterruptedException e) {
- // do nothing, this is ok
- }
- }
- cloud.registerActionJob(id, this);
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- cloud.destroyInstance(instance.getId());
- }
- });
- } finally {
- cloud.removeActionJob(id, this);
- pm.done();
- }
- return Status.OK_STATUS;
- }
- }
-
private void makeActions() {
refreshAction = new Action() {
public void run() {
@@ -593,17 +491,6 @@
instanceActions.put(DeltaCloudInstance.DESTROY, destroyAction);
}
- private DeltaCloudInstance refreshInstance(DeltaCloudInstance instance) {
- DeltaCloudInstance[] instances =
(DeltaCloudInstance[])contentProvider.getElements(currCloud);
- for (int i = 0; i < instances.length; ++i) {
- DeltaCloudInstance d = instances[i];
- if (d.getId().equals(instance.getId())) {
- return currCloud.refreshInstance(d.getId());
- }
- }
- return null;
- }
-
@Override
public void setFocus() {
// TODO Auto-generated method stub
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformDestroyInstanceActionThread.java 2010-09-29
21:30:58 UTC (rev 25313)
@@ -0,0 +1,54 @@
+package org.jboss.tools.deltacloud.ui.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.swt.widgets.Display;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+
+public class PerformDestroyInstanceActionThread extends Job {
+ private DeltaCloud cloud;
+ private DeltaCloudInstance instance;
+ private String taskName;
+
+ public PerformDestroyInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance
instance,
+ String title, String taskName) {
+ super(title);
+ this.cloud = cloud;
+ this.instance = instance;
+ this.taskName = taskName;
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor pm) {
+ String id = instance.getId();
+ try {
+ pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
+ pm.worked(1);
+ // To handle the user starting a new action when we haven't confirmed the last one
yet,
+ // cancel the previous job and then go on performing this action
+ Job job = cloud.getActionJob(id);
+ if (job != null) {
+ job.cancel();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // do nothing, this is ok
+ }
+ }
+ cloud.registerActionJob(id, this);
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ cloud.destroyInstance(instance.getId());
+ }
+ });
+ } finally {
+ cloud.removeActionJob(id, this);
+ pm.done();
+ }
+ return Status.OK_STATUS;
+ }
+}
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java 2010-09-29
21:30:58 UTC (rev 25313)
@@ -0,0 +1,63 @@
+package org.jboss.tools.deltacloud.ui.views;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
+import org.jboss.tools.deltacloud.core.DeltaCloudException;
+import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
+
+public class PerformInstanceActionThread extends Job {
+ private DeltaCloud cloud;
+ private DeltaCloudInstance instance;
+ private String action;
+ private String taskName;
+ private String expectedState;
+
+ public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
+ String action, String title, String taskName, String expectedState) {
+ super(title);
+ this.cloud = cloud;
+ this.instance = instance;
+ this.action = action;
+ this.taskName = taskName;
+ this.expectedState = expectedState;
+ }
+
+ @Override
+ public IStatus run(IProgressMonitor pm) {
+ String id = instance.getId();
+ try {
+ pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
+ pm.worked(1);
+ // To handle the user starting a new action when we haven't confirmed the last one
yet,
+ // cancel the previous job and then go on performing this action
+ Job job = cloud.getActionJob(id);
+ if (job != null) {
+ job.cancel();
+ try {
+ job.join();
+ } catch (InterruptedException e) {
+ // do nothing, this is ok
+ }
+ }
+ cloud.performInstanceAction(id, action);
+ while (instance != null && !(instance.getState().equals(expectedState))
+ && !(instance.getState().equals(DeltaCloudInstance.TERMINATED))) {
+ instance = cloud.refreshInstance(id);
+ try {
+ Thread.sleep(300);
+ } catch (InterruptedException e) {
+ break;
+ }
+ }
+ } catch (DeltaCloudException e) {
+ // do nothing..action had problem executing..perhaps illegal
+ } finally {
+ cloud.removeActionJob(id, this);
+ pm.done();
+ }
+ return Status.OK_STATUS;
+ }
+}