Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2013-05-14 07:17:31 -0400
committerUwe Stieber2013-05-14 07:34:05 -0400
commitd3a39f85ad83f2a18ad33b47941f5c97405613ec (patch)
tree5f52922dd7c174c45fb6e40bbbe49b287892ea7b
parent03fb42f7b5cd808eca68ea870c0be57c4527ca9f (diff)
downloadorg.eclipse.tcf-d3a39f85ad83f2a18ad33b47941f5c97405613ec.tar.gz
org.eclipse.tcf-d3a39f85ad83f2a18ad33b47941f5c97405613ec.tar.xz
org.eclipse.tcf-d3a39f85ad83f2a18ad33b47941f5c97405613ec.zip
Target Explorer: Fix some cases of illegal thread access
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java8
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java65
2 files changed, 44 insertions, 29 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java
index 2f5c79288..24496674b 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/LocatorListener.java
@@ -63,6 +63,8 @@ public class LocatorListener implements ILocator.LocatorListener {
*/
@Override
public void peerAdded(IPeer peer) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_LISTENER)) {
CoreBundleActivator.getTraceHandler().trace("LocatorListener.peerAdded( " + (peer != null ? peer.getID() : null) + " )", ITracing.ID_TRACE_LOCATOR_LISTENER, this); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -184,6 +186,8 @@ public class LocatorListener implements ILocator.LocatorListener {
*/
@Override
public void peerChanged(IPeer peer) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
// Protect ourself from reentrant calls while processing a changed peer.
if (peer != null) {
AtomicBoolean guard = PEER_CHANGED_GUARDIANS.get(peer);
@@ -243,6 +247,8 @@ public class LocatorListener implements ILocator.LocatorListener {
*/
@Override
public void peerRemoved(String id) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_LISTENER)) {
CoreBundleActivator.getTraceHandler().trace("LocatorListener.peerRemoved( " + id + " )", ITracing.ID_TRACE_LOCATOR_LISTENER, this); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -357,6 +363,8 @@ public class LocatorListener implements ILocator.LocatorListener {
*/
@Override
public void peerHeartBeat(String id) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_LISTENER)) {
CoreBundleActivator.getTraceHandler().trace("LocatorListener.peerHeartBeat( " + id + " )", ITracing.ID_TRACE_LOCATOR_LISTENER, this); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
index 8a849a746..b00388c53 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java
@@ -15,6 +15,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.PlatformObject;
@@ -55,9 +56,9 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
private boolean disposed;
// The list of known peers
- private final Map<String, IPeerModel> peers = new HashMap<String, IPeerModel>();
+ /* default */ final Map<String, IPeerModel> peers = new HashMap<String, IPeerModel>();
// The list of "proxied" peers per proxy peer id
- private final Map<String, List<IPeerModel>> peerChildren = new HashMap<String, List<IPeerModel>>();
+ /* default */ final Map<String, List<IPeerModel>> peerChildren = new HashMap<String, List<IPeerModel>>();
// Reference to the scanner
private IScanner scanner = null;
@@ -125,6 +126,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
*/
@Override
public IModelListener[] getListener() {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
return modelListener.toArray(new IModelListener[modelListener.size()]);
}
@@ -188,19 +190,43 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
*/
@Override
public IPeerModel[] getPeers() {
- return peers.values().toArray(new IPeerModel[peers.values().size()]);
+ final AtomicReference<IPeerModel[]> result = new AtomicReference<IPeerModel[]>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ result.set(peers.values().toArray(new IPeerModel[peers.values().size()]));
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ return result.get();
}
/* (non-Javadoc)
* @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getChildren(java.lang.String)
*/
@Override
- public List<IPeerModel> getChildren(String parentPeerID) {
+ public List<IPeerModel> getChildren(final String parentPeerID) {
Assert.isNotNull(parentPeerID);
- List<IPeerModel> children = peerChildren.get(parentPeerID);
- if (children == null) children = Collections.emptyList();
- return Collections.unmodifiableList(children);
+ final AtomicReference<List<IPeerModel>> result = new AtomicReference<List<IPeerModel>>();
+
+ Runnable runnable = new Runnable() {
+ @Override
+ public void run() {
+ List<IPeerModel> children = peerChildren.get(parentPeerID);
+ if (children == null) children = Collections.emptyList();
+ result.set(children);
+ }
+ };
+
+ if (Protocol.isDispatchThread()) runnable.run();
+ else Protocol.invokeAndWait(runnable);
+
+ return Collections.unmodifiableList(result.get());
}
/* (non-Javadoc)
@@ -301,6 +327,8 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
*/
protected ILocator.LocatorListener doCreateLocatorListener(ILocatorModel model) {
Assert.isNotNull(model);
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
return new LocatorListener(model);
}
@@ -731,6 +759,7 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
* @return <code>True</code> if the given id belongs to a root node, <code>false</code> otherwise.
*/
private boolean isRootNode(String id) {
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
Assert.isNotNull(id);
boolean isRoot = false;
@@ -746,26 +775,4 @@ public class LocatorModel extends PlatformObject implements ILocatorModel {
return isRoot;
}
-
- /**
- * Fire the model listener for the given peer model.
- *
- * @param peer The peer model. Must not be <code>null</code>.
- * @param added <code>True</code> if the peer model got added, <code>false</code> if it got removed.
- */
- protected void fireListener(final IPeerModel peer, final boolean added) {
- Assert.isNotNull(peer);
-
- final IModelListener[] listeners = getListener();
- if (listeners.length > 0) {
- Protocol.invokeLater(new Runnable() {
- @Override
- public void run() {
- for (IModelListener listener : listeners) {
- listener.locatorModelChanged(LocatorModel.this, peer, added);
- }
- }
- });
- }
- }
}

Back to the top