Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Stieber2014-07-24 05:44:40 -0400
committerUwe Stieber2014-07-24 05:45:06 -0400
commit064c22544b0150c3278eb0509521c26077bd42de (patch)
tree52524fb4b6b70a938cad4b0a59b4815af92dfb84
parentcec539106cc80f6e5b8b8963da82921940bba55f (diff)
downloadorg.eclipse.tcf-064c22544b0150c3278eb0509521c26077bd42de.tar.gz
org.eclipse.tcf-064c22544b0150c3278eb0509521c26077bd42de.tar.xz
org.eclipse.tcf-064c22544b0150c3278eb0509521c26077bd42de.zip
Target Explorer: Extend channel logging
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/events/ChannelEvent.java4
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.core/src/org/eclipse/tcf/te/tcf/core/internal/channelmanager/steps/ChainPeerStep.java10
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/ChannelTraceListenerManager.java156
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/listener/EventListener.java11
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.java3
-rw-r--r--target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.properties3
6 files changed, 184 insertions, 3 deletions
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 4929d1c46..f0199badb 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
@@ -19,9 +19,11 @@ import org.eclipse.tcf.protocol.IChannel;
public final class ChannelEvent extends EventObject {
private static final long serialVersionUID = 864759021559875199L;
- public static final String TYPE_OPEN = "open"; //$NON-NLS-1$
+ 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$
public static final String TYPE_CLOSE = "close"; //$NON-NLS-1$
+ public static final String TYPE_MARK = "mark"; //$NON-NLS-1$
// The channel
private IChannel channel;
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 d3870c414..f1b2b6319 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
@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.tcf.protocol.IChannel;
import org.eclipse.tcf.protocol.IPeer;
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.stepper.StepperAttributeUtil;
@@ -27,6 +28,7 @@ import org.eclipse.tcf.te.runtime.stepper.interfaces.IFullQualifiedId;
import org.eclipse.tcf.te.runtime.stepper.interfaces.IStepContext;
import org.eclipse.tcf.te.runtime.utils.StatusHelper;
import org.eclipse.tcf.te.tcf.core.channelmanager.OpenChannelException;
+import org.eclipse.tcf.te.tcf.core.events.ChannelEvent;
import org.eclipse.tcf.te.tcf.core.interfaces.steps.ITcfStepAttributes;
import org.eclipse.tcf.te.tcf.core.steps.AbstractPeerStep;
@@ -71,7 +73,15 @@ public class ChainPeerStep extends AbstractPeerStep {
if (c == null) {
c = peer.openChannel();
channel.set(c);
+
+ String message = "to " + peer.getID(); //$NON-NLS-1$
+ ChannelEvent event = new ChannelEvent(ChainPeerStep.this, c, ChannelEvent.TYPE_OPENING, message);
+ 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);
+ EventManager.getInstance().fireEvent(event);
+
c.redirect(peer.getAttributes());
}
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 2158bae63..d3d5adc1f 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
@@ -13,14 +13,17 @@ import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.core.runtime.Assert;
import org.eclipse.osgi.util.NLS;
import org.eclipse.tcf.core.AbstractChannel;
import org.eclipse.tcf.protocol.IChannel;
+import org.eclipse.tcf.protocol.IPeer;
import org.eclipse.tcf.protocol.Protocol;
import org.eclipse.tcf.te.tcf.log.core.activator.CoreBundleActivator;
import org.eclipse.tcf.te.tcf.log.core.events.MonitorEvent;
@@ -41,6 +44,9 @@ public class ChannelTraceListenerManager {
// The map of trace listeners per channel
private final Map<IChannel, AbstractChannel.TraceListener> listeners = new HashMap<IChannel, AbstractChannel.TraceListener>();
+ // The map of queued messaged per channel
+ private final Map<IChannel, List<String>> queued = new HashMap<IChannel, List<String>>();
+
/*
* Thread save singleton instance creation.
*/
@@ -74,7 +80,7 @@ public class ChannelTraceListenerManager {
// The trace listener interface does not have a onChannelOpenend method, but
// for consistency, log the channel opening similar to the others.
if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER)) {
- CoreBundleActivator.getTraceHandler().trace("TraceListener.onChannelOpened ( " + channel + " )", //$NON-NLS-1$ //$NON-NLS-2$
+ CoreBundleActivator.getTraceHandler().trace("TraceListener.onChannelOpened ( " + channel + ", \"" + message + "\" )", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER, this);
}
@@ -116,6 +122,17 @@ public class ChannelTraceListenerManager {
if (writer != null) {
try {
writer.write("\n\n\n"); //$NON-NLS-1$
+
+ // Write the queued redirects
+ List<String> queue = queued.remove(channel);
+ if (queue != null) {
+ for (String m : queue) {
+ writer.write(m);
+ writer.write("\n"); //$NON-NLS-1$
+ }
+ }
+
+ // Write the opened message
writer.write(fullMessage);
writer.write("\n"); //$NON-NLS-1$
writer.flush();
@@ -127,6 +144,140 @@ public class ChannelTraceListenerManager {
}
/**
+ * Channel is opening.
+ * <p>
+ * This is the state where {@link IPeer#openChannel()} got called but no
+ * further redirect or channel listener got invoked.
+ *
+ * @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) {
+ Assert.isNotNull(channel);
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
+ // The trace listener interface does not have a onChannelOpenend method, but
+ // for consistency, log the channel opening similar to the others.
+ if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER)) {
+ CoreBundleActivator.getTraceHandler().trace("TraceListener.onChannelOpening ( " + channel + ", \"" + message + "\" )", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER, this);
+ }
+
+ // Get the preference key if or if not logging is enabled
+ boolean loggingEnabled = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED);
+ // If false, we are done here and wont create any console or trace listener.
+ if (!loggingEnabled) return;
+
+ // Log the channel opening
+ String date = DATE_FORMAT.format(new Date(System.currentTimeMillis()));
+
+ String fullMessage = NLS.bind(Messages.ChannelTraceListener_channelOpening_message,
+ new Object[] {
+ date,
+ Integer.toHexString(channel.hashCode()),
+ message != null ? "(" + message.trim() + ")" : "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ });
+
+ List<String> queue = queued.get(channel);
+ if (queue == null) {
+ queue = new ArrayList<String>();
+ queued.put(channel, queue);
+ }
+ queue.add(fullMessage);
+ }
+
+ /**
+ * Channel got redirected.
+ *
+ * @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) {
+ Assert.isNotNull(channel);
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
+ // The trace listener interface does not have a onChannelOpenend method, but
+ // for consistency, log the channel opening similar to the others.
+ if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER)) {
+ CoreBundleActivator.getTraceHandler().trace("TraceListener.onChannelRedirected ( " + channel + ", \"" + message + "\" )", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER, this);
+ }
+
+ // Get the preference key if or if not logging is enabled
+ boolean loggingEnabled = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED);
+ // If false, we are done here and wont create any console or trace listener.
+ if (!loggingEnabled) return;
+
+ // Log the channel opening
+ String date = DATE_FORMAT.format(new Date(System.currentTimeMillis()));
+
+ String fullMessage = NLS.bind(Messages.ChannelTraceListener_channelRedirected_message,
+ new Object[] {
+ date,
+ Integer.toHexString(channel.hashCode()),
+ message != null ? "(" + message.trim() + ")" : "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ });
+
+ List<String> queue = queued.get(channel);
+ if (queue == null) {
+ queue = new ArrayList<String>();
+ queued.put(channel, queue);
+ }
+ queue.add(fullMessage);
+ }
+
+ /**
+ * Mark an event in the channel log.
+ *
+ * @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) {
+ Assert.isNotNull(channel);
+ Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+
+ // The trace listener interface does not have a onChannelOpenend method, but
+ // for consistency, log the channel opening similar to the others.
+ if (CoreBundleActivator.getTraceHandler().isSlotEnabled(0, ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER)) {
+ CoreBundleActivator.getTraceHandler().trace("TraceListener.onMark ( " + channel + ", \"" + message + "\" )", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ITracing.ID_TRACE_CHANNEL_TRACE_LISTENER, this);
+ }
+
+ // If the channel is opened to a ValueAdd, do not write a log file.
+ String value = channel.getRemotePeer().getAttributes().get("ValueAdd"); //$NON-NLS-1$
+ boolean isValueAdd = value != null && ("1".equals(value.trim()) || Boolean.parseBoolean(value.trim())); //$NON-NLS-1$
+ if (isValueAdd) return;
+
+ // Get the preference key if or if not logging is enabled
+ boolean loggingEnabled = CoreBundleActivator.getScopedPreferences().getBoolean(IPreferenceKeys.PREF_LOGGING_ENABLED);
+ // If false, we are done here and wont create any console or trace listener.
+ if (!loggingEnabled) return;
+
+ // Log the channel opening
+ String date = DATE_FORMAT.format(new Date(System.currentTimeMillis()));
+
+ String fullMessage = NLS.bind(Messages.ChannelTraceListener_channelMark_message,
+ new Object[] {
+ date,
+ Integer.toHexString(channel.hashCode()),
+ message != null ? "(" + message.trim() + ")" : "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ });
+
+ // Get the file writer
+ FileWriter writer = LogManager.getInstance().getWriter(channel);
+ if (writer != null) {
+ try {
+ // Write the message
+ writer.write(fullMessage);
+ writer.write("\n"); //$NON-NLS-1$
+ writer.flush();
+ } catch (IOException e) {
+ /* ignored on purpose */
+ }
+ }
+ }
+
+ /**
* Channel closed. Detach the channel trace listener if any.
*
* @param channel The channel. Must not be <code>null</code>.
@@ -135,6 +286,9 @@ public class ChannelTraceListenerManager {
Assert.isNotNull(channel);
Assert.isTrue(Protocol.isDispatchThread(), "Illegal Thread Access"); //$NON-NLS-1$
+ // Remove the queued messages
+ queued.remove(channel);
+
// The trace listeners can be accessed only via AbstractChannel
if (!(channel instanceof AbstractChannel)) return;
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 dde27f425..92fb36c10 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
@@ -45,12 +45,21 @@ public final class EventListener extends PlatformObject implements IEventListene
final String type = ((ChannelEvent)event).getType();
final String message = ((ChannelEvent)event).getMessage();
- if (ChannelEvent.TYPE_OPEN.equals(type)) {
+ if (ChannelEvent.TYPE_OPENING.equals(type)) {
+ ChannelTraceListenerManager.getInstance().onChannelOpening(channel, message);
+ }
+ else if (ChannelEvent.TYPE_REDIRECT.equals(type)) {
+ ChannelTraceListenerManager.getInstance().onChannelRedirected(channel, message);
+ }
+ else if (ChannelEvent.TYPE_OPEN.equals(type)) {
ChannelTraceListenerManager.getInstance().onChannelOpened(channel, message);
}
else if (ChannelEvent.TYPE_CLOSE.equals(type)) {
ChannelTraceListenerManager.getInstance().onChannelClosed(channel);
}
+ else if (ChannelEvent.TYPE_MARK.equals(type)) {
+ ChannelTraceListenerManager.getInstance().onMark(channel, message);
+ }
}
}
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.java
index 3f151a64c..c734866c6 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.java
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.java
@@ -29,8 +29,11 @@ public class Messages extends NLS {
// **** Declare externalized string id's down here *****
+ public static String ChannelTraceListener_channelOpening_message;
+ public static String ChannelTraceListener_channelRedirected_message;
public static String ChannelTraceListener_channelOpened_message;
public static String ChannelTraceListener_channelClosed_message;
+ public static String ChannelTraceListener_channelMark_message;
public static String LogManager_dispose_message;
public static String LogManager_error_renameFailed;
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.properties
index d13b2c07c..bf8e3c507 100644
--- a/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.properties
+++ b/target_explorer/plugins/org.eclipse.tcf.te.tcf.log.core/src/org/eclipse/tcf/te/tcf/log/core/internal/nls/Messages.properties
@@ -8,8 +8,11 @@
# Wind River Systems - initial API and implementation
###############################################################################
+ChannelTraceListener_channelOpening_message=# {0}: Opening channel {1} {2}
+ChannelTraceListener_channelRedirected_message=# {0}: Redirected channel {1} {2}
ChannelTraceListener_channelOpened_message=# {0}: Opened channel {1} {2}
ChannelTraceListener_channelClosed_message=# {0}: Closed channel {1} (error={2})
+ChannelTraceListener_channelMark_message=# {0}: Channel {1}: {2}
LogManager_dispose_message=# {0}: Closed session
LogManager_error_renameFailed=Failed to rename file while cycling the log files.\n\nFrom: {0}\nTo: {1}

Back to the top