diff options
author | Uwe Stieber | 2014-08-06 14:29:31 +0000 |
---|---|---|
committer | Uwe Stieber | 2014-08-06 14:29:31 +0000 |
commit | 11b1dfdefde1d24321e2f15e0162d2ed4102b8de (patch) | |
tree | 749e0dd803c5491820c127449969753123f24008 /target_explorer | |
parent | 0ed06ed8fe1a81433f19899f05f2de7e1b31f33f (diff) | |
download | org.eclipse.tcf-11b1dfdefde1d24321e2f15e0162d2ed4102b8de.tar.gz org.eclipse.tcf-11b1dfdefde1d24321e2f15e0162d2ed4102b8de.tar.xz org.eclipse.tcf-11b1dfdefde1d24321e2f15e0162d2ed4102b8de.zip |
Target Explorer: Rework channel event to carry a properties container data object
Diffstat (limited to 'target_explorer')
14 files changed, 203 insertions, 58 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.properties index 6b9aa15c8..ea2eda675 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.properties @@ -25,6 +25,7 @@ ShutDownStep.name=Close all TCF channels LaunchValueAddStep.name=Launch value-add ChainPeerStep.name=Redirect channel +CalculateLogNameStep.name=Calculate channel communication log file name InitializeLoggingStep.name=Initialize channel communication logging ApplyPatMapsStep.name=Apply path map to channel CloseChannelStep.name=Close channel diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml index 31db3299e..eabb3f8cd 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/plugin.xml @@ -68,6 +68,10 @@ class="org.eclipse.tcf.te.tcf.core.internal.channelmanager.steps.ShutdownValueAddStep" label="%ShutdownValueAddStep.name"/> + <step + id="org.eclipse.tcf.te.tcf.core.channelmanager.calculateLogNameStep" + class="org.eclipse.tcf.te.tcf.core.internal.channelmanager.steps.CalculateLogNameStep" + label="%CalculateLogNameStep.name"/> </extension> <!-- Step contributions --> @@ -75,6 +79,7 @@ <stepGroup id="org.eclipse.tcf.te.tcf.core.channelmanager.openChannelStepGroup"> <references> <reference id="org.eclipse.tcf.te.tcf.core.channelmanager.launchValueAddsStepGroup"/> + <reference id="org.eclipse.tcf.te.tcf.core.channelmanager.calculateLogNameStep"/> <reference id="org.eclipse.tcf.te.tcf.core.channelmanager.chainPeersStepGroup"/> <reference id="org.eclipse.tcf.te.tcf.core.channelmanager.initializeLoggingStep"/> <reference id="org.eclipse.tcf.te.tcf.core.channelmanager.applyPathMapsStep"/> diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/ChannelEvent.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/ChannelEvent.java index 746eed9a3..f71b723c9 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/ChannelEvent.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/ChannelEvent.java @@ -12,6 +12,7 @@ package org.eclipse.tcf.te.tcf.core.events; import java.util.EventObject; import org.eclipse.tcf.protocol.IChannel; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; /** * Channel event implementation. @@ -19,6 +20,8 @@ import org.eclipse.tcf.protocol.IChannel; public final class ChannelEvent extends EventObject { private static final long serialVersionUID = 864759021559875199L; + // Event type constants + public static final String TYPE_OPENING = "opening"; //$NON-NLS-1$ public static final String TYPE_REDIRECT = "redirect"; //$NON-NLS-1$ public static final String TYPE_OPEN = "open"; //$NON-NLS-1$ @@ -26,12 +29,16 @@ public final class ChannelEvent extends EventObject { public static final String TYPE_MARK = "mark"; //$NON-NLS-1$ public static final String TYPE_CLOSE_WRITER = "closeWriter"; //$NON-NLS-1$ + // Property constants + public static final String PROP_MESSAGE = "message"; //$NON-NLS-1$ + public static final String PROP_LOG_NAME = "logname"; //$NON-NLS-1$ + // The channel - private IChannel channel; + private final IChannel channel; // The event type - private String type; - // The optional message - private String message; + private final String type; + // The event data + private final IPropertiesContainer data; /** * Constructor @@ -39,9 +46,9 @@ public final class ChannelEvent extends EventObject { * @param source The source object. Must not be <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param type The event type. Must not be <code>null</code>. - * @param message A message or <code>null</code>. + * @param data The event data <code>null</code>. */ - public ChannelEvent(Object source, IChannel channel, String type, String message) { + public ChannelEvent(Object source, IChannel channel, String type, IPropertiesContainer data) { super(source); if (channel == null) { @@ -54,7 +61,7 @@ public final class ChannelEvent extends EventObject { this.channel = channel; this.type = type; - this.message = message; + this.data = data; } /** @@ -76,11 +83,11 @@ public final class ChannelEvent extends EventObject { } /** - * Returns the optional message. + * Returns the event data. * - * @return The optional message or <code>null</code>. + * @return The event data or <code>null</code>. */ - public String getMessage() { - return message; + public IPropertiesContainer getData() { + return data; } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/steps/ITcfStepAttributes.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/steps/ITcfStepAttributes.java index b34ab15b3..cac8972c7 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/steps/ITcfStepAttributes.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/interfaces/steps/ITcfStepAttributes.java @@ -41,4 +41,9 @@ public interface ITcfStepAttributes { * Step attribute: Flag if the peer should not be added to the list of peers to chain in {@link ChainPeersIterator}. */ public static final String ATTR_SKIP_PEER_TO_CHAIN = ITcfStepAttributes.ATTR_PREFIX + ".skip_peer_to_chain"; //$NON-NLS-1$ + + /** + * Step attribute: The log file name + */ + public static final String ATTR_LOG_NAME = ITcfStepAttributes.ATTR_PREFIX + ".logname"; //$NON-NLS-1$ } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CalculateLogNameStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CalculateLogNameStep.java new file mode 100644 index 000000000..9c1641958 --- /dev/null +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CalculateLogNameStep.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2014 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.core.internal.channelmanager.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.IPeer; +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.StepperAttributeUtil; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; +import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; +import org.eclipse.tcf.te.tcf.core.interfaces.steps.ITcfStepAttributes; +import org.eclipse.tcf.te.tcf.core.steps.AbstractPeerStep; + +/** + * Calculate the log name to use for logging the backend communication. + */ +public class CalculateLogNameStep extends AbstractPeerStep { + + /* (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 { + Assert.isNotNull(context); + Assert.isNotNull(data); + Assert.isNotNull(fullQualifiedId); + Assert.isNotNull(monitor); + } + + /* (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 IPeer peer = getActivePeerContext(context, data, fullQualifiedId); + Assert.isNotNull(peer); + + Runnable runnable = new Runnable() { + @Override + public void run() { + // Get the peer name + String logname = peer.getName(); + + if (logname != null) { + // Get the peer host IP address + String ip = peer.getAttributes().get(IPeer.ATTR_IP_HOST); + // Fallback: The peer id + if (ip == null || "".equals(ip.trim())) { //$NON-NLS-1$ + ip = peer.getID(); + } + + // Append the peer host IP address + if (ip != null && !"".equals(ip.trim())) { //$NON-NLS-1$ + logname += " " + ip.trim(); //$NON-NLS-1$ + } + + // Write to the data store + StepperAttributeUtil.setProperty(ITcfStepAttributes.ATTR_LOG_NAME, fullQualifiedId, data, logname, true); + } + + callback(data, fullQualifiedId, callback, Status.OK_STATUS, null); + } + }; + + if (Protocol.isDispatchThread()) runnable.run(); + else Protocol.invokeLater(runnable); + } +} diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/ChainPeerStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/ChainPeerStep.java index 6ea429b6f..6ec5c5807 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/ChainPeerStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/ChainPeerStep.java @@ -23,6 +23,7 @@ import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.events.EventManager; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil; import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; @@ -42,6 +43,10 @@ public class ChainPeerStep extends AbstractPeerStep { */ @Override public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { + Assert.isNotNull(context); + Assert.isNotNull(data); + Assert.isNotNull(fullQualifiedId); + Assert.isNotNull(monitor); } /* (non-Javadoc) @@ -57,6 +62,7 @@ public class ChainPeerStep extends AbstractPeerStep { final AtomicReference<IChannel> channel = new AtomicReference<IChannel>((IChannel)StepperAttributeUtil.getProperty(ITcfStepAttributes.ATTR_CHANNEL, fullQualifiedId, data)); final IPeer peer = getActivePeerContext(context, data, fullQualifiedId); + final String logname = StepperAttributeUtil.getStringProperty(ITcfStepAttributes.ATTR_LOG_NAME, fullQualifiedId, data); Runnable runnable = new Runnable() { @Override @@ -75,11 +81,21 @@ public class ChainPeerStep extends AbstractPeerStep { channel.set(c); String message = "to " + peer.getID(); //$NON-NLS-1$ - ChannelEvent event = new ChannelEvent(ChainPeerStep.this, c, ChannelEvent.TYPE_OPENING, message); + + IPropertiesContainer eventData = new PropertiesContainer(); + eventData.setProperty(ChannelEvent.PROP_MESSAGE, message); + eventData.setProperty(ChannelEvent.PROP_LOG_NAME, logname); + + ChannelEvent event = new ChannelEvent(ChainPeerStep.this, c, ChannelEvent.TYPE_OPENING, eventData); EventManager.getInstance().fireEvent(event); } else { String message = c.getRemotePeer().getID() + " --> " + peer.getID(); //$NON-NLS-1$ - ChannelEvent event = new ChannelEvent(ChainPeerStep.this, c, ChannelEvent.TYPE_REDIRECT, message); + + IPropertiesContainer eventData = new PropertiesContainer(); + eventData.setProperty(ChannelEvent.PROP_MESSAGE, message); + eventData.setProperty(ChannelEvent.PROP_LOG_NAME, logname); + + ChannelEvent event = new ChannelEvent(ChainPeerStep.this, c, ChannelEvent.TYPE_REDIRECT, eventData); EventManager.getInstance().fireEvent(event); c.redirect(peer.getAttributes()); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CloseChannelStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CloseChannelStep.java index 99191b206..724f16a7e 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CloseChannelStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/CloseChannelStep.java @@ -33,6 +33,10 @@ public class CloseChannelStep extends AbstractPeerStep { */ @Override public void validateExecute(IStepContext context, IPropertiesContainer data, IFullQualifiedId fullQualifiedId, IProgressMonitor monitor) throws CoreException { + Assert.isNotNull(context); + Assert.isNotNull(data); + Assert.isNotNull(fullQualifiedId); + Assert.isNotNull(monitor); } /* (non-Javadoc) diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/InitializeLoggingStep.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/InitializeLoggingStep.java index 7ced62b10..467dd4c6b 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/InitializeLoggingStep.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/InitializeLoggingStep.java @@ -18,6 +18,7 @@ import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.te.runtime.events.EventManager; import org.eclipse.tcf.te.runtime.interfaces.callback.ICallback; import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; +import org.eclipse.tcf.te.runtime.properties.PropertiesContainer; import org.eclipse.tcf.te.runtime.stepper.StepperAttributeUtil; import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId; import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext; @@ -61,6 +62,7 @@ public class InitializeLoggingStep extends AbstractPeerStep { final IChannel channel = (IChannel)StepperAttributeUtil.getProperty(ITcfStepAttributes.ATTR_CHANNEL, fullQualifiedId, data); Assert.isNotNull(channel); + final String logname = StepperAttributeUtil.getStringProperty(ITcfStepAttributes.ATTR_LOG_NAME, fullQualifiedId, data); if (channel.getState() == IChannel.STATE_OPEN) { boolean forceNew = StepperAttributeUtil.getBooleanProperty(IChannelManager.FLAG_FORCE_NEW, fullQualifiedId, data); @@ -72,7 +74,11 @@ public class InitializeLoggingStep extends AbstractPeerStep { if (noValueAdd) message += ", No Value Add"; //$NON-NLS-1$ if (noPathMap) message += ", Not Applying Path Map"; //$NON-NLS-1$ - ChannelEvent event = new ChannelEvent(InitializeLoggingStep.this, channel, ChannelEvent.TYPE_OPEN, message); + IPropertiesContainer eventData = new PropertiesContainer(); + eventData.setProperty(ChannelEvent.PROP_MESSAGE, message); + eventData.setProperty(ChannelEvent.PROP_LOG_NAME, logname); + + ChannelEvent event = new ChannelEvent(InitializeLoggingStep.this, channel, ChannelEvent.TYPE_OPEN, eventData); EventManager.getInstance().fireEvent(event); } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/META-INF/MANIFEST.MF b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/META-INF/MANIFEST.MF index 154ddab3c..62793c287 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/META-INF/MANIFEST.MF +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/META-INF/MANIFEST.MF @@ -17,4 +17,5 @@ Export-Package: org.eclipse.tcf.te.tcf.log.core.activator;x-internal:=true, org.eclipse.tcf.te.tcf.log.core.interfaces, org.eclipse.tcf.te.tcf.log.core.internal;x-internal:=true, org.eclipse.tcf.te.tcf.log.core.internal.listener;x-internal:=true, - org.eclipse.tcf.te.tcf.log.core.internal.nls;x-internal:=true + org.eclipse.tcf.te.tcf.log.core.internal.nls;x-internal:=true, + org.eclipse.tcf.te.tcf.log.core.manager diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/activator/CoreBundleActivator.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/activator/CoreBundleActivator.java index c375268ec..2a31f3ee2 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/activator/CoreBundleActivator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/activator/CoreBundleActivator.java @@ -12,7 +12,7 @@ package org.eclipse.tcf.te.tcf.log.core.activator; import org.eclipse.core.runtime.Plugin; import org.eclipse.tcf.te.runtime.preferences.ScopedEclipsePreferences; import org.eclipse.tcf.te.runtime.tracing.TraceHandler; -import org.eclipse.tcf.te.tcf.log.core.internal.LogManager; +import org.eclipse.tcf.te.tcf.log.core.manager.LogManager; import org.osgi.framework.BundleContext; /** diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java index 9290733da..ca4fbdede 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java @@ -24,8 +24,8 @@ import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent; import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys; import org.eclipse.tcf.te.tcf.log.core.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.log.core.internal.LogManager; import org.eclipse.tcf.te.tcf.log.core.internal.nls.Messages; +import org.eclipse.tcf.te.tcf.log.core.manager.LogManager; /** * TCF logging channel trace listener implementation. @@ -43,15 +43,20 @@ public class ChannelTraceListener implements TraceListener { // Reference to the channel private final IChannel channel; + // The log name + private final String logname; private final boolean reverseReceived; /** * Constructor. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. */ - public ChannelTraceListener(IChannel channel) { + public ChannelTraceListener(String logname, IChannel channel) { + this.logname = logname; + Assert.isNotNull(channel); this.channel = channel; @@ -88,7 +93,7 @@ public class ChannelTraceListener implements TraceListener { }); // Get the file writer - FileWriter writer = LogManager.getInstance().getWriter(channel); + FileWriter writer = LogManager.getInstance().getWriter(logname, channel); if (writer != null) { try { writer.write(message); @@ -153,7 +158,7 @@ public class ChannelTraceListener implements TraceListener { // Format the message final String message = formatMessage(type, token, service, name, data, received); // Get the file writer - FileWriter writer = LogManager.getInstance().getWriter(channel); + FileWriter writer = LogManager.getInstance().getWriter(logname, channel); if (writer != null) { try { writer.write(message); diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java index 31646179a..363645576 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java @@ -29,8 +29,8 @@ import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator; import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent; import org.eclipse.tcf.te.tcf.log.core.interfaces.IPreferenceKeys; import org.eclipse.tcf.te.tcf.log.core.interfaces.ITracing; -import org.eclipse.tcf.te.tcf.log.core.internal.LogManager; import org.eclipse.tcf.te.tcf.log.core.internal.nls.Messages; +import org.eclipse.tcf.te.tcf.log.core.manager.LogManager; /** * TCF logging channel trace listener manager implementation. @@ -70,10 +70,11 @@ public class ChannelTraceListenerManager { /** * New channel opened. Attach a channel trace listener. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param message A message or <code>null</code>. */ - public void onChannelOpened(final IChannel channel, String message) { + public void onChannelOpened(String logname, IChannel channel, String message) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ @@ -96,7 +97,7 @@ public class ChannelTraceListenerManager { AbstractChannel.TraceListener traceListener = listeners.remove(channel); if (traceListener != null) ((AbstractChannel)channel).removeTraceListener(traceListener); // Create a new trace listener instance - traceListener = new ChannelTraceListener(channel); + traceListener = new ChannelTraceListener(logname, channel); // Attach trace listener to the channel ((AbstractChannel)channel).addTraceListener(traceListener); // Remember the associated trace listener @@ -113,7 +114,7 @@ public class ChannelTraceListenerManager { }); // Get the file writer - FileWriter writer = LogManager.getInstance().getWriter(channel); + FileWriter writer = LogManager.getInstance().getWriter(logname, channel); if (writer != null) { try { writer.write("\n\n\n"); //$NON-NLS-1$ @@ -144,10 +145,11 @@ public class ChannelTraceListenerManager { * This is the state where {@link IPeer#openChannel()} got called but no * further redirect or channel listener got invoked. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param message A message or <code>null</code>. */ - public void onChannelOpening(final IChannel channel, String message) { + public void onChannelOpening(String logname, IChannel channel, String message) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ @@ -184,10 +186,11 @@ public class ChannelTraceListenerManager { /** * Channel got redirected. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param message A message or <code>null</code>. */ - public void onChannelRedirected(final IChannel channel, String message) { + public void onChannelRedirected(String logname, IChannel channel, String message) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ @@ -224,10 +227,11 @@ public class ChannelTraceListenerManager { /** * Mark an event in the channel log. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param message A message or <code>null</code>. */ - public void onMark(final IChannel channel, String message) { + public void onMark(String logname, IChannel channel, String message) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ @@ -254,7 +258,7 @@ public class ChannelTraceListenerManager { }); // Get the file writer - FileWriter writer = LogManager.getInstance().getWriter(channel); + FileWriter writer = LogManager.getInstance().getWriter(logname, channel); if (writer != null) { try { // Write the message @@ -270,9 +274,10 @@ public class ChannelTraceListenerManager { /** * Channel closed. Detach the channel trace listener if any. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. */ - public void onChannelClosed(final IChannel channel) { + public void onChannelClosed(String logname, final IChannel channel) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java index 190a16df5..58e57edf8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java @@ -17,8 +17,9 @@ import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.Protocol; import org.eclipse.tcf.te.runtime.interfaces.events.IEventFireDelegate; import org.eclipse.tcf.te.runtime.interfaces.events.IEventListener; +import org.eclipse.tcf.te.runtime.interfaces.properties.IPropertiesContainer; import org.eclipse.tcf.te.tcf.core.events.ChannelEvent; -import org.eclipse.tcf.te.tcf.log.core.internal.LogManager; +import org.eclipse.tcf.te.tcf.log.core.manager.LogManager; /** * Channel event listener. @@ -42,27 +43,32 @@ public final class EventListener extends PlatformObject implements IEventListene Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ if (event instanceof ChannelEvent) { - final IChannel channel = ((ChannelEvent)event).getChannel(); - final String type = ((ChannelEvent)event).getType(); - final String message = ((ChannelEvent)event).getMessage(); + IChannel channel = ((ChannelEvent)event).getChannel(); + String type = ((ChannelEvent)event).getType(); + IPropertiesContainer data = ((ChannelEvent)event).getData(); + + String message = data != null ? data.getStringProperty(ChannelEvent.PROP_MESSAGE) : null; + String logname = data != null ? data.getStringProperty(ChannelEvent.PROP_LOG_NAME) : null; + + if (logname != null) logname = LogManager.getInstance().makeValid(logname); if (ChannelEvent.TYPE_OPENING.equals(type)) { - ChannelTraceListenerManager.getInstance().onChannelOpening(channel, message); + ChannelTraceListenerManager.getInstance().onChannelOpening(logname, channel, message); } else if (ChannelEvent.TYPE_REDIRECT.equals(type)) { - ChannelTraceListenerManager.getInstance().onChannelRedirected(channel, message); + ChannelTraceListenerManager.getInstance().onChannelRedirected(logname, channel, message); } else if (ChannelEvent.TYPE_OPEN.equals(type)) { - ChannelTraceListenerManager.getInstance().onChannelOpened(channel, message); + ChannelTraceListenerManager.getInstance().onChannelOpened(logname, channel, message); } else if (ChannelEvent.TYPE_CLOSE.equals(type)) { - ChannelTraceListenerManager.getInstance().onChannelClosed(channel); + ChannelTraceListenerManager.getInstance().onChannelClosed(logname, channel); } else if (ChannelEvent.TYPE_MARK.equals(type)) { - ChannelTraceListenerManager.getInstance().onMark(channel, message); + ChannelTraceListenerManager.getInstance().onMark(logname, channel, message); } else if (ChannelEvent.TYPE_CLOSE_WRITER.equals(type)) { - LogManager.getInstance().closeWriter(channel, message); + LogManager.getInstance().closeWriter(logname, channel, message); } } } diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/manager/LogManager.java index d0b7759ed..e13e0efa4 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/manager/LogManager.java @@ -7,7 +7,7 @@ * Contributors: * Wind River Systems - initial API and implementation *******************************************************************************/ -package org.eclipse.tcf.te.tcf.log.core.internal; +package org.eclipse.tcf.te.tcf.log.core.manager; import java.io.File; import java.io.FileWriter; @@ -127,26 +127,27 @@ public final class LogManager { /** * Returns the file writer instance to use for the given channel. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @return The file writer instance or <code>null</code>. */ - public FileWriter getWriter(IChannel channel) { + public FileWriter getWriter(String logname, IChannel channel) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ // Before looking up the writer, check the file limits - checkLimits(channel); + checkLimits(logname, channel); - String logName = getLogName(channel); - FileWriter writer = logName != null ? fileWriterMap.get(logName) : null; - if (writer == null && logName != null) { + if (logname == null) logname = getLogName(channel); + FileWriter writer = logname != null ? fileWriterMap.get(logname) : null; + if (writer == null && logname != null) { // Create the writer IPath path = getLogDir(); if (path != null) { - path = path.append(logName + ".log"); //$NON-NLS-1$ + path = path.append(logname + ".log"); //$NON-NLS-1$ try { writer = new FileWriter(path.toFile(), true); - fileWriterMap.put(logName, writer); + fileWriterMap.put(logname, writer); } catch (IOException e) { /* ignored on purpose */ } @@ -159,16 +160,17 @@ public final class LogManager { /** * Close the writer instance used for the given channel. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @param message The last message to write or <code>null</code>. */ - public void closeWriter(IChannel channel, String message) { + public void closeWriter(String logname, IChannel channel, String message) { Assert.isNotNull(channel); Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$ // Remove the writer from the map - String logName = getLogName(channel); - FileWriter writer = logName != null ? fileWriterMap.remove(logName) : null; + if (logname == null) logname = getLogName(channel); + FileWriter writer = logname != null ? fileWriterMap.remove(logname) : null; if (writer != null) { try { // If specified, write the last message. @@ -222,11 +224,6 @@ public final class LogManager { // Get the peer name logName = peer.getName(); - // If the locator communication logging is enabled, it will make sense to - // also log communication to the proxies which may not have a name attribute set - boolean locatorEvents = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_SHOW_LOCATOR_EVENTS); - if (locatorEvents && logName == null) logName = peer.getID(); - if (logName != null) { // Get the peer host IP address String ip = peer.getAttributes().get(IPeer.ATTR_IP_HOST); @@ -254,7 +251,7 @@ public final class LogManager { * @param name The name. Must not be <code>null</code>. * @return The modified name. */ - private String makeValid(String name) { + public String makeValid(String name) { Assert.isNotNull(name); String result = name.replaceAll("\\s", "_"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -312,10 +309,11 @@ public final class LogManager { /** * Checks the limits set by the preferences. * + * @param logname The log name or <code>null</code>. * @param channel The channel. Must not be <code>null</code>. * @return The checked file writer instance. */ - private void checkLimits(IChannel channel) { + private void checkLimits(String logname, IChannel channel) { Assert.isNotNull(channel); String logName = getLogName(channel); @@ -330,7 +328,7 @@ public final class LogManager { // Max log file size reached -> cycle files // If there is an active writer, flush and close the writer - closeWriter(channel, null); + closeWriter(logname, channel, null); // Determine if the maximum number of files in the cycle has been reached File maxFileInCycle = path.append(logName + "_" + maxInCycle + ".log").toFile(); //$NON-NLS-1$ //$NON-NLS-2$ |