Skip to content

Commit

Permalink
WHACK-23: Drop deprecated Log interface
Browse files Browse the repository at this point in the history
Instead of using `org.xmpp.component.Log`, an SLF4j provided Logger should be used.
  • Loading branch information
guusdk authored and Fishbowler committed Nov 20, 2024
1 parent f940b42 commit 7bcd40f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 219 deletions.
22 changes: 12 additions & 10 deletions source/java/org/jivesoftware/whack/ExternalComponent.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2005 Jive Software.
* Copyright 2005 Jive Software, 2024 Ignite Realtime Foundation
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +38,8 @@
import org.dom4j.io.XPPPacketReader;
import org.jivesoftware.whack.util.StringUtils;
import org.jivesoftware.whack.util.TaskEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
Expand All @@ -66,6 +64,8 @@
*/
public class ExternalComponent implements Component {

private static final Logger Log = LoggerFactory.getLogger(ExternalComponent.class);

/**
* The utf-8 charset for decoding and encoding XMPP packet streams.
*/
Expand Down Expand Up @@ -353,7 +353,7 @@ public void run() {
iqResultListener.receivedAnswer(iq);
}
catch (Exception e) {
manager.getLog().error("Error processing answer of remote entity", e);
Log.error("Error processing answer of remote entity", e);
}
return;
}
Expand All @@ -374,7 +374,7 @@ public void send(Packet packet) {
}
catch (IOException e) {
// Log the exception
manager.getLog().error(e);
Log.error("Unable to send stanza: {}", packet, e);
if (!shutdown) {
// Connection was lost so try to reconnect
connectionLost();
Expand Down Expand Up @@ -429,7 +429,7 @@ private void disconnect() {
socket.close();
}
catch (Exception e) {
manager.getLog().error(e);
Log.error("Unable to close socket.", e);
}
}
}
Expand Down Expand Up @@ -469,7 +469,7 @@ public void connectionLost() {
start();
}
} catch (ComponentException e) {
manager.getLog().error("Error trying to reconnect with the server", e);
Log.error("Error trying to reconnect with the server", e);
// Wait for 5 seconds until the next retry
try {
Thread.sleep(5000);
Expand Down Expand Up @@ -507,6 +507,8 @@ void addIQResultListener(String id, IQResultListener listener, long timeoutmilli
*/
private class KeepAliveTask extends TimerTask {

private final Logger Log = LoggerFactory.getLogger(KeepAliveTask.class);

public void run() {
synchronized (writer) {
// Send heartbeat if no packet has been sent to the server for a given time
Expand All @@ -517,7 +519,7 @@ public void run() {
}
catch (IOException e) {
// Log the exception
manager.getLog().error(e);
Log.error("Unable to send a whitespace ping.", e);
if (!shutdown) {
// Connection was lost so try to reconnect
connectionLost();
Expand Down
71 changes: 1 addition & 70 deletions source/java/org/jivesoftware/whack/ExternalComponentManager.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2005 Jive Software.
* Copyright 2005 Jive Software, 2024 Ignite Realtime Foundation.
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +29,6 @@
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.component.IQResultListener;
import org.xmpp.component.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
Expand Down Expand Up @@ -103,9 +98,6 @@ public class ExternalComponentManager implements ComponentManager {
*/
private Map<Component, ExternalComponent> components = new Hashtable<Component,ExternalComponent>();

@Deprecated
private Log oldLogger;

/**
* Constructs a new ExternalComponentManager that will make connections
* to the specified XMPP server on the default external component port (5275).
Expand All @@ -131,8 +123,6 @@ public ExternalComponentManager(String host, int port) {
this.host = host;
this.port = port;

createDummyLogger();

// Set this ComponentManager as the current component manager
ComponentManagerFactory.setComponentManager(this);
}
Expand All @@ -145,8 +135,6 @@ public ExternalComponentManager(String host, int port, boolean startEncrypted) {
this.port = port;
this.startEncrypted = startEncrypted;

createDummyLogger();

// Set this ComponentManager as the current component manager
ComponentManagerFactory.setComponentManager(this);
}
Expand Down Expand Up @@ -360,61 +348,4 @@ public void setConnectTimeout(int connectTimeout) {
public boolean isExternalMode() {
return true;
}

@Deprecated
public Log getLog() {
return oldLogger;
}

private void createDummyLogger() {
this.oldLogger = new Log() {
public void error(String message) {
Logger.error(message);
}

public void error(String message, Throwable throwable) {
Logger.error(message, throwable);
}

public void error(Throwable throwable) {
Logger.error("", throwable);
}

public void warn(String message) {
Logger.warn(message);
}

public void warn(String message, Throwable throwable) {
Logger.warn(message, throwable);
}

public void warn(Throwable throwable) {
Logger.warn("", throwable);
}

public void info(String message) {
Logger.info(message);
}

public void info(String message, Throwable throwable) {
Logger.info(message, throwable);
}

public void info(Throwable throwable) {
Logger.info("", throwable);
}

public void debug(String message) {
Logger.debug(message);
}

public void debug(String message, Throwable throwable) {
Logger.debug(message, throwable);
}

public void debug(Throwable throwable) {
Logger.debug("", throwable);
}
};
}
}
16 changes: 8 additions & 8 deletions source/java/org/jivesoftware/whack/SocketReadThread.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright 2005 Jive Software.
* Copyright 2005 Jive Software, 2024 Ignite Realtime Foundation
*
* All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +18,8 @@

import org.dom4j.Element;
import org.dom4j.io.XPPPacketReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.*;

Expand All @@ -35,6 +33,8 @@
*/
class SocketReadThread extends Thread {

private static final Logger Log = LoggerFactory.getLogger(SocketReadThread.class);

private ExternalComponent component;
private boolean shutdown = false;

Expand Down Expand Up @@ -67,15 +67,15 @@ public void run() {
// Do nothing if the exception occured while shutting down the component otherwise
// log the error and try to establish a new connection
if (!shutdown) {
component.getManager().getLog().error(se);
Log.error("Unexpected exception", se);
component.connectionLost();
}
}
catch (XmlPullParserException ie) {
component.getManager().getLog().error(ie);
Log.error("Unexpected XML parsing exception", ie);
}
catch (Exception e) {
component.getManager().getLog().warn(e);
Log.warn("Unexpected exception", e);
}
}

Expand Down
131 changes: 0 additions & 131 deletions source/java/org/xmpp/component/Log.java

This file was deleted.

0 comments on commit 7bcd40f

Please sign in to comment.