changeset 220:96345741f7ce

[commands] Use logging over Debug class. Reviewed-by: jkang Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-July/024349.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Fri, 28 Jul 2017 18:48:35 +0200
parents 7a5d4d4f9cae
children 1a1e29c83c7b
files services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/AgentSocketsRegistry.java services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/CommandChannelAgentSocket.java services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/Debug.java
diffstat 3 files changed, 11 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/AgentSocketsRegistry.java	Thu Jul 27 14:36:55 2017 -0400
+++ b/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/AgentSocketsRegistry.java	Fri Jul 28 18:48:35 2017 +0200
@@ -43,11 +43,15 @@
 import java.util.TimerTask;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
 
 import javax.websocket.Session;
 
+import com.redhat.thermostat.gateway.common.util.LoggingUtil;
+
 class AgentSocketsRegistry {
 
+    private static final Logger logger = LoggingUtil.getLogger(AgentSocketsRegistry.class);
     private static final double PERCENT_85 = 0.85;
     private static final Map<String, AgentSessionHolder> agentSockets = new ConcurrentHashMap<>();
     private static final String TIMER_NAME = "com.redhat.thermostat.gateway.service.commands.ReceiverPingTimer";
@@ -104,9 +108,7 @@
             synchronized (session) {
                 if (session.isOpen()) {
                     ByteBuffer payload = ByteBuffer.wrap(pingPayload.getBytes("UTF-8"));
-                    if (Debug.isOn()) {
-                        System.err.println("Server: sending ping msg <<" + pingPayload + ">>");
-                    }
+                    logger.fine("Server: sending ping msg <<" + pingPayload + ">>");
                     session.getBasicRemote().sendPing(payload);
                 }
             }
--- a/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/CommandChannelAgentSocket.java	Thu Jul 27 14:36:55 2017 -0400
+++ b/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/CommandChannelAgentSocket.java	Fri Jul 28 18:48:35 2017 +0200
@@ -40,11 +40,14 @@
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
 import java.util.concurrent.TimeUnit;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.websocket.PongMessage;
 import javax.websocket.Session;
 
 import com.redhat.thermostat.gateway.common.core.auth.basic.RoleAwareUser;
+import com.redhat.thermostat.gateway.common.util.LoggingUtil;
 import com.redhat.thermostat.gateway.service.commands.channel.ClientAgentCommunication;
 import com.redhat.thermostat.gateway.service.commands.channel.CommunicationsRegistry;
 import com.redhat.thermostat.gateway.service.commands.channel.model.Message;
@@ -52,6 +55,7 @@
 
 class CommandChannelAgentSocket extends CommandChannelSocket {
 
+    private static final Logger logger = LoggingUtil.getLogger(CommandChannelAgentSocket.class);
     private static final long SOCKET_SESSION_IDLE_TIMEOUT = TimeUnit.MINUTES.toMillis(10);
     private static final String UNKNOWN_PAYLOAD = "UNKNOWN";
     private static final String AGENT_PROVIDER_PREFIX = "thermostat-commands-provider-";
@@ -91,9 +95,9 @@
 
     @Override
     public void onPongMessage(PongMessage message) {
-        if (Debug.isOn()) {
+        if (logger.isLoggable(Level.FINE)) {
             String payload = extractPayload(message);
-            System.err.println("Server: Got pong message <<" + payload + ">>");
+            logger.fine("Server: Got pong message <<" + payload + ">>");
         }
     }
 
--- a/services/commands/src/main/java/com/redhat/thermostat/gateway/service/commands/socket/Debug.java	Thu Jul 27 14:36:55 2017 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
- * Copyright 2012-2017 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.gateway.service.commands.socket;
-
-class Debug {
-
-    static boolean isOn() {
-        return false;
-    }
-}