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();
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[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);
* 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) {
* 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();
}
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;
}
}
}
}
- private String getHomePath() {
+ private static String getHomePath() {
return System.getProperty("user.home");
}
*
* @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;
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 {
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();
}