diff options
Diffstat (limited to 'target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal')
8 files changed, 0 insertions, 574 deletions
diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/ChannelManager.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/ChannelManager.java deleted file mode 100644 index 29b6e2ce1..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/ChannelManager.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal; - -import java.util.Map; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.PlatformObject; -import org.eclipse.tcf.core.AbstractPeer; -import org.eclipse.tcf.core.TransientPeer; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.IPeer; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tm.te.tcf.core.interfaces.IChannelManager; - - -/** - * TCF channel manager implementation. - */ -public final class ChannelManager extends PlatformObject implements IChannelManager { - - /** - * Constructor. - */ - public ChannelManager() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.core.interfaces.IChannelManager#openChannel(org.eclipse.tcf.protocol.IPeer, org.eclipse.tm.te.tcf.core.interfaces.IChannelManager.DoneOpenChannel) - */ - @Override - public void openChannel(final IPeer peer, final DoneOpenChannel done) { - if (Protocol.isDispatchThread()) { - internalOpenChannel(peer, done); - } else { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - internalOpenChannel(peer, done); - } - }); - } - } - - /** - * Internal implementation of {@link #openChannel(IPeer, org.eclipse.tm.te.tcf.core.interfaces.IChannelManager.DoneOpenChannel)}. - * <p> - * Method must be called within the TCF dispatch thread. - * - * @param peer The peer. Must not be <code>null</code>. - * @param done The client callback. Must not be <code>null</code>. - */ - /* default */ void internalOpenChannel(final IPeer peer, final DoneOpenChannel done) { - Assert.isNotNull(peer); - Assert.isNotNull(done); - Assert.isTrue(Protocol.isDispatchThread()); - - // Open the channel - final IChannel channel = peer.openChannel(); - // Register the channel listener - if (channel != null) { - channel.addChannelListener(new IChannel.IChannelListener() { - - @Override - public void onChannelOpened() { - // Remove ourself as listener from the channel - channel.removeChannelListener(this); - // Channel opening succeeded - done.doneOpenChannel(null, channel); - } - - @Override - public void onChannelClosed(Throwable error) { - // Remove ourself as listener from the channel - channel.removeChannelListener(this); - // Channel opening failed - done.doneOpenChannel(error, channel); - } - - @Override - public void congestionLevel(int level) { - // ignored - } - }); - } else { - // Channel is null? Something went terrible wrong. - done.doneOpenChannel(new Exception("Unexpected null return value from IPeer#openChannel()!"), null); //$NON-NLS-1$ - } - - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.core.interfaces.IChannelManager#openChannel(java.util.Map, org.eclipse.tm.te.tcf.core.interfaces.IChannelManager.DoneOpenChannel) - */ - @Override - public void openChannel(final Map<String, String> peerAttributes, final DoneOpenChannel done) { - if (Protocol.isDispatchThread()) { - internalOpenChannel(peerAttributes, done); - } else { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - internalOpenChannel(peerAttributes, done); - } - }); - } - } - - /** - * Internal implementation of {@link #openChannel(Map, org.eclipse.tm.te.tcf.core.interfaces.IChannelManager.DoneOpenChannel)}. - * <p> - * Method must be called within the TCF dispatch thread. - * - * @param peerAttributes The peer attributes. Must not be <code>null</code>. - * @param done The client callback. Must not be <code>null</code>. - */ - /* default */ void internalOpenChannel(final Map<String, String> peerAttributes, final DoneOpenChannel done) { - Assert.isNotNull(peerAttributes); - Assert.isNotNull(done); - Assert.isTrue(Protocol.isDispatchThread()); - internalOpenChannel(getOrCreatePeerInstance(peerAttributes), done); - } - - /** - * Tries to find an existing peer instance or create an new {@link IPeer} - * instance if not found. - * <p> - * <b>Note:</b> This method must be invoked at the TCF dispatch thread. - * - * @param peerAttributes The peer attributes. Must not be <code>null</code>. - * @return The peer instance. - */ - private IPeer getOrCreatePeerInstance(final Map<String, String> peerAttributes) { - Assert.isNotNull(peerAttributes); - Assert.isTrue(Protocol.isDispatchThread()); - - // Get the peer id from the properties - String peerId = peerAttributes.get(IPeer.ATTR_ID); - Assert.isNotNull(peerId); - - // Check if we shall open the peer transient - boolean isTransient = peerAttributes.containsKey("transient") ? Boolean.parseBoolean(peerAttributes.remove("transient")) : false; //$NON-NLS-1$ //$NON-NLS-2$ - - // Look the peer via the Locator Service. - IPeer peer = Protocol.getLocator().getPeers().get(peerId); - // If not peer could be found, create a new one - if (peer == null) { - peer = isTransient ? new TransientPeer(peerAttributes) : new AbstractPeer(peerAttributes); - } - - // Return the peer instance - return peer; - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/Startup.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/Startup.java deleted file mode 100644 index 817bd85cd..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/Startup.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tm.te.tcf.core.Tcf; -import org.eclipse.tm.te.tcf.core.activator.CoreBundleActivator; - - -/** - * Class loaded by the TCF core framework when the framework is fired up. The static - * constructor of the class will trigger whatever is necessary in this case. - * <p> - * <b>Note:</b> This will effectively trigger {@link CoreBundleActivator#start(org.osgi.framework.BundleContext)} - * to be called. - */ -public class Startup { - // Atomic boolean to store the started state of the TCF core framework - /* default */ final static AtomicBoolean STARTED = new AtomicBoolean(false); - - static { - // We might get here on shutdown as well, and if TCF has not - // been loaded, than we will run into an NPE. Lets double check. - if (Protocol.getEventQueue() != null) { - // Initialize the framework status by scheduling a simple - // runnable to execute and be invoked once the framework - // is fully up and usable. - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - // Core framework is scheduling the runnables, means it is started. - setStarted(true); - } - }); - } - } - - /** - * Set the core framework started state to the given state. - * - * @param started <code>True</code> when the framework is started, <code>false</code> otherwise. - */ - public static final void setStarted(boolean started) { - STARTED.set(started); - - // Start/Stop should be called in the TCF protocol dispatch thread - if (Protocol.getEventQueue() != null) { - // Catch IllegalStateException: TCF event dispatcher has shut down - try { - Protocol.invokeLater(new Runnable() { - @Override - public void run() { - if (STARTED.get()) Tcf.start(); else Tcf.stop(); - } - }); - } catch (IllegalStateException e) { - if (!STARTED.get() && "TCF event dispatcher has shut down".equals(e.getLocalizedMessage())) { //$NON-NLS-1$ - // ignore the exception on shutdown - } else { - // re-throw in any other case - throw e; - } - } - } - } - - /** - * Returns if or if not the core framework has been started. - * - * @return <code>True</code> when the framework is started, <code>false</code> otherwise. - */ - public static final boolean isStarted() { - return STARTED.get(); - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/interfaces/IChannelOpenListener.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/interfaces/IChannelOpenListener.java deleted file mode 100644 index 6da8c45b8..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/interfaces/IChannelOpenListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal.interfaces; - -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.Protocol.ChannelOpenListener; - -/** - * Enhanced channel open listener interface for internal use. - */ -public interface IChannelOpenListener extends ChannelOpenListener { - - /** - * Stores the given channel listener to the internal map. The map - * key is the given channel. If the given channel listener is <code>null</code>, - * the channel is removed from the internal map. - * - * @param channel The channel. Must not be <code>null</code>. - * @param listener The channel listener or <code>null</code>. - */ - public void setChannelListener(IChannel channel, IChannel.IChannelListener listener); -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelListener.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelListener.java deleted file mode 100644 index 5729c5128..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelListener.java +++ /dev/null @@ -1,100 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal.listener; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.osgi.util.NLS; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tm.te.tcf.core.Tcf; -import org.eclipse.tm.te.tcf.core.internal.interfaces.IChannelOpenListener; -import org.eclipse.tm.te.tcf.core.internal.nls.Messages; -import org.eclipse.tm.te.tcf.core.internal.utils.LogUtils; - - -/** - * Internal channel listener. Attached to a TCF channel for tracing purpose. - */ -public class InternalChannelListener implements IChannel.IChannelListener { - // The reference to the channel - private final IChannel channel; - - /** - * Constructor. - * - * @param channel The channel. Must not be <code>null</code>. - */ - public InternalChannelListener(IChannel channel) { - Assert.isNotNull(channel); - this.channel = channel; - } - - /** - * Return the associated channel. - * - * @return The channel instance. - */ - protected final IChannel getChannel() { - return channel; - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#congestionLevel(int) - */ - @Override - public void congestionLevel(int level) { - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#onChannelClosed(java.lang.Throwable) - */ - @Override - public void onChannelClosed(Throwable error) { - Assert.isTrue(Protocol.isDispatchThread()); - - // Detach the listeners cleanly - detachListeners(getChannel()); - - // Construct the cause message - String cause = ""; //$NON-NLS-1$ - if (error != null) { - cause = NLS.bind(Messages.InternalChannelListener_onChannelClosed_cause, error.getLocalizedMessage()); - } - - // Trace the channel closing - LogUtils.logMessageForChannel(getChannel(), NLS.bind(Messages.InternalChannelListener_onChannelClosed_message, cause), "debug/channels", this); //$NON-NLS-1$ - - // Fire the property change event for the channel - Tcf.fireChannelStateChangeListeners(getChannel(), IChannel.STATE_CLOSED); - } - - /** - * Detach all registered listeners from the given channel. - * - * @param channel The channel. Must not be <code>null</code>. - */ - protected void detachListeners(IChannel channel) { - Assert.isNotNull(channel); - - // Cleanly remove all listeners from the channel - channel.removeChannelListener(this); - - // And remove the listener references from the global channel open listener - IChannelOpenListener openListener = (IChannelOpenListener)Tcf.getAdapter(IChannelOpenListener.class); - if (openListener != null) openListener.setChannelListener(channel, null); - } - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.IChannel.IChannelListener#onChannelOpened() - */ - @Override - public void onChannelOpened() { - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelOpenListener.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelOpenListener.java deleted file mode 100644 index a9b576d81..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/listener/InternalChannelOpenListener.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal.listener; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tcf.protocol.IChannel.IChannelListener; -import org.eclipse.tcf.protocol.Protocol; -import org.eclipse.tm.te.tcf.core.Tcf; -import org.eclipse.tm.te.tcf.core.internal.interfaces.IChannelOpenListener; -import org.eclipse.tm.te.tcf.core.internal.nls.Messages; -import org.eclipse.tm.te.tcf.core.internal.utils.LogUtils; - - -/** - * Internal channel open listener taking care of logging and caching. - */ -public class InternalChannelOpenListener implements IChannelOpenListener { - // Static map containing the channel listeners per channel. Access to the - // map should happen from the TCF protocol dispatch thread only. - private final Map<IChannel, IChannel.IChannelListener> channelListeners = new HashMap<IChannel, IChannel.IChannelListener>(); - - /* (non-Javadoc) - * @see org.eclipse.tcf.protocol.Protocol.ChannelOpenListener#onChannelOpen(org.eclipse.tcf.protocol.IChannel) - */ - @Override - public void onChannelOpen(IChannel channel) { - Assert.isNotNull(channel); - Assert.isTrue(Protocol.isDispatchThread()); - - // Trace the channel opening - LogUtils.logMessageForChannel(channel, Messages.InternalChannelOpenListener_onChannelOpen_message, "debug/channels", this); //$NON-NLS-1$ - - // As the channel has just opened, there should be no channel listener, but better be safe and check. - IChannel.IChannelListener channelListener = channelListeners.remove(channel); - if (channelListener != null) channel.removeChannelListener(channelListener); - // Create a new channel listener instance - channelListener = new InternalChannelListener(channel); - // Add the channel listener to the global map - setChannelListener(channel, channelListener); - // Attach channel listener to the channel - channel.addChannelListener(channelListener); - - // Fire the property change event for the channel - Tcf.fireChannelStateChangeListeners(channel, IChannel.STATE_OPEN); - } - - /* (non-Javadoc) - * @see org.eclipse.tm.te.tcf.core.internal.interfaces.IChannelOpenListener#setChannelListener(org.eclipse.tcf.protocol.IChannel, org.eclipse.tcf.protocol.IChannel.IChannelListener) - */ - @Override - public void setChannelListener(IChannel channel, IChannelListener listener) { - Assert.isNotNull(channel); - if (listener != null) channelListeners.put(channel, listener); - else channelListeners.remove(channel); - } -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.java deleted file mode 100644 index 4c34cf391..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal.nls; - -import java.lang.reflect.Field; - -import org.eclipse.osgi.util.NLS; - -/** - * Plug-in externalized strings management. - */ -public class Messages extends NLS { - - // The plug-in resource bundle name - private static final String BUNDLE_NAME = "org.eclipse.tm.te.tcf.core.internal.nls.Messages"; //$NON-NLS-1$ - - /** - * Static constructor. - */ - static { - // Load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, Messages.class); - } - - /** - * Returns if or if not this NLS manager contains a constant for - * the given externalized strings key. - * - * @param key The externalized strings key or <code>null</code>. - * @return <code>True</code> if a constant for the given key exists, <code>false</code> otherwise. - */ - public static boolean hasString(String key) { - if (key != null) { - try { - Field field = Messages.class.getDeclaredField(key); - return field != null; - } catch (NoSuchFieldException e) { /* ignored on purpose */ } - } - - return false; - } - - /** - * Returns the corresponding string for the given externalized strings - * key or <code>null</code> if the key does not exist. - * - * @param key The externalized strings key or <code>null</code>. - * @return The corresponding string or <code>null</code>. - */ - public static String getString(String key) { - if (key != null) { - try { - Field field = Messages.class.getDeclaredField(key); - if (field != null) { - return (String)field.get(null); - } - } catch (Exception e) { /* ignored on purpose */ } - } - - return null; - } - - // **** Declare externalized string id's down here ***** - - public static String InternalChannelOpenListener_onChannelOpen_message; - - public static String InternalChannelListener_onChannelClosed_message; - public static String InternalChannelListener_onChannelClosed_cause; - -} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.properties deleted file mode 100644 index 5c3039f1a..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/nls/Messages.properties +++ /dev/null @@ -1,9 +0,0 @@ -# -# org.eclipse.tm.te.tcf.core -# Externalized Strings. -# - -InternalChannelOpenListener_onChannelOpen_message=Channel opened. - -InternalChannelListener_onChannelClosed_message=Channel closed. {0} -InternalChannelListener_onChannelClosed_cause=; Possibly caused by: {0} diff --git a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/utils/LogUtils.java b/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/utils/LogUtils.java deleted file mode 100644 index cdff90d36..000000000 --- a/target_explorer/plugins/org.eclipse.tm.te.tcf.core/src/org/eclipse/tm/te/tcf/core/internal/utils/LogUtils.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * 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.tm.te.tcf.core.internal.utils; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.tcf.protocol.IChannel; -import org.eclipse.tm.te.tcf.core.activator.CoreBundleActivator; - - -/** - * Logging utilities helper implementations. - */ -public final class LogUtils { - - /** - * Log the given message for the given channel. - * - * @param channel The channel. Must not be <code>null</code>. - * @param message The message to log. Must not be <code>null</code>. - * @param slotId The Eclipse debug slot id which must be enabled to log the message. Must not be <code>null</code>. - * @param clazz The invoking class or <code>null</code>. - */ - public static void logMessageForChannel(IChannel channel, String message, String slotId, Object clazz) { - Assert.isNotNull(channel); - Assert.isNotNull(message); - Assert.isNotNull(slotId); - - // Trace the message - String fullMessage = channel.toString() + ": " + message; //$NON-NLS-1$ - - if (Boolean.parseBoolean(Platform.getDebugOption(CoreBundleActivator.getUniqueIdentifier() + "/" + slotId))) { //$NON-NLS-1$ - IStatus status = new Status(IStatus.INFO, CoreBundleActivator.getUniqueIdentifier(), fullMessage.trim()); - Platform.getLog(CoreBundleActivator.getContext().getBundle()).log(status); - } - } -} |