rm) {
- rm.setData(value1 + value2);
- rm.done();
- }
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncHelloWorld.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncHelloWorld.java
deleted file mode 100644
index 293c0b399f8..00000000000
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncHelloWorld.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems and others.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.dd.examples.dsf.requestmonitor;
-
-import java.util.concurrent.Executor;
-
-import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
-import org.eclipse.dd.dsf.concurrent.RequestMonitor;
-
-/**
- * "Hello world" example which uses an asynchronous method to print out
- * the result.
- *
- * The main method uses an immediate executor, which executes runnables
- * as soon as they are submitted, in creating its request monitor.
- *
- */
-public class AsyncHelloWorld {
-
- public static void main(String[] args) {
- Executor executor = ImmediateExecutor.getInstance();
- RequestMonitor rm = new RequestMonitor(executor, null);
- asyncHelloWorld(rm);
- }
-
- static void asyncHelloWorld(RequestMonitor rm) {
- System.out.println("Hello world");
- // TODO Exercise 1: - Call the second async. "Hello world 2" method.
- // Hint: Calling an asynchronous method requires passing to it a
- // request monitor. A new request monitor can be constructed with
- // a parent RequestMonitor as an argument argument. The parent gets
- // completed automatically when the lower level request monitor is
- // completed.
- rm.done();
- }
-
- // TODO: Exercise 1 - Add a second async. "Hello world 2" method.
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncQuicksort.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncQuicksort.java
deleted file mode 100644
index f6b6a16e86b..00000000000
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/AsyncQuicksort.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems and others.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.dd.examples.dsf.requestmonitor;
-
-import java.util.Arrays;
-import java.util.concurrent.Executor;
-
-import org.eclipse.dd.dsf.concurrent.CountingRequestMonitor;
-import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
-import org.eclipse.dd.dsf.concurrent.RequestMonitor;
-
-/**
- * Example of using a CountingRequestMonitor to wait for multiple
- * asynchronous calls to complete.
- */
-public class AsyncQuicksort {
-
- static Executor fgExecutor = ImmediateExecutor.getInstance();
-
- public static void main(String[] args) {
- final int[] array = {5, 7, 8, 3, 2, 1, 9, 5, 4};
-
- System.out.println("To sort: " + Arrays.toString(array));
- asyncQuicksort(
- array, 0, array.length - 1,
- new RequestMonitor(fgExecutor, null) {
- @Override
- protected void handleCompleted() {
- System.out.println("Sorted: " + Arrays.toString(array));
- }
- });
- }
-
- static void asyncQuicksort(final int[] array, final int left,
- final int right, final RequestMonitor rm)
- {
- if (right > left) {
- int pivot = left;
- // TODO: Exercise 2 - Convert the call to partition into an
- // asynchronous call to asyncPartition().
- // Hint: The rest of the code below should be executed inside
- // the DataRequestMonitor.handleCompleted() overriding method.
- int newPivot = partition(array, left, right, pivot);
- printArray(array, left, right, newPivot);
-
- CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
- asyncQuicksort(array, left, newPivot - 1, countingRm);
- asyncQuicksort(array, newPivot + 1, right, countingRm);
- countingRm.setDoneCount(2);
- } else {
- rm.done();
- }
- }
-
- // TODO Exercise 2 - Convert partition to an asynchronous method.
- // Hint: a DataRequestMonitor should be used to carry the
- // return value to the caller.
- static int partition(int[] array, int left, int right, int pivot)
- {
- int pivotValue = array[pivot];
- array[pivot] = array[right];
- array[right] = pivotValue;
- int store = left;
- for (int i = left; i < right; i++) {
- if (array[i] <= pivotValue) {
- int tmp = array[store];
- array[store] = array[i];
- array[i] = tmp;
- store++;
- }
- }
- array[right] = array[store];
- array[store] = pivotValue;
-
- // TODO: Request Monitors Exercise 2 - Return the data to caller using
- // a request monitor.
- return store;
- }
-
- static void printArray(int[] array, int left, int right, int pivot) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < array.length; i++ ) {
- if (i == left) {
- buffer.append('>');
- } else if (i == pivot) {
- buffer.append('-');
- } else {
- buffer.append(' ');
- }
- buffer.append(array[i]);
-
- if (i == right) {
- buffer.append('<');
- } else if (i == pivot) {
- buffer.append('-');
- } else {
- buffer.append(' ');
- }
- }
-
- System.out.println(buffer);
- }
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/Async2Plus2.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/Async2Plus2.java
deleted file mode 100644
index d775c0c1e1e..00000000000
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/Async2Plus2.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems and others.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.dd.examples.dsf.requestmonitor.answers;
-
-import java.util.concurrent.Executor;
-
-import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
-import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
-
-/**
- * Example of using a DataRequestMonitor to retrieve a result from an
- * asynchronous method.
- */
-public class Async2Plus2 {
-
- public static void main(String[] args) {
- Executor executor = ImmediateExecutor.getInstance();
- DataRequestMonitor rm =
- new DataRequestMonitor(executor, null) {
- @Override
- protected void handleCompleted() {
- System.out.println("2 + 2 = " + getData());
- }
- };
- asyncAdd(2, 2, rm);
- }
-
- static void asyncAdd(int value1, int value2, DataRequestMonitor rm) {
- rm.setData(value1 + value2);
- rm.done();
- }
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncHelloWorld.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncHelloWorld.java
deleted file mode 100644
index 89061748a35..00000000000
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncHelloWorld.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems and others.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.dd.examples.dsf.requestmonitor.answers;
-
-import java.util.concurrent.Executor;
-
-import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
-import org.eclipse.dd.dsf.concurrent.RequestMonitor;
-
-/**
- * "Hello world" example which uses an asynchronous method to print out
- * the result.
- *
- * The main method uses an immediate executor, which executes runnables
- * as soon as they are submitted, in creating its request monitor.
- *
- */
-public class AsyncHelloWorld {
-
- public static void main(String[] args) {
- Executor executor = ImmediateExecutor.getInstance();
- RequestMonitor rm = new RequestMonitor(executor, null);
- asyncHelloWorld(rm);
- }
-
- static void asyncHelloWorld(RequestMonitor rm) {
- System.out.println("Hello world");
- RequestMonitor rm2 = new RequestMonitor(ImmediateExecutor.getInstance(), rm);
- asyncHelloWorld2(rm2);
- }
-
- static void asyncHelloWorld2(RequestMonitor rm) {
- System.out.println("Hello world 2");
- rm.done();
- }
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncQuicksort.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncQuicksort.java
deleted file mode 100644
index 10b510d389d..00000000000
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/requestmonitor/answers/AsyncQuicksort.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems and others.
- * 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:
- * Wind River Systems - initial API and implementation
- *******************************************************************************/
-package org.eclipse.dd.examples.dsf.requestmonitor.answers;
-
-import java.util.Arrays;
-import java.util.concurrent.Executor;
-
-import org.eclipse.dd.dsf.concurrent.CountingRequestMonitor;
-import org.eclipse.dd.dsf.concurrent.DataRequestMonitor;
-import org.eclipse.dd.dsf.concurrent.ImmediateExecutor;
-import org.eclipse.dd.dsf.concurrent.RequestMonitor;
-
-/**
- * Example of using a CountingRequestMonitor to wait for multiple
- * asynchronous calls to complete.
- */
-public class AsyncQuicksort {
-
- static Executor fgExecutor = ImmediateExecutor.getInstance();
-
- public static void main(String[] args) {
- final int[] array = {5, 7, 8, 3, 2, 1, 9, 5, 4};
-
- System.out.println("To sort: " + Arrays.toString(array));
- asyncQuicksort(
- array, 0, array.length - 1,
- new RequestMonitor(fgExecutor, null) {
- @Override
- protected void handleCompleted() {
- System.out.println("Sorted: " + Arrays.toString(array));
- }
- });
- }
-
- static void asyncQuicksort(final int[] array, final int left,
- final int right, final RequestMonitor rm)
- {
- if (right > left) {
- int pivot = left;
- asyncPartition(
- array, left, right, pivot,
- new DataRequestMonitor(fgExecutor, rm) {
- @Override
- protected void handleCompleted() {
- int newPivot = getData();
- printArray(array, left, right, newPivot);
-
- CountingRequestMonitor countingRm = new CountingRequestMonitor(fgExecutor, rm);
- asyncQuicksort(array, left, newPivot - 1, countingRm);
- asyncQuicksort(array, newPivot + 1, right, countingRm);
- countingRm.setDoneCount(2);
- }
- });
- } else {
- rm.done();
- }
- }
-
- static void asyncPartition(int[] array, int left, int right, int pivot, DataRequestMonitor rm)
- {
- int pivotValue = array[pivot];
- array[pivot] = array[right];
- array[right] = pivotValue;
- int store = left;
- for (int i = left; i < right; i++) {
- if (array[i] <= pivotValue) {
- int tmp = array[store];
- array[store] = array[i];
- array[i] = tmp;
- store++;
- }
- }
- array[right] = array[store];
- array[store] = pivotValue;
-
- // Java 5 automatically converts the int type of the store variable
- // to an Integer object.
- rm.setData(store);
- rm.done();
- }
-
- static void printArray(int[] array, int left, int right, int pivot) {
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < array.length; i++ ) {
- if (i == left) {
- buffer.append('>');
- } else if (i == pivot) {
- buffer.append('-');
- } else {
- buffer.append(' ');
- }
- buffer.append(array[i]);
-
- if (i == right) {
- buffer.append('<');
- } else if (i == pivot) {
- buffer.append('-');
- } else {
- buffer.append(' ');
- }
- }
-
- System.out.println(buffer);
- }
-}
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/AlarmsVMNode.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/AlarmsVMNode.java
index 4d67b00ac01..d4ad61525d1 100644
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/AlarmsVMNode.java
+++ b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/AlarmsVMNode.java
@@ -43,32 +43,22 @@ class AlarmsVMNode extends AbstractDMVMNode
@Override
protected void updateElementsInSessionThread(final IChildrenUpdate update) {
- // Check that the services are available
- if ( getServicesTracker().getService(AlarmService.class) == null ) {
- handleFailedUpdate(update);
- return;
- }
- if ( getServicesTracker().getService(TimerService.class) == null ) {
- handleFailedUpdate(update);
- return;
- }
-
- // Find the trigger and timer contexts. If not found, fail.
+ // Check that the service is available and find the trigger and timer contexts.
+ // If not found, fail.
+ AlarmService alarmService = getServicesTracker().getService(AlarmService.class, null);
TriggerDMContext alarmDmc = findDmcInPath(
update.getViewerInput(), update.getElementPath(), TriggerDMContext.class);
TimerDMContext timerDmc = findDmcInPath(
update.getViewerInput(), update.getElementPath(), TimerDMContext.class);
- if (alarmDmc == null || timerDmc == null) {
+ if (alarmService == null || alarmDmc == null || timerDmc == null) {
update.setStatus(new Status(IStatus.ERROR, DsfExamplesPlugin.PLUGIN_ID, "Required elements not found in path"));
update.done();
return;
}
// Get the alarm context then check the triggered value.
- final AlarmDMContext alarmStatusDmc = getServicesTracker().getService(AlarmService.class).
- getAlarm(alarmDmc, timerDmc);
- boolean triggered = getServicesTracker().getService(AlarmService.class).
- isAlarmTriggered(alarmStatusDmc);
+ final AlarmDMContext alarmStatusDmc = alarmService.getAlarm(alarmDmc, timerDmc);
+ boolean triggered = alarmService.isAlarmTriggered(alarmStatusDmc);
// Only return the alarm in list of elements if it is triggered.
if (triggered) {
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TimersVMNode.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TimersVMNode.java
index d0714e4fe74..e9b8e4fa22a 100644
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TimersVMNode.java
+++ b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TimersVMNode.java
@@ -84,14 +84,15 @@ class TimersVMNode extends AbstractDMVMNode
@Override
protected void updateElementsInSessionThread(final IChildrenUpdate update) {
- if ( getServicesTracker().getService(TimerService.class) == null ) {
+ TimerService timerService = getServicesTracker().getService(TimerService.class, null);
+ if ( timerService == null ) {
handleFailedUpdate(update);
return;
}
// Retrieve the timer DMContexts, create the corresponding VMCs array, and
// set them as result.
- TimerDMContext[] timers = getServicesTracker().getService(TimerService.class).getTimers();
+ TimerDMContext[] timers = timerService.getTimers();
fillUpdateWithVMCs(update, timers);
update.done();
}
@@ -116,21 +117,15 @@ class TimersVMNode extends AbstractDMVMNode
@ConfinedToDsfExecutor("getSession#getExecutor")
private void updatePropertiesInSessionThread(final IPropertiesUpdate update) {
// Find the timer context in the element being updated
- final TimerDMContext dmc = findDmcInPath(
- update.getViewerInput(), update.getElementPath(), TimerDMContext.class);
-
+ TimerDMContext dmc = findDmcInPath(update.getViewerInput(), update.getElementPath(), TimerDMContext.class);
+ TimerService timerService = getServicesTracker().getService(TimerService.class, null);
+
// If either update or service are not valid, fail the update and exit.
- if ( dmc == null ) {
+ if ( dmc == null || timerService == null) {
handleFailedUpdate(update);
return;
}
- TimerService timerService = getServicesTracker().getService(TimerService.class, null);
- if ( timerService == null ) {
- handleFailedUpdate(update);
- return;
- }
-
int value = timerService.getTimerValue(dmc);
if (value == -1) {
diff --git a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TriggersVMNode.java b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TriggersVMNode.java
index 78f29ad4937..96c138000b2 100644
--- a/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TriggersVMNode.java
+++ b/plugins/org.eclipse.dd.examples.dsf/src/org/eclipse/dd/examples/dsf/timers/TriggersVMNode.java
@@ -85,12 +85,13 @@ class TriggersVMNode extends AbstractDMVMNode
@Override
protected void updateElementsInSessionThread(final IChildrenUpdate update) {
- if ( getServicesTracker().getService(AlarmService.class) == null ) {
+ AlarmService alarmService = getServicesTracker().getService(AlarmService.class, null);
+ if ( alarmService == null ) {
handleFailedUpdate(update);
return;
}
- TriggerDMContext[] triggers = getServicesTracker().getService(AlarmService.class).getTriggers();
+ TriggerDMContext[] triggers = alarmService.getTriggers();
fillUpdateWithVMCs(update, triggers);
update.done();
}
@@ -120,19 +121,14 @@ class TriggersVMNode extends AbstractDMVMNode
// Find the trigger context in the element being updated
TriggerDMContext triggerCtx = findDmcInPath(
update.getViewerInput(), update.getElementPath(), TriggerDMContext.class);
+ AlarmService alarmService = getServicesTracker().getService(AlarmService.class, null);
// If either update or service are not valid, fail the update and return.
- if ( triggerCtx == null ) {
+ if ( triggerCtx == null || alarmService == null) {
handleFailedUpdate(update);
return;
}
- AlarmService alarmService = getServicesTracker().getService(AlarmService.class, null);
- if ( alarmService == null ) {
- handleFailedUpdate(update);
- return;
- }
-
// Calculate and set the update properties.
int value = alarmService.getTriggerValue(triggerCtx);