package org.lttng.ust.agent;
+import java.util.Collection;
import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;
return decrementEventCount(eventName, enabledEvents);
}
+ /*
+ * Implementation of this method is domain-specific.
+ */
@Override
- public Iterable<String> listEnabledEvents() {
- List<String> events = new LinkedList<String>();
-
- if (enabledWildcards.get() > 0) {
- events.add(WILDCARD);
- }
- for (String prefix : enabledEventPrefixes.keySet()) {
- events.add(new String(prefix + WILDCARD));
- }
- events.addAll(enabledEvents.keySet());
- return events;
- }
+ public abstract Collection<String> listAvailableEvents();
@Override
public boolean isEventEnabled(String eventName) {
package org.lttng.ust.agent.client;
+import java.util.Collection;
+
import org.lttng.ust.agent.session.EventRule;
/**
boolean eventDisabled(String eventName);
/**
- * List the all events currently enabled in the current tracing sessions.
+ * List the events that are available in the agent's tracing domain.
+ *
+ * In Java terms, this means loggers that have at least one LTTng log
+ * handler of their corresponding domain attached.
*
- * @return The list of enabled events
+ * @return The list of available events
*/
- Iterable<String> listEnabledEvents();
+ Collection<String> listAvailableEvents();
}
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
/**
* Session daemon command asking the Java agent to list its registered loggers,
@Override
public LttngAgentResponse execute(ILttngTcpClientListener agent) {
- final List<String> loggerList = new ArrayList<String>();
+ final Collection<String> loggerList = agent.listAvailableEvents();
int dataSize = 0;
- for (String event : agent.listEnabledEvents()) {
- loggerList.add(event);
+ for (String event : agent.listAvailableEvents()) {
dataSize += event.length() + 1;
}
private final static int SIZE = 12;
- private final List<String> loggers;
+ private final Collection<String> loggers;
private final int dataSize;
- public SessiondListLoggersResponse(List<String> loggers, int dataSize) {
+ public SessiondListLoggersResponse(Collection<String> loggers, int dataSize) {
this.loggers = loggers;
this.dataSize = dataSize;
}
package org.lttng.ust.agent.jul;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.LogManager;
+import java.util.logging.Logger;
+
import org.lttng.ust.agent.AbstractLttngAgent;
/**
return instance;
}
+ @Override
+ public Collection<String> listAvailableEvents() {
+ List<String> ret = new ArrayList<String>();
+
+ List<String> loggersNames = Collections.list(LogManager.getLogManager().getLoggerNames());
+ for (String name : loggersNames) {
+ /*
+ * Skip the root logger. An empty string is not a valid event name
+ * in LTTng.
+ */
+ if (name.equals("")) {
+ continue;
+ }
+
+ /*
+ * Check if that logger has at least one LTTng JUL handler attached.
+ */
+ Logger logger = Logger.getLogger(name);
+ if (hasLttngHandlerAttached(logger)) {
+ ret.add(name);
+ }
+ }
+
+ return ret;
+ }
+
+ private static boolean hasLttngHandlerAttached(Logger logger) {
+ for (Handler handler : logger.getHandlers()) {
+ if (handler instanceof LttngLogHandler) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
package org.lttng.ust.agent.log4j;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
import org.lttng.ust.agent.AbstractLttngAgent;
/**
return instance;
}
+ @Override
+ public Collection<String> listAvailableEvents() {
+ List<String> ret = new ArrayList<String>();
+
+ @SuppressWarnings("unchecked")
+ List<Logger> loggers = Collections.list(LogManager.getCurrentLoggers());
+ for (Logger logger : loggers) {
+ /*
+ * Check if that logger has at least one LTTng log4j appender
+ * attached.
+ */
+ if (hasLttngAppenderAttached(logger)) {
+ ret.add(logger.getName());
+ }
+ }
+
+ return ret;
+ }
+
+ private static boolean hasLttngAppenderAttached(Logger logger) {
+ @SuppressWarnings("unchecked")
+ List<Appender> appenders = Collections.list(logger.getAllAppenders());
+ for (Appender appender : appenders) {
+ if (appender instanceof LttngLogAppender) {
+ return true;
+ }
+ }
+ return false;
+ }
}