cleanup: Coding style fixes to the Java agent
[lttng-ust.git] / liblttng-ust-java-agent / java / org / lttng / ust / agent / LTTngTCPSessiondClient.java
index ab800ede606b6d4ada1c9f811b01d1ecfa8d4769..d376f672e5e04c39c97a02100f0690b52f4d3546 100644 (file)
 
 package org.lttng.ust.agent;
 
-import java.util.concurrent.Semaphore;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.lang.Integer;
-import java.io.IOException;
-import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
 import java.io.DataInputStream;
-import java.io.FileReader;
+import java.io.DataOutputStream;
 import java.io.FileNotFoundException;
-import java.net.*;
+import java.io.FileReader;
+import java.io.IOException;
 import java.lang.management.ManagementFactory;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+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();
@@ -48,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;
@@ -69,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;
                }
        }
 
@@ -141,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[this.headerCmd.SIZE];
+               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);
@@ -159,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) {
@@ -174,14 +171,13 @@ class LTTngTCPSessiondClient implements Runnable {
         * Handle session command from the session daemon.
         */
        private void handleSessiondCmd() throws Exception {
-               int ret_code;
                byte data[] = null;
 
                while (true) {
                        /* Get header from session daemon. */
                        recvHeader();
 
-                       if (headerCmd.data_size > 0) {
+                       if (headerCmd.dataSize > 0) {
                                data = recvPayload();
                        }
 
@@ -238,8 +234,6 @@ class LTTngTCPSessiondClient implements Runnable {
                                        data = new byte[4];
                                        ByteBuffer buf = ByteBuffer.wrap(data);
                                        buf.order(ByteOrder.BIG_ENDIAN);
-                                       LTTngSessiondCmd2_6.lttng_agent_ret_code code =
-                                               LTTngSessiondCmd2_6.lttng_agent_ret_code.CODE_INVALID_CMD;
                                        break;
                                }
                        }
@@ -250,7 +244,7 @@ class LTTngTCPSessiondClient implements Runnable {
                }
        }
 
-       private String getHomePath() {
+       private static String getHomePath() {
                return System.getProperty("user.home");
        }
 
@@ -259,7 +253,7 @@ class LTTngTCPSessiondClient implements Runnable {
         *
         * @return port value if found else 0.
         */
-       private int getPortFromFile(String path) throws IOException {
+       private static int getPortFromFile(String path) throws IOException {
                int port;
                BufferedReader br;
 
@@ -284,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(this.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 {
@@ -311,8 +303,8 @@ class LTTngTCPSessiondClient implements Runnable {
 
                buf.putInt(this.agentDomain.value());
                buf.putInt(Integer.parseInt(pid));
-               buf.putInt(this.protocolMajorVersion);
-               buf.putInt(this.protocolMinorVersion);
+               buf.putInt(protocolMajorVersion);
+               buf.putInt(protocolMinorVersion);
                this.outToSessiond.write(data, 0, data.length);
                this.outToSessiond.flush();
        }
This page took 0.026882 seconds and 4 git commands to generate.