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/plugins/org.eclipse.tcf.te.tcf.log.core | |
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/plugins/org.eclipse.tcf.te.tcf.log.core')
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/META-INF/MANIFEST.MF | 3 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/activator/CoreBundleActivator.java | 2 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListener.java | 13 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java | 23 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java | 26 | ||||
-rw-r--r-- | target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/manager/LogManager.java (renamed from target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/LogManager.java) | 36 |
6 files changed, 59 insertions, 44 deletions
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$ |