diff options
author | Tobias Schwarz | 2013-12-17 13:33:03 +0000 |
---|---|---|
committer | Tobias Schwarz | 2013-12-17 13:33:03 +0000 |
commit | 8384bf58f9acf5778d1f88ffee9764f7c3622ad1 (patch) | |
tree | b21cdd8028e1631289cd4b91825df0b67cd9412f /target_explorer/plugins/org.eclipse.tcf.te.tcf.locator | |
parent | 9c70311b440b7192b6af02fd9dd5fc806492b66a (diff) | |
download | org.eclipse.tcf-8384bf58f9acf5778d1f88ffee9764f7c3622ad1.tar.gz org.eclipse.tcf-8384bf58f9acf5778d1f88ffee9764f7c3622ad1.tar.xz org.eclipse.tcf-8384bf58f9acf5778d1f88ffee9764f7c3622ad1.zip |
Target Explorer: split peer and ocator model
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tcf.te.tcf.locator')
36 files changed, 1022 insertions, 2563 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF index deffea96f..c10b704bc 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/META-INF/MANIFEST.MF @@ -20,8 +20,7 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Bundle-Localization: plugin -Export-Package: org.eclipse.tcf.te.tcf.locator, - org.eclipse.tcf.te.tcf.locator.activator;x-internal:=true, +Export-Package: org.eclipse.tcf.te.tcf.locator.activator;x-internal:=true, org.eclipse.tcf.te.tcf.locator.help, org.eclipse.tcf.te.tcf.locator.interfaces, org.eclipse.tcf.te.tcf.locator.interfaces.nodes, diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.properties index ae021d7b4..e7704f9b2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.properties @@ -19,5 +19,4 @@ StopSimulatorStep.name=Stop Simulator StartDebuggerStep.name=Start Debugger StopDebuggerStep.name=Stop Debugger WaitForReadyStep.name=Wait until peer becomes ready -SignalPeerDisconnectedStep.name=Signal peer disconnected state SetAsDefaultContextStep.name=Set peer as default context diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml index dc7703c96..2dc9a96fa 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/plugin.xml @@ -53,7 +53,7 @@ class="org.eclipse.tcf.te.tcf.locator.internal.PeerModelPropertyTester" id="org.eclipse.tcf.te.tcf.locator.LocatorModelPropertyTester" namespace="org.eclipse.tcf.te.tcf.locator" - properties="name,nameRegex,osName,osNameRegex,hasLocalService,hasRemoteService,hasOfflineService,hasAttribute,isAttribute,isStaticPeer,isRedirected,isProxy,isValueAdd,isOfType" + properties="name,nameRegex,osName,osNameRegex,hasLocalService,hasRemoteService,hasOfflineService,hasAttribute,isAttribute,isRedirected,isProxy,isValueAdd,isOfType" type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"> </propertyTester> @@ -61,7 +61,7 @@ class="org.eclipse.tcf.te.tcf.locator.internal.PeerModelPropertyTester" id="org.eclipse.tcf.te.tcf.locator.LocatorModelPropertyTester2" namespace="org.eclipse.tcf.te.tcf.locator" - properties="name,nameRegex,osName,osNameRegex,hasLocalService,hasRemoteService,hasOfflineService,hasAttribute,isAttribute,isStaticPeer,isRedirected,isProxy,isValueAdd,isOfType" + properties="name,nameRegex,osName,osNameRegex,hasLocalService,hasRemoteService,hasOfflineService,hasAttribute,isAttribute,sRedirected,isProxy,isValueAdd,isOfType" type="org.eclipse.tcf.protocol.IPeer"> </propertyTester> @@ -142,7 +142,6 @@ </serviceType> <enablement> <instanceof value="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"/> - <test forcePluginActivation="true" property="org.eclipse.tcf.te.tcf.locator.isStaticPeer" value="true"/> <test forcePluginActivation="true" property="org.eclipse.tcf.te.tcf.locator.isOfType" value="null"/> </enablement> </service> @@ -178,10 +177,6 @@ class="org.eclipse.tcf.te.tcf.locator.steps.WaitForReadyStep" label="%WaitForReadyStep.name"/> <step - id="org.eclipse.tcf.te.tcf.locator.signalPeerDisconnectedStep" - class="org.eclipse.tcf.te.tcf.locator.steps.SignalPeerDisconnectedStep" - label="%SignalPeerDisconnectedStep.name"/> - <step id="org.eclipse.tcf.te.tcf.locator.setAsDefaultContextStep" class="org.eclipse.tcf.te.tcf.locator.steps.SetAsDefaultContextStep" label="%SetAsDefaultContextStep.name"/> @@ -225,7 +220,6 @@ <reference id="org.eclipse.tcf.te.tcf.locator.stopDebuggerStep"/> <reference id="org.eclipse.tcf.te.tcf.core.shutDownStep"/> <reference id="org.eclipse.tcf.te.tcf.locator.stopSimulatorStep"/> - <reference id="org.eclipse.tcf.te.tcf.locator.signalPeerDisconnectedStep"/> <reference id="org.eclipse.tcf.te.core.setConnectStateStep"> <parameter name="state" value="disconnected" /> </reference> @@ -262,7 +256,7 @@ <extension point="org.eclipse.core.expressions.definitions"> <!-- Expression to test if current variable - is adaptable to IPeerModel and has a simulator service + is adaptable to IPeerNode and has a simulator service --> <definition id="te.expressions.peerModel.hasSimulatorService"> <adapt type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"> @@ -274,7 +268,7 @@ </definition> <!-- Expression to test if the active editor input - is adaptable to IPeerModel and has a simulator service + is adaptable to IPeerNode and has a simulator service --> <definition id="te.expressions.editor.hasSimulatorService"> <with variable="activeEditorInput"> @@ -283,7 +277,7 @@ </definition> <!-- Expression to test if the selection - is adaptable to IPeerModel and has a simulator service + is adaptable to IPeerNode and has a simulator service --> <definition id="te.expressions.selection.hasSimulatorService"> <with variable="selection"> @@ -295,7 +289,7 @@ </definition> <!-- Expression to test if current variable - is adaptable to IPeerModel and has remote or offline run control + is adaptable to IPeerNode and has remote or offline run control --> <definition id="te.expressions.peerModel.hasRunControl"> <adapt type="org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode"> @@ -307,7 +301,7 @@ </definition> <!-- Expression to test if the active editor input - is adaptable to IPeerModel and has remote or offline run control + is adaptable to IPeerNode and has remote or offline run control --> <definition id="te.expressions.editor.hasRunControl"> <with variable="activeEditorInput"> @@ -316,7 +310,7 @@ </definition> <!-- Expression to test if the selection - is adaptable to IPeerModel and has remote or offline run control + is adaptable to IPeerNode and has remote or offline run control --> <definition id="te.expressions.selection.hasRunControl"> <with variable="selection"> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/Scanner.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/Scanner.java deleted file mode 100644 index a1ca4425b..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/Scanner.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.callback.AsyncCallbackCollector; -import org.eclipse.tcf.te.runtime.callback.Callback; -import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; -import org.eclipse.tcf.te.tcf.core.async.CallbackInvocationDelegate; -import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; -import org.eclipse.tcf.te.tcf.locator.interfaces.IScanner; -import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.model.Model; - - -/** - * Locator model scanner implementation. - */ -public class Scanner extends Job implements IScanner { - // Reference to the parent model instance. - private final IPeerModel parentModel; - - // Reference to the scanner configuration - private final Map<String, Object> configuration = new HashMap<String, Object>(); - - // Flag to mark if the scanner is terminated - private AtomicBoolean terminated = new AtomicBoolean(false); - - /** - * Constructor. - * - * @param parentModel The parent model instance. Must not be <code>null</code>. - */ - public Scanner(IPeerModel parentModel) { - super(Scanner.class.getName()); - Assert.isNotNull(parentModel); - this.parentModel = parentModel; - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Scanner created.", ITracing.ID_TRACE_SCANNER, Scanner.this); //$NON-NLS-1$ - } - } - - /** - * Returns the parent model instance. - * - * @return The parent model instance. - */ - protected IPeerModel getParentModel() { - return parentModel; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.IScanner#setConfiguration(java.util.Map) - */ - @Override - public void setConfiguration(Map<String, Object> configuration) { - Assert.isNotNull(configuration); - this.configuration.clear(); - this.configuration.putAll(configuration); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.IScanner#getConfiguration() - */ - @Override - public Map<String, Object> getConfiguration() { - return configuration; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - protected IStatus run(IProgressMonitor monitor) { - if (monitor == null) monitor = new NullProgressMonitor(); - - // Get the current list of peers known to the parent model - IPeerNode[] peers = getParentModel().getPeerNodes(); - // Do we have something to scan at all - if (peers.length > 0) { - try { - // The first runnable is setting the thread which will finish - // the job at the end - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - Scanner.this.setThread(Thread.currentThread()); - } - }); - - // Create the callback collector keeping track of all scan processes - final IProgressMonitor finMonitor = monitor; - final AsyncCallbackCollector collector = new AsyncCallbackCollector(new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Terminate the job as soon all scanner runnable's are process - // and reschedule the job (if not terminated) - final IStatus result = finMonitor.isCanceled() ? Status.CANCEL_STATUS : Status.OK_STATUS; - if (getState() != Job.NONE) Scanner.this.done(result); - - if (!isTerminated()) { - Long delay = (Long)getConfiguration().get(IScanner.PROP_SCHEDULE); - if (delay != null) { - Scanner.this.schedule(delay.longValue()); - } - } - } - }, new CallbackInvocationDelegate()); - - // Loop the nodes and try to get an channel - for (IPeerNode peer : peers) { - // Check for the progress monitor getting canceled - if (monitor.isCanceled() || isTerminated()) break; - // Scan the peer - doScan(peer, collector, monitor); - } - - // Mark the collector initialization done - collector.initDone(); - } catch (IllegalStateException e) { - /* ignored on purpose */ - } - } - - return peers.length > 0 ? ASYNC_FINISH : Status.OK_STATUS; - } - - /** - * Scan the given peer model node and possible child nodes. - * - * @param peer The peer model node. Must not be <code>null</code>. - * @param collector The callback collector. Must not be <code>null</code>. - * @param monitor The progress monitor. Must not be <code>null</code>. - */ - /* default */ void doScan(final IPeerNode peer, final AsyncCallbackCollector collector, final IProgressMonitor monitor) { - Assert.isNotNull(peer); - Assert.isNotNull(collector); - Assert.isNotNull(monitor); - - // Check for the progress monitor getting canceled - if (monitor.isCanceled() || isTerminated()) return; - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Schedule scanner runnable for peer '" + peer.getName() + "' (" + peer.getPeerId() + ")", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITracing.ID_TRACE_SCANNER, Scanner.this); - } - - final AtomicBoolean isExcluded = new AtomicBoolean(false); - - Runnable runnable = new Runnable() { - - @Override - public void run() { - isExcluded.set(peer.getBooleanProperty(IPeerNodeProperties.PROP_SCANNER_EXCLUDE)); - } - }; - - if (Protocol.isDispatchThread()) runnable.run(); - else Protocol.invokeAndWait(runnable); - - // If the PROP_SCANNER_EXCLUDE is not set, scan this node - if (!isExcluded.get()) { - // Create the callback - ICallback callback = new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Check for the progress monitor getting canceled - if (!monitor.isCanceled() && !isTerminated()) { - // Get the children of the scanned peer model and make sure - // they are scanned too if not excluded - List<IPeerNode> candidates = Model.getModel().getChildren(peer.getPeerId()); - if (candidates != null && candidates.size() > 0) { - for (IPeerNode candidate : candidates) { - doScan(candidate, collector, monitor); - } - } - } - - // Remove the callback from the collector - collector.removeCallback(this); - } - }; - // Add the callback to the collector - collector.addCallback(callback); - // Create the scanner runnable - Runnable scannerRunnable = new ScannerRunnable(this, peer, callback); - // Submit for execution - Protocol.invokeLater(scannerRunnable); - } - - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.IScanner#terminate() - */ - @Override - public void terminate() { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // Return immediately if the scanner has been terminated already - if (terminated.get()) return; - - // Mark the scanner job as terminated. This flag is checked by - // the asynchronous callbacks and will stop the processing - terminated.set(true); - // Mark the job done from the job manager POV - if (getState() != Job.NONE) done(Status.CANCEL_STATUS); - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Scanner terminated.", ITracing.ID_TRACE_SCANNER, Scanner.this); //$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.IScanner#isTerminated() - */ - @Override - public final boolean isTerminated() { - return terminated.get(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#shouldRun() - */ - @Override - public boolean shouldRun() { - return Platform.isRunning() && !getParentModel().isDisposed() && !isTerminated(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#shouldSchedule() - */ - @Override - public boolean shouldSchedule() { - return Platform.isRunning() && !getParentModel().isDisposed() && !isTerminated(); - } -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/ScannerRunnable.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/ScannerRunnable.java deleted file mode 100644 index 829906bd4..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/ScannerRunnable.java +++ /dev/null @@ -1,539 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator; - -import java.net.InetAddress; -import java.net.SocketTimeoutException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.tcf.core.Command; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.IPeer; -import org.eclipse.tcf.protocol.IToken; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.services.ILocator; -import org.eclipse.tcf.te.runtime.callback.Callback; -import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; -import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; -import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.peers.Peer; -import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; -import org.eclipse.tcf.te.tcf.locator.interfaces.IScanner; -import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; -import org.eclipse.tcf.te.tcf.locator.nodes.PeerNode; -import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; - - -/** - * Scanner runnable to be executed for each peer to probe within the - * TCF event dispatch thread. - */ -public class ScannerRunnable implements Runnable, IChannel.IChannelListener { - - // Reference to the parent model scanner - private final IScanner parentScanner; - // Reference to the peer model node to update - /* default */ final IPeerNode peerNode; - // Reference to the channel - /* default */ IChannel channel = null; - // Mark if the used channel is a shared channel instance - /* default */ boolean sharedChannel = false; - - // Optional callback to invoke once the scan has been completed - private final ICallback callback; - - /** - * Constructor. - * - * @param scanner The parent model scanner or <code>null</code> if the runnable is constructed from outside a scanner. - * @param peerNode The peer model instance. Must not be <code>null</code>. - */ - public ScannerRunnable(IScanner scanner, IPeerNode peerNode) { - this(scanner, peerNode, null); - } - - /** - * Constructor. - * - * @param scanner The parent model scanner or <code>null</code> if the runnable is constructed from outside a scanner. - * @param peerNode The peer model instance. Must not be <code>null</code>. - * @param callback The callback to invoke once the scan has been completed or <code>null</code>. - */ - public ScannerRunnable(IScanner scanner, IPeerNode peerNode, ICallback callback) { - super(); - - parentScanner = scanner; - - Assert.isNotNull(peerNode); - this.peerNode = peerNode; - - this.callback = callback; - } - - /** - * Returns the parent scanner instance. - * - * @return The parent scanner instance or <code>null</code>. - */ - protected final IScanner getParentScanner() { - return parentScanner; - } - - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ - @Override - public void run() { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // If the parent scanner is terminated, don't do anything - IScanner scanner = getParentScanner(); - if (scanner != null && scanner.isTerminated()) { - if (callback != null) callback.done(this, Status.OK_STATUS); - return; - } - - // If a scanner runnable already active for this peer node, there - // is no need to run another scan. - if (peerNode.getProperty("scanner.transient") != null) { //$NON-NLS-1$ - if (callback != null) callback.done(this, Status.OK_STATUS); - return; - } - peerNode.setProperty("scanner.transient", this); //$NON-NLS-1$ - - // Determine the peer - IPeer peer = peerNode.getPeer(); - if (peer == null) { - if (callback != null) callback.done(this, Status.OK_STATUS); - return; - } - - // Don't scan value-adds - String value = peer.getAttributes().get("ValueAdd"); //$NON-NLS-1$ - boolean isValueAdd = value != null && ("1".equals(value.trim()) || Boolean.parseBoolean(value.trim())); //$NON-NLS-1$ - - if (isValueAdd) { - if (callback != null) callback.done(this, Status.OK_STATUS); - return; - } - - // Don't scan "CLI" peers - boolean isCLI = peer.getName() != null - && (peer.getName().startsWith("Eclipse CLI") //$NON-NLS-1$ - || peer.getName().startsWith("Eclipse Command Server") //$NON-NLS-1$ - || peer.getName().endsWith("CLI Server") //$NON-NLS-1$ - || peer.getName().endsWith("CLI Client")); //$NON-NLS-1$ - if (isCLI) { - if (callback != null) callback.done(this, Status.OK_STATUS); - return; - } - - // Do not open a channel to incomplete peer nodes - if (peerNode.isComplete()) { - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Scanner runnable invoked for peer '" + peerNode.getName() + "' (" + peerNode.getPeerId() + "). Attempting to open channel ...", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITracing.ID_TRACE_SCANNER, ScannerRunnable.this); - } - - // Check if there is a shared channel available which is still in open state - channel = Tcf.getChannelManager().getChannel(peer); - if (channel == null || channel.getState() != IChannel.STATE_OPEN) { - sharedChannel = false; - // Open the channel - channel = peer.openChannel(); - // Add ourself as channel listener - channel.addChannelListener(this); - } else { - sharedChannel = true; - // Shared channel is in open state -> use it - onChannelOpened(); - } - } - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#onChannelOpened() - */ - @Override - public void onChannelOpened() { - // Peer is reachable - if (channel != null && !sharedChannel) { - // Remove ourself as channel listener - channel.removeChannelListener(this); - } - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Scanner runnable onChannelOpened invoked for peer '" + peerNode.getName() + "' (" + peerNode.getPeerId() + ").", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITracing.ID_TRACE_SCANNER, ScannerRunnable.this); - } - - // Turn off change notifications temporarily - final boolean changed = peerNode.setChangeEventsEnabled(false); - - peerNode.setProperty(IPeerNodeProperties.PROP_LAST_SCANNER_ERROR, null); - - // Get the parent model from the model mode - final IPeerModel model = (IPeerModel)peerNode.getAdapter(IPeerModel.class); - - if (channel != null && channel.getState() == IChannel.STATE_OPEN) { - - // Update the services lists - IPeerModelUpdateService updateService = model != null ? model.getService(IPeerModelUpdateService.class) : null; - if (updateService != null) { - Collection<String> localServices = channel.getLocalServices(); - Collection<String> remoteServices = channel.getRemoteServices(); - - updateService.updatePeerServices(peerNode, localServices, remoteServices); - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Services: local = " + localServices + ", remote = " + remoteServices, //$NON-NLS-1$ //$NON-NLS-2$ - ITracing.ID_TRACE_SCANNER, ScannerRunnable.this); - } - } - - // If we don't queried the DNS name of the peer, or the peer IP changed, - // trigger a query (can run in any thread, outside TCF dispatch and UI - // thread). This make sense only if there is an IP address to query at all. - final String ip = channel.getRemotePeer().getAttributes().get(IPeer.ATTR_IP_HOST); - if (ip != null && !"".equals(ip)) { //$NON-NLS-1$ - if (peerNode.getStringProperty("dns.name.transient") == null || !ip.equals(peerNode.getStringProperty("dns.lastIP.transient"))) { //$NON-NLS-1$ //$NON-NLS-2$ - // If the IP address changed, reset the "do not query again" marker - if (!ip.equals(peerNode.getStringProperty("dns.lastIP.transient"))) { //$NON-NLS-1$ - peerNode.setProperty("dns.lastIP.transient", ip); //$NON-NLS-1$ - peerNode.setProperty("dns.skip.transient", false); //$NON-NLS-1$ - } - - if (!peerNode.getBooleanProperty("dns.skip.transient")) { //$NON-NLS-1$ - Runnable runnable = new Runnable() { - @Override - public void run() { - try { - InetAddress address = InetAddress.getByName(ip); - final AtomicReference<String> nameRef = new AtomicReference<String>(); - nameRef.set(address.getCanonicalHostName()); - - if (ip.equals(nameRef.get()) && IPAddressUtil.getInstance().isLocalHost(ip)) { - String[] candidates = IPAddressUtil.getInstance().getCanonicalHostNames(); - for (String candidate : candidates) { - if (!ip.equals(candidate)) { - nameRef.set(candidate); - break; - } - } - } - - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - String name = nameRef.get(); - if (name != null && !"".equals(name) && !ip.equals(name)) { //$NON-NLS-1$ - String dnsName = name.indexOf('.') != -1 ? name.substring(0, name.indexOf('.')) : name; - if (!ip.equalsIgnoreCase(dnsName)) { - peerNode.setProperty("dns.name.transient", dnsName.toLowerCase()); //$NON-NLS-1$ - } - } - } - }); - } - catch (UnknownHostException e) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - peerNode.setProperty("dns.skip.transient", true); //$NON-NLS-1$ - } - }); - } - } - }; - - Thread thread = new Thread(runnable, "DNS Query Thread for " + ip); //$NON-NLS-1$ - thread.start(); - } - } - } - - // Check if the agent ID is already set - String agentID = channel.getRemotePeer().getAgentID(); - if (agentID == null && channel.getRemotePeer() instanceof Peer) { - // Determine the agent ID of the remote agent - ILocator locator = channel.getRemoteService(ILocator.class); - if (locator != null) { - locator.getAgentID(new ILocator.DoneGetAgentID() { - @Override - public void doneGetAgentID(IToken token, Exception error, String agentID) { - // Ignore errors. If the agent does not implement this command, we - // do not fail. - if (agentID != null) { - // Update the peer attributes - Map<String, String> attrs = new HashMap<String, String>(channel.getRemotePeer().getAttributes()); - attrs.put(IPeer.ATTR_AGENT_ID, agentID); - peerNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, new Peer(attrs)); - } - - if (isGetPeersAllowed(channel)) { - // Get the peers from the remote locator - getPeers(channel, model, ip, new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Complete - onDone(peerNode, changed); - } - }); - } else { - onDone(peerNode, changed); - } - } - }); - } else { - // Complete - onDone(peerNode, changed); - } - } else { - if (isGetPeersAllowed(channel)) { - // Get the peers from the remote locator - getPeers(channel, model, ip, new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Complete - onDone(peerNode, changed); - } - }); - } else { - onDone(peerNode, changed); - } - } - } else { - // Complete - onDone(peerNode, changed); - } - } - - /** - * Returns if or if not "getPeers" is allowed for the given channel. - * - * @param channel The channel. Must not be <code>null</code>. - * @return <code>True</code> if "getPeers" is allowed, <code>false</code> otherwise. - */ - /* default */ boolean isGetPeersAllowed(IChannel channel) { - String remoteIP = channel.getRemotePeer().getAttributes().get(IPeer.ATTR_IP_HOST); - boolean isLocal = remoteIP != null && IPAddressUtil.getInstance().isLocalHost(remoteIP); - - boolean isCLI = channel.getRemotePeer().getName() != null - && (channel.getRemotePeer().getName().startsWith("Eclipse CLI") //$NON-NLS-1$ - || channel.getRemotePeer().getName().endsWith("CLI Server") //$NON-NLS-1$ - || channel.getRemotePeer().getName().endsWith("CLI Client")); //$NON-NLS-1$ - - isCLI |= channel.getLocalPeer().getName() != null - && (channel.getLocalPeer().getName().startsWith("Eclipse CLI") //$NON-NLS-1$ - || channel.getLocalPeer().getName().endsWith("CLI Server") //$NON-NLS-1$ - || channel.getLocalPeer().getName().endsWith("CLI Client")); //$NON-NLS-1$ - - return !isLocal && !isCLI; - } - - /** - * Query the peers from the remote locator. - * - * @param channel The channel. Must not be <code>null</code>. - * @param model The locator model. Must not be <code>null</code>. - * @param ip The IP address or <code>null</code>. - * @param callback The callback. Must not be <code>null</code>. - */ - @SuppressWarnings("unused") - protected void getPeers(final IChannel channel, final IPeerModel model, final String ip, final ICallback callback) { - Assert.isNotNull(channel); - Assert.isNotNull(model); - Assert.isNotNull(callback); - - // Keep the channel open as long as the query for the remote peers is running. - boolean keepOpen = false; - - // Get the agent ID of the remote agent we are connected too. - // Have to use the peer model node here. - final String agentID = peerNode.getPeer().getAgentID(); - - // Ask for discovered peers from the remote agents POV. - // - // Note: For simulators connected via NAT, we have to do this for localhost address - // as well. Otherwise we miss the discoverable agents only known to the simulator. - // The same applies to agent being discovered. If you don't ask for discovered peers - // here too, we may miss some routes. - if (ip != null && !"".equals(ip)) { //$NON-NLS-1$ - // Use the open channel to ask the remote peer what other peers it knows - ILocator locator = channel.getRemoteService(ILocator.class); - if (locator != null) { - // Channel must be kept open as long as the command runs - keepOpen = true; - // Issue the command - new Command(channel, locator, "getPeers", null) { //$NON-NLS-1$ - @Override - public void done(Exception error, Object[] args) { - if (error == null) { - Assert.isTrue(args.length == 2); - error = toError(args[0]); - } - // If the error is still null here, process the returned peers - if (error == null && args[1] != null) { - // Get the parent peer - IPeer parentPeer = channel.getRemotePeer(); - // Get the old child list - List<IPeerNode> oldChildren = new ArrayList<IPeerNode>(model.getChildren(parentPeer.getID())); - - // "getPeers" returns a collection of peer attribute maps - @SuppressWarnings("unchecked") - Collection<Map<String,String>> peerAttributesList = (Collection<Map<String,String>>)args[1]; - for (Map<String,String> attributes : peerAttributesList) { - // Don't process value-add's - String value = attributes.get("ValueAdd"); //$NON-NLS-1$ - boolean isValueAdd = value != null && ("1".equals(value.trim()) || Boolean.parseBoolean(value.trim())); //$NON-NLS-1$ - - // Don't process CLI service or clients - String name = attributes.get(IPeer.ATTR_NAME); - boolean isCLI = name != null - && (name.startsWith("Eclipse CLI") //$NON-NLS-1$ - || name.endsWith("CLI Server") //$NON-NLS-1$ - || name.endsWith("CLI Client")); //$NON-NLS-1$ - - if (isValueAdd || isCLI) continue; - - // Get the peer id - String peerId = attributes.get(IPeer.ATTR_ID); - // Create a peer instance - IPeer peer = new PeerRedirector(parentPeer, attributes); - // Try to find an existing peer node first - IPeerNode peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(parentPeer.getID(), peerId); - if (peerNode == null) { - // Not yet known -> add it - peerNode = new PeerNode(model, peer); - peerNode.setParent(ScannerRunnable.this.peerNode); - peerNode.setProperty(IPeerNodeProperties.PROP_SCANNER_EXCLUDE, true); - // Validate the peer node before adding - peerNode = model.validateChildPeerNodeForAdd(peerNode); - if (peerNode != null) { - // Add the child peer node to model - model.getService(IPeerModelUpdateService.class).addChild(peerNode); - } - } else { - // The parent node should be set and match - Assert.isTrue(peerNode.getParent(IPeerNode.class) != null && peerNode.getParent(IPeerNode.class).equals(ScannerRunnable.this.peerNode)); - // Peer node found, update the peer instance - peerNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); - // And remove it from the old child list - oldChildren.remove(peerNode); - } - } - } - - // Once everything is processed, close the channel - if (!sharedChannel) channel.close(); - // Invoke the callback - callback.done(ScannerRunnable.this, Status.OK_STATUS); - } - }; - } - } - - // And close the channel - if (!sharedChannel && !keepOpen) channel.close(); - - // Invoke the callback - if (!keepOpen) callback.done(ScannerRunnable.this, Status.OK_STATUS); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#onChannelClosed(java.lang.Throwable) - */ - @Override - public void onChannelClosed(Throwable error) { - // Peer is not reachable - - if (channel != null) { - // Remove ourself as channel listener - channel.removeChannelListener(this); - } - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_SCANNER)) { - CoreBundleActivator.getTraceHandler().trace("Scanner runnable onChannelClosed invoked for peer '" + peerNode.getName() + "' (" + peerNode.getPeerId() + "). Error was: " + (error != null ? error.getLocalizedMessage() : null), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITracing.ID_TRACE_SCANNER, ScannerRunnable.this); - } - - // Set the peer state property, if the scanner the runnable - // has been scheduled from is still active. - if (parentScanner == null || !parentScanner.isTerminated()) { - // Turn off change notifications temporarily - boolean changed = peerNode.setChangeEventsEnabled(false); - - peerNode.setProperty(IPeerNodeProperties.PROP_CHANNEL_REF_COUNTER, null); - peerNode.setProperty(IPeerNodeProperties.PROP_LAST_SCANNER_ERROR, error instanceof SocketTimeoutException ? null : error); - - // Clear out previously determined services - IPeerModel model = (IPeerModel)peerNode.getAdapter(IPeerModel.class); - if (model != null) { - IPeerModelUpdateService updateService = model.getService(IPeerModelUpdateService.class); - updateService.updatePeerServices(peerNode, null, null); - - // Clean out possible child nodes - model.setChildren(peerNode.getPeerId(), null); - } - - // Clean out DNS name detection - peerNode.setProperty("dns.name.transient", null); //$NON-NLS-1$ - peerNode.setProperty("dns.lastIP.transient", null); //$NON-NLS-1$ - peerNode.setProperty("dns.skip.transient", null); //$NON-NLS-1$ - - // Complete - onDone(peerNode, changed); - } - } - - /** - * Called from {@link #onChannelOpened()} and {@link #onChannelClosed(Throwable)} once - * all operations of the scanner are completed. - * - * @param node The peer model node. Must not be <code>null</code>. - * @param changed <code>True</code> if the change events shall be enabled, <code>false</code> otherwise. - */ - protected void onDone(IPeerNode node, boolean changed) { - Assert.isNotNull(node); - - // Reset the scanner runnable marker - node.setProperty("scanner.transient", null); //$NON-NLS-1$ - - // Re-enable the change events and fire a "properties" change event - if (changed) { - node.setChangeEventsEnabled(true); - node.fireChangeEvent("properties", null, peerNode.getProperties()); //$NON-NLS-1$ - } - - if (callback != null) callback.done(this, Status.OK_STATUS); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#congestionLevel(int) - */ - @Override - public void congestionLevel(int level) { - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/activator/CoreBundleActivator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/activator/CoreBundleActivator.java index 5584d8615..a990260e8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/activator/CoreBundleActivator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/activator/CoreBundleActivator.java @@ -87,7 +87,7 @@ public class CoreBundleActivator extends Plugin { plugin = null; // Dispose the locator model - final IPeerModel model = Model.getModel(true); + final IPeerModel model = Model.getPeerModel(true); if (model != null) { Runnable runnable = new Runnable() { @Override diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ITracing.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ITracing.java index b8475fb93..24567a348 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ITracing.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/ITracing.java @@ -16,9 +16,14 @@ public interface ITracing { /** + * If enabled, prints information about peer model method invocations. + */ + public static String ID_TRACE_PEER_MODEL = "trace/peerModel"; //$NON-NLS-1$ + + /** * If enabled, prints information about locator model method invocations. */ - public static String ID_TRACE_LOCATOR_MODEL = "trace/peerModel"; //$NON-NLS-1$ + public static String ID_TRACE_LOCATOR_MODEL = "trace/locatorModel"; //$NON-NLS-1$ /** * If enabled, prints information about locator listener method invocations. @@ -29,14 +34,4 @@ public interface ITracing { * If enabled, prints information about locator model property tester invocations. */ public static String ID_TRACE_PROPERTY_TESTER = "trace/propertyTester"; //$NON-NLS-1$ - - /** - * If enabled, prints information about channel state change listener method invocations. - */ - public static String ID_TRACE_CHANNEL_STATE_CHANGE_LISTENER = "trace/channelStateChangeListener"; //$NON-NLS-1$ - - /** - * If enabled, prints information about the scanner. - */ - public static String ID_TRACE_SCANNER = "trace/scanner"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java new file mode 100644 index 000000000..dd636b057 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/ILocatorModel.java @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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.tcf.te.tcf.locator.interfaces.nodes; + +import java.util.List; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.services.ILocator; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelService; + + +/** + * The locator model is an extension to the TCF locator service. The + * model allows to store additional properties for each peer, keep + * track of peers from different origins. + * <p> + * <b>Note:</b> Updates to the locator model, and the locator model + * children needs to be performed in the TCF dispatch thread. The + * locator model and all child model nodes do assert this core + * assumption. To maintain consistency, and to avoid any performance + * overhead for thread synchronization, the model read access must + * happen in the TCF dispatch thread as well. + * + * @see ILocator + */ +public interface ILocatorModel extends IAdaptable { + + /** + * Dispose the locator model instance. + */ + public void dispose(); + + /** + * Returns if or if not the locator model instance is disposed. + * + * @return <code>True</code> if the locator model instance is disposed, <code>false/code> otherwise. + */ + public boolean isDisposed(); + + /** + * Returns the list of known peers. + * + * @return The list of known peers or an empty list. + */ + public IPeer[] getPeers(); + + /** + * Returns an unmodifiable list of known children for the given parent peer. + * + * @param parentPeerID The parent peer id. Must not be <code>null</code>. + * @return The child list. + */ + public List<IPeer> getChildren(String parentPeerID); + + /** + * Sets the list of known children for the given parent peer. + * + * @param parentPeerID The parent peer id. Must not be <code>null</code>. + * @param children The list of children or <code>null</code> to remove the parent peer. + */ + public void setChildren(String parentPeerID, List<IPeer> children); + + /** + * Returns the locator model service, implementing at least the specified + * service interface. + * + * @param serviceInterface The service interface class. Must not be <code>null</code>. + * @return The service instance implementing the specified service interface, or <code>null</code>. + */ + public <V extends ILocatorModelService> V getService(Class<V> serviceInterface); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerModel.java index daf6d8218..145765c35 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/nodes/IPeerModel.java @@ -9,13 +9,10 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.interfaces.nodes; -import java.util.List; - import org.eclipse.core.runtime.IAdaptable; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.services.ILocator; import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; -import org.eclipse.tcf.te.tcf.locator.interfaces.IScanner; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelService; @@ -78,43 +75,6 @@ public interface IPeerModel extends IAdaptable { public IPeerNode[] getPeerNodes(); /** - * Returns an unmodifiable list of known children for the given parent peer. - * - * @param parentPeerID The parent peer id. Must not be <code>null</code>. - * @return The child list. - */ - public List<IPeerNode> getChildren(String parentPeerID); - - /** - * Sets the list of known children for the given parent peer. - * - * @param parentPeerID The parent peer id. Must not be <code>null</code>. - * @param children The list of children or <code>null</code> to remove the parent peer. - */ - public void setChildren(String parentPeerID, List<IPeerNode> children); - - /** - * Returns the scanner instance being associated with the - * locator model. - * - * @return The scanner instance. - */ - public IScanner getScanner(); - - /** - * Starts the scanner. - * - * @param delay The delay in millisecond before the scanning starts. - * @param schedule The time in millisecond between the scanner runs. - */ - public void startScanner(long delay, long schedule); - - /** - * Stops the scanner. - */ - public void stopScanner(); - - /** * Returns the locator model service, implementing at least the specified * service interface. * @@ -133,26 +93,4 @@ public interface IPeerModel extends IAdaptable { */ public IPeer validatePeer(IPeer peer); - /** - * Validate the given peer model if or if not it can be added to the locator model as new peer - * node. - * - * @param node The peer model. Must not be <code>null</code>. - * @return The peer node if it allowed add it to the model, or <code>null</code> if not. - */ - public IPeerNode validatePeerNodeForAdd(IPeerNode node); - - /** - * Validate the given child peer model node if or if not it can be added to the locator model - * as new child peer node for the associated parent peer model node. - * <p> - * <b>Note:</b> The parent peer node is determined by calling {@link IPeerNode#getParentNode()}. - * The call has to return a non-null value, otherwise {@link #validateChildPeerNodeForAdd(IPeerNode)} - * will do nothing. - * - * @param node The peer model. Must not be <code>null</code>. - * @return The peer node if it allowed add it to the model, or <code>null</code> if not. - */ - public IPeerNode validateChildPeerNodeForAdd(IPeerNode node); - } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java new file mode 100644 index 000000000..c0cce36a0 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelLookupService.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.interfaces.services; + +import org.eclipse.tcf.protocol.IPeer; + +/** + * The service to lookup/search in the parent locator model. + */ +public interface ILocatorModelLookupService extends ILocatorModelService { + + /** + * Lookup the locator model for the given peer id. + * + * @param id The peer id. Must not be <code>null</code>. + * @return The peer instance, or <code>null</code> if the peer cannot be found. + */ + public IPeer lkupPeerById(String id); + + /** + * Lookup the matching peer instances for the given agent id. + * + * @param agentId The agent id. Must not be <code>null</code>. + * @return The peer instances, or an empty list if the given agent id could not be matched. + */ + public IPeer[] lkupPeerByAgentId(String agentId); + + /** + * Lookup matching peer instances for the given name. + * + * @param name The name. Must not be <code>null</code>. + * @return The peer instances, or an empty list if the given name could not be matched. + */ + public IPeer[] lkupPeerByName(String name); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java new file mode 100644 index 000000000..bde998762 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelRefreshService.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.interfaces.services; + +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; + +/** + * The service to refresh the parent locator model from remote. + */ +public interface ILocatorModelRefreshService extends ILocatorModelService { + + /** + * Refreshes the list of known peers from the local locator service + * and update the locator model. + * + * @param callback The callback to invoke once the refresh operation finished, or <code>null</code>. + */ + public void refresh(ICallback callback); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelService.java new file mode 100644 index 000000000..6dfeb3686 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelService.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2011 Wind River Systems, Inc. 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.tcf.te.tcf.locator.interfaces.services; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; + +/** + * Common parent interface for locator model services. + */ +public interface ILocatorModelService extends IAdaptable { + + /** + * Returns the parent locator model. + * + * @return The parent locator model. + */ + public ILocatorModel getLocatorModel(); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java new file mode 100644 index 000000000..da368553a --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/ILocatorModelUpdateService.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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.tcf.te.tcf.locator.interfaces.services; + +import org.eclipse.tcf.protocol.IPeer; + +/** + * The service to update the properties of given locator node. + */ +public interface ILocatorModelUpdateService extends ILocatorModelService { + + /** + * Adds the given peer to the list of know peers. + * + * @param peer The peer to add. Must not be <code>null</code>. + */ + public void add(IPeer peer); + + /** + * Removes the given peer from the list of known peers. + * + * @param peer The peer to remove. Must not be <code>null</code. + */ + public void remove(IPeer peer); + + /** + * Update an old peer with the given new one. + * @param oldPeer The old peer to update. Must not be <code>null</code. + * @param newPeer The new peer. Must not be <code>null</code. + */ + public void update(IPeer oldPeer, IPeer newPeer); +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelLookupService.java index 63121f94d..8d5850e6f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelLookupService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelLookupService.java @@ -9,11 +9,10 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.interfaces.services; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; /** - * The service to lookup/search in the parent locator model. + * The service to lookup/search in the parent peer model. */ public interface IPeerModelLookupService extends IPeerModelService { @@ -21,70 +20,35 @@ public interface IPeerModelLookupService extends IPeerModelService { * Lookup the peer model for the given peer id. * * @param id The peer id. Must not be <code>null</code>. - * @return The peer model instance, or <code>null</code> if the peer model cannot be found. + * @return The peer node instance, or <code>null</code> if the peer node cannot be found. */ public IPeerNode lkupPeerModelById(String id); /** - * Lookup the peer model for the given peer id from the peers child list of - * the peer identified by the given parent id. - * - * @param parentId The parent peer id. Must not be <code>null</code>. - * @param id The peer id. Must not be <code>null</code>. - * @return The peer model instance, or <code>null</code> if the peer model cannot be found. - */ - public IPeerNode lkupPeerModelById(String parentId, String id); - - /** - * Lookup the matching peer model instances for the given agent id. + * Lookup the matching peer node instances for the given agent id. * * @param agentId The agent id. Must not be <code>null</code>. - * @return The peer model instances, or an empty list if the given agent id could not be matched. + * @return The peer node instances, or an empty list if the given agent id could not be matched. */ public IPeerNode[] lkupPeerModelByAgentId(String agentId); /** - * Lookup the matching peer model instances for the given agent id. - * - * @param parentId The parent peer id. Must not be <code>null</code>. - * @param agentId The agent id. Must not be <code>null</code>. - * @return The peer model instances, or an empty list if the given agent id could not be matched. - */ - public IPeerNode[] lkupPeerModelByAgentId(String parentId, String agentId); - - /** - * Lookup matching peer model instances for the given name. + * Lookup matching peer node instances for the given name. * * @param name The name. Must not be <code>null</code>. - * @return The peer model instances, or an empty list if the given name could not be matched. + * @return The peer node instances, or an empty list if the given name could not be matched. */ public IPeerNode[] lkupPeerModelByName(String name); /** - * Lookup matching peer model instances which supports the listed local and remote services. + * Lookup matching peer node instances which supports the listed local and remote services. * <p> * <b>Note:</b> This method must be called outside the TCF dispatch thread. * * @param expectedLocalServices The list of local service names to be supported, or <code>null</code>. * @param expectedRemoteServices The list of remote service names to be supported, or <code>null</code>. * - * @return The peer model instances, or an empty list if the listed services are not supported by any of the peers. + * @return The peer node instances, or an empty list if the listed services are not supported by any of the peers node. */ public IPeerNode[] lkupPeerModelBySupportedServices(String[] expectedLocalServices, String[] expectedRemoteServices); - - /** - * Lookup the matching static peer model instances for the given peer model node. - * - * @param peerNode The peer model node. Must not be <code>null</code>. - * @return The matching peer model instances or an empty list. - */ - public IPeerNode[] lkupMatchingStaticPeerModels(IPeerNode peerNode); - - /** - * Lookup the matching static peer model instances for the given peer. - * - * @param peer The peer or <code>null</code>. - * @return The matching peer model instances or an empty list. - */ - public IPeerNode[] lkupMatchingStaticPeerModels(IPeer peer); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java index 70c937814..49c080d57 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelQueryService.java @@ -12,14 +12,14 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; /** - * The service to query asynchronous properties of peers. + * The service to query asynchronous properties of peer nodes. */ public interface IPeerModelQueryService extends IPeerModelService { /** - * Query the list of available local services for the given peer. + * Query the list of available local services for the given peer node. * <p> - * <b>Note:</b> The result of the query is cached within the given peer model + * <b>Note:</b> The result of the query is cached within the given peer * node and subsequent calls will return immediately with the cached value. * <p> * <b>Note:</b> This method must be called outside the TCF dispatch thread. @@ -30,9 +30,9 @@ public interface IPeerModelQueryService extends IPeerModelService { public String queryLocalServices(IPeerNode node); /** - * Query the list of available remote services for the given peer. + * Query the list of available remote services for the given peer node. * <p> - * <b>Note:</b> The result of the query is cached within the given peer model + * <b>Note:</b> The result of the query is cached within the given peer * node and subsequent calls will return immediately with the cached value. * <p> * <b>Note:</b> This method must be called outside the TCF dispatch thread. @@ -55,7 +55,7 @@ public interface IPeerModelQueryService extends IPeerModelService { } /** - * Asynchronously query the services for the given peer model node. + * Asynchronously query the services for the given peer node. * <p> * <b>Note:</b> This method must be called from within the TCF dispatch thread. * diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelRefreshService.java index dc683ea76..201ee399f 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelRefreshService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelRefreshService.java @@ -10,32 +10,16 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; /** - * The service to refresh the parent locator model from remote. + * The service to refresh the parent peer model. */ public interface IPeerModelRefreshService extends IPeerModelService { /** - * Refreshes the list of known peers from the local locator service - * and update the locator model. + * Refreshes the list of known peer nodes and update the peer model. * * @param callback The callback to invoke once the refresh operation finished, or <code>null</code>. */ public void refresh(ICallback callback); - - /** - * Refreshes the list of static peers only and merge them with the peers - * already known to the locator model via the dynamic discovery. - */ - public void refreshStaticPeers(); - - /** - * Refresh the agent ID's of the given or all reachable static peers. - * - * @param nodes The list of nodes to refresh or <code>null</code> to refresh all. - * @param callback The callback to invoke once the refresh operation finished, or <code>null</code>. - */ - public void refreshAgentIDs(IPeerNode[] nodes, ICallback callback); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelUpdateService.java index ca2734a98..0b6782734 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelUpdateService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/interfaces/services/IPeerModelUpdateService.java @@ -11,28 +11,24 @@ package org.eclipse.tcf.te.tcf.locator.interfaces.services; import java.util.Collection; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; - /** - * The service to update the properties of given locator model nodes. + * The service to update the properties of given peer node. */ public interface IPeerModelUpdateService extends IPeerModelService { /** - * Adds the given peer to the list of know peers. - * <p> - * A previous mapping to a peer model with the same id as the given peer model is overwritten. + * Adds the given peer node to the list of know peer nodes. * - * @param peer The peer model object. Must not be <code>null</code>. + * @param peer The peer node to add. Must not be <code>null</code>. */ public void add(IPeerNode peer); /** - * Removes the given peer from the list of known peers. + * Removes the given peer node from the list of known peer nodes. * - * @param peer The peer model object. Must not be <code>null</code. + * @param peer The peer node to remove. Must not be <code>null</code. */ public void remove(IPeerNode peer); @@ -40,42 +36,10 @@ public interface IPeerModelUpdateService extends IPeerModelService { * Update the service nodes of the given peer node with the new set of * local and/or remote services. * - * @param peerNode The peer model instance. Must not be <code>null</code>. + * @param peerNode The peer node instance. Must not be <code>null</code>. * @param localServices The list of local service names or <code>null</code>. * @param remoteServices The list of remote service names or <code>null</code>. */ public void updatePeerServices(IPeerNode peerNode, Collection<String> localServices, Collection<String> remoteServices); - /** - * Adds the given child peer to the parent peer. - * <p> - * <b>Note:</b> The parent peer node is determined by calling {@link IPeerNode#getParentNode()}. - * The call has to return a non-null value, otherwise {@link #addChild(IPeerNode)} - * will do nothing. - * - * @param parent The parent peer model node. Must not be <code>null</code>. - * @param child The child peer model object. Must not be <code>null</code>. - */ - public void addChild(IPeerNode child); - - /** - * Removes the given child peer from the parent peer. - * <p> - * <b>Note:</b> The parent peer node is determined by calling {@link IPeerNode#getParentNode()}. - * The call has to return a non-null value, otherwise {@link #removeChild(IPeerNode)} - * will do nothing. - * - * @param parent The parent peer model node. Must not be <code>null</code>. - * @param child The child peer model object. Must not be <code>null</code>. - */ - public void removeChild(IPeerNode child); - - /** - * Merge user defined peer attributes from the given peer into the given peer node. - * - * @param node The peer node. Must not be <code>null</code>. - * @param peer The peer. Must not be <code>null</code>. - * @param force If <code>true</code>, the peer attributes are merged even if the peer id's don't match. - */ - public void mergeUserDefinedAttributes(IPeerNode node, IPeer peer, boolean force); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java index 572fd793e..b8ab91c25 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/PeerModelPropertyTester.java @@ -19,12 +19,8 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.Platform; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; -import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService; import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; /** @@ -45,28 +41,12 @@ public class PeerModelPropertyTester extends PropertyTester { final IPeerNode peerNode = (IPeerNode)receiver; final AtomicBoolean result = new AtomicBoolean(); - // If we have to test for local or remote services, we have to handle it special - if ("hasLocalService".equals(property) || "hasRemoteService".equals(property)) { //$NON-NLS-1$ //$NON-NLS-2$ - // This tests must happen outside the TCF dispatch thread's - if (!Protocol.isDispatchThread()) { - result.set(testServices(peerNode, property, args, expectedValue)); + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + result.set(testPeerModel(peerNode, property, args, expectedValue)); } - } - else { - Runnable runnable = new Runnable() { - @Override - public void run() { - result.set(testPeerModel(peerNode, property, args, expectedValue)); - } - }; - - if (Protocol.isDispatchThread()) { - runnable.run(); - } - else { - Protocol.invokeAndWait(runnable); - } - } + }); return result.get(); } @@ -114,14 +94,6 @@ public class PeerModelPropertyTester extends PropertyTester { } } - if ("isStaticPeer".equals(property)) { //$NON-NLS-1$ - String value = peer.getAttributes().get("static.transient"); //$NON-NLS-1$ - boolean isStaticPeer = value != null && Boolean.parseBoolean(value.trim()); - if (expectedValue instanceof Boolean) { - return ((Boolean) expectedValue).booleanValue() == isStaticPeer; - } - } - if ("isRedirected".equals(property)) { //$NON-NLS-1$ boolean isRedirected = peer instanceof PeerRedirector; if (expectedValue instanceof Boolean) { @@ -174,53 +146,29 @@ public class PeerModelPropertyTester extends PropertyTester { List<String> remote = remoteServices != null ? Arrays.asList(remoteServices.split(",\\s*")) : null; //$NON-NLS-1$ boolean hasOfflineService = (remote == null) ? offline.contains(expectedValue) : remote.contains(expectedValue); if (expectedValue instanceof Boolean) { - return ((Boolean) expectedValue).booleanValue() == hasOfflineService; + return ((Boolean)expectedValue).booleanValue() == hasOfflineService; } return hasOfflineService; } - return false; - } - - /** - * Test for the peer model node local or remote services. - * <p> - * <b>Node:</b> This method cannot be called from within the TCF Dispatch Thread. - * - * @param node The model node. Must not be <code>null</code>. - * @param property The property to test. - * @param args The property arguments. - * @param expectedValue The expected value. - * - * @return <code>True</code> if the property to test has the expected value, <code>false</code> - * otherwise. - */ - protected boolean testServices(final IPeerNode node, final String property, final Object[] args, final Object expectedValue) { - Assert.isNotNull(node); - Assert.isTrue(!Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - String services = null; - - IPeerModel model = node.getModel(); - IPeerModelQueryService queryService = model.getService(IPeerModelQueryService.class); - if ("hasLocalService".equals(property)) { //$NON-NLS-1$ - services = queryService.queryLocalServices(node); - } else { - services = queryService.queryRemoteServices(node); - } - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(ITracing.ID_TRACE_PROPERTY_TESTER)) { - CoreBundleActivator.getTraceHandler().trace("testServices: property = " + property + ", expectedValue = " + expectedValue + ", services = " + services, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - ITracing.ID_TRACE_PROPERTY_TESTER, PeerModelPropertyTester.this); + if ("hasRemoteService".equals(property)) { //$NON-NLS-1$ + String remoteServices = peerNode.getStringProperty(IPeerNodeProperties.PROP_REMOTE_SERVICES); + List<String> remote = remoteServices != null ? Arrays.asList(remoteServices.split(",\\s*")) : Collections.EMPTY_LIST; //$NON-NLS-1$ + boolean hasRemoteService = remote.contains(expectedValue); + if (expectedValue instanceof Boolean) { + return ((Boolean)expectedValue).booleanValue() == hasRemoteService; + } + return hasRemoteService; } - if (services != null) { - // Lookup each service individually to avoid "accidental" matching - for (String service : services.split(",")) { //$NON-NLS-1$ - if (service != null && service.trim().equals(expectedValue)) { - return true; - } + if ("hasLocalService".equals(property)) { //$NON-NLS-1$ + String localServices = peerNode.getStringProperty(IPeerNodeProperties.PROP_LOCAL_SERVICES); + List<String> remote = localServices != null ? Arrays.asList(localServices.split(",\\s*")) : Collections.EMPTY_LIST; //$NON-NLS-1$ + boolean hasLocalService = remote.contains(expectedValue); + if (expectedValue instanceof Boolean) { + return ((Boolean)expectedValue).booleanValue() == hasLocalService; } + return hasLocalService; } return false; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java index cdbede25b..17d0c1318 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/internal/adapters/AdapterFactory.java @@ -70,7 +70,7 @@ public class AdapterFactory implements IAdapterFactory { @Override public void run() { String id = peer.getID(); - IPeerModel model = Model.getModel(); + IPeerModel model = Model.getPeerModel(); Assert.isNotNull(model); IPeerNode candidate = model.getService(IPeerModelLookupService.class).lkupPeerModelById(id); if (candidate != null) node.set(candidate); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java deleted file mode 100644 index 599383404..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ChannelStateChangeListener.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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.tcf.te.tcf.locator.listener; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.IPeer; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; -import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; -import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; - - -/** - * Channel state change listener implementation. - */ -public class ChannelStateChangeListener implements IChannelStateChangeListener { - // Reference to the parent model - private final IPeerModel model; - - /** - * Constructor. - * - * @param model The parent locator model. Must not be <code>null</code>. - */ - public ChannelStateChangeListener(IPeerModel model) { - Assert.isNotNull(model); - this.model = model; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.tcf.core.interfaces.listeners.IChannelStateChangeListener#stateChanged(org.eclipse.tcf.protocol.IChannel, int) - */ - @Override - public void stateChanged(IChannel channel, int state) { - Assert.isNotNull(channel); - Assert.isTrue(Protocol.isDispatchThread()); - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_CHANNEL_STATE_CHANGE_LISTENER)) { - CoreBundleActivator.getTraceHandler().trace("ChannelStateChangeListener.stateChanged( " + channel + ", " + (state == IChannel.STATE_OPEN ? "OPEN" : "CLOSED") + " )", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ - ITracing.ID_TRACE_CHANNEL_STATE_CHANGE_LISTENER, this); - } - - switch (state) { - case IChannel.STATE_OPEN: - IPeer peer = channel.getRemotePeer(); - if (peer != null && peer.getID() != null) { - // Find the corresponding model node - IPeerNode node = model.getService(IPeerModelLookupService.class).lkupPeerModelById(peer.getID()); - if (node != null) { - // Increase the channel reference counter by 1 - int counter = node.getIntProperty(IPeerNodeProperties.PROP_CHANNEL_REF_COUNTER); - if (counter < 0) counter = 0; - counter++; - node.setProperty(IPeerNodeProperties.PROP_CHANNEL_REF_COUNTER, counter); - } - } - break; - case IChannel.STATE_CLOSED: - peer = channel.getRemotePeer(); - if (peer != null && peer.getID() != null) { - // Find the corresponding model node - IPeerNode node = model.getService(IPeerModelLookupService.class).lkupPeerModelById(peer.getID()); - if (node != null) { - // Decrease the channel reference counter by 1 - int counter = node.getIntProperty(IPeerNodeProperties.PROP_CHANNEL_REF_COUNTER); - counter--; - if (counter < 0) counter = 0; - node.setProperty(IPeerNodeProperties.PROP_CHANNEL_REF_COUNTER, counter); - } - } - break; - } - } -} 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 81c31c723..8df69f05a 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 @@ -9,49 +9,30 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.listener; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.tcf.core.AbstractPeer; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.services.ILocator; -import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; -import org.eclipse.tcf.te.tcf.core.peers.Peer; -import org.eclipse.tcf.te.tcf.locator.ScannerRunnable; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; -import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; -import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; -import org.eclipse.tcf.te.tcf.locator.nodes.PeerNode; -import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; - +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; /** * Locator listener implementation. */ public final class LocatorListener implements ILocator.LocatorListener { // Reference to the parent model - /* default */ final IPeerModel model; + /* default */ final ILocatorModel model; /** * Constructor. * * @param model The parent locator model. Must not be <code>null</code>. */ - public LocatorListener(IPeerModel model) { + public LocatorListener(ILocatorModel model) { super(); Assert.isNotNull(model); @@ -95,107 +76,20 @@ public final class LocatorListener implements ILocator.LocatorListener { if (isFiltered(peer)) return; if (model != null && peer != null) { - // find the corresponding model node to remove (expected to be null) - IPeerNode peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(peer.getID()); - if (peerNode == null) { + IPeer lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(peer.getID()); + if (lkupPeer == null) { // Double check with "ClientID" if set String clientID = peer.getAttributes().get("ClientID"); //$NON-NLS-1$ if (clientID != null) { - peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(clientID); + lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(clientID); } } - // If not found, create a new peer node instance - if (peerNode == null) { - peerNode = new PeerNode(model, peer); - // Validate the peer node before adding - peerNode = model.validatePeerNodeForAdd(peerNode); - // Add the peer node to the model - if (peerNode != null) { - // If there are reachable static peers without an agent ID associated or - // static peers with unknown link state, refresh the agent ID's first. - List<IPeerNode> nodes = new ArrayList<IPeerNode>(); - - for (IPeerNode node : model.getPeerNodes()) { - // We expect the agent ID to be set - if (node.getPeer().getAgentID() == null || "".equals(node.getPeer().getAgentID())) { //$NON-NLS-1$ - nodes.add(node); - } - } - - // Create the runnable to execute after the agent ID refresh (if needed) - final IPeerNode finPeerNode = peerNode; - final IPeer finPeer = peer; - final Runnable runnable = new Runnable() { - @Override - public void run() { - IPeerNode[] matches = model.getService(IPeerModelLookupService.class).lkupMatchingStaticPeerModels(finPeerNode); - if (matches.length == 0) { - // If the peer node is still in the model, schedule for immediate status update - if (model.getService(IPeerModelLookupService.class).lkupPeerModelById(finPeerNode.getPeerId()) != null) { - Runnable runnable2 = new ScannerRunnable(model.getScanner(), finPeerNode); - Protocol.invokeLater(runnable2); - } - } else { - // Remove the preliminary added node from the model again - model.getService(IPeerModelUpdateService.class).remove(finPeerNode); - - for (IPeerNode match : matches) { - IPeer myPeer = model.validatePeer(finPeer); - if (myPeer != null) { - // Update the matching static node - boolean changed = match.setChangeEventsEnabled(false); - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(match, myPeer, true); - if (changed) match.setChangeEventsEnabled(true); - match.fireChangeEvent(IPeerNodeProperties.PROP_INSTANCE, myPeer, match.getPeer()); - // And schedule for immediate status update - Runnable runnable2 = new ScannerRunnable(model.getScanner(), match); - Protocol.invokeLater(runnable2); - } - } - } - } - }; - - // Preliminary add the node to the model now. If we have to refresh the agent ID, - // this is an asynchronous operation and other peerAdded events might be processed before. - model.getService(IPeerModelUpdateService.class).add(peerNode); - - if (nodes.size() > 0) { - // Refresh the agent ID's first - model.getService(IPeerModelRefreshService.class).refreshAgentIDs(nodes.toArray(new IPeerNode[nodes.size()]), new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Ignore errors - runnable.run(); - } - }); - } else { - // No need to refresh the agent ID's -> run runnable - runnable.run(); - } - } - } else { - // Peer node found, update the peer instance - // Validate the peer node before updating - IPeer myPeer = model.validatePeer(peer); - if (myPeer != null) { - boolean changed = peerNode.setChangeEventsEnabled(false); - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, myPeer, true); - if (changed) peerNode.setChangeEventsEnabled(true); - peerNode.fireChangeEvent(IPeerNodeProperties.PROP_INSTANCE, myPeer, peerNode.getPeer()); - // And schedule for immediate status update - Runnable runnable = new ScannerRunnable(model.getScanner(), peerNode); - Protocol.invokeLater(runnable); - } + if (lkupPeer == null) { + model.getService(ILocatorModelUpdateService.class).add(peer); } } } - // Map of guardian objects per peer - private final Map<IPeer, AtomicBoolean> PEER_CHANGED_GUARDIANS = new HashMap<IPeer, AtomicBoolean>(); - /* (non-Javadoc) * @see org.eclipse.tcf.services.ILocator.LocatorListener#peerChanged(org.eclipse.tcf.protocol.IPeer) */ @@ -209,54 +103,21 @@ public final class LocatorListener implements ILocator.LocatorListener { if (isFiltered(peer)) return; - // Protect ourself from reentrant calls while processing a changed peer. - if (peer != null) { - AtomicBoolean guard = PEER_CHANGED_GUARDIANS.get(peer); - if (guard != null && guard.get()) return; - if (guard != null) guard.set(true); - else PEER_CHANGED_GUARDIANS.put(peer, new AtomicBoolean(true)); - } - if (model != null && peer != null) { // find the corresponding model node to remove - IPeerNode peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(peer.getID()); - if (peerNode == null) { + IPeer lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(peer.getID()); + if (lkupPeer == null) { // Double check with "ClientID" if set String clientID = peer.getAttributes().get("ClientID"); //$NON-NLS-1$ if (clientID != null) { - peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(clientID); + lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(clientID); } } // Update the peer instance - if (peerNode != null) { - // Get the old peer instance - IPeer oldPeer = peerNode.getPeer(); - // If old peer and new peer instance are the same _objects_, nothing to do - if (oldPeer != peer) { - // Peers visible to the locator are replaced with the new instance - if (oldPeer instanceof AbstractPeer) { - peerNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); - } - // Non-visible peers are updated - else { - // Validate the peer node before updating - IPeer myPeer = model.validatePeer(peer); - if (myPeer != null) { - boolean changed = peerNode.setChangeEventsEnabled(false); - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, myPeer, true); - if (changed) peerNode.setChangeEventsEnabled(true); - peerNode.fireChangeEvent(IPeerNodeProperties.PROP_INSTANCE, myPeer, peerNode.getPeer()); - } - } - } + if (lkupPeer != null) { + model.getService(ILocatorModelUpdateService.class).update(lkupPeer, peer); } - // Refresh static peers and merge attributes if required - model.getService(IPeerModelRefreshService.class).refreshStaticPeers(); } - - // Clean up the guardians - if (peer != null) PEER_CHANGED_GUARDIANS.remove(peer); } /* (non-Javadoc) @@ -272,11 +133,11 @@ public final class LocatorListener implements ILocator.LocatorListener { if (model != null && id != null) { // find the corresponding model node to remove - IPeerNode peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(id); + IPeer lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(id); // If we cannot find a model node, it is probably because the remove is sent for the // non-loopback addresses of the localhost. We have to double check this. - if (peerNode == null) { + if (lkupPeer == null) { int beginIndex = id.indexOf(':'); int endIndex = id.lastIndexOf(':'); String ip = id.substring(beginIndex+1, endIndex); @@ -299,73 +160,12 @@ public final class LocatorListener implements ILocator.LocatorListener { newId.append(id.substring(endIndex + 1)); // Try the lookup again - peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(newId.toString()); + lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(newId.toString()); } // If the model node is found in the model, process the removal. - if (peerNode != null) { - boolean changed = peerNode.setChangeEventsEnabled(false); - IPeer peer = peerNode.getPeer(); - - // Create a modifiable copy of the peer attributes - Map<String, String> attrs = new HashMap<String, String>(peerNode.getPeer().getAttributes()); - // Remember the remote peer id before removing it - String remotePeerID = attrs.get("remote.id.transient"); //$NON-NLS-1$ - - // Remove all merged attributes from the peer instance - String merged = attrs.remove("remote.merged.transient"); //$NON-NLS-1$ - if (merged != null) { - merged = merged.replace('[', ' ').replace(']', ' ').trim(); - List<String> keysToRemove = Arrays.asList(merged.split(",\\ ")); //$NON-NLS-1$ - String[] keys = attrs.keySet().toArray(new String[attrs.keySet().size()]); - for (String key : keys) { - if (keysToRemove.contains(key)) { - attrs.remove(key); - } - } - - // Make sure the ID is set correctly - if (attrs.get(IPeer.ATTR_ID) == null) { - attrs.put(IPeer.ATTR_ID, peer.getID()); - } - - // Update the peer attributes - if (peer instanceof PeerRedirector) { - ((PeerRedirector)peer).updateAttributes(attrs); - } else if (peer instanceof Peer) { - ((Peer)peer).updateAttributes(attrs); - } - } - - // Remove the attributes stored at peer node level - peerNode.setProperty(IPeerNodeProperties.PROP_LOCAL_SERVICES, null); - peerNode.setProperty(IPeerNodeProperties.PROP_REMOTE_SERVICES, null); - - // Check if we have to remote the peer in the underlying locator service too - if (remotePeerID != null) { - Map<String, IPeer> peers = Protocol.getLocator().getPeers(); - IPeer remotePeer = peers.get(remotePeerID); - if (remotePeer instanceof AbstractPeer) ((AbstractPeer)remotePeer).dispose(); - } - - // Clean out possible child nodes - peerNode.getModel().setChildren(peerNode.getPeerId(), null); - - if (changed) peerNode.setChangeEventsEnabled(true); - peerNode.fireChangeEvent(IPeerNodeProperties.PROP_INSTANCE, peer, peerNode.getPeer()); - - final IModelListener[] listeners = model.getListener(); - if (listeners.length > 0) { - final IPeerNode finPeerNode = peerNode; - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (IModelListener listener : listeners) { - listener.locatorModelChanged(model, finPeerNode, false); - } - } - }); - } + if (lkupPeer != null) { + model.getService(ILocatorModelUpdateService.class).remove(lkupPeer); } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ProtocolStateChangeListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ProtocolStateChangeListener.java index 4f3a46afd..cf90ec9d2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ProtocolStateChangeListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/listener/ProtocolStateChangeListener.java @@ -23,7 +23,7 @@ public class ProtocolStateChangeListener implements IProtocolStateChangeListener @Override public void stateChanged(boolean state) { // If the TCF frame work got started, initialize the locator model as well - if (state) Model.getModel(); + if (state) Model.getPeerModel(); } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/Model.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/Model.java index 2af3c5844..b70b3a09a 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/Model.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/model/Model.java @@ -11,18 +11,62 @@ package org.eclipse.tcf.te.tcf.locator.model; import org.eclipse.core.runtime.Assert; import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.nodes.LocatorModel; import org.eclipse.tcf.te.tcf.locator.nodes.PeerModel; /** - * Helper class to instantiate and initialize the TCF locator model. + * Helper class to instantiate and initialize the peer and locator model. */ public final class Model { - // Reference to the locator model + // Reference to the peer model /* default */ static volatile IPeerModel peerModel; + // Reference to the locator model + /* default */ static volatile ILocatorModel locatorModel; + + /** + * Returns the shared peer model instance. + * <p> + * If the shared peer model instance has not been yet initialized, + * the method does initialize the shared peer model instance. + * + * @return The shared peer model. + */ + public static IPeerModel getPeerModel() { + return getPeerModel(false); + } + + /** + * Returns the shared peer model instance. + * <p> + * If the shared peer model instance has not been yet initialized, + * and <code>shutdown</code> is <code>false</code>, the method does + * initialize the shared peer model instance. + * + * @param shutdown <code>True</code> if the method is called during shutdown and + * the model should not be initialized if not done anyway. <code> + * false</code> in any other case. + * + * @return The shared peer model. + */ + public static IPeerModel getPeerModel(boolean shutdown) { + // Access to the locator model must happen in the TCF dispatch thread + if (peerModel == null && !shutdown) { + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + initialize(); + } + }); + } + return peerModel; + } + /** * Returns the shared locator model instance. * <p> @@ -31,8 +75,8 @@ public final class Model { * * @return The shared locator model. */ - public static IPeerModel getModel() { - return getModel(false); + public static ILocatorModel getLocatorModel() { + return getLocatorModel(false); } /** @@ -48,21 +92,17 @@ public final class Model { * * @return The shared locator model. */ - public static IPeerModel getModel(boolean shutdown) { + public static ILocatorModel getLocatorModel(boolean shutdown) { // Access to the locator model must happen in the TCF dispatch thread - if (peerModel == null && !shutdown) { - if (Protocol.isDispatchThread()) { - initialize(); - } else { - Protocol.invokeAndWait(new Runnable() { - @Override - public void run() { - initialize(); - } - }); - } + if (locatorModel == null && !shutdown) { + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + initialize(); + } + }); } - return peerModel; + return locatorModel; } /** @@ -71,37 +111,50 @@ public final class Model { protected static void initialize() { Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - // If locator model is set in the mean while, initialize got + // If peer model is set in the mean while, initialize got // called twice. Return immediately in this case. - if (peerModel != null) return; + if (peerModel == null) { + // Create the model instance + peerModel = new PeerModel(); + // Refresh the model right away + peerModel.getService(IPeerModelRefreshService.class).refresh(null); + } - // Create the model instance - peerModel = new PeerModel(); - // Refresh the model right away - peerModel.getService(IPeerModelRefreshService.class).refresh(null); - // Start the scanner - peerModel.startScanner(5000, 120000); + // If locator model is set in the mean while, initialize got + // called twice. Return immediately in this case. + if (locatorModel == null) { + // Create the model instance + locatorModel = new LocatorModel(); + // Refresh the model right away + locatorModel.getService(ILocatorModelRefreshService.class).refresh(null); + } } /** * Dispose the root node. */ public static void dispose() { - if (peerModel == null) return; - - // Access to the locator model must happen in the TCF dispatch thread - if (Protocol.isDispatchThread()) { - peerModel.dispose(); - } else { + if (peerModel != null) { + // Access to the peer model must happen in the TCF dispatch thread Protocol.invokeAndWait(new Runnable() { @Override public void run() { peerModel.dispose(); } }); + peerModel = null; } - peerModel = null; + if (locatorModel != null) { + // Access to the locator model must happen in the TCF dispatch thread + Protocol.invokeAndWait(new Runnable() { + @Override + public void run() { + locatorModel.dispose(); + } + }); + locatorModel = null; + } } } 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 new file mode 100644 index 000000000..215ea5145 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/LocatorModel.java @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.nodes; + +import java.util.ArrayList; +import java.util.Collections; +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; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.services.ILocator; +import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; +import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; +import org.eclipse.tcf.te.tcf.locator.listener.LocatorListener; +import org.eclipse.tcf.te.tcf.locator.services.LocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.services.LocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.services.LocatorModelUpdateService; + + +/** + * Default locator model implementation. + */ +public class LocatorModel extends PlatformObject implements ILocatorModel { + // The unique model id + private final UUID uniqueId = UUID.randomUUID(); + // Flag to mark the model disposed + private boolean disposed; + + // The list of known peers + /* default */ final Map<String, IPeer> peers = new HashMap<String, IPeer>(); + // The list of "proxied" peers per proxy peer id + /* default */ final Map<String, List<IPeer>> peerChildren = new HashMap<String, List<IPeer>>(); + + // Reference to the model locator listener + private ILocator.LocatorListener locatorListener = null; + + // Reference to the refresh service + private final ILocatorModelRefreshService refreshService = new LocatorModelRefreshService(this); + // Reference to the lookup service + private final ILocatorModelLookupService lookupService = new LocatorModelLookupService(this); + // Reference to the update service + private final ILocatorModelUpdateService updateService = new LocatorModelUpdateService(this); + /** + * Constructor. + */ + public LocatorModel() { + super(); + disposed = false; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#dispose() + */ + @Override + public void dispose() { + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { + CoreBundleActivator.getTraceHandler().trace("PeerModel.dispose()", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ + } + + // If already disposed, we are done immediately + if (disposed) return; + + disposed = true; + + if (locatorListener != null) { + Protocol.getLocator().removeListener(locatorListener); + locatorListener = null; + } + + peers.clear(); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#isDisposed() + */ + @Override + public boolean isDisposed() { + return disposed; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getPeers() + */ + @Override + public IPeer[] getPeers() { + final AtomicReference<IPeer[]> result = new AtomicReference<IPeer[]>(); + + Runnable runnable = new Runnable() { + @Override + public void run() { + result.set(peers.values().toArray(new IPeer[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<IPeer> getChildren(final String parentPeerID) { + Assert.isNotNull(parentPeerID); + + final AtomicReference<List<IPeer>> result = new AtomicReference<List<IPeer>>(); + + Runnable runnable = new Runnable() { + @Override + public void run() { + List<IPeer> 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) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#setChildren(java.lang.String, java.util.List) + */ + @Override + public void setChildren(String parentPeerID, List<IPeer> children) { + Assert.isNotNull(parentPeerID); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + if (children == null || children.size() == 0) { + peerChildren.remove(parentPeerID); + } else { + peerChildren.put(parentPeerID, new ArrayList<IPeer>(children)); + } + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) + */ + @Override + public Object getAdapter(Class adapter) { + if (adapter.isAssignableFrom(ILocator.LocatorListener.class)) { + return locatorListener; + } + if (adapter.isAssignableFrom(ILocatorModelRefreshService.class)) { + return refreshService; + } + if (adapter.isAssignableFrom(ILocatorModelLookupService.class)) { + return lookupService; + } + if (adapter.isAssignableFrom(ILocatorModelUpdateService.class)) { + return updateService; + } + if (adapter.isAssignableFrom(Map.class)) { + return peers; + } + + return super.getAdapter(adapter); + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + return uniqueId.hashCode(); + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public final boolean equals(Object obj) { + if (obj instanceof LocatorModel) { + return uniqueId.equals(((LocatorModel)obj).uniqueId); + } + return super.equals(obj); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel#getService(java.lang.Class) + */ + @Override + @SuppressWarnings("unchecked") + public <V extends ILocatorModelService> V getService(Class<V> serviceInterface) { + Assert.isNotNull(serviceInterface); + return (V)getAdapter(serviceInterface); + } + + /** + * Check if the locator listener has been created and registered + * to the global locator service. + * <p> + * <b>Note:</b> This method is not intended to be call from clients. + */ + public void checkLocatorListener() { + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + Assert.isNotNull(Protocol.getLocator()); + + if (locatorListener == null) { + locatorListener = doCreateLocatorListener(this); + Protocol.getLocator().addListener(locatorListener); + } + } + + /** + * Creates the locator listener instance. + * + * @param model The parent model. Must not be <code>null</code>. + * @return The locator listener instance. + */ + protected ILocator.LocatorListener doCreateLocatorListener(ILocatorModel model) { + Assert.isNotNull(model); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + return new LocatorListener(model); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java index 594031ffd..6731388a1 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/nodes/PeerModel.java @@ -10,7 +10,6 @@ package org.eclipse.tcf.te.tcf.locator.nodes; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -19,17 +18,11 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.core.runtime.jobs.Job; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.services.ILocator; import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; -import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.listeners.interfaces.IChannelStateChangeListener; -import org.eclipse.tcf.te.tcf.locator.Scanner; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; -import org.eclipse.tcf.te.tcf.locator.interfaces.IScanner; import org.eclipse.tcf.te.tcf.locator.interfaces.ITracing; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; @@ -38,8 +31,6 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelService; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; -import org.eclipse.tcf.te.tcf.locator.listener.ChannelStateChangeListener; -import org.eclipse.tcf.te.tcf.locator.listener.LocatorListener; import org.eclipse.tcf.te.tcf.locator.services.PeerModelLookupService; import org.eclipse.tcf.te.tcf.locator.services.PeerModelQueryService; import org.eclipse.tcf.te.tcf.locator.services.PeerModelRefreshService; @@ -47,7 +38,7 @@ import org.eclipse.tcf.te.tcf.locator.services.PeerModelUpdateService; /** - * Default locator model implementation. + * Default peer model implementation. */ public class PeerModel extends PlatformObject implements IPeerModel { // The unique model id @@ -56,17 +47,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { private boolean disposed; // The list of known peers - /* default */ final Map<String, IPeerNode> peers = new HashMap<String, IPeerNode>(); - // The list of "proxied" peers per proxy peer id - /* default */ final Map<String, List<IPeerNode>> peerChildren = new HashMap<String, List<IPeerNode>>(); - - // Reference to the scanner - private IScanner scanner = null; - - // Reference to the model locator listener - private ILocator.LocatorListener locatorListener = null; - // Reference to the model channel state change listener - private IChannelStateChangeListener channelStateChangeListener = null; + /* default */ final Map<String, IPeerNode> peerNodes = new HashMap<String, IPeerNode>(); // The list of registered model listeners private final List<IModelListener> modelListener = new ArrayList<IModelListener>(); @@ -86,9 +67,6 @@ public class PeerModel extends PlatformObject implements IPeerModel { public PeerModel() { super(); disposed = false; - - channelStateChangeListener = new ChannelStateChangeListener(this); - Tcf.addChannelStateChangeListener(channelStateChangeListener); } /* (non-Javadoc) @@ -99,8 +77,8 @@ public class PeerModel extends PlatformObject implements IPeerModel { Assert.isNotNull(listener); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.addListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_PEER_MODEL)) { + CoreBundleActivator.getTraceHandler().trace("PeerModel.addListener( " + listener + " )", ITracing.ID_TRACE_PEER_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ } if (!modelListener.contains(listener)) modelListener.add(listener); @@ -114,8 +92,8 @@ public class PeerModel extends PlatformObject implements IPeerModel { Assert.isNotNull(listener); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.removeListener( " + listener + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_PEER_MODEL)) { + CoreBundleActivator.getTraceHandler().trace("PeerModel.removeListener( " + listener + " )", ITracing.ID_TRACE_PEER_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ } modelListener.remove(listener); @@ -137,8 +115,8 @@ public class PeerModel extends PlatformObject implements IPeerModel { public void dispose() { Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.dispose()", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_PEER_MODEL)) { + CoreBundleActivator.getTraceHandler().trace("PeerModel.dispose()", ITracing.ID_TRACE_PEER_MODEL, this); //$NON-NLS-1$ } // If already disposed, we are done immediately @@ -159,22 +137,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { } modelListener.clear(); - if (locatorListener != null) { - Protocol.getLocator().removeListener(locatorListener); - locatorListener = null; - } - - if (channelStateChangeListener != null) { - Tcf.removeChannelStateChangeListener(channelStateChangeListener); - channelStateChangeListener = null; - } - - if (scanner != null) { - stopScanner(); - scanner = null; - } - - peers.clear(); + peerNodes.clear(); } /* (non-Javadoc) @@ -195,7 +158,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { Runnable runnable = new Runnable() { @Override public void run() { - result.set(peers.values().toArray(new IPeerNode[peers.values().size()])); + result.set(peerNodes.values().toArray(new IPeerNode[peerNodes.values().size()])); } }; @@ -206,55 +169,10 @@ public class PeerModel extends PlatformObject implements IPeerModel { } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel#getChildren(java.lang.String) - */ - @Override - public List<IPeerNode> getChildren(final String parentPeerID) { - Assert.isNotNull(parentPeerID); - - final AtomicReference<List<IPeerNode>> result = new AtomicReference<List<IPeerNode>>(); - - Runnable runnable = new Runnable() { - @Override - public void run() { - List<IPeerNode> 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) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel#setChildren(java.lang.String, java.util.List) - */ - @Override - public void setChildren(String parentPeerID, List<IPeerNode> children) { - Assert.isNotNull(parentPeerID); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - if (children == null || children.size() == 0) { - peerChildren.remove(parentPeerID); - } else { - peerChildren.put(parentPeerID, new ArrayList<IPeerNode>(children)); - } - } - - /* (non-Javadoc) * @see org.eclipse.core.runtime.PlatformObject#getAdapter(java.lang.Class) */ @Override public Object getAdapter(Class adapter) { - if (adapter.isAssignableFrom(ILocator.LocatorListener.class)) { - return locatorListener; - } - if (adapter.isAssignableFrom(IScanner.class)) { - return scanner; - } if (adapter.isAssignableFrom(IPeerModelRefreshService.class)) { return refreshService; } @@ -268,7 +186,7 @@ public class PeerModel extends PlatformObject implements IPeerModel { return queryService; } if (adapter.isAssignableFrom(Map.class)) { - return peers; + return peerNodes; } return super.getAdapter(adapter); @@ -303,88 +221,6 @@ public class PeerModel extends PlatformObject implements IPeerModel { return (V)getAdapter(serviceInterface); } - /** - * Check if the locator listener has been created and registered - * to the global locator service. - * <p> - * <b>Note:</b> This method is not intended to be call from clients. - */ - public void checkLocatorListener() { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Assert.isNotNull(Protocol.getLocator()); - - if (locatorListener == null) { - locatorListener = doCreateLocatorListener(this); - Protocol.getLocator().addListener(locatorListener); - } - } - - /** - * Creates the locator listener instance. - * - * @param model The parent model. Must not be <code>null</code>. - * @return The locator listener instance. - */ - protected ILocator.LocatorListener doCreateLocatorListener(IPeerModel model) { - Assert.isNotNull(model); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - return new LocatorListener(model); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#getScanner() - */ - @Override - public IScanner getScanner() { - if (scanner == null) scanner = new Scanner(this); - return scanner; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#startScanner(long, long) - */ - @Override - public void startScanner(long delay, long schedule) { - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.startScanner( " + delay + ", " + schedule + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - IScanner scanner = getScanner(); - Assert.isNotNull(scanner); - - // Pass on the schedule parameter - Map<String, Object> config = new HashMap<String, Object>(scanner.getConfiguration()); - config.put(IScanner.PROP_SCHEDULE, Long.valueOf(schedule)); - scanner.setConfiguration(config); - - // The default scanner implementation is a job. - // -> schedule here if it is a job - if (scanner instanceof Job) { - Job job = (Job)scanner; - job.setSystem(true); - job.setPriority(Job.DECORATE); - job.schedule(delay); - } - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#stopScanner() - */ - @Override - public void stopScanner() { - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.stopScanner()", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ - } - - if (scanner != null) { - // Terminate the scanner - scanner.terminate(); - // Reset the scanner reference - scanner = null; - } - } - /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel#validatePeer(org.eclipse.tcf.protocol.IPeer) */ @@ -393,8 +229,8 @@ public class PeerModel extends PlatformObject implements IPeerModel { Assert.isNotNull(peer); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeer( " + peer.getID() + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_PEER_MODEL)) { + CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeer( " + peer.getID() + " )", ITracing.ID_TRACE_PEER_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ } IPeer result = peer; @@ -410,374 +246,12 @@ public class PeerModel extends PlatformObject implements IPeerModel { // Not loopback address -> drop the peer result = null; - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { + if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_PEER_MODEL)) { CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeer: local host peer but not loopback address -> peer node dropped" //$NON-NLS-1$ - , ITracing.ID_TRACE_LOCATOR_MODEL, this); + , ITracing.ID_TRACE_PEER_MODEL, this); } } return result; } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.ILocatorModel#validatePeerNodeForAdd(org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.IPeerModel) - */ - @Override - public IPeerNode validatePeerNodeForAdd(IPeerNode node) { - Assert.isNotNull(node); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // Get the peer from the peer node - IPeer peer = node.getPeer(); - if (peer == null) return node; - - // Skip static peer IP address validation - return node; - -// // Skip validation if the transport type is not TCP or SSL -// String transport = peer.getTransportName(); -// if (transport == null || !"TCP".equals(transport) && !"SSL".equals(transport)){ //$NON-NLS-1$ //$NON-NLS-2$ -// return node; -// } -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd( " + peer.getID() + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ -// } -// -// IPeerNode result = node; -// -// // Get the loopback address -// String loopback = IPAddressUtil.getInstance().getIPv4LoopbackAddress(); -// // Get the peer IP -// String peerIP = peer.getAttributes().get(IPeer.ATTR_IP_HOST); -// -// // If the peer node is for local host, we ignore all peers not being -// // associated with the loopback address. -// if (IPAddressUtil.getInstance().isLocalHost(peerIP) && !loopback.equals(peerIP)) { -// boolean drop = true; -// -// // Simulator nodes appears on local host IP addresses too, but does not have -// // a loopback peer available. We have to check the agent ID to determine if -// // a specific node can be dropped -// String agentID = peer.getAgentID(); -// if (agentID != null) { -// // Get all discovered peers -// Map<String, IPeer> peers = Protocol.getLocator().getPeers(); -// // Sort them by agent id -// Map<String, List<IPeer>> byAgentID = new HashMap<String, List<IPeer>>(); -// -// for (IPeer candidate : peers.values()) { -// if (candidate.getAgentID() == null) continue; -// -// List<IPeer> l = byAgentID.get(candidate.getAgentID()); -// if (l == null) { -// l = new ArrayList<IPeer>(); -// byAgentID.put(candidate.getAgentID(), l); -// } -// Assert.isNotNull(l); -// if (!l.contains(candidate)) l.add(candidate); -// } -// -// // Check all peers found for the same agent ID as the current peer to validate -// List<IPeer> candidates = byAgentID.get(agentID); -// if (candidates != null && candidates.size() > 1) { -// // Check if the found peers contains one with the loopback address -// drop = false; -// for (IPeer candidate : candidates) { -// String ip = candidate.getAttributes().get(IPeer.ATTR_IP_HOST); -// if (IPAddressUtil.getInstance().isLocalHost(ip) && loopback.equals(ip)) { -// drop = true; -// break; -// } -// } -// } else { -// // No other node for this agent ID -> do not drop the peer -// drop = false; -// } -// } -// -// -// if (drop) { -// // Not loopback address -> drop the peer -// result = null; -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: local host peer but not loopback address -> peer node dropped", //$NON-NLS-1$ -// ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// } -// } -// -// // Continue filtering if the node is not yet dropped -// if (result != null) { -// List<IPeerNode> previousNodes = new ArrayList<IPeerNode>(); -// -// // Peers are filtered by agent id. Don't add the peer node if we have another peer -// // node already having the same agent id -// String agentId = peer.getAgentID(); -// if (agentId != null) { -// previousNodes.addAll(Arrays.asList(getService(IPeerModelLookupService.class).lkupPeerModelByAgentId(agentId))); -// } -// -// // Lookup for matching static peer nodes not found by the agent id lookup -// IPeerNode[] candidates = getService(IPeerModelLookupService.class).lkupMatchingStaticPeerModels(peer); -// for (IPeerNode candidate : candidates) { -// if (!previousNodes.contains(candidate)) previousNodes.add(candidate); -// } -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: agentId=" + agentId + ", Matching peer nodes " //$NON-NLS-1$ //$NON-NLS-2$ -// + (previousNodes.size() > 0 ? "found (" + previousNodes.size() +")" : "not found --> DONE") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ -// , ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// -// for (IPeerNode previousNode : previousNodes) { -// // Get the peer for the previous node -// IPeer previousPeer = previousNode.getPeer(); -// if (previousPeer != null) { -// // Get the IP address of the previous node -// String previousPeerIP = previousPeer.getAttributes().get(IPeer.ATTR_IP_HOST); -// if (IPAddressUtil.getInstance().isLocalHost(previousPeerIP) && !loopback.equals(previousPeerIP) && loopback.equals(peerIP)) { -// // Remove the previous node from the model -// getService(IPeerModelUpdateService.class).remove(previousNode); -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: Previous peer removed and replaced by new peer representing the loopback address" //$NON-NLS-1$ -// , ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// -// continue; -// } -// -// // Get the ports -// String peerPort = peer.getAttributes().get(IPeer.ATTR_IP_PORT); -// String previousPeerPort = previousPeer.getAttributes().get(IPeer.ATTR_IP_PORT); -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: peerIP=" + peerIP //$NON-NLS-1$ -// + ", peerPort=" + peerPort + ", previousPeerPort=" + previousPeerPort //$NON-NLS-1$ //$NON-NLS-2$ -// , ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// -// // If the ports of the agent instances are identical, -// // than try to find the best representation of the agent instance -// if (peerPort != null && peerPort.equals(previousPeerPort)) { -// // Drop the current node -// result = null; -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: Previous peer node kept, new peer node dropped" //$NON-NLS-1$ -// , ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// -// -// // Break the loop if the ports matched -// break; -// } -// -// if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { -// CoreBundleActivator.getTraceHandler().trace("PeerModel.validatePeerNodeForAdd: Previous peer node kept, new peer node added (Port mismatch)" //$NON-NLS-1$ -// , ITracing.ID_TRACE_LOCATOR_MODEL, this); -// } -// } -// } -// } -// -// return result; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel#validateChildPeerNodeForAdd(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) - */ - @Override - public IPeerNode validateChildPeerNodeForAdd(final IPeerNode node) { - Assert.isNotNull(node); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.validateChildPeerNodeForAdd( " + node.getPeerId() + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ - } - - // Determine the parent node. If null, the child node is invalid - // and cannot be added - final IPeerNode parent = node.getParent(IPeerNode.class); - if (parent == null) return null; - - return validateChildPeerNodeForAdd(parent, node); - } - - /** - * Validates the given child peer model node in relation to the given parent peer model node - * hierarchy. - * <p> - * The method is recursive. - * - * @param parent The parent model node. Must not be <code>null</code>. - * @param node The child model node. Must not be <code>null</code>. - * - * @return The validated child peer model node, or <code>null</code>. - */ - protected IPeerNode validateChildPeerNodeForAdd(IPeerNode parent, IPeerNode node) { - Assert.isNotNull(parent); - Assert.isNotNull(node); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.validateChildPeerNodeForAdd( " + parent.getPeerId() + ", " + node.getPeerId() + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - // Validate against the given parent - if (doValidateChildPeerNodeForAdd(parent, node) == null) { - return null; - } - - // If the parent node is child node by itself, validate the - // child node against the parent parent node. - if (parent.getParent(IPeerNode.class) != null) { - IPeerNode parentParentNode = parent.getParent(IPeerNode.class); - if (doValidateChildPeerNodeForAdd(parentParentNode, node) == null) { - return null; - } - - // And validate the child node against all child nodes of the parent parent. - List<IPeerNode> childrenList = getChildren(parentParentNode.getPeerId()); - IPeerNode[] children = childrenList.toArray(new IPeerNode[childrenList.size()]); - for (IPeerNode parentParentChild : children) { - if (node.equals(parentParentChild) || parent.equals(parentParentChild)) { - return null; - } - if (doValidateChildPeerNodeForAdd(parentParentChild, node) == null) { - return null; - } - } - } - - return node; - } - - /** - * Validates the given child peer model node in relation to the given parent peer model node. - * <p> - * The method is non-recursive. - * - * @param parent The parent model node. Must not be <code>null</code>. - * @param node The child model node. Must not be <code>null</code>. - * - * @return The validated child peer model node, or <code>null</code>. - */ - protected IPeerNode doValidateChildPeerNodeForAdd(IPeerNode parent, IPeerNode node) { - Assert.isNotNull(parent); - Assert.isNotNull(node); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_LOCATOR_MODEL)) { - CoreBundleActivator.getTraceHandler().trace("PeerModel.doValidateChildPeerNodeForAdd( " + parent.getPeerId() + ", " + node.getPeerId() + " )", ITracing.ID_TRACE_LOCATOR_MODEL, this); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - - // If the child node is already visible as root node, drop the child node - String id = node.getPeerId(); - if (isRootNode(id)) { - return null; - } - - int beginIndex = id.indexOf(':'); - int endIndex = id.lastIndexOf(':'); - String ip = beginIndex != -1 && endIndex != -1 ? id.substring(beginIndex+1, endIndex) : ""; //$NON-NLS-1$ - - // Get the loopback address - String loopback = IPAddressUtil.getInstance().getIPv4LoopbackAddress(); - // Empty IP address means loopback - if ("".equals(ip)) ip = loopback; //$NON-NLS-1$ - - // If the IP is a localhost IP, try the loopback IP - if (IPAddressUtil.getInstance().isLocalHost(ip)) { - // Build up the new id to lookup - StringBuilder newId = new StringBuilder(); - newId.append(id.substring(0, beginIndex)); - newId.append(':'); - newId.append(loopback); - newId.append(':'); - newId.append(id.substring(endIndex + 1)); - - // Try the lookup again - if (isRootNode(newId.toString())) { - return null; - } - } - - // Get the peer from the peer node - IPeer peer = node.getPeer(); - - // If the child peer represents the same agent as the parent peer, - // drop the child peer - String parentAgentID = parent.getPeer().getAgentID(); - if (parentAgentID != null && parentAgentID.equals(peer.getAgentID())) { - return null; - } - // If the child peer represents the same agent as another child peer, - // drop the child peer - String agentID = node.getPeer().getAgentID(); - if (agentID != null) { - IPeerNode[] matches = getService(IPeerModelLookupService.class).lkupPeerModelByAgentId(parent.getPeerId(), agentID); - for (IPeerNode match : matches) { - if (agentID.equals(match.getPeer().getAgentID())) { - // Try to keep the peer with the real IP, filter the "127.0.0.1" peer - if ("127.0.0.1".equals(node.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST)) //$NON-NLS-1$ - && !"127.0.0.1".equals(match.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST))) { //$NON-NLS-1$ - // Keep the other child node - return null; - } - - if (!"127.0.0.1".equals(node.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST)) //$NON-NLS-1$ - && "127.0.0.1".equals(match.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST))) { //$NON-NLS-1$ - // Keep the node - getService(IPeerModelUpdateService.class).removeChild(match); - } - - // If both nodes have a IP different from "127.0.0.1", keep the first node - if (!"127.0.0.1".equals(node.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST)) //$NON-NLS-1$ - && !"127.0.0.1".equals(match.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST))) { //$NON-NLS-1$ - // Keep the other child node - return null; - } - } - } - } - // If the child peer's IP address and port are the same as the parent's - // IP address and port, drop the child node - Map<String, String> parentPeerAttributes = parent.getPeer().getAttributes(); - if (parentPeerAttributes.get(IPeer.ATTR_IP_HOST) != null && parentPeerAttributes.get(IPeer.ATTR_IP_HOST).equals(peer.getAttributes().get(IPeer.ATTR_IP_HOST))) { - String parentPort = parentPeerAttributes.get(IPeer.ATTR_IP_PORT); - String port = peer.getAttributes().get(IPeer.ATTR_IP_PORT); - - if (parentPort != null && parentPort.equals(port)) return null; - } - - return node; - } - - /** - * Checks if the given peer id belongs to an already known root node - * or to one of the discovered nodes. - * - * @param id The peer id. Must not be <code>null</code>. - * @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; - - if (getService(IPeerModelLookupService.class).lkupPeerModelById(id) != null) { - isRoot = true; - } else { - Map<String, IPeer> peers = Protocol.getLocator().getPeers(); - if (peers.containsKey(id)) { - isRoot = true; - } - } - - return isRoot; - } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/GsonPeerPersistenceDelegate.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/GsonPeerPersistenceDelegate.java index a274f8129..1b94b1e6b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/GsonPeerPersistenceDelegate.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/persistence/GsonPeerPersistenceDelegate.java @@ -85,10 +85,10 @@ public class GsonPeerPersistenceDelegate extends GsonMapPersistenceDelegate { String id = peer.getID(); if (id != null) { // Lookup the id within the model - IPeerNode peerNode = Model.getModel().getService(IPeerModelLookupService.class).lkupPeerModelById(id); + IPeerNode peerNode = Model.getPeerModel().getService(IPeerModelLookupService.class).lkupPeerModelById(id); if (peerNode == null) { // Not found in the model -> create a ghost object - peerNode = new PeerNode(Model.getModel(), peer); + peerNode = new PeerNode(Model.getPeerModel(), peer); peerNode.setProperty(IModelNode.PROPERTY_IS_GHOST, true); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/AbstractLocatorModelService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/AbstractLocatorModelService.java new file mode 100644 index 000000000..5650583f1 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/AbstractLocatorModelService.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.services; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelService; + + +/** + * Abstract locator model service base implementation. + */ +public abstract class AbstractLocatorModelService extends PlatformObject implements ILocatorModelService { + // Reference to the parent locator model + private final ILocatorModel locatorModel; + + /** + * Constructor. + * + * @param parentModel The parent locator model instance. Must not be <code>null</code>. + */ + public AbstractLocatorModelService(ILocatorModel parentModel) { + Assert.isNotNull(parentModel); + locatorModel = parentModel; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelService#getPeerModel() + */ + @Override + public final ILocatorModel getLocatorModel() { + return locatorModel; + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java new file mode 100644 index 000000000..bd603bdab --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelLookupService.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.services; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; + + +/** + * Default locator model lookup service implementation. + */ +public class LocatorModelLookupService extends AbstractLocatorModelService implements ILocatorModelLookupService { + + /** + * Constructor. + * + * @param parentModel The parent locator model instance. Must not be <code>null</code>. + */ + public LocatorModelLookupService(ILocatorModel parentModel) { + super(parentModel); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupPeerById(java.lang.String) + */ + @Override + public IPeer lkupPeerById(String id) { + Assert.isNotNull(id); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + IPeer node = null; + for (IPeer peer : getLocatorModel().getPeers()) { + if (id.equals(peer.getID())) { + node = peer; + break; + } + } + + return node; + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupPeerByAgentId(java.lang.String) + */ + @Override + public IPeer[] lkupPeerByAgentId(String agentId) { + Assert.isNotNull(agentId); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + List<IPeer> nodes = new ArrayList<IPeer>(); + for (IPeer peer : getLocatorModel().getPeers()) { + if (agentId.equals(peer.getAgentID())) { + nodes.add(peer); + } + } + + return nodes.toArray(new IPeer[nodes.size()]); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService#lkupPeerByName(java.lang.String) + */ + @Override + public IPeer[] lkupPeerByName(String name) { + Assert.isNotNull(name); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + List<IPeer> nodes = new ArrayList<IPeer>(); + for (IPeer peer : getLocatorModel().getPeers()) { + if (name.equals(peer.getName())) { + nodes.add(peer); + } + } + + return nodes.toArray(new IPeer[nodes.size()]); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java new file mode 100644 index 000000000..399e15ad8 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelRefreshService.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.services; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.Status; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; +import org.eclipse.tcf.te.tcf.core.Tcf; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelLookupService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelRefreshService; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; + + +/** + * Default locator model refresh service implementation. + */ +public class LocatorModelRefreshService extends AbstractLocatorModelService implements ILocatorModelRefreshService { + + /** + * Constructor. + * + * @param parentModel The parent locator model instance. Must not be <code>null</code>. + */ + public LocatorModelRefreshService(ILocatorModel parentModel) { + super(parentModel); + } + + /** + * Asynchronously invoke the callback within the TCF dispatch thread. + * + * @param callback The callback to invoke or <code>null</code>. + */ + protected final void invokeCallback(final ICallback callback) { + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + if (callback != null) { + Protocol.invokeLater(new Runnable() { + @Override + public void run() { + callback.done(LocatorModelRefreshService.this, Status.OK_STATUS); + } + }); + } + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService#refresh(org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) + */ + @Override + public void refresh(final ICallback callback) { + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + // Get the parent peer model + ILocatorModel model = getLocatorModel(); + + // If the parent model is already disposed, the service will drop out immediately + if (model.isDisposed()) { + invokeCallback(callback); + return; + } + + // If the TCF framework isn't initialized yet, the service will drop out immediately + if (!Tcf.isRunning()) { + invokeCallback(callback); + return; + } + + // Get the list of old children (update node instances where possible) + final List<IPeer> oldChildren = new ArrayList<IPeer>(Arrays.asList(model.getPeers())); + + // Refresh the static peer definitions + processPeers(Protocol.getLocator().getPeers(), oldChildren, model); + + // Invoke the callback + invokeCallback(callback); + } + + /** + * Process the given map of peers and update the given locator model. + * + * @param peers The map of peers to process. Must not be <code>null</code>. + * @param oldChildren The list of old children. Must not be <code>null</code>. + * @param model The locator model. Must not be <code>null</code>. + */ + protected void processPeers(Map<String, IPeer> peers, List<IPeer> oldChildren, ILocatorModel model) { + Assert.isNotNull(peers); + Assert.isNotNull(oldChildren); + Assert.isNotNull(model); + + for (Entry<String, IPeer> entry : peers.entrySet()) { + // Get the peer instance for the current peer id + IPeer peer = entry.getValue(); + // Try to find an existing peer node first + IPeer lkupPeer = model.getService(ILocatorModelLookupService.class).lkupPeerById(entry.getKey()); + // And create a new one if we cannot find it + if (lkupPeer == null) { + model.getService(ILocatorModelUpdateService.class).add(peer); + } + else { + oldChildren.remove(peer); + } + } + + if (!oldChildren.isEmpty()) { + for (IPeer oldPeer : oldChildren) { + model.getService(ILocatorModelUpdateService.class).remove(oldPeer); + } + } + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java new file mode 100644 index 000000000..124660f4a --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/LocatorModelUpdateService.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2011, 2012 Wind River Systems, Inc. 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.tcf.te.tcf.locator.services; + +import java.util.Map; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.tcf.protocol.IPeer; +import org.eclipse.tcf.protocol.Protocol; +import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.ILocatorModel; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService; + + +/** + * Default locator model update service implementation. + */ +public class LocatorModelUpdateService extends AbstractLocatorModelService implements ILocatorModelUpdateService { + + /** + * Constructor. + * + * @param parentModel The parent locator model instance. Must not be <code>null</code>. + */ + public LocatorModelUpdateService(ILocatorModel parentModel) { + super(parentModel); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#add(org.eclipse.tcf.protocol.IPeer) + */ + @Override + public void add(final IPeer peer) { + Assert.isNotNull(peer); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(peers); + peers.put(peer.getID(), peer); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#remove(org.eclipse.tcf.protocol.IPeer) + */ + @Override + public void remove(final IPeer peer) { + Assert.isNotNull(peer); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(peers); + peers.remove(peer.getID()); + } + + /* (non-Javadoc) + * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.ILocatorModelUpdateService#update(org.eclipse.tcf.protocol.IPeer, org.eclipse.tcf.protocol.IPeer) + */ + @Override + public void update(IPeer oldPeer, IPeer newPeer) { + Assert.isNotNull(oldPeer); + Assert.isNotNull(newPeer); + Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ + + Map<String, IPeer> peers = (Map<String, IPeer>)getLocatorModel().getAdapter(Map.class); + Assert.isNotNull(peers); + peers.remove(oldPeer.getID()); + peers.put(newPeer.getID(), newPeer); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java index 2dbca2eef..75fcefca4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelLookupService.java @@ -22,14 +22,14 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService /** - * Default locator model lookup service implementation. + * Default peer model lookup service implementation. */ public class PeerModelLookupService extends AbstractPeerModelService implements IPeerModelLookupService { /** * Constructor. * - * @param parentModel The parent locator model instance. Must not be <code>null</code>. + * @param parentModel The parent peer model instance. Must not be <code>null</code>. */ public PeerModelLookupService(IPeerModel parentModel) { super(parentModel); @@ -60,31 +60,6 @@ public class PeerModelLookupService extends AbstractPeerModelService implements } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupPeerModelById(java.lang.String, java.lang.String) - */ - @Override - public IPeerNode lkupPeerModelById(String parentId, String id) { - Assert.isNotNull(parentId); - Assert.isNotNull(id); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - IPeerNode node = null; - for (IPeerNode candidate : getPeerModel().getChildren(parentId)) { - IPeer peer = candidate.getPeer(); - if (id.equals(peer.getID())) { - node = candidate; - break; - } else if (peer.getAttributes().get("remote.id.transient") != null //$NON-NLS-1$ - && peer.getAttributes().get("remote.id.transient").equals(id)) { //$NON-NLS-1$ - node = candidate; - break; - } - } - - return node; - } - - /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupPeerModelByAgentId(java.lang.String) */ @Override @@ -104,26 +79,6 @@ public class PeerModelLookupService extends AbstractPeerModelService implements } /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupPeerModelByAgentId(java.lang.String, java.lang.String) - */ - @Override - public IPeerNode[] lkupPeerModelByAgentId(String parentId, String agentId) { - Assert.isNotNull(parentId); - Assert.isNotNull(agentId); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - List<IPeerNode> nodes = new ArrayList<IPeerNode>(); - for (IPeerNode candidate : getPeerModel().getChildren(parentId)) { - IPeer peer = candidate.getPeer(); - if (agentId.equals(peer.getAgentID())) { - nodes.add(candidate); - } - } - - return nodes.toArray(new IPeerNode[nodes.size()]); - } - - /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupPeerModelByName(java.lang.String) */ @Override @@ -195,53 +150,4 @@ public class PeerModelLookupService extends AbstractPeerModelService implements return nodes.toArray(new IPeerNode[nodes.size()]); } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupMatchingStaticPeerModels(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) - */ - @Override - public IPeerNode[] lkupMatchingStaticPeerModels(IPeerNode peerNode) { - Assert.isNotNull(peerNode); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - return lkupMatchingStaticPeerModels(peerNode.getPeer()); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelLookupService#lkupMatchingStaticPeerModels(org.eclipse.tcf.protocol.IPeer) - */ - @Override - public IPeerNode[] lkupMatchingStaticPeerModels(IPeer peer) { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - List<IPeerNode> nodes = new ArrayList<IPeerNode>(); - - if (peer != null) { - for (IPeerNode candidate : getPeerModel().getPeerNodes()) { - // If the agent id is available, match up the agent id first. - if (candidate.getPeer().getAgentID() != null && candidate.getPeer().getAgentID().equals(peer.getAgentID())) { - nodes.add(candidate); - continue; - } - - // Get the transport types. Transport type must match and must be either "TCP" or "SSL". - String t1 = peer.getTransportName(); - String t2 = candidate.getPeer().getTransportName(); - - if (t1 != null && t1.equals(t2) && ("TCP".equals(t1) || "SSL".equals(t1))) { //$NON-NLS-1$ //$NON-NLS-2$ - // Compare IP and Port. If they match, add the candidate to the result list - String i1 = peer.getAttributes().get(IPeer.ATTR_IP_HOST); - String i2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST); - if (i1 != null && i1.equals(i2)) { - String p1 = peer.getAttributes().get(IPeer.ATTR_IP_PORT); - String p2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT); - if (p1 != null && p1.equals(p2)) { - nodes.add(candidate); - } - } - } - } - } - - return nodes.toArray(new IPeerNode[nodes.size()]); - } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java index 3e5cda423..63eef4d92 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelQueryService.java @@ -30,14 +30,14 @@ import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelQueryService import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; /** - * Default locator model peer node query service implementation. + * Default peer model peer node query service implementation. */ public class PeerModelQueryService extends AbstractPeerModelService implements IPeerModelQueryService { /** * Constructor. * - * @param parentModel The parent locator model instance. Must not be <code>null</code>. + * @param parentModel The parent peer model instance. Must not be <code>null</code>. */ public PeerModelQueryService(IPeerModel parentModel) { super(parentModel); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java index 9c6c75306..c5ab977ff 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelRefreshService.java @@ -12,7 +12,6 @@ package org.eclipse.tcf.te.tcf.locator.services; import java.io.File; import java.io.FileFilter; import java.io.IOException; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -23,26 +22,16 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; -import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.IPeer; -import org.eclipse.tcf.protocol.IToken; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.services.ILocator; -import org.eclipse.tcf.te.runtime.callback.AsyncCallbackCollector; -import org.eclipse.tcf.te.runtime.callback.Callback; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties; import org.eclipse.tcf.te.runtime.persistence.interfaces.IURIPersistenceService; import org.eclipse.tcf.te.runtime.services.ServiceManager; -import org.eclipse.tcf.te.runtime.utils.net.IPAddressUtil; import org.eclipse.tcf.te.tcf.core.Tcf; -import org.eclipse.tcf.te.tcf.core.async.CallbackInvocationDelegate; -import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; import org.eclipse.tcf.te.tcf.core.peers.Peer; -import org.eclipse.tcf.te.tcf.locator.ScannerRunnable; import org.eclipse.tcf.te.tcf.locator.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; @@ -57,14 +46,14 @@ import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; /** - * Default locator model refresh service implementation. + * Default peer model refresh service implementation. */ public class PeerModelRefreshService extends AbstractPeerModelService implements IPeerModelRefreshService { /** * Constructor. * - * @param parentModel The parent locator model instance. Must not be <code>null</code>. + * @param parentModel The parent peer model instance. Must not be <code>null</code>. */ public PeerModelRefreshService(IPeerModel parentModel) { super(parentModel); @@ -95,7 +84,7 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements public void refresh(final ICallback callback) { Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - // Get the parent locator model + // Get the parent peer model IPeerModel model = getPeerModel(); // If the parent model is already disposed, the service will drop out immediately @@ -116,34 +105,16 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements // Refresh the static peer definitions refreshStaticPeers(oldChildren, model); -// // Get the locator service -// ILocator locatorService = Protocol.getLocator(); -// if (locatorService != null) { -// // Check for the locator listener to be created and registered -// if (model instanceof PeerModel) { -// ((PeerModel)model).checkLocatorListener(); -// } -// // Get the map of peers known to the locator service. -// Map<String, IPeer> peers = locatorService.getPeers(); -// // Process the peers -// processPeers(peers, oldChildren, model); -// } - - // If there are remaining old children, remove them from the model (non-recursive) - for (IPeerNode oldChild : oldChildren) { - model.getService(IPeerModelUpdateService.class).remove(oldChild); - } - // Invoke the callback invokeCallback(callback); } /** - * Process the given map of peers and update the given locator model. + * Process the given map of peers and update the given peer model. * * @param peers The map of peers to process. Must not be <code>null</code>. * @param oldChildren The list of old children. Must not be <code>null</code>. - * @param model The locator model. Must not be <code>null</code>. + * @param model The peer model. Must not be <code>null</code>. */ protected void processPeers(Map<String, IPeer> peers, List<IPeerNode> oldChildren, IPeerModel model) { Assert.isNotNull(peers); @@ -158,102 +129,27 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements // And create a new one if we cannot find it if (peerNode == null) { peerNode = new PeerNode(model, peer); + model.getService(IPeerModelUpdateService.class).add(peerNode); } else { oldChildren.remove(peerNode); } if (peerNode.getPeer() != peer) { - String value = peerNode.getPeer().getAttributes().get(IPersistableNodeProperties.PROPERTY_URI); - URI uri = value != null ? URI.create(value) : null; - File file = uri != null && "file".equals(uri.getScheme()) ? new File(uri.normalize()) : null; //$NON-NLS-1$ - if (file != null && !file.exists()) { - peerNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); - } else { - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, peer, false); - } + peerNode.setProperty(IPeerNodeProperties.PROP_INSTANCE, peer); } + } - // Validate the peer node before adding - peerNode = model.validatePeerNodeForAdd(peerNode); - if (peerNode != null) { - // There is still the chance that the node we add is a static node and - // there exist an dynamically discovered node with a different id but - // for the same peer. Do this check only if the peer to add is a static one. - IPeerNode toRemove = null; - for (IPeerNode candidate : model.getPeerNodes()) { - if (candidate.equals(peerNode))continue; - String peerID = peerNode.getPeerId(); - String clientID = candidate.getPeer().getAttributes().get("ClientID"); //$NON-NLS-1$ - if (clientID != null && clientID.equals(peerID)) { - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(candidate, peerNode.getPeer(), true); - peerNode = null; - break; - } - - if (peerNode.getPeer().getTransportName() != null && peerNode.getPeer().getTransportName().equals(candidate.getPeer().getTransportName())) { - // Same transport name - if ("PIPE".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$ - // Compare the pipe name - String name1 = peerNode.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$ - String name2 = candidate.getPeer().getAttributes().get("PipeName"); //$NON-NLS-1$ - // Same pipe -> same node - if (name1 != null && name1.equals(name2)) { - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, candidate.getPeer(), true); - toRemove = candidate; - break; - } - } else if ("Loop".equals(candidate.getPeer().getTransportName())) { //$NON-NLS-1$ - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, candidate.getPeer(), true); - toRemove = candidate; - break; - } else { - // Compare IP_HOST and IP_Port; - String ip1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST); - String ip2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_HOST); - if (IPAddressUtil.getInstance().isSameHost(ip1, ip2)) { - // Compare the ports - String port1 = peerNode.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT); - String port2 = candidate.getPeer().getAttributes().get(IPeer.ATTR_IP_PORT); - - if (port1 != null && port1.equals(port2)) { - // Merge user configured properties between the peers - model.getService(IPeerModelUpdateService.class).mergeUserDefinedAttributes(peerNode, candidate.getPeer(), true); - toRemove = candidate; - break; - } - } - } - } - } - - if (toRemove != null) { - model.getService(IPeerModelUpdateService.class).remove(toRemove); - toRemove = null; - } - - if (peerNode != null) { - // Add the peer node to model - model.getService(IPeerModelUpdateService.class).add(peerNode); - // And schedule for immediate status update - Runnable runnable = new ScannerRunnable(model.getScanner(), peerNode); - Protocol.invokeLater(runnable); - } - } + if (!oldChildren.isEmpty()) { + for (IPeerNode oldPeerNode : oldChildren) { + model.getService(IPeerModelUpdateService.class).remove(oldPeerNode); + } } } private final AtomicBoolean REFRESH_STATIC_PEERS_GUARD = new AtomicBoolean(false); - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService#refreshStaticPeers() - */ - @Override - public void refreshStaticPeers() { + protected void refreshStaticPeers() { Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ // This method might be called reentrant while processing. Return immediately @@ -263,7 +159,7 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements } REFRESH_STATIC_PEERS_GUARD.set(true); - // Get the parent locator model + // Get the parent peer model IPeerModel model = getPeerModel(); // If the parent model is already disposed, the service will drop out immediately @@ -284,7 +180,7 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements * Refresh the static peer definitions. * * @param oldChildren The list of old children. Must not be <code>null</code>. - * @param model The locator model. Must not be <code>null</code>. + * @param model The peer model. Must not be <code>null</code>. */ protected void refreshStaticPeers(List<IPeerNode> oldChildren, IPeerModel model) { Assert.isNotNull(oldChildren); @@ -304,8 +200,7 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements @Override public boolean accept(File pathname) { IPath path = new Path(pathname.getAbsolutePath()); - return path.getFileExtension() != null && - (path.getFileExtension().toLowerCase().equals("json") || path.getFileExtension().toLowerCase().equals("peer")); //$NON-NLS-1$ //$NON-NLS-2$ + return path.getFileExtension() != null && path.getFileExtension().toLowerCase().equals("peer"); //$NON-NLS-1$ } }); // If there are ini files to read, process them @@ -320,8 +215,6 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements // Remember the file path within the properties attrs.put(IPersistableNodeProperties.PROPERTY_URI, candidate.getAbsoluteFile().toURI().toString()); - // Mark the node as static peer model node - attrs.put("static.transient", "true"); //$NON-NLS-1$ //$NON-NLS-2$ // Validate the name attribute. If not set, set // it to the file name without the .ini extension. @@ -418,26 +311,6 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements if (!peers.isEmpty()) { processPeers(peers, oldChildren, model); } - - // Scan the peers for redirected ones ... and set up the peer model association - for (Entry<String, IPeer> entry : peers.entrySet()) { - IPeer peer = entry.getValue(); - if (!(peer instanceof PeerRedirector)) { - continue; - } - - // Get the peers peer model object - IPeerNode peerNode = model.getService(IPeerModelLookupService.class).lkupPeerModelById(entry.getKey()); - Assert.isNotNull(peerNode); - - // The peer is a peer redirector -> get the proxy peer id and proxy peer model - String proxyPeerId = ((PeerRedirector)peer).getParent().getID(); - IPeerNode proxy = model.getService(IPeerModelLookupService.class).lkupPeerModelById(proxyPeerId); - Assert.isNotNull(proxy); - - peerNode.setParent(proxy); - model.getService(IPeerModelUpdateService.class).addChild(peerNode); - } } } @@ -475,125 +348,4 @@ public class PeerModelRefreshService extends AbstractPeerModelService implements return rootLocations.toArray(new File[rootLocations.size()]); } - - /* default */ final List<ICallback> refreshAgentIDCallbacks = new ArrayList<ICallback>(); - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelRefreshService#refreshAgentIDs(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode[], org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) - */ - @Override - public void refreshAgentIDs(IPeerNode[] nodes, final ICallback callback) { - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // This method might be called reentrant while processing. Add - // the callback to the "wait" list and return immediately. - if (refreshAgentIDCallbacks.size() > 0) { - refreshAgentIDCallbacks.add(callback); - return; - } - refreshAgentIDCallbacks.add(callback); - - // Get the parent locator model - IPeerModel model = getPeerModel(); - - // If the parent model is already disposed, the service will drop out immediately - if (model.isDisposed()) { - return; - } - - // The callback collector will fire once all static peers have been refreshed - final AsyncCallbackCollector collector = new AsyncCallbackCollector(new Callback() { - @Override - protected void internalDone(Object caller, IStatus status) { - // Make a copy of the callbacks to invoke - List<ICallback> callbacks = new ArrayList<ICallback>(refreshAgentIDCallbacks); - refreshAgentIDCallbacks.clear(); - // And invoke the final callbacks - for (ICallback callback : callbacks) { - invokeCallback(callback); - } - } - }, new CallbackInvocationDelegate()); - - // Make a copy of the current list of static peers before processing - List<IPeerNode> nodesToProcess = new ArrayList<IPeerNode>(Arrays.asList(nodes != null ? nodes : model.getPeerNodes())); - // Loop the list of static peers and try to get the agent ID - for (IPeerNode node : nodesToProcess) { - // If not static or not complete --> ignore - if (!node.isComplete()) continue; - // Refresh the agent ID - refreshAgentID(node, new AsyncCallbackCollector.SimpleCollectorCallback(collector)); - } - - // Mark the collector initialization as done - collector.initDone(); - } - - /** - * Refreshes the agent ID of the given static peer node, if reachable. - * - * @param node The peer model node. Must not be <code>null</code>. - * @param callback The callback. Must not be <code>null</code>. - */ - protected void refreshAgentID(final IPeerNode node, final ICallback callback) { - Assert.isNotNull(node); - Assert.isNotNull(callback); - - if (!(node.getPeer() instanceof Peer)) return; - - // Try to open a channel to the node - Map<String, Boolean> flags = new HashMap<String, Boolean>(); - flags.put(IChannelManager.FLAG_FORCE_NEW, Boolean.TRUE); - flags.put(IChannelManager.FLAG_NO_VALUE_ADD, Boolean.TRUE); - - Tcf.getChannelManager().openChannel(node.getPeer(), flags, new IChannelManager.DoneOpenChannel() { - - @Override - public void doneOpenChannel(Throwable error, final IChannel channel) { - if (channel != null && channel.getState() == IChannel.STATE_OPEN) { - // Get the locator service - ILocator service = channel.getRemoteService(ILocator.class); - if (service != null) { - // Query the agent ID - service.getAgentID(new ILocator.DoneGetAgentID() { - @Override - public void doneGetAgentID(IToken token, Exception error, String agentID) { - // Close the channel - Tcf.getChannelManager().closeChannel(channel); - - // Update the peer - if (agentID == null || "".equals(agentID)) { //$NON-NLS-1$ - if (node.getPeer().getAgentID() != null) { - // Remove the old agent ID - Map<String, String> attrs = new HashMap<String, String>(channel.getRemotePeer().getAttributes()); - attrs.remove(IPeer.ATTR_AGENT_ID); - node.setProperty(IPeerNodeProperties.PROP_INSTANCE, new Peer(attrs)); - } - } else if (node.getPeer().getAgentID() == null || !agentID.equals(node.getPeer().getAgentID())){ - // Set the new agent ID - Map<String, String> attrs = new HashMap<String, String>(channel.getRemotePeer().getAttributes()); - attrs.put(IPeer.ATTR_AGENT_ID, agentID); - node.setProperty(IPeerNodeProperties.PROP_INSTANCE, new Peer(attrs)); - } - - // Invoke the callback - callback.done(PeerModelRefreshService.this, Status.OK_STATUS); - } - }); - } else { - // Close the channel - Tcf.getChannelManager().closeChannel(channel); - // Invoke the callback - callback.done(PeerModelRefreshService.this, Status.OK_STATUS); - } - } else { - // Close the channel in any case - if (channel != null) Tcf.getChannelManager().closeChannel(channel); - // Invoke the callback - callback.done(PeerModelRefreshService.this, Status.OK_STATUS); - } - - } - }); - } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelUpdateService.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelUpdateService.java index 0f4684ca4..53651c041 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelUpdateService.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/services/PeerModelUpdateService.java @@ -9,34 +9,26 @@ *******************************************************************************/ package org.eclipse.tcf.te.tcf.locator.services; -import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.core.runtime.Assert; -import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.persistence.interfaces.IPersistableNodeProperties; -import org.eclipse.tcf.te.tcf.core.peers.Peer; -import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNodeProperties; import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; -import org.eclipse.tcf.te.tcf.locator.nodes.PeerRedirector; /** - * Default locator model update service implementation. + * Default peer model update service implementation. */ public class PeerModelUpdateService extends AbstractPeerModelService implements IPeerModelUpdateService { /** * Constructor. * - * @param parentModel The parent locator model instance. Must not be <code>null</code>. + * @param parentModel The parent peer model instance. Must not be <code>null</code>. */ public PeerModelUpdateService(IPeerModel parentModel) { super(parentModel); @@ -46,52 +38,26 @@ public class PeerModelUpdateService extends AbstractPeerModelService implements * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.services.ILocatorModelUpdateService#add(org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.IPeerModel) */ @Override - public void add(final IPeerNode peer) { - Assert.isNotNull(peer); + public void add(final IPeerNode peerNode) { + Assert.isNotNull(peerNode); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Map<String, IPeerNode> peers = (Map<String, IPeerNode>)getPeerModel().getAdapter(Map.class); - Assert.isNotNull(peers); - peers.put(peer.getPeerId(), peer); - - final IModelListener[] listeners = getPeerModel().getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (IModelListener listener : listeners) { - listener.locatorModelChanged(getPeerModel(), peer, true); - } - } - }); - } + Map<String, IPeerNode> peerNodes = (Map<String, IPeerNode>)getPeerModel().getAdapter(Map.class); + Assert.isNotNull(peerNodes); + peerNodes.put(peerNode.getPeerId(), peerNode); } /* (non-Javadoc) * @see org.eclipse.tcf.te.tcf.locator.core.interfaces.services.ILocatorModelUpdateService#remove(org.eclipse.tcf.te.tcf.locator.core.interfaces.nodes.IPeerModel) */ @Override - public void remove(final IPeerNode peer) { - Assert.isNotNull(peer); + public void remove(final IPeerNode peerNode) { + Assert.isNotNull(peerNode); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - Map<String, IPeerNode> peers = (Map<String, IPeerNode>)getPeerModel().getAdapter(Map.class); - Assert.isNotNull(peers); - peers.remove(peer.getPeerId()); - - getPeerModel().setChildren(peer.getPeerId(), null); - - final IModelListener[] listeners = getPeerModel().getListener(); - if (listeners.length > 0) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - for (IModelListener listener : listeners) { - listener.locatorModelChanged(getPeerModel(), peer, false); - } - } - }); - } + Map<String, IPeerNode> peerNodes = (Map<String, IPeerNode>)getPeerModel().getAdapter(Map.class); + Assert.isNotNull(peerNodes); + peerNodes.remove(peerNode.getPeerId()); } /* (non-Javadoc) @@ -122,138 +88,4 @@ public class PeerModelUpdateService extends AbstractPeerModelService implements return buffer.trim(); } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService#addChild(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) - */ - @Override - public void addChild(final IPeerNode child) { - Assert.isNotNull(child); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // Determine the parent node - final IPeerNode parent = child.getParent(IPeerNode.class); - if (parent == null) return; - - // Determine the peer id of the parent - String parentPeerId = parent.getPeerId(); - Assert.isNotNull(parentPeerId); - - // Get the list of existing children - List<IPeerNode> children = new ArrayList<IPeerNode>(getPeerModel().getChildren(parentPeerId)); - if (!children.contains(child)) { - children.add(child); - getPeerModel().setChildren(parentPeerId, children); - } - - // Notify listeners - parent.fireChangeEvent("changed", null, children); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService#removeChild(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode) - */ - @Override - public void removeChild(final IPeerNode child) { - Assert.isNotNull(child); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // Determine the parent node - final IPeerNode parent = child.getParent(IPeerNode.class); - if (parent == null) return; - - // Determine the peer id of the parent - String parentPeerId = parent.getPeerId(); - Assert.isNotNull(parentPeerId); - - // Get the list of existing children - List<IPeerNode> children = new ArrayList<IPeerNode>(getPeerModel().getChildren(parentPeerId)); - if (children.contains(child)) { - children.remove(child); - getPeerModel().setChildren(parentPeerId, children); - } - - // Notify listeners - parent.fireChangeEvent("changed", null, children); //$NON-NLS-1$ - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService#mergeUserDefinedAttributes(org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode, org.eclipse.tcf.protocol.IPeer, boolean) - */ - @Override - public void mergeUserDefinedAttributes(IPeerNode node, IPeer peer, boolean force) { - Assert.isNotNull(node); - Assert.isNotNull(peer); - Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ - - // We can merge the peer attributes only if the destination peer is a AbstractPeer - IPeer dst = node.getPeer(); - // If not of correct type, than we cannot update the attributes - if (!(dst instanceof PeerRedirector) && !(dst instanceof Peer)) return; - // If destination and source peer are the same objects(!) nothing to do here - if (dst == peer) return; - - // If not forced, the peer id's of both attribute maps must be the same - if (!force) Assert.isTrue(dst.getID().equals(peer.getID()) - || (dst.getAttributes().get("remote.id.transient") != null && dst.getAttributes().get("remote.id.transient").equals(peer.getID()))); //$NON-NLS-1$ //$NON-NLS-2$ - - // Get a modifiable copy of the destination peer attributes - Map<String, String> dstAttrs = new HashMap<String, String>(dst.getAttributes()); - - // Get a modifiable copy of the source peer attributes - Map<String, String> srcAttrs = new HashMap<String, String>(peer.getAttributes()); - - // Remove the URI from the destination if requested - boolean removeURI = srcAttrs.containsKey(IPersistableNodeProperties.PROPERTY_URI + ".remove"); //$NON-NLS-1$ - removeURI = removeURI ? Boolean.parseBoolean(srcAttrs.remove(IPersistableNodeProperties.PROPERTY_URI + ".remove")) : false; //$NON-NLS-1$ - if (removeURI) dstAttrs.remove(IPersistableNodeProperties.PROPERTY_URI); - - // Determine the peer class - String peerClassSimpleName = peer.getClass().getSimpleName(); - if (peer.getAttributes().containsKey("remote.transient")) { //$NON-NLS-1$ - peerClassSimpleName = "RemotePeer"; //$NON-NLS-1$ - } - - // If the source is a RemotePeer and the destination not, attributes from - // the remote peer overwrites local attributes. - if ("RemotePeer".equals(peerClassSimpleName) && !"RemotePeer".equals(dst.getClass().getSimpleName())) { //$NON-NLS-1$ //$NON-NLS-2$ - // The ID is not merged from remote to local - srcAttrs.remove(IPeer.ATTR_ID); - // The Name is not merged from remote to local - srcAttrs.remove(IPeer.ATTR_NAME); - - // Eliminate all attributes already set in the destination attributes map - String merged = dstAttrs.get("remote.merged.transient"); //$NON-NLS-1$ - for (String key : dstAttrs.keySet()) { - if (merged == null || !merged.contains(key)) { - srcAttrs.remove(key); - } - } - } - - // Mark the peer as a remote peer and remember the remote peer id - if ("RemotePeer".equals(peerClassSimpleName) && !"RemotePeer".equals(dst.getClass().getSimpleName())) { //$NON-NLS-1$ //$NON-NLS-2$ - srcAttrs.put("remote.transient", Boolean.TRUE.toString()); //$NON-NLS-1$ - srcAttrs.put("remote.id.transient", peer.getID()); //$NON-NLS-1$ - srcAttrs.put("remote.merged.transient", srcAttrs.keySet().toString()); //$NON-NLS-1$ - } - - // Copy all remaining attributes from source to destination - if (!srcAttrs.isEmpty()) { - dstAttrs.putAll(srcAttrs); - } - - // If the ID's are different between the peers to merge and force is set, - // we have set the ID in dstAttrs to the original one as set in the destination peer. - if (force && !dst.getID().equals(dstAttrs.get(IPeer.ATTR_ID))) { - dstAttrs.put(IPeer.ATTR_ID, dst.getID()); - } - - // And update the destination peer attributes - if (dst instanceof PeerRedirector) { - ((PeerRedirector)dst).updateAttributes(dstAttrs); - } else if (dst instanceof Peer) { - ((Peer)dst).updateAttributes(dstAttrs); - } - } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/SignalPeerDisconnectedStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/SignalPeerDisconnectedStep.java deleted file mode 100644 index f29164fca..000000000 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/SignalPeerDisconnectedStep.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2013 Wind River Systems, Inc. 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.tcf.te.tcf.locator.steps; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; -import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; -import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; -import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; -import org.eclipse.tcf.te.tcf.locator.interfaces.IModelListener; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerModel; -import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; -import org.eclipse.tcf.te.tcf.locator.model.Model; - -/** - * Signal peer disconnected step. - */ -public class SignalPeerDisconnectedStep extends AbstractPeerNodeStep { - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#validateExecute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor) - */ - @Override - public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.te.runtime.stepper.interfaces.IStep#execute(org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext, org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer, org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId, org.eclipse.core.runtime.IProgressMonitor, org.eclipse.tcf.te.runtime.interfaces.callback.ICallback) - */ - @Override - public void execute(final IStepContext context, final IPropertiesContainer data, final IFullQualifiedId fullQualifiedId, final IProgressMonitor monitor, final ICallback callback) { - Assert.isNotNull(context); - Assert.isNotNull(data); - Assert.isNotNull(fullQualifiedId); - Assert.isNotNull(monitor); - Assert.isNotNull(callback); - - final IPeerNode peerNode = getActivePeerModelContext(context, data, fullQualifiedId); - if (peerNode != null) { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - IPeerModel model = Model.getModel(); - for (IModelListener listener : model.getListener()) { - listener.locatorModelChanged(model, peerNode, false); - } - callback.done(SignalPeerDisconnectedStep.this, Status.OK_STATUS); - } - }); - } - } - -} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java index f1c79cc7a..8530a59a0 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.locator/src/org/eclipse/tcf/te/tcf/locator/steps/WaitForReadyStep.java @@ -10,6 +10,9 @@ package org.eclipse.tcf.te.tcf.locator.steps; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.concurrent.TimeoutException; import org.eclipse.core.runtime.CoreException; @@ -28,6 +31,7 @@ import org.eclipse.tcf.te.runtime.utils.StatusHelper; import org.eclipse.tcf.te.tcf.core.Tcf; import org.eclipse.tcf.te.tcf.core.interfaces.IChannelManager; import org.eclipse.tcf.te.tcf.locator.interfaces.nodes.IPeerNode; +import org.eclipse.tcf.te.tcf.locator.interfaces.services.IPeerModelUpdateService; import org.eclipse.tcf.te.tcf.locator.nls.Messages; /** @@ -85,10 +89,26 @@ public class WaitForReadyStep extends AbstractPeerNodeStep { } // Close the channel right away - if (channel != null) Tcf.getChannelManager().closeChannel(channel); +// if (channel != null) Tcf.getChannelManager().closeChannel(channel); // If we have an OK status, we are done if (status != null && status.isOK()) { + // Get the local service + List<String> localServices = new ArrayList<String>(channel.getLocalServices()); + // Get the remote services + List<String> remoteServices = new ArrayList<String>(channel.getRemoteServices()); + + // Close the channel + Tcf.getChannelManager().closeChannel(channel); + + // Sort the service lists + Collections.sort(localServices); + Collections.sort(remoteServices); + + // Update the services + IPeerModelUpdateService updateService = peerNode.getModel().getService(IPeerModelUpdateService.class); + updateService.updatePeerServices(peerNode, localServices, remoteServices); + callback(data, fullQualifiedId, callback, status, null); return; } |