Introduce a verbose mode for the Java agent
[deliverable/lttng-ust.git] / liblttng-ust-java-agent / java / lttng-ust-agent-common / org / lttng / ust / agent / client / LttngTcpSessiondClient.java
index 6cf971384260524869026351e868cfd5a4b608c2..6177feac7a849cefb44e959197e30894b295f529 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2015-2016 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
  * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
  *
  * This library is free software; you can redistribute it and/or modify it
@@ -31,6 +32,8 @@ import java.nio.ByteOrder;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
+import org.lttng.ust.agent.utils.LttngUstAgentLogger;
+
 /**
  * Client for agents to connect to a local session daemon, using a TCP socket.
  *
@@ -108,12 +111,14 @@ public class LttngTcpSessiondClient implements Runnable {
                                /*
                                 * Connect to the session daemon before anything else.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Connecting to sessiond");
                                connectToSessiond();
 
                                /*
                                 * Register to the session daemon as the Java component of the
                                 * UST application.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Registering to sessiond");
                                registerToSessiond();
 
                                /*
@@ -121,6 +126,7 @@ public class LttngTcpSessiondClient implements Runnable {
                                 * session daemon. This will return if and only if there is a
                                 * fatal error or the socket closes.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Waiting on sessiond commands...");
                                handleSessiondCmd();
                        } catch (UnknownHostException uhe) {
                                uhe.printStackTrace();
@@ -138,6 +144,7 @@ public class LttngTcpSessiondClient implements Runnable {
         * Dispose this client and close any socket connection it may hold.
         */
        public void close() {
+               LttngUstAgentLogger.log(getClass(), "Closing client");
                this.quit = true;
 
                try {
@@ -246,37 +253,67 @@ public class LttngTcpSessiondClient implements Runnable {
                                 * We don't send any reply to the registration done command.
                                 * This just marks the end of the initial session setup.
                                 */
+                               LttngUstAgentLogger.log(getClass(), "Registration done");
                                continue;
                        }
                        case CMD_LIST:
                        {
-                               ISessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
+                               SessiondCommand listLoggerCmd = new SessiondListLoggersCommand();
                                LttngAgentResponse response = listLoggerCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received list loggers command");
                                break;
                        }
-                       case CMD_ENABLE:
+                       case CMD_EVENT_ENABLE:
                        {
                                if (inputData == null) {
                                        /* Invalid command */
                                        responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
                                        break;
                                }
-                               ISessiondCommand enableCmd = new SessiondEnableEventCommand(inputData);
-                               LttngAgentResponse response = enableCmd.execute(logAgent);
+                               SessiondCommand enableEventCmd = new SessiondEnableEventCommand(inputData);
+                               LttngAgentResponse response = enableEventCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received enable event command");
                                break;
                        }
-                       case CMD_DISABLE:
+                       case CMD_EVENT_DISABLE:
                        {
                                if (inputData == null) {
                                        /* Invalid command */
                                        responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
                                        break;
                                }
-                               ISessiondCommand disableCmd = new SessiondDisableEventCommand(inputData);
-                               LttngAgentResponse response = disableCmd.execute(logAgent);
+                               SessiondCommand disableEventCmd = new SessiondDisableEventCommand(inputData);
+                               LttngAgentResponse response = disableEventCmd.execute(logAgent);
+                               responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received disable event command");
+                               break;
+                       }
+                       case CMD_APP_CTX_ENABLE:
+                       {
+                               if (inputData == null) {
+                                       /* This commands expects a payload, invalid command */
+                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       break;
+                               }
+                               SessiondCommand enableAppCtxCmd = new SessiondEnableAppContextCommand(inputData);
+                               LttngAgentResponse response = enableAppCtxCmd.execute(logAgent);
+                               responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received enable app-context command");
+                               break;
+                       }
+                       case CMD_APP_CTX_DISABLE:
+                       {
+                               if (inputData == null) {
+                                       /* This commands expects a payload, invalid command */
+                                       responseData = LttngAgentResponse.FAILURE_RESPONSE.getBytes();
+                                       break;
+                               }
+                               SessiondCommand disableAppCtxCmd = new SessiondDisableAppContextCommand(inputData);
+                               LttngAgentResponse response = disableAppCtxCmd.execute(logAgent);
                                responseData = response.getBytes();
+                               LttngUstAgentLogger.log(getClass(), "Received disable app-context command");
                                break;
                        }
                        default:
@@ -285,11 +322,13 @@ public class LttngTcpSessiondClient implements Runnable {
                                responseData = new byte[4];
                                ByteBuffer buf = ByteBuffer.wrap(responseData);
                                buf.order(ByteOrder.BIG_ENDIAN);
+                               LttngUstAgentLogger.log(getClass(), "Received unknown command, ignoring");
                                break;
                        }
                        }
 
                        /* Send response to the session daemon. */
+                       LttngUstAgentLogger.log(getClass(), "Sending response");
                        this.outToSessiond.write(responseData, 0, responseData.length);
                        this.outToSessiond.flush();
                }
This page took 0.042189 seconds and 5 git commands to generate.