import java.util.concurrent.TimeUnit;
public class LTTngAgent {
+
/* Domains */
static enum Domain {
JUL(3), LOG4J(4);
}
}
+ private static final int SEM_TIMEOUT = 3; /* Seconds */
+
private static LogFramework julUser;
private static LogFramework julRoot;
private static LogFramework log4jUser;
private static boolean initialized = false;
private static Semaphore registerSem;
- private final static int semTimeout = 3; /* Seconds */
/*
* Constructor is private. This is a singleton and a reference should be
private void initAgentJULClasses() {
try {
Class<?> lttngJUL = loadClass("org.lttng.ust.agent.jul.LTTngJUL");
- julUser = (LogFramework)lttngJUL.getDeclaredConstructor(new Class[] {Boolean.class}).newInstance(false);
- julRoot = (LogFramework)lttngJUL.getDeclaredConstructor(new Class[] {Boolean.class}).newInstance(true);
+ julUser = (LogFramework) lttngJUL.getDeclaredConstructor(new Class[] { Boolean.class }).newInstance(false);
+ julRoot = (LogFramework) lttngJUL.getDeclaredConstructor(new Class[] { Boolean.class }).newInstance(true);
this.useJUL = true;
} catch (ClassNotFoundException e) {
/* LTTng JUL classes not found, no need to create the relevant objects */
/* Wait for each registration to end. */
try {
registerSem.tryAcquire(numThreads,
- semTimeout,
+ SEM_TIMEOUT,
TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
import java.util.List;
interface LTTngSessiondCmd2_6 {
+
/**
* Maximum name length for a logger name to be send to sessiond.
*/
- final static int NAME_MAX = 255;
+ int NAME_MAX = 255;
/*
* Size of a primitive type int in byte. Because you know, Java can't
* provide that since it does not makes sense...
+ *
+ *
*/
- final static int INT_SIZE = 4;
+ int INT_SIZE = 4;
- public interface SessiondResponse {
+ interface SessiondResponse {
/**
* Gets a byte array of the command so that it may be streamed
*
public byte[] getBytes();
}
- public interface SessiondCommand {
+ interface SessiondCommand {
/**
* Populate the class from a byte array
*
public void populate(byte[] data);
}
- public enum lttng_agent_command {
+ enum lttng_agent_command {
/** List logger(s). */
CMD_LIST(1),
/** Enable logger by name. */
}
}
- public class sessiond_hdr implements SessiondCommand {
+ class sessiond_hdr implements SessiondCommand {
+
/** ABI size of command header. */
public final static int SIZE = 16;
/** Payload size in bytes following this header. */
- public long data_size;
+ public long dataSize;
/** Command type. */
public lttng_agent_command cmd;
/** Command version. */
- public int cmd_version;
+ public int cmdVersion;
+ @Override
public void populate(byte[] data) {
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.BIG_ENDIAN);
- data_size = buf.getLong();
+ dataSize = buf.getLong();
cmd = lttng_agent_command.values()[buf.getInt() - 1];
- cmd_version = buf.getInt();
+ cmdVersion = buf.getInt();
}
}
- public class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
- private final static int SIZE = 4;
+ class sessiond_enable_handler implements SessiondResponse, SessiondCommand {
+
+ private static final int SIZE = 4;
public String name;
public int lttngLogLevel;
public int lttngLogLevelType;
@Override
public void populate(byte[] data) {
- int data_offset = INT_SIZE * 2;
+ int dataOffset = INT_SIZE * 2;
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.LITTLE_ENDIAN);
lttngLogLevel = buf.getInt();
lttngLogLevelType = buf.getInt();
- name = new String(data, data_offset, data.length - data_offset).trim();
+ name = new String(data, dataOffset, data.length - dataOffset).trim();
}
@Override
}
}
- public class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
+ class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
+
private final static int SIZE = 4;
public String name;
}
}
- public class sessiond_list_logger implements SessiondResponse {
+ class sessiond_list_logger implements SessiondResponse {
+
private final static int SIZE = 12;
- private int data_size = 0;
- private int nb_logger = 0;
+ private int dataSize = 0;
+ private int nbLogger = 0;
- List<String> logger_list = new ArrayList<String>();
+ List<String> loggerList = new ArrayList<String>();
/** Return status code to the session daemon. */
public lttng_agent_ret_code code;
@Override
public byte[] getBytes() {
- byte data[] = new byte[SIZE + data_size];
+ byte data[] = new byte[SIZE + dataSize];
ByteBuffer buf = ByteBuffer.wrap(data);
buf.order(ByteOrder.BIG_ENDIAN);
/* Returned code */
buf.putInt(code.getCode());
- buf.putInt(data_size);
- buf.putInt(nb_logger);
+ buf.putInt(dataSize);
+ buf.putInt(nbLogger);
- for (String logger: logger_list) {
+ for (String logger: loggerList) {
buf.put(logger.getBytes());
/* NULL terminated byte after the logger name. */
buf.put((byte) 0x0);
Iterator<String> loggers = log.listLoggers();
while (loggers.hasNext()) {
loggerName = loggers.next();
- this.logger_list.add(loggerName);
- this.nb_logger++;
- this.data_size += loggerName.length() + 1;
+ this.loggerList.add(loggerName);
+ this.nbLogger++;
+ this.dataSize += loggerName.length() + 1;
}
this.code = lttng_agent_ret_code.CODE_SUCCESS_CMD;
class LTTngTCPSessiondClient implements Runnable {
+ private static final String SESSION_HOST = "127.0.0.1";
+ private static final String ROOT_PORT_FILE = "/var/run/lttng/agent.port";
+ private static final String USER_PORT_FILE = "/.lttng/agent.port";
+
+ private static Integer protocolMajorVersion = 1;
+ private static Integer protocolMinorVersion = 0;
+
/* Command header from the session deamon. */
private LTTngSessiondCmd2_6.sessiond_hdr headerCmd =
new LTTngSessiondCmd2_6.sessiond_hdr();
private Semaphore registerSem;
- private static final String sessiondHost = "127.0.0.1";
- private static final String rootPortFile = "/var/run/lttng/agent.port";
- private static final String userPortFile = "/.lttng/agent.port";
-
- private static Integer protocolMajorVersion = 1;
- private static Integer protocolMinorVersion = 0;
private LTTngAgent.Domain agentDomain;
- /* Indicate if we've already release the semaphore. */
- private boolean sem_posted = false;
+ /* Indicate if we've already released the semaphore. */
+ private boolean semPosted = false;
public LTTngTCPSessiondClient(LTTngAgent.Domain domain, LogFramework log, Semaphore sem) {
this.agentDomain = domain;
/*
* Try to release the registerSem if it's not already done.
*/
- private void tryReleaseSem()
- {
+ private void tryReleaseSem() {
/* Release semaphore so we unblock the agent. */
- if (!this.sem_posted) {
+ if (!this.semPosted) {
this.registerSem.release();
- this.sem_posted = true;
+ this.semPosted = true;
}
}
* static buffer of the right size.
*/
private void recvHeader() throws Exception {
- int read_len;
byte data[] = new byte[LTTngSessiondCmd2_6.sessiond_hdr.SIZE];
- read_len = this.inFromSessiond.read(data, 0, data.length);
- if (read_len != data.length) {
+ int readLen = this.inFromSessiond.read(data, 0, data.length);
+ if (readLen != data.length) {
throw new IOException();
}
this.headerCmd.populate(data);
* is expected after the header.
*/
private byte[] recvPayload() throws Exception {
- byte payload[] = new byte[(int) this.headerCmd.data_size];
+ byte payload[] = new byte[(int) this.headerCmd.dataSize];
/* Failsafe check so we don't waste our time reading 0 bytes. */
if (payload.length == 0) {
/* Get header from session daemon. */
recvHeader();
- if (headerCmd.data_size > 0) {
+ if (headerCmd.dataSize > 0) {
data = recvPayload();
}
int port;
if (this.log.isRoot()) {
- port = getPortFromFile(rootPortFile);
+ port = getPortFromFile(ROOT_PORT_FILE);
if (port == 0) {
/* No session daemon available. Stop and retry later. */
throw new IOException();
}
} else {
- port = getPortFromFile(getHomePath() + userPortFile);
+ port = getPortFromFile(getHomePath() + USER_PORT_FILE);
if (port == 0) {
/* No session daemon available. Stop and retry later. */
throw new IOException();
}
}
- this.sessiondSock = new Socket(sessiondHost, port);
- this.inFromSessiond = new DataInputStream(
- sessiondSock.getInputStream());
- this.outToSessiond = new DataOutputStream(
- sessiondSock.getOutputStream());
+ this.sessiondSock = new Socket(SESSION_HOST, port);
+ this.inFromSessiond = new DataInputStream(sessiondSock.getInputStream());
+ this.outToSessiond = new DataOutputStream(sessiondSock.getOutputStream());
}
private void registerToSessiond() throws Exception {
public abstract class LogFrameworkSkeleton implements LogFramework {
/* A map of event name and reference count */
- private Map<String, Integer> enabledLoggers;
+ private final Map<String, Integer> enabledLoggers;
public LogFrameworkSkeleton() {
this.enabledLoggers = new HashMap<String, Integer>();
import java.util.logging.LogRecord;
class LTTngLogHandler extends Handler {
- private Boolean is_root;
+
+ private final Boolean isRoot;
public LTTngLogHandler(Boolean isRoot) {
super();
- this.is_root = isRoot;
+ this.isRoot = isRoot;
/* Initialize LTTng UST tracer. */
try {
System.loadLibrary("lttng-ust-jul-jni"); //$NON-NLS-1$
}
public Boolean isRoot() {
- return this.is_root;
+ return this.isRoot;
}
@Override
@Override
public void publish(LogRecord record) {
/*
- * Specific tracepoing designed for JUL events. The source class of the
+ * Specific tracepoint designed for JUL events. The source class of the
* caller is used for the event name, the raw message is taken, the
* loglevel of the record and the thread ID.
*/
- if (this.is_root) {
+ if (this.isRoot) {
tracepointS(record.getMessage(),
record.getLoggerName(), record.getSourceClassName(),
record.getSourceMethodName(), record.getMillis(),
}
/* Use for a user session daemon. */
- private native void tracepointU(String msg, String logger_name, String class_name,
- String method_name, long millis, int log_level, int thread_id);
+ private native void tracepointU(String msg,
+ String logger_name,
+ String class_name,
+ String method_name,
+ long millis,
+ int log_level,
+ int thread_id);
/* Use for a root session daemon. */
- private native void tracepointS(String msg, String logger_name, String class_name,
- String method_name, long millis, int log_level, int thread_id);
+ private native void tracepointS(String msg,
+ String logger_name,
+ String class_name,
+ String method_name,
+ long millis,
+ int log_level,
+ int thread_id);
}
import org.apache.log4j.spi.LoggingEvent;
class LTTngLogAppender extends AppenderSkeleton {
- private Boolean is_root;
+
+ private Boolean isRoot;
public LTTngLogAppender(Boolean isRoot) {
super();
- this.is_root = isRoot;
+ this.isRoot = isRoot;
try {
System.loadLibrary("lttng-ust-log4j-jni"); //$NON-NLS-1$
} catch (SecurityException e) {
}
public Boolean isRoot() {
- return this.is_root;
+ return this.isRoot;
}
@Override
line = -1;
}
- if (this.is_root) {
+ if (this.isRoot) {
tracepointS(event.getRenderedMessage(),
- event.getLoggerName(),
- event.getLocationInformation().getClassName(),
- event.getLocationInformation().getMethodName(),
- event.getLocationInformation().getFileName(),
- line,
- event.getTimeStamp(),
- event.getLevel().toInt(),
- event.getThreadName());
+ event.getLoggerName(),
+ event.getLocationInformation().getClassName(),
+ event.getLocationInformation().getMethodName(),
+ event.getLocationInformation().getFileName(),
+ line,
+ event.getTimeStamp(),
+ event.getLevel().toInt(),
+ event.getThreadName());
} else {
tracepointU(event.getRenderedMessage(),
- event.getLoggerName(),
- event.getLocationInformation().getClassName(),
- event.getLocationInformation().getMethodName(),
- event.getLocationInformation().getFileName(),
- line,
- event.getTimeStamp(),
- event.getLevel().toInt(),
- event.getThreadName());
+ event.getLoggerName(),
+ event.getLocationInformation().getClassName(),
+ event.getLocationInformation().getMethodName(),
+ event.getLocationInformation().getFileName(),
+ line,
+ event.getTimeStamp(),
+ event.getLevel().toInt(),
+ event.getThreadName());
}
}