cleanup: Coding style fixes to the Java agent
authorAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 29 Jun 2015 20:55:00 +0000 (16:55 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Mon, 29 Jun 2015 23:25:14 +0000 (19:25 -0400)
- Use camelCase for regular members and FULL_CAPS for static final
  ones (except for API classes).
- All members of an interface are public static final by default,
  no need to repeat the modifiers.
- Marked final some fields that could be.

Signed-off-by: Alexandre Montplaisir <alexmonthy@efficios.com>
liblttng-ust-java-agent/java/org/lttng/ust/agent/LTTngAgent.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/LTTngSessiondCmd2_6.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/LTTngTCPSessiondClient.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/LogFrameworkSkeleton.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/jul/LTTngLogHandler.java
liblttng-ust-java-agent/java/org/lttng/ust/agent/log4j/LTTngLogAppender.java

index 8dc329fb9dfc6e1069749f353b79f9edcf0f52da..ca7bc777fa24b1042acf3d41bbd27fcc4e73a547 100644 (file)
@@ -23,6 +23,7 @@ import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
 public class LTTngAgent {
+
        /* Domains */
        static enum Domain {
                JUL(3), LOG4J(4);
@@ -37,6 +38,8 @@ public class LTTngAgent {
                }
        }
 
+       private static final int SEM_TIMEOUT = 3; /* Seconds */
+
        private static LogFramework julUser;
        private static LogFramework julRoot;
        private static LogFramework log4jUser;
@@ -63,7 +66,6 @@ public class LTTngAgent {
        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
@@ -142,8 +144,8 @@ public class LTTngAgent {
        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 */
@@ -212,7 +214,7 @@ public class LTTngAgent {
                /* Wait for each registration to end. */
                try {
                        registerSem.tryAcquire(numThreads,
-                                                   semTimeout,
+                                                   SEM_TIMEOUT,
                                                    TimeUnit.SECONDS);
                } catch (InterruptedException e) {
                        e.printStackTrace();
index 3497689ab9d534d371540896edc6500cb8837309..7a33e4252c679f72b9cd1516064e9ca4057b83c7 100644 (file)
@@ -25,18 +25,21 @@ import java.util.Iterator;
 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
                 *
@@ -45,7 +48,7 @@ interface LTTngSessiondCmd2_6 {
                public byte[] getBytes();
        }
 
-       public interface SessiondCommand {
+       interface SessiondCommand {
                /**
                 * Populate the class from a byte array
                 *
@@ -55,7 +58,7 @@ interface LTTngSessiondCmd2_6 {
                public void populate(byte[] data);
        }
 
-       public enum lttng_agent_command {
+       enum lttng_agent_command {
                /** List logger(s). */
                CMD_LIST(1),
                /** Enable logger by name. */
@@ -91,28 +94,31 @@ interface LTTngSessiondCmd2_6 {
                }
        }
 
-       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;
@@ -122,13 +128,13 @@ interface LTTngSessiondCmd2_6 {
 
                @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
@@ -153,7 +159,8 @@ interface LTTngSessiondCmd2_6 {
                }
        }
 
-       public class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
+       class sessiond_disable_handler implements SessiondResponse, SessiondCommand {
+
                private final static int SIZE = 4;
                public String name;
 
@@ -190,29 +197,30 @@ interface LTTngSessiondCmd2_6 {
                }
        }
 
-       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);
@@ -226,9 +234,9 @@ interface LTTngSessiondCmd2_6 {
                        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;
index db4e1f70c75d31b861d26b9d39c91628ccbf01a5..d376f672e5e04c39c97a02100f0690b52f4d3546 100644 (file)
@@ -32,6 +32,13 @@ import java.util.concurrent.Semaphore;
 
 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();
@@ -46,17 +53,11 @@ class LTTngTCPSessiondClient implements Runnable {
 
        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;
@@ -67,12 +68,11 @@ class LTTngTCPSessiondClient implements Runnable {
        /*
         * 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;
                }
        }
 
@@ -139,11 +139,10 @@ class LTTngTCPSessiondClient implements Runnable {
         * 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);
@@ -157,7 +156,7 @@ class LTTngTCPSessiondClient implements Runnable {
         * 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) {
@@ -178,7 +177,7 @@ class LTTngTCPSessiondClient implements Runnable {
                        /* Get header from session daemon. */
                        recvHeader();
 
-                       if (headerCmd.data_size > 0) {
+                       if (headerCmd.dataSize > 0) {
                                data = recvPayload();
                        }
 
@@ -279,24 +278,22 @@ class LTTngTCPSessiondClient implements Runnable {
                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 {
index 4ad981e9375b59596ce5bcb21dfd3a13733ca6c4..6d1ea9f68c9e85889e19db7a185588c2bc52d0a7 100644 (file)
@@ -25,7 +25,7 @@ import java.util.Iterator;
 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>();
index a20aed21707b48d67fbf2431e1e1d58527339989..b844d2f675b50760cacb635ada85a8b1f409e2a1 100644 (file)
@@ -23,11 +23,12 @@ import java.util.logging.Handler;
 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$
@@ -42,7 +43,7 @@ class LTTngLogHandler extends Handler {
        }
 
        public Boolean isRoot() {
-               return this.is_root;
+               return this.isRoot;
        }
 
        @Override
@@ -54,11 +55,11 @@ class LTTngLogHandler extends Handler {
        @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(),
@@ -72,10 +73,20 @@ class LTTngLogHandler extends Handler {
        }
 
        /* 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);
 }
index 0d4d6f32b853538a684cca3a8fb7e184524d07d2..30fac23f8c32f1837bfa1979efea6f0bdf0fb1d9 100644 (file)
@@ -23,11 +23,12 @@ import org.apache.log4j.AppenderSkeleton;
 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) {
@@ -41,7 +42,7 @@ class LTTngLogAppender extends AppenderSkeleton {
        }
 
        public Boolean isRoot() {
-               return this.is_root;
+               return this.isRoot;
        }
 
        @Override
@@ -59,26 +60,26 @@ class LTTngLogAppender extends AppenderSkeleton {
                        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());
                }
        }
 
This page took 0.034914 seconds and 4 git commands to generate.