Project

General

Profile

Bug #933 ยป 0001-Fix-Return-the-correct-list-of-available-Java-events.patch

Anonymous, 09/09/2015 05:56 PM

View differences:

liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/AbstractLttngAgent.java
19 19
package org.lttng.ust.agent;
20 20

  
21 21
import java.util.HashSet;
22
import java.util.LinkedList;
23 22
import java.util.List;
24 23
import java.util.Map;
25 24
import java.util.NavigableMap;
......
234 233
		return decrementEventCount(eventName, enabledEvents);
235 234
	}
236 235

  
236
	/*
237
	 * Implementation of this method is domain-specific.
238
	 */
237 239
	@Override
238
	public Iterable<String> listEnabledEvents() {
239
		List<String> events = new LinkedList<String>();
240

  
241
		if (enabledWildcards.get() > 0) {
242
			events.add(WILDCARD);
243
		}
244
		for (String prefix : enabledEventPrefixes.keySet()) {
245
			events.add(new String(prefix + WILDCARD));
246
		}
247
		events.addAll(enabledEvents.keySet());
248
		return events;
249
	}
240
	public abstract List<String> listAvailableEvents();
250 241

  
251 242
	@Override
252 243
	public boolean isEventEnabled(String eventName) {
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/ILttngTcpClientListener.java
17 17

  
18 18
package org.lttng.ust.agent.client;
19 19

  
20
import java.util.List;
21

  
20 22
import org.lttng.ust.agent.session.EventRule;
21 23

  
22 24
/**
......
53 55
	boolean eventDisabled(String eventName);
54 56

  
55 57
	/**
56
	 * List the all events currently enabled in the current tracing sessions.
58
	 * List the events that are available in the agent's tracing domain.
59
	 *
60
	 * In Java terms, this means loggers that have at least one LTTng log
61
	 * handler of their corresponding domain attached.
57 62
	 *
58
	 * @return The list of enabled events
63
	 * @return The list of available events
59 64
	 */
60
	Iterable<String> listEnabledEvents();
65
	List<String> listAvailableEvents();
61 66
}
liblttng-ust-java-agent/java/lttng-ust-agent-common/org/lttng/ust/agent/client/SessiondListLoggersCommand.java
20 20

  
21 21
import java.nio.ByteBuffer;
22 22
import java.nio.ByteOrder;
23
import java.util.ArrayList;
24 23
import java.util.List;
25 24

  
26 25
/**
......
34 33

  
35 34
	@Override
36 35
	public LttngAgentResponse execute(ILttngTcpClientListener agent) {
37
		final List<String> loggerList = new ArrayList<String>();
36
		final List<String> loggerList = agent.listAvailableEvents();
38 37
		int dataSize = 0;
39 38

  
40
		for (String event : agent.listEnabledEvents()) {
41
			loggerList.add(event);
39
		for (String event : agent.listAvailableEvents()) {
42 40
			dataSize += event.length() + 1;
43 41
		}
44 42

  
liblttng-ust-java-agent/java/lttng-ust-agent-jul/org/lttng/ust/agent/jul/LttngJulAgent.java
17 17

  
18 18
package org.lttng.ust.agent.jul;
19 19

  
20
import java.util.ArrayList;
21
import java.util.Enumeration;
22
import java.util.List;
23
import java.util.logging.Handler;
24
import java.util.logging.LogManager;
25
import java.util.logging.Logger;
26

  
20 27
import org.lttng.ust.agent.AbstractLttngAgent;
21 28

  
22 29
/**
......
39 46
		return instance;
40 47
	}
41 48

  
49
	@Override
50
	public List<String> listAvailableEvents() {
51
		List<String> ret = new ArrayList<String>();
52

  
53
		Enumeration<String> loggers = LogManager.getLogManager().getLoggerNames();
54
		while (loggers.hasMoreElements()) {
55
			String name = loggers.nextElement();
56
			/*
57
			 * Skip the root logger. An empty string is not a valid event name
58
			 * in LTTng.
59
			 */
60
			if (name.equals("")) {
61
				continue;
62
			}
63

  
64
			/*
65
			 * Check if that logger has at least one LTTng JUL handler attached.
66
			 */
67
			Logger logger = Logger.getLogger(name);
68
			if (hasLttngHandlerAttached(logger)) {
69
				ret.add(name);
70
			}
71
		}
72

  
73
		return ret;
74
	}
75

  
76
	private static boolean hasLttngHandlerAttached(Logger logger) {
77
		for (Handler handler : logger.getHandlers()) {
78
			if (handler instanceof LttngLogHandler) {
79
				return true;
80
			}
81
		}
82
		return false;
83
	}
84

  
42 85
}
liblttng-ust-java-agent/java/lttng-ust-agent-log4j/org/lttng/ust/agent/log4j/LttngLog4jAgent.java
17 17

  
18 18
package org.lttng.ust.agent.log4j;
19 19

  
20
import java.util.ArrayList;
21
import java.util.Enumeration;
22
import java.util.List;
23

  
24
import org.apache.log4j.Appender;
25
import org.apache.log4j.LogManager;
26
import org.apache.log4j.Logger;
20 27
import org.lttng.ust.agent.AbstractLttngAgent;
21 28

  
22 29
/**
......
40 47
		return instance;
41 48
	}
42 49

  
50
	@Override
51
	public List<String> listAvailableEvents() {
52
		List<String> ret = new ArrayList<String>();
53

  
54
		@SuppressWarnings("unchecked")
55
		Enumeration<Logger> loggers = LogManager.getCurrentLoggers();
56
		while (loggers.hasMoreElements()) {
57
			Logger logger = loggers.nextElement();
58

  
59
			/*
60
			 * Check if that logger has at least one LTTng log4j appender
61
			 * attached.
62
			 */
63
			if (hasLttngAppenderAttached(logger)) {
64
				ret.add(logger.getName());
65
			}
66
		}
67

  
68
		return ret;
69
	}
70

  
71
	private static boolean hasLttngAppenderAttached(Logger logger) {
72
		@SuppressWarnings("unchecked")
73
		Enumeration<Appender> appenders = logger.getAllAppenders();
74
		while (appenders.hasMoreElements()) {
75
			Appender appender = appenders.nextElement();
76

  
77
			if (appender instanceof LttngLogAppender) {
78
				return true;
79
			}
80
		}
81
		return false;
82
	}
43 83
}
44
- 
    (1-1/1)