From 632b4de66f5866d3f37507d9a325468b515194d0 Mon Sep 17 00:00:00 2001 From: Uwe Stieber Date: Sat, 3 May 2014 16:31:35 +0200 Subject: Target Explorer: Simplify simulator utils implementation --- .../tcf/te/tcf/locator/utils/SimulatorUtils.java | 58 ++++++++++------------ 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/SimulatorUtils.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/SimulatorUtils.java index 157529342..7ada3d342 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/SimulatorUtils.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/utils/SimulatorUtils.java @@ -11,12 +11,12 @@ package org.eclipse.tcf.te.tcf.locator.utils; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; +import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; @@ -78,43 +78,35 @@ public final class SimulatorUtils { public static Result getSimulatorService(final IPeerNode peerNode) { Assert.isNotNull(peerNode); - final AtomicBoolean isEnabled = new AtomicBoolean(false); - final AtomicReference type = new AtomicReference(); - final AtomicReference properties = new AtomicReference(); - - Runnable runnable = new Runnable() { - @Override - public void run() { - String value = peerNode.getPeer().getAttributes().get(IPeerNodeProperties.PROP_SIM_ENABLED); - if (value != null) { - isEnabled.set(Boolean.parseBoolean(value)); - } - - type.set(peerNode.getPeer().getAttributes().get(IPeerNodeProperties.PROP_SIM_TYPE)); - properties.set(peerNode.getPeer().getAttributes().get(IPeerNodeProperties.PROP_SIM_PROPERTIES)); - } - }; - - if (Protocol.isDispatchThread()) runnable.run(); - else Protocol.invokeAndWait(runnable); - Result result = null; - if (isEnabled.get()) { - IService[] services = ServiceManager.getInstance().getServices(peerNode, ISimulatorService.class, false); - for (IService service : services) { - Assert.isTrue(service instanceof ISimulatorService); - // Get the UI service which is associated with the simulator service - String id = service.getId(); - if (id != null && id.equals(type.get())) { - result = new Result(); - result.service = (ISimulatorService)service; - result.id = id; - result.settings = properties.get(); - break; + IPeer peer = peerNode.getPeer(); + if (peer != null) { + boolean isEnabled = false; + + String value = peer.getAttributes().get(IPeerNodeProperties.PROP_SIM_ENABLED); + if (value != null) isEnabled = Boolean.parseBoolean(value); + + String type = peer.getAttributes().get(IPeerNodeProperties.PROP_SIM_TYPE); + String properties = peer.getAttributes().get(IPeerNodeProperties.PROP_SIM_PROPERTIES); + + if (isEnabled) { + IService[] services = ServiceManager.getInstance().getServices(peerNode, ISimulatorService.class, false); + for (IService service : services) { + Assert.isTrue(service instanceof ISimulatorService); + // Get the UI service which is associated with the simulator service + String id = service.getId(); + if (id != null && id.equals(type)) { + result = new Result(); + result.service = (ISimulatorService)service; + result.id = id; + result.settings = properties; + break; + } } } } + return result; } -- cgit v1.2.3