remove obsolete plugins package
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java
index e05bc1b..ebe366b 100755
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawAppender.java
@@ -17,12 +17,7 @@
package org.apache.log4j.chainsaw;
import java.time.Instant;
-import java.time.ZonedDateTime;
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEventBuilder;
-import org.apache.log4j.plugins.Receiver;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender;
import org.apache.logging.log4j.core.config.plugins.Plugin;
diff --git a/src/main/java/org/apache/log4j/chainsaw/ChainsawReceiverSkeleton.java b/src/main/java/org/apache/log4j/chainsaw/ChainsawReceiverSkeleton.java
index 1a97eb0..687b06e 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ChainsawReceiverSkeleton.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ChainsawReceiverSkeleton.java
@@ -22,7 +22,6 @@
import java.util.List;
import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
import org.apache.log4j.chainsaw.logevents.Level;
-import org.apache.log4j.plugins.Receiver;
/**
*
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
index 77cb9bb..abffaf3 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogPanel.java
@@ -61,7 +61,6 @@
import java.util.List;
import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
import org.apache.log4j.chainsaw.logevents.Level;
-import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.spi.LoggingEventFieldResolver;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
diff --git a/src/main/java/org/apache/log4j/chainsaw/LogUI.java b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
index c400866..d9dac30 100644
--- a/src/main/java/org/apache/log4j/chainsaw/LogUI.java
+++ b/src/main/java/org/apache/log4j/chainsaw/LogUI.java
@@ -25,18 +25,11 @@
import org.apache.log4j.chainsaw.icons.ChainsawIcons;
import org.apache.log4j.chainsaw.icons.LineIconFactory;
import org.apache.log4j.chainsaw.osx.OSXIntegration;
-import org.apache.log4j.chainsaw.plugins.PluginClassLoaderFactory;
import org.apache.log4j.chainsaw.prefs.*;
import org.apache.log4j.chainsaw.receivers.ReceiversPanel;
-import org.apache.log4j.chainsaw.vfs.VFSLogFilePatternReceiver;
-import org.apache.log4j.net.SocketNodeEventListener;
-import org.apache.log4j.plugins.*;
import org.apache.log4j.rule.ExpressionRule;
import org.apache.log4j.rule.Rule;
import org.apache.log4j.spi.Decoder;
-import org.apache.log4j.spi.LoggerRepository;
-import org.apache.log4j.spi.LoggerRepositoryEx;
-import org.apache.log4j.spi.LoggingEvent;
import org.apache.log4j.xml.DOMConfigurator;
import org.apache.log4j.xml.XMLDecoder;
@@ -236,7 +229,13 @@
}
if (lookAndFeelClassName != null && !(lookAndFeelClassName.trim().equals(""))) {
- loadLookAndFeelUsingPluginClassLoader(lookAndFeelClassName);
+ try{
+ UIManager.setLookAndFeel(lookAndFeelClassName);
+ }catch(Exception ex){}
+ }else{
+ try{
+ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+ }catch(Exception ex){}
}
createChainsawGUI(model, null);
});
@@ -309,7 +308,7 @@
try {
URL configURL = new URL(config);
logger.info("Using '" + config + "' for auto-configuration");
- logUI.loadConfigurationUsingPluginClassLoader(configURL);
+// logUI.loadConfigurationUsingPluginClassLoader(configURL);
} catch (MalformedURLException e) {
logger.error("Initial configuration - failed to convert config string to url", e);
} catch (IOException e) {
@@ -328,7 +327,7 @@
URL newConfigurationURL = new URL(newConfiguration);
File file = new File(newConfigurationURL.toURI());
if (file.exists()) {
- logUI.loadConfigurationUsingPluginClassLoader(newConfigurationURL);
+// logUI.loadConfigurationUsingPluginClassLoader(newConfigurationURL);
} else {
logger.info("Updated configuration but file does not exist");
}
@@ -387,7 +386,7 @@
SettingsManager.getInstance().configure(new ApplicationPreferenceModelSaver(model));
EventQueue.invokeLater(() -> {
- loadLookAndFeelUsingPluginClassLoader(model.getLookAndFeelClassName());
+// loadLookAndFeelUsingPluginClassLoader(model.getLookAndFeelClassName());
createChainsawGUI(model, null);
getApplicationPreferenceModel().apply(model);
activateViewer();
@@ -460,38 +459,6 @@
}
- private void initPlugins(PluginRegistry pluginRegistry) {
- pluginRegistry.addPluginListener(
- new PluginListener() {
- public void pluginStarted(PluginEvent e) {
- if (e.getPlugin() instanceof JComponent) {
- JComponent plugin = (JComponent) e.getPlugin();
- getTabbedPane().addANewTab(plugin.getName(), plugin, null, null);
- getPanelMap().put(plugin.getName(), plugin);
- }
- }
-
- public void pluginStopped(PluginEvent e) {
- //TODO remove the plugin from the gui
- }
- });
-
- // TODO this should all be in a config file
-// ChainsawCentral cc = new ChainsawCentral();
-// pluginRegistry.addPlugin(cc);
-// cc.activateOptions();
-
- try {
- Class<? extends Plugin> pluginClass = Class.forName("org.apache.log4j.chainsaw.zeroconf.ZeroConfPlugin").asSubclass(Plugin.class);
- Plugin plugin = pluginClass.newInstance();
- pluginRegistry.addPlugin(plugin);
- plugin.activateOptions();
- statusBar.setMessage("Looks like ZeroConf is available... WooHoo!");
- } catch (Throwable e) {
- statusBar.setMessage("Doesn't look like ZeroConf is available");
- }
- }
-
private void setupReceiverPanel() {
receiversPanel = new ReceiversPanel(this, statusBar);
receiversPanel.addPropertyChangeListener(
@@ -1794,49 +1761,6 @@
}
}
- /**
- * Loads the log4j configuration file specified by the url, using
- * the PluginClassLoader instance as a TCCL, but only replacing it temporarily, with the original
- * TCCL being restored in a finally block to ensure consitency.
- *
- * @param url
- */
- private void loadConfigurationUsingPluginClassLoader(final URL url) {
- ClassLoader classLoader = PluginClassLoaderFactory.getInstance().getClassLoader();
- ClassLoader previousTCCL = Thread.currentThread().getContextClassLoader();
-
- if (url != null) {
- try {
- // we temporarily swap the TCCL so that plugins can find resources
- Thread.currentThread().setContextClassLoader(classLoader);
- try {
- DOMConfigurator.configure(url);
- } catch (Exception e) {
- logger.warn("Unable to load configuration URL: " + url, e);
- }
- } finally {
- // now switch it back...
- Thread.currentThread().setContextClassLoader(previousTCCL);
- }
- }
- }
-
- private static void loadLookAndFeelUsingPluginClassLoader(String lookAndFeelClassName) {
- ClassLoader classLoader = PluginClassLoaderFactory.getInstance().getClassLoader();
- ClassLoader previousTCCL = Thread.currentThread().getContextClassLoader();
- try {
- // we temporarily swap the TCCL so that plugins can find resources
- Thread.currentThread().setContextClassLoader(classLoader);
- UIManager.setLookAndFeel(lookAndFeelClassName);
- UIManager.getLookAndFeelDefaults().put("ClassLoader", classLoader);
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- // now switch it back...
- Thread.currentThread().setContextClassLoader(previousTCCL);
- }
- }
-
private class TabIconHandler implements EventCountListener, ChangeListener {
//the tabIconHandler is associated with a new tab, and a new tab always
//shows the 'new events' icon
diff --git a/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java b/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
index 2e5499c..fbb7c91 100644
--- a/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
@@ -19,7 +19,6 @@
import org.apache.log4j.chainsaw.helper.SwingHelper;
import org.apache.log4j.chainsaw.prefs.SettingsManager;
import org.apache.log4j.net.UDPReceiver;
-import org.apache.log4j.plugins.Receiver;
import javax.swing.*;
import javax.swing.text.SimpleAttributeSet;
@@ -695,9 +694,9 @@
return Integer.parseInt(networkReceiverPortComboBoxModel.getSelectedItem().toString());
}
- Class<? extends Receiver> getNetworkReceiverClass() throws ClassNotFoundException {
- return Class.forName(networkReceiverClassNameComboBoxModel.getSelectedItem().toString()).asSubclass(Receiver.class);
- }
+// Class<? extends Receiver> getNetworkReceiverClass() throws ClassNotFoundException {
+// return Class.forName(networkReceiverClassNameComboBoxModel.getSelectedItem().toString()).asSubclass(Receiver.class);
+// }
boolean isLoadConfig() {
diff --git a/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java b/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java
deleted file mode 100644
index d7579ff..0000000
--- a/src/main/java/org/apache/log4j/chainsaw/plugins/GUIPluginSkeleton.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.chainsaw.plugins;
-
-import org.apache.log4j.plugins.Plugin;
-import org.apache.log4j.spi.LoggerRepository;
-
-import javax.swing.*;
-import java.awt.*;
-
-
-/**
- */
-public abstract class GUIPluginSkeleton extends JPanel implements Plugin {
- private LoggerRepository loggerRepository;
- private boolean active;
-
- /**
- *
- */
- public GUIPluginSkeleton() {
- super();
- }
-
- /**
- * @param isDoubleBuffered
- */
- public GUIPluginSkeleton(boolean isDoubleBuffered) {
- super(isDoubleBuffered);
- }
-
- /**
- * @param layout
- */
- public GUIPluginSkeleton(LayoutManager layout) {
- super(layout);
- }
-
- /**
- * @param layout
- * @param isDoubleBuffered
- */
- public GUIPluginSkeleton(LayoutManager layout, boolean isDoubleBuffered) {
- super(layout, isDoubleBuffered);
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Plugin#getLoggerRepository()
- */
- public LoggerRepository getLoggerRepository() {
- return this.loggerRepository;
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Plugin#setLoggerRepository(org.apache.log4j.spi.LoggerRepository)
- */
- public void setLoggerRepository(LoggerRepository repository) {
- this.loggerRepository = repository;
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Plugin#isActive()
- */
- public boolean isActive() {
- return active;
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Plugin#isEquivalent(org.apache.log4j.plugins.Plugin)
- */
- public boolean isEquivalent(Plugin testPlugin) {
- // TODO Auto-generated method stub
- return false;
- }
-
- /**
- * @param active The active to set.
- */
- public final void setActive(boolean active) {
- boolean oldValue = this.active;
- this.active = active;
- firePropertyChange("active", oldValue, this.active);
- }
-}
diff --git a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java b/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java
deleted file mode 100644
index 9ffabd1..0000000
--- a/src/main/java/org/apache/log4j/chainsaw/plugins/PluginClassLoaderFactory.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j.chainsaw.plugins;
-
-import org.apache.log4j.chainsaw.prefs.SettingsManager;
-
-import java.io.File;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A factory class to create a Classloader that can refenerence jars/classes/resources
- * within a users plugin directory.
- * <p>
- * Currently a work in progress to see if this allows external jars required by
- * some 3rd party vendors for things like the JMSReceiver.
- *
- * @author psmith
- */
-public class PluginClassLoaderFactory {
- private final ClassLoader pluginClassLoader;
-
- private static final PluginClassLoaderFactory instance = new PluginClassLoaderFactory();
-
- private PluginClassLoaderFactory() {
- this.pluginClassLoader = PluginClassLoaderFactory.create(new File(SettingsManager.getInstance().getSettingsDirectory() + File.separator + "plugins"));
-
- }
-
- public static PluginClassLoaderFactory getInstance() {
- return instance;
- }
-
- public ClassLoader getClassLoader() {
- return this.pluginClassLoader;
- }
-
- /**
- * Creates a Classloader that will be able to access any of the classes found
- * in any .JAR file contained within the specified directory path, PLUS
- * the actual Plugin directory itself, so it acts like the WEB-INF/classes directory,
- * any class file in the directory will be accessible
- *
- * @param pluginDirectory
- * @return
- * @throws IllegalArgumentException if the pluginDirectory is null, does not exist, or cannot be read
- * @throws RuntimeException if turning a File into a URL failed, which would be very unexpected
- */
- private static final ClassLoader create(File pluginDirectory) {
- if (pluginDirectory == null || !pluginDirectory.exists() || !pluginDirectory.canRead()) {
- return PluginClassLoaderFactory.class.getClassLoader();
- }
-
- String[] strings = pluginDirectory.list((dir, name) -> name.toUpperCase().endsWith(".JAR"));
-
-
- List<URL> list = new ArrayList<>();
- // add the plugin directory as a resource loading path
- try {
- list.add(pluginDirectory.toURI().toURL());
- } catch (Exception e) {
- throw new RuntimeException(e.getMessage());
- }
- if (strings != null) {
- for (String name : strings) {
- File file = new File(pluginDirectory, name);
- try {
- list.add(file.toURI().toURL());
- System.out.println("Added " + file.getAbsolutePath()
- + " to Plugin class loader list");
- } catch (Exception e) {
- System.err.println("Failed to retrieve the URL for file: "
- + file.getAbsolutePath());
- throw new RuntimeException(e.getMessage());
- }
- }
- }
- ClassLoader parent = PluginClassLoaderFactory.class.getClassLoader();
- URL[] urls = (URL[]) list.toArray(new URL[list.size()]);
- return new URLClassLoader(urls, parent);
- }
-
-}
diff --git a/src/main/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java b/src/main/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java
index 968cead..6f85f4a 100644
--- a/src/main/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/receivers/NewReceiverDialogPanel.java
@@ -19,8 +19,6 @@
import org.apache.log4j.chainsaw.help.HelpManager;
import org.apache.log4j.chainsaw.helper.OkCancelPanel;
-import org.apache.log4j.plugins.Plugin;
-import org.apache.log4j.plugins.Receiver;
import javax.swing.*;
import java.awt.*;
@@ -68,17 +66,17 @@
pluginEditorPanel.addPropertyChangeListener("plugin",
evt -> {
- Plugin plugin = (Plugin) evt.getNewValue();
- URL url = HelpManager.getInstance().getHelpForClass(
- plugin.getClass());
-
- try {
- javaDocPane.setPage(url);
- } catch (IOException e) {
- logger.error(
- "Failed to load the Help resource for " +
- plugin.getClass(), e);
- }
+// Plugin plugin = (Plugin) evt.getNewValue();
+// URL url = HelpManager.getInstance().getHelpForClass(
+// plugin.getClass());
+//
+// try {
+// javaDocPane.setPage(url);
+// } catch (IOException e) {
+// logger.error(
+// "Failed to load the Help resource for " +
+// plugin.getClass(), e);
+// }
});
}
diff --git a/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiverTreeCellRenderer.java b/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiverTreeCellRenderer.java
index 0481921..25ec87e 100644
--- a/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiverTreeCellRenderer.java
+++ b/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiverTreeCellRenderer.java
@@ -20,7 +20,6 @@
import org.apache.log4j.chainsaw.Generator;
import org.apache.log4j.chainsaw.icons.ChainsawIcons;
import org.apache.log4j.chainsaw.icons.LevelIconFactory;
-import org.apache.log4j.plugins.Plugin;
import org.apache.log4j.spi.Thresholdable;
import javax.swing.*;
@@ -71,8 +70,6 @@
} else if (o instanceof String) {
setText(o.toString());
setIcon(null);
- } else if (o instanceof Plugin) {
- setText(((Plugin) o).getName());
} else if (o instanceof Generator) {
Generator generator = (Generator) o;
setText(generator.getName());
diff --git a/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java b/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
index 4e6582c..297126c 100644
--- a/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
@@ -31,7 +31,6 @@
import org.apache.log4j.chainsaw.prefs.SettingsListener;
import org.apache.log4j.chainsaw.prefs.SettingsManager;
import org.apache.log4j.net.SocketNodeEventListener;
-import org.apache.log4j.plugins.*;
import javax.swing.*;
import javax.swing.event.*;
@@ -414,7 +413,7 @@
return null;
}
- private Receiver[] getSelectedReceivers() {
+ private ChainsawReceiver[] getSelectedReceivers() {
TreePath[] paths = receiversTree.getSelectionPaths();
Collection receivers = new ArrayList();
@@ -422,12 +421,12 @@
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) path.getLastPathComponent();
- if ((node != null) && node.getUserObject() instanceof Receiver) {
+ if ((node != null) && node.getUserObject() instanceof ChainsawReceiver) {
receivers.add(node.getUserObject());
}
}
- return (Receiver[]) receivers.toArray(new Receiver[0]);
+ return (ChainsawReceiver[]) receivers.toArray(new ChainsawReceiver[0]);
}
/**
@@ -456,15 +455,8 @@
* The user is NOT asked to confirm this operation
*/
private void pauseCurrentlySelectedReceiver() {
- new Thread(
- () -> {
- Object obj = getCurrentlySelectedUserObject();
-
- if ((obj != null) && obj instanceof Pauseable) {
- ((Pauseable) obj).setPaused(true);
- updateCurrentlySelectedNodeInDispatchThread();
- }
- }).start();
+ getCurrentlySelectedReceiver().setPaused(true);
+ updateCurrentlySelectedNodeInDispatchThread();
}
/**
@@ -472,16 +464,8 @@
* true
*/
private void playCurrentlySelectedReceiver() {
- new Thread(
- () -> {
- Object obj = getCurrentlySelectedUserObject();
-
- if ((obj != null) && obj instanceof Pauseable) {
- ((Pauseable) obj).setPaused(false);
-
- updateCurrentlySelectedNodeInDispatchThread();
- }
- }).start();
+ getCurrentlySelectedReceiver().setPaused(false);
+ updateCurrentlySelectedNodeInDispatchThread();
}
/**
@@ -498,10 +482,10 @@
"Confirm stop of Receiver", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
new Thread(
() -> {
- Receiver[] receivers = getSelectedReceivers();
+ ChainsawReceiver[] receivers = getSelectedReceivers();
if (receivers != null) {
- for (Receiver receiver : receivers) {
+ for (ChainsawReceiver receiver : receivers) {
receiver.shutdown();
}
}
@@ -516,10 +500,10 @@
private void updateActions() {
Object object = getCurrentlySelectedUserObject();
- if ((object != null) && object instanceof Pauseable) {
- Pauseable pauseable = (Pauseable) object;
+ if ((object != null) && object instanceof ChainsawReceiver) {
+ ChainsawReceiver pauseable = (ChainsawReceiver) object;
- if (!pauseable.isPaused()) {
+ if (!pauseable.getPaused()) {
pauseReceiverButtonAction.setEnabled(true);
playReceiverButtonAction.setEnabled(false);
} else {
@@ -531,7 +515,7 @@
playReceiverButtonAction.setEnabled(false);
}
- if (object instanceof Receiver) {
+ if (object instanceof ChainsawReceiver) {
newReceiverButtonAction.setEnabled(true);
shutdownReceiverButtonAction.setEnabled(true);
restartReceiverButtonAction.setEnabled(true);
diff --git a/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfDeviceModel.java b/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfDeviceModel.java
index 7b4f166..095f088 100644
--- a/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfDeviceModel.java
+++ b/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfDeviceModel.java
@@ -28,7 +28,7 @@
private List<ServiceInfo> deviceList = new ArrayList<>();
private ZeroConfPreferenceModel zeroConfPreferenceModel;
- private transient ZeroConfPlugin plugin;
+// private transient ZeroConfPlugin plugin;
public ZeroConfDeviceModel() {
}
@@ -58,7 +58,7 @@
case 2:
return zeroConfPreferenceModel.getAutoConnectDevices().contains(getAutoConnectHandle(info)) ? Boolean.TRUE : Boolean.FALSE;
case 3:
- return plugin.isConnectedTo(info) ? "Connected" : "Not Connected";
+// return plugin.isConnectedTo(info) ? "Connected" : "Not Connected";
// return plugin.isConnectedTo(info)?new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT):new ImageIcon();
default:
return "";
@@ -135,9 +135,9 @@
fireTableDataChanged();
}
- void setZeroConfPluginParent(ZeroConfPlugin parent) {
- this.plugin = parent;
- }
+// void setZeroConfPluginParent(ZeroConfPlugin parent) {
+// this.plugin = parent;
+// }
}
diff --git a/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java b/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
index eb47a58..ebd3409 100644
--- a/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
+++ b/src/main/java/org/apache/log4j/chainsaw/zeroconf/ZeroConfPlugin.java
@@ -1,582 +1,582 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j.chainsaw.zeroconf;
-
-import com.thoughtworks.xstream.XStream;
-import com.thoughtworks.xstream.io.xml.DomDriver;
-import org.apache.log4j.BasicConfigurator;
-import org.apache.log4j.LogManager;
-import org.apache.log4j.Logger;
-import org.apache.log4j.chainsaw.ChainsawConstants;
-import org.apache.log4j.chainsaw.LogFilePatternLayoutBuilder;
-import org.apache.log4j.chainsaw.SmallButton;
-import org.apache.log4j.chainsaw.help.HelpManager;
-import org.apache.log4j.chainsaw.icons.ChainsawIcons;
-import org.apache.log4j.chainsaw.plugins.GUIPluginSkeleton;
-import org.apache.log4j.chainsaw.prefs.SettingsManager;
-import org.apache.log4j.chainsaw.vfs.VFSLogFilePatternReceiver;
-import org.apache.log4j.helpers.LogLog;
-import org.apache.log4j.net.*;
-import org.apache.log4j.plugins.Plugin;
-import org.apache.log4j.plugins.PluginEvent;
-import org.apache.log4j.plugins.PluginListener;
-import org.apache.log4j.plugins.Receiver;
-import org.apache.log4j.spi.LoggerRepositoryEx;
-
-import javax.jmdns.JmDNS;
-import javax.jmdns.ServiceEvent;
-import javax.jmdns.ServiceInfo;
-import javax.jmdns.ServiceListener;
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.util.*;
-import org.apache.log4j.chainsaw.ChainsawReceiver;
-
-/**
- * This plugin is designed to detect specific Zeroconf zones (Rendevouz/Bonjour,
- * whatever people are calling it) and allow the user to double click on
- * 'devices' to try and connect to them with no configuration needed.
- * <p>
- * TODO need to handle
- * NON-log4j devices that may be broadcast in the interested zones
- * TODO add the
- * default Zone, and the list of user-specified zones to a preferenceModel
- *
- * @author psmith
- */
-public class ZeroConfPlugin extends GUIPluginSkeleton {
-
- private static final Logger LOG = Logger.getLogger(ZeroConfPlugin.class);
-
- private ZeroConfDeviceModel discoveredDevices = new ZeroConfDeviceModel();
-
- private JTable deviceTable = new JTable(discoveredDevices);
-
- private final JScrollPane scrollPane = new JScrollPane(deviceTable);
-
- private ZeroConfPreferenceModel preferenceModel;
-
- private final Map<ServiceInfo, Plugin> serviceInfoToReceiveMap = new HashMap<>();
-
- private JMenu connectToMenu = new JMenu("Connect to");
- private JMenuItem helpItem = new JMenuItem(new AbstractAction("Learn more about ZeroConf...",
- ChainsawIcons.ICON_HELP) {
-
- public void actionPerformed(ActionEvent e) {
- HelpManager.getInstance()
- .showHelpForClass(ZeroConfPlugin.class);
- }
- });
-
- private JMenuItem nothingToConnectTo = new JMenuItem("No devices discovered");
- private static final String MULTICAST_APPENDER_SERVICE_NAME = "_log4j_xml_mcast_appender.local.";
- private static final String UDP_APPENDER_SERVICE_NAME = "_log4j_xml_udp_appender.local.";
- private static final String XML_SOCKET_APPENDER_SERVICE_NAME = "_log4j_xml_tcpconnect_appender.local.";
- private static final String TCP_APPENDER_SERVICE_NAME = "_log4j._tcp.local.";
- private static final String NEW_UDP_APPENDER_SERVICE_NAME = "_log4j._udp.local.";
-
- private JmDNS jmDNS;
-
- public ZeroConfPlugin() {
- setName("Zeroconf");
- deviceTable.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
- }
-
- public void shutdown() {
- if (jmDNS != null) {
- try {
- jmDNS.close();
- } catch (Exception e) {
- LOG.error("Unable to close JMDNS", e);
- }
- }
- save();
- }
-
- private void save() {
- File fileLocation = getPreferenceFileLocation();
- XStream stream = new XStream(new DomDriver());
- try {
- stream.toXML(preferenceModel, new FileWriter(fileLocation));
- } catch (Exception e) {
- LOG.error("Failed to save ZeroConfPlugin configuration file", e);
- }
- }
-
- private File getPreferenceFileLocation() {
- return new File(SettingsManager.getInstance().getSettingsDirectory(), "zeroconfprefs.xml");
- }
-
- public void activateOptions() {
- setLayout(new BorderLayout());
- jmDNS = (JmDNS) ZeroConfSupport.getJMDNSInstance();
-
- registerServiceListenersForAppenders();
-
- deviceTable.addMouseListener(new ConnectorMouseListener());
-
-
- JToolBar toolbar = new JToolBar();
- SmallButton helpButton = new SmallButton(helpItem.getAction());
- helpButton.setText(helpItem.getText());
- toolbar.add(helpButton);
- toolbar.setFloatable(false);
- add(toolbar, BorderLayout.NORTH);
- add(scrollPane, BorderLayout.CENTER);
-
- injectMenu();
-
- ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPluginListener(new PluginListener() {
-
- public void pluginStarted(PluginEvent e) {
-
- }
-
- public void pluginStopped(PluginEvent e) {
- Plugin plugin = e.getPlugin();
- synchronized (serviceInfoToReceiveMap) {
- for (Iterator<Map.Entry<ServiceInfo, Plugin>> iter = serviceInfoToReceiveMap.entrySet().iterator(); iter.hasNext(); ) {
- Map.Entry<ServiceInfo, Plugin> entry = iter.next();
- if (entry.getValue() == plugin) {
- iter.remove();
- }
- }
- }
-// need to make sure that the menu item tracking this item has it's icon and enabled state updade
- discoveredDevices.fireTableDataChanged();
- }
- });
-
- File fileLocation = getPreferenceFileLocation();
- XStream stream = new XStream(new DomDriver());
- if (fileLocation.exists()) {
- try {
- this.preferenceModel = (ZeroConfPreferenceModel) stream
- .fromXML(new FileReader(fileLocation));
- } catch (Exception e) {
- LOG.error("Failed to load ZeroConfPlugin configuration file", e);
- }
- } else {
- this.preferenceModel = new ZeroConfPreferenceModel();
- }
- discoveredDevices.setZeroConfPreferenceModel(preferenceModel);
- discoveredDevices.setZeroConfPluginParent(this);
- }
-
- private void registerServiceListenersForAppenders() {
- Set<String> serviceNames = new HashSet<>();
- serviceNames.add(MULTICAST_APPENDER_SERVICE_NAME);
- serviceNames.add(UDP_APPENDER_SERVICE_NAME);
- serviceNames.add(XML_SOCKET_APPENDER_SERVICE_NAME);
- serviceNames.add(TCP_APPENDER_SERVICE_NAME);
- serviceNames.add(NEW_UDP_APPENDER_SERVICE_NAME);
-
- for (Object serviceName1 : serviceNames) {
- String serviceName = serviceName1.toString();
- jmDNS.addServiceListener(
- serviceName,
- new ZeroConfServiceListener());
-
- jmDNS.addServiceListener(serviceName, discoveredDevices);
- }
-
- //now add each appender constant
- }
-
- /**
- * Attempts to find a JFrame container as a parent,and addse a "Connect to" menu
- */
- private void injectMenu() {
-
- JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
- if (frame == null) {
- LOG.info("Could not locate parent JFrame to add menu to");
- } else {
- JMenuBar menuBar = frame.getJMenuBar();
- if (menuBar == null) {
- menuBar = new JMenuBar();
- frame.setJMenuBar(menuBar);
- }
- insertToLeftOfHelp(menuBar, connectToMenu);
- connectToMenu.add(nothingToConnectTo);
-
- discoveredDevices.addTableModelListener(e -> {
- if (discoveredDevices.getRowCount() == 0) {
- connectToMenu.add(nothingToConnectTo, 0);
- } else if (discoveredDevices.getRowCount() > 0) {
- connectToMenu.remove(nothingToConnectTo);
- }
-
- });
-
- nothingToConnectTo.setEnabled(false);
-
- connectToMenu.addSeparator();
- connectToMenu.add(helpItem);
- }
- }
-
- /**
- * Hack method to locate the JMenu that is the Help menu, and inserts the new menu
- * just to the left of it.
- *
- * @param menuBar
- * @param item
- */
- private void insertToLeftOfHelp(JMenuBar menuBar, JMenu item) {
- for (int i = 0; i < menuBar.getMenuCount(); i++) {
- JMenu menu = menuBar.getMenu(i);
- if (menu.getText().equalsIgnoreCase("help")) {
- menuBar.add(item, i - 1);
- }
- }
- LOG.warn("menu '" + item.getText() + "' was NOT added because the 'Help' menu could not be located");
- }
-
- /**
- * When a device is discovered, we create a menu item for it so it can be connected to via that
- * GUI mechanism, and also if the device is one of the auto-connect devices then a background thread
- * is created to connect the device.
- *
- * @param info
- */
- private void deviceDiscovered(final ServiceInfo info) {
- final String name = info.getName();
-// TODO currently adding ALL devices to autoConnectlist
-// preferenceModel.addAutoConnectDevice(name);
-
-
- JMenuItem connectToDeviceMenuItem = new JMenuItem(new AbstractAction(info.getName()) {
-
- public void actionPerformed(ActionEvent e) {
- connectTo(info);
- }
- });
-
- if (discoveredDevices.getRowCount() > 0) {
- Component[] menuComponents = connectToMenu.getMenuComponents();
- boolean located = false;
- for (int i = 0; i < menuComponents.length; i++) {
- Component c = menuComponents[i];
- if (!(c instanceof JPopupMenu.Separator)) {
- JMenuItem item = (JMenuItem) menuComponents[i];
- if (item.getText().compareToIgnoreCase(name) < 0) {
- connectToMenu.insert(connectToDeviceMenuItem, i);
- located = true;
- break;
- }
- }
- }
- if (!located) {
- connectToMenu.insert(connectToDeviceMenuItem, 0);
- }
- } else {
- connectToMenu.insert(connectToDeviceMenuItem, 0);
- }
-// if the device name is one of the autoconnect devices, then connect immediately
- if (preferenceModel != null && preferenceModel.getAutoConnectDevices() != null && preferenceModel.getAutoConnectDevices().contains(name)) {
- new Thread(() -> {
- LOG.info("Auto-connecting to " + name);
- connectTo(info);
- }).start();
- }
- }
-
- /**
- * When a device is removed or disappears we need to remove any JMenu item associated with it.
- *
- * @param name
- */
- private void deviceRemoved(String name) {
- Component[] menuComponents = connectToMenu.getMenuComponents();
- for (Component c : menuComponents) {
- if (!(c instanceof JPopupMenu.Separator)) {
- JMenuItem item = (JMenuItem) c;
- if (item.getText().compareToIgnoreCase(name) == 0) {
- connectToMenu.remove(item);
- break;
- }
- }
- }
- }
-
- /**
- * Listens out on the JmDNS/ZeroConf network for new devices that appear
- * and adds/removes these device information from the list/model.
- */
- private class ZeroConfServiceListener implements ServiceListener {
-
- public void serviceAdded(final ServiceEvent event) {
- LOG.info("Service Added: " + event);
- /**
- * it's not very clear whether we should do the resolving in a
- * background thread or not.. All it says is to NOT do it in the AWT
- * thread, so I'm thinking it probably should be a background thread
- */
- Runnable runnable = () -> ZeroConfPlugin.this.jmDNS.requestServiceInfo(event
- .getType(), event.getName());
- Thread thread = new Thread(runnable,
- "ChainsawZeroConfRequestResolutionThread");
- thread.setPriority(Thread.MIN_PRIORITY);
- thread.start();
- }
-
- public void serviceRemoved(ServiceEvent event) {
- LOG.info("Service Removed: " + event);
- deviceRemoved(event.getName());
- }
-
- public void serviceResolved(ServiceEvent event) {
- LOG.info("Service Resolved: " + event);
- deviceDiscovered(event.getInfo());
- }
-
- }
-
-
- /**
- * When the user double clicks on a row, then the device is connected to,
- * the only exception is when clicking in the check box column for auto connect.
- */
- private class ConnectorMouseListener extends MouseAdapter {
-
- public void mouseClicked(MouseEvent e) {
- if (e.getClickCount() == 2) {
- int row = deviceTable.rowAtPoint(e.getPoint());
- if (deviceTable.columnAtPoint(e.getPoint()) == 2) {
- return;
- }
- ServiceInfo info = discoveredDevices.getServiceInfoAtRow(row);
-
- if (!isConnectedTo(info)) {
- connectTo(info);
- } else {
- disconnectFrom(info);
- }
- }
- }
-
- public void mousePressed(MouseEvent e) {
- /**
- * This methodh handles when the user clicks the
- * auto-connect
- */
-// int index = listBox.locationToIndex(e.getPoint());
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one or more
+// * contributor license agreements. See the NOTICE file distributed with
+// * this work for additional information regarding copyright ownership.
+// * The ASF licenses this file to You under the Apache License, Version 2.0
+// * (the "License"); you may not use this file except in compliance with
+// * the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// */
+//package org.apache.log4j.chainsaw.zeroconf;
//
-// if (index != -1) {
-//// Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), )
-// Component c = SwingUtilities.getDeepestComponentAt(ZeroConfPlugin.this, e.getX(), e.getY());
-// if (c instanceof JCheckBox) {
-// ServiceInfo info = (ServiceInfo) listBox.getModel()
-// .getElementAt(index);
-// String name = info.getName();
-// if (preferenceModel.getAutoConnectDevices().contains(name)) {
-// preferenceModel.removeAutoConnectDevice(name);
-// } else {
-// preferenceModel.addAutoConnectDevice(name);
+//import com.thoughtworks.xstream.XStream;
+//import com.thoughtworks.xstream.io.xml.DomDriver;
+//import org.apache.log4j.BasicConfigurator;
+//import org.apache.log4j.LogManager;
+//import org.apache.log4j.Logger;
+//import org.apache.log4j.chainsaw.ChainsawConstants;
+//import org.apache.log4j.chainsaw.LogFilePatternLayoutBuilder;
+//import org.apache.log4j.chainsaw.SmallButton;
+//import org.apache.log4j.chainsaw.help.HelpManager;
+//import org.apache.log4j.chainsaw.icons.ChainsawIcons;
+//import org.apache.log4j.chainsaw.plugins.GUIPluginSkeleton;
+//import org.apache.log4j.chainsaw.prefs.SettingsManager;
+//import org.apache.log4j.chainsaw.vfs.VFSLogFilePatternReceiver;
+//import org.apache.log4j.helpers.LogLog;
+//import org.apache.log4j.net.*;
+//import org.apache.log4j.plugins.Plugin;
+//import org.apache.log4j.plugins.PluginEvent;
+//import org.apache.log4j.plugins.PluginListener;
+//import org.apache.log4j.plugins.Receiver;
+//import org.apache.log4j.spi.LoggerRepositoryEx;
+//
+//import javax.jmdns.JmDNS;
+//import javax.jmdns.ServiceEvent;
+//import javax.jmdns.ServiceInfo;
+//import javax.jmdns.ServiceListener;
+//import javax.swing.*;
+//import java.awt.*;
+//import java.awt.event.ActionEvent;
+//import java.awt.event.MouseAdapter;
+//import java.awt.event.MouseEvent;
+//import java.io.File;
+//import java.io.FileReader;
+//import java.io.FileWriter;
+//import java.util.*;
+//import org.apache.log4j.chainsaw.ChainsawReceiver;
+//
+///**
+// * This plugin is designed to detect specific Zeroconf zones (Rendevouz/Bonjour,
+// * whatever people are calling it) and allow the user to double click on
+// * 'devices' to try and connect to them with no configuration needed.
+// * <p>
+// * TODO need to handle
+// * NON-log4j devices that may be broadcast in the interested zones
+// * TODO add the
+// * default Zone, and the list of user-specified zones to a preferenceModel
+// *
+// * @author psmith
+// */
+//public class ZeroConfPlugin extends GUIPluginSkeleton {
+//
+// private static final Logger LOG = Logger.getLogger(ZeroConfPlugin.class);
+//
+// private ZeroConfDeviceModel discoveredDevices = new ZeroConfDeviceModel();
+//
+// private JTable deviceTable = new JTable(discoveredDevices);
+//
+// private final JScrollPane scrollPane = new JScrollPane(deviceTable);
+//
+// private ZeroConfPreferenceModel preferenceModel;
+//
+// private final Map<ServiceInfo, Plugin> serviceInfoToReceiveMap = new HashMap<>();
+//
+// private JMenu connectToMenu = new JMenu("Connect to");
+// private JMenuItem helpItem = new JMenuItem(new AbstractAction("Learn more about ZeroConf...",
+// ChainsawIcons.ICON_HELP) {
+//
+// public void actionPerformed(ActionEvent e) {
+// HelpManager.getInstance()
+// .showHelpForClass(ZeroConfPlugin.class);
+// }
+// });
+//
+// private JMenuItem nothingToConnectTo = new JMenuItem("No devices discovered");
+// private static final String MULTICAST_APPENDER_SERVICE_NAME = "_log4j_xml_mcast_appender.local.";
+// private static final String UDP_APPENDER_SERVICE_NAME = "_log4j_xml_udp_appender.local.";
+// private static final String XML_SOCKET_APPENDER_SERVICE_NAME = "_log4j_xml_tcpconnect_appender.local.";
+// private static final String TCP_APPENDER_SERVICE_NAME = "_log4j._tcp.local.";
+// private static final String NEW_UDP_APPENDER_SERVICE_NAME = "_log4j._udp.local.";
+//
+// private JmDNS jmDNS;
+//
+// public ZeroConfPlugin() {
+// setName("Zeroconf");
+// deviceTable.setRowHeight(ChainsawConstants.DEFAULT_ROW_HEIGHT);
+// }
+//
+// public void shutdown() {
+// if (jmDNS != null) {
+// try {
+// jmDNS.close();
+// } catch (Exception e) {
+// LOG.error("Unable to close JMDNS", e);
+// }
+// }
+// save();
+// }
+//
+// private void save() {
+// File fileLocation = getPreferenceFileLocation();
+// XStream stream = new XStream(new DomDriver());
+// try {
+// stream.toXML(preferenceModel, new FileWriter(fileLocation));
+// } catch (Exception e) {
+// LOG.error("Failed to save ZeroConfPlugin configuration file", e);
+// }
+// }
+//
+// private File getPreferenceFileLocation() {
+// return new File(SettingsManager.getInstance().getSettingsDirectory(), "zeroconfprefs.xml");
+// }
+//
+// public void activateOptions() {
+// setLayout(new BorderLayout());
+// jmDNS = (JmDNS) ZeroConfSupport.getJMDNSInstance();
+//
+// registerServiceListenersForAppenders();
+//
+// deviceTable.addMouseListener(new ConnectorMouseListener());
+//
+//
+// JToolBar toolbar = new JToolBar();
+// SmallButton helpButton = new SmallButton(helpItem.getAction());
+// helpButton.setText(helpItem.getText());
+// toolbar.add(helpButton);
+// toolbar.setFloatable(false);
+// add(toolbar, BorderLayout.NORTH);
+// add(scrollPane, BorderLayout.CENTER);
+//
+// injectMenu();
+//
+// ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPluginListener(new PluginListener() {
+//
+// public void pluginStarted(PluginEvent e) {
+//
+// }
+//
+// public void pluginStopped(PluginEvent e) {
+// Plugin plugin = e.getPlugin();
+// synchronized (serviceInfoToReceiveMap) {
+// for (Iterator<Map.Entry<ServiceInfo, Plugin>> iter = serviceInfoToReceiveMap.entrySet().iterator(); iter.hasNext(); ) {
+// Map.Entry<ServiceInfo, Plugin> entry = iter.next();
+// if (entry.getValue() == plugin) {
+// iter.remove();
+// }
// }
-// discoveredDevices.fireContentsChanged();
-// repaint();
+// }
+//// need to make sure that the menu item tracking this item has it's icon and enabled state updade
+// discoveredDevices.fireTableDataChanged();
+// }
+// });
+//
+// File fileLocation = getPreferenceFileLocation();
+// XStream stream = new XStream(new DomDriver());
+// if (fileLocation.exists()) {
+// try {
+// this.preferenceModel = (ZeroConfPreferenceModel) stream
+// .fromXML(new FileReader(fileLocation));
+// } catch (Exception e) {
+// LOG.error("Failed to load ZeroConfPlugin configuration file", e);
+// }
+// } else {
+// this.preferenceModel = new ZeroConfPreferenceModel();
+// }
+// discoveredDevices.setZeroConfPreferenceModel(preferenceModel);
+// discoveredDevices.setZeroConfPluginParent(this);
+// }
+//
+// private void registerServiceListenersForAppenders() {
+// Set<String> serviceNames = new HashSet<>();
+// serviceNames.add(MULTICAST_APPENDER_SERVICE_NAME);
+// serviceNames.add(UDP_APPENDER_SERVICE_NAME);
+// serviceNames.add(XML_SOCKET_APPENDER_SERVICE_NAME);
+// serviceNames.add(TCP_APPENDER_SERVICE_NAME);
+// serviceNames.add(NEW_UDP_APPENDER_SERVICE_NAME);
+//
+// for (Object serviceName1 : serviceNames) {
+// String serviceName = serviceName1.toString();
+// jmDNS.addServiceListener(
+// serviceName,
+// new ZeroConfServiceListener());
+//
+// jmDNS.addServiceListener(serviceName, discoveredDevices);
+// }
+//
+// //now add each appender constant
+// }
+//
+// /**
+// * Attempts to find a JFrame container as a parent,and addse a "Connect to" menu
+// */
+// private void injectMenu() {
+//
+// JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
+// if (frame == null) {
+// LOG.info("Could not locate parent JFrame to add menu to");
+// } else {
+// JMenuBar menuBar = frame.getJMenuBar();
+// if (menuBar == null) {
+// menuBar = new JMenuBar();
+// frame.setJMenuBar(menuBar);
+// }
+// insertToLeftOfHelp(menuBar, connectToMenu);
+// connectToMenu.add(nothingToConnectTo);
+//
+// discoveredDevices.addTableModelListener(e -> {
+// if (discoveredDevices.getRowCount() == 0) {
+// connectToMenu.add(nothingToConnectTo, 0);
+// } else if (discoveredDevices.getRowCount() > 0) {
+// connectToMenu.remove(nothingToConnectTo);
+// }
+//
+// });
+//
+// nothingToConnectTo.setEnabled(false);
+//
+// connectToMenu.addSeparator();
+// connectToMenu.add(helpItem);
+// }
+// }
+//
+// /**
+// * Hack method to locate the JMenu that is the Help menu, and inserts the new menu
+// * just to the left of it.
+// *
+// * @param menuBar
+// * @param item
+// */
+// private void insertToLeftOfHelp(JMenuBar menuBar, JMenu item) {
+// for (int i = 0; i < menuBar.getMenuCount(); i++) {
+// JMenu menu = menuBar.getMenu(i);
+// if (menu.getText().equalsIgnoreCase("help")) {
+// menuBar.add(item, i - 1);
+// }
+// }
+// LOG.warn("menu '" + item.getText() + "' was NOT added because the 'Help' menu could not be located");
+// }
+//
+// /**
+// * When a device is discovered, we create a menu item for it so it can be connected to via that
+// * GUI mechanism, and also if the device is one of the auto-connect devices then a background thread
+// * is created to connect the device.
+// *
+// * @param info
+// */
+// private void deviceDiscovered(final ServiceInfo info) {
+// final String name = info.getName();
+//// TODO currently adding ALL devices to autoConnectlist
+//// preferenceModel.addAutoConnectDevice(name);
+//
+//
+// JMenuItem connectToDeviceMenuItem = new JMenuItem(new AbstractAction(info.getName()) {
+//
+// public void actionPerformed(ActionEvent e) {
+// connectTo(info);
+// }
+// });
+//
+// if (discoveredDevices.getRowCount() > 0) {
+// Component[] menuComponents = connectToMenu.getMenuComponents();
+// boolean located = false;
+// for (int i = 0; i < menuComponents.length; i++) {
+// Component c = menuComponents[i];
+// if (!(c instanceof JPopupMenu.Separator)) {
+// JMenuItem item = (JMenuItem) menuComponents[i];
+// if (item.getText().compareToIgnoreCase(name) < 0) {
+// connectToMenu.insert(connectToDeviceMenuItem, i);
+// located = true;
+// break;
+// }
// }
// }
- }
- }
-
- private void disconnectFrom(ServiceInfo info) {
- if (!isConnectedTo(info)) {
- return; // not connected, who cares
- }
- Plugin plugin;
- synchronized (serviceInfoToReceiveMap) {
- plugin = serviceInfoToReceiveMap.get(info);
- }
- ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().stopPlugin(plugin.getName());
-
- JMenuItem item = locateMatchingMenuItem(info.getName());
- if (item != null) {
- item.setIcon(null);
- item.setEnabled(true);
- }
- }
-
- /**
- * returns true if the serviceInfo record already has a matching connected receiver
- *
- * @param info
- * @return
- */
- boolean isConnectedTo(ServiceInfo info) {
- return serviceInfoToReceiveMap.containsKey(info);
- }
-
- /**
- * Starts a receiver to the appender referenced within the ServiceInfo
- *
- * @param info
- */
- private void connectTo(ServiceInfo info) {
- LOG.info("Connection request for " + info);
- //Chainsaw can construct receivers from discovered appenders
- ChainsawReceiver receiver = getReceiver(info);
- //if null, unable to resolve the service name..no-op
- if (receiver == null) {
- return;
- }
- // TODO tell LogUI that we have a new receiver
-
-// ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPlugin(receiver);
-// receiver.activateOptions();
-// LOG.info("Receiver '" + receiver.getName() + "' has been started");
-//
-// // ServiceInfo obeys equals() and hashCode() contracts, so this should be safe.
-// synchronized (serviceInfoToReceiveMap) {
-// serviceInfoToReceiveMap.put(info, receiver);
+// if (!located) {
+// connectToMenu.insert(connectToDeviceMenuItem, 0);
+// }
+// } else {
+// connectToMenu.insert(connectToDeviceMenuItem, 0);
// }
-
-// this instance of the menu item needs to be disabled, and have an icon added
- JMenuItem item = locateMatchingMenuItem(info.getName());
- if (item != null) {
- item.setIcon(new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT));
- item.setEnabled(false);
- }
-// // now notify the list model has changed, it needs redrawing of the receiver icon now it's connected
-// discoveredDevices.fireContentsChanged();
- }
-
- private ChainsawReceiver getReceiver(ServiceInfo info) {
- String zone = info.getType();
- int port = info.getPort();
- String hostAddress = info.getHostAddress();
- String name = info.getName();
- String decoderClass = info.getPropertyString("decoder");
-
- if (NEW_UDP_APPENDER_SERVICE_NAME.equals(zone)) {
- UDPReceiver receiver = new UDPReceiver();
- receiver.setPort(port);
- receiver.setName(name + "-receiver");
- return receiver;
- }
- //FileAppender or socketappender
- //TODO: add more checks (actual layout format, etc)
- if (TCP_APPENDER_SERVICE_NAME.equals(zone)) {
- //CHECK content type
- //text/plain = VFSLogFilePatternReceiver (if structured=false)
- String contentType = info.getPropertyString("contentType").toLowerCase();
- //won't work with log4j2, as Chainsaw depends on log4j1.x
- //this will work - regular text log files are fine
- if ("text/plain".equals(contentType)) {
- VFSLogFilePatternReceiver receiver = new VFSLogFilePatternReceiver();
- receiver.setAppendNonMatches(true);
- receiver.setFileURL(info.getPropertyString("fileURI"));
- receiver.setLogFormat(LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(info.getPropertyString("format")));
- receiver.setTimestampFormat(LogFilePatternLayoutBuilder.getTimeStampFormat(info.getPropertyString("format")));
- receiver.setName(name + "-receiver");
- receiver.setTailing(true);
- return receiver;
- }
- }
-
- //MulticastAppender
- if (MULTICAST_APPENDER_SERVICE_NAME.equals(zone)) {
- MulticastReceiver receiver = new MulticastReceiver();
- //this needs to be a multicast address, not the host address, so we need to use a property
- receiver.setAddress(info.getPropertyString("multicastAddress"));
- receiver.setPort(port);
- receiver.setName(name + "-receiver");
- if (decoderClass != null && !decoderClass.equals("")) {
- receiver.setDecoder(decoderClass);
- }
-
- return receiver;
- }
- //UDPAppender
- if (UDP_APPENDER_SERVICE_NAME.equals(zone)) {
- UDPReceiver receiver = new UDPReceiver();
- receiver.setPort(port);
- receiver.setName(name + "-receiver");
- if (decoderClass != null && !decoderClass.equals("")) {
- receiver.setDecoder(decoderClass);
- }
- return receiver;
- }
-
- //non-log4j XML-based socketappender
- if (XML_SOCKET_APPENDER_SERVICE_NAME.equals(zone)) {
- XMLSocketReceiver receiver = new XMLSocketReceiver();
- receiver.setPort(port);
- receiver.setName(name + "-receiver");
- if (decoderClass != null && !decoderClass.equals("")) {
- receiver.setDecoder(decoderClass);
- }
- return receiver;
- }
-
- //not recognized
- LogLog.debug("Unable to find receiver for appender with service name: " + zone);
- return null;
- }
-
- /**
- * Finds the matching JMenuItem based on name, may return null if there is no match.
- *
- * @param name
- * @return
- */
- private JMenuItem locateMatchingMenuItem(String name) {
- Component[] menuComponents = connectToMenu.getMenuComponents();
- for (Component c : menuComponents) {
- if (!(c instanceof JPopupMenu.Separator)) {
- JMenuItem item = (JMenuItem) c;
- if (item.getText().compareToIgnoreCase(name) == 0) {
- return item;
- }
- }
- }
- return null;
- }
-
- public static void main(String[] args) {
-
- BasicConfigurator.resetConfiguration();
- BasicConfigurator.configure();
-
- final ZeroConfPlugin plugin = new ZeroConfPlugin();
-
-
- JFrame frame = new JFrame();
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
-
- frame.getContentPane().setLayout(new BorderLayout());
- frame.getContentPane().add(plugin, BorderLayout.CENTER);
-
- // needs to be activated after being added to the JFrame for Menu injection to work
- plugin.activateOptions();
-
- frame.pack();
- frame.setVisible(true);
-
- Thread thread = new Thread(plugin::shutdown);
- Runtime.getRuntime().addShutdownHook(thread);
- }
-
-}
+//// if the device name is one of the autoconnect devices, then connect immediately
+// if (preferenceModel != null && preferenceModel.getAutoConnectDevices() != null && preferenceModel.getAutoConnectDevices().contains(name)) {
+// new Thread(() -> {
+// LOG.info("Auto-connecting to " + name);
+// connectTo(info);
+// }).start();
+// }
+// }
+//
+// /**
+// * When a device is removed or disappears we need to remove any JMenu item associated with it.
+// *
+// * @param name
+// */
+// private void deviceRemoved(String name) {
+// Component[] menuComponents = connectToMenu.getMenuComponents();
+// for (Component c : menuComponents) {
+// if (!(c instanceof JPopupMenu.Separator)) {
+// JMenuItem item = (JMenuItem) c;
+// if (item.getText().compareToIgnoreCase(name) == 0) {
+// connectToMenu.remove(item);
+// break;
+// }
+// }
+// }
+// }
+//
+// /**
+// * Listens out on the JmDNS/ZeroConf network for new devices that appear
+// * and adds/removes these device information from the list/model.
+// */
+// private class ZeroConfServiceListener implements ServiceListener {
+//
+// public void serviceAdded(final ServiceEvent event) {
+// LOG.info("Service Added: " + event);
+// /**
+// * it's not very clear whether we should do the resolving in a
+// * background thread or not.. All it says is to NOT do it in the AWT
+// * thread, so I'm thinking it probably should be a background thread
+// */
+// Runnable runnable = () -> ZeroConfPlugin.this.jmDNS.requestServiceInfo(event
+// .getType(), event.getName());
+// Thread thread = new Thread(runnable,
+// "ChainsawZeroConfRequestResolutionThread");
+// thread.setPriority(Thread.MIN_PRIORITY);
+// thread.start();
+// }
+//
+// public void serviceRemoved(ServiceEvent event) {
+// LOG.info("Service Removed: " + event);
+// deviceRemoved(event.getName());
+// }
+//
+// public void serviceResolved(ServiceEvent event) {
+// LOG.info("Service Resolved: " + event);
+// deviceDiscovered(event.getInfo());
+// }
+//
+// }
+//
+//
+// /**
+// * When the user double clicks on a row, then the device is connected to,
+// * the only exception is when clicking in the check box column for auto connect.
+// */
+// private class ConnectorMouseListener extends MouseAdapter {
+//
+// public void mouseClicked(MouseEvent e) {
+// if (e.getClickCount() == 2) {
+// int row = deviceTable.rowAtPoint(e.getPoint());
+// if (deviceTable.columnAtPoint(e.getPoint()) == 2) {
+// return;
+// }
+// ServiceInfo info = discoveredDevices.getServiceInfoAtRow(row);
+//
+// if (!isConnectedTo(info)) {
+// connectTo(info);
+// } else {
+// disconnectFrom(info);
+// }
+// }
+// }
+//
+// public void mousePressed(MouseEvent e) {
+// /**
+// * This methodh handles when the user clicks the
+// * auto-connect
+// */
+//// int index = listBox.locationToIndex(e.getPoint());
+////
+//// if (index != -1) {
+////// Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), )
+//// Component c = SwingUtilities.getDeepestComponentAt(ZeroConfPlugin.this, e.getX(), e.getY());
+//// if (c instanceof JCheckBox) {
+//// ServiceInfo info = (ServiceInfo) listBox.getModel()
+//// .getElementAt(index);
+//// String name = info.getName();
+//// if (preferenceModel.getAutoConnectDevices().contains(name)) {
+//// preferenceModel.removeAutoConnectDevice(name);
+//// } else {
+//// preferenceModel.addAutoConnectDevice(name);
+//// }
+//// discoveredDevices.fireContentsChanged();
+//// repaint();
+//// }
+//// }
+// }
+// }
+//
+// private void disconnectFrom(ServiceInfo info) {
+// if (!isConnectedTo(info)) {
+// return; // not connected, who cares
+// }
+// Plugin plugin;
+// synchronized (serviceInfoToReceiveMap) {
+// plugin = serviceInfoToReceiveMap.get(info);
+// }
+// ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().stopPlugin(plugin.getName());
+//
+// JMenuItem item = locateMatchingMenuItem(info.getName());
+// if (item != null) {
+// item.setIcon(null);
+// item.setEnabled(true);
+// }
+// }
+//
+// /**
+// * returns true if the serviceInfo record already has a matching connected receiver
+// *
+// * @param info
+// * @return
+// */
+// boolean isConnectedTo(ServiceInfo info) {
+// return serviceInfoToReceiveMap.containsKey(info);
+// }
+//
+// /**
+// * Starts a receiver to the appender referenced within the ServiceInfo
+// *
+// * @param info
+// */
+// private void connectTo(ServiceInfo info) {
+// LOG.info("Connection request for " + info);
+// //Chainsaw can construct receivers from discovered appenders
+// ChainsawReceiver receiver = getReceiver(info);
+// //if null, unable to resolve the service name..no-op
+// if (receiver == null) {
+// return;
+// }
+// // TODO tell LogUI that we have a new receiver
+//
+//// ((LoggerRepositoryEx) LogManager.getLoggerRepository()).getPluginRegistry().addPlugin(receiver);
+//// receiver.activateOptions();
+//// LOG.info("Receiver '" + receiver.getName() + "' has been started");
+////
+//// // ServiceInfo obeys equals() and hashCode() contracts, so this should be safe.
+//// synchronized (serviceInfoToReceiveMap) {
+//// serviceInfoToReceiveMap.put(info, receiver);
+//// }
+//
+//// this instance of the menu item needs to be disabled, and have an icon added
+// JMenuItem item = locateMatchingMenuItem(info.getName());
+// if (item != null) {
+// item.setIcon(new ImageIcon(ChainsawIcons.ANIM_NET_CONNECT));
+// item.setEnabled(false);
+// }
+//// // now notify the list model has changed, it needs redrawing of the receiver icon now it's connected
+//// discoveredDevices.fireContentsChanged();
+// }
+//
+// private ChainsawReceiver getReceiver(ServiceInfo info) {
+// String zone = info.getType();
+// int port = info.getPort();
+// String hostAddress = info.getHostAddress();
+// String name = info.getName();
+// String decoderClass = info.getPropertyString("decoder");
+//
+// if (NEW_UDP_APPENDER_SERVICE_NAME.equals(zone)) {
+// UDPReceiver receiver = new UDPReceiver();
+// receiver.setPort(port);
+// receiver.setName(name + "-receiver");
+// return receiver;
+// }
+// //FileAppender or socketappender
+// //TODO: add more checks (actual layout format, etc)
+// if (TCP_APPENDER_SERVICE_NAME.equals(zone)) {
+// //CHECK content type
+// //text/plain = VFSLogFilePatternReceiver (if structured=false)
+// String contentType = info.getPropertyString("contentType").toLowerCase();
+// //won't work with log4j2, as Chainsaw depends on log4j1.x
+// //this will work - regular text log files are fine
+// if ("text/plain".equals(contentType)) {
+// VFSLogFilePatternReceiver receiver = new VFSLogFilePatternReceiver();
+// receiver.setAppendNonMatches(true);
+// receiver.setFileURL(info.getPropertyString("fileURI"));
+// receiver.setLogFormat(LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(info.getPropertyString("format")));
+// receiver.setTimestampFormat(LogFilePatternLayoutBuilder.getTimeStampFormat(info.getPropertyString("format")));
+// receiver.setName(name + "-receiver");
+// receiver.setTailing(true);
+// return receiver;
+// }
+// }
+//
+// //MulticastAppender
+// if (MULTICAST_APPENDER_SERVICE_NAME.equals(zone)) {
+// MulticastReceiver receiver = new MulticastReceiver();
+// //this needs to be a multicast address, not the host address, so we need to use a property
+// receiver.setAddress(info.getPropertyString("multicastAddress"));
+// receiver.setPort(port);
+// receiver.setName(name + "-receiver");
+// if (decoderClass != null && !decoderClass.equals("")) {
+// receiver.setDecoder(decoderClass);
+// }
+//
+// return receiver;
+// }
+// //UDPAppender
+// if (UDP_APPENDER_SERVICE_NAME.equals(zone)) {
+// UDPReceiver receiver = new UDPReceiver();
+// receiver.setPort(port);
+// receiver.setName(name + "-receiver");
+// if (decoderClass != null && !decoderClass.equals("")) {
+// receiver.setDecoder(decoderClass);
+// }
+// return receiver;
+// }
+//
+// //non-log4j XML-based socketappender
+// if (XML_SOCKET_APPENDER_SERVICE_NAME.equals(zone)) {
+// XMLSocketReceiver receiver = new XMLSocketReceiver();
+// receiver.setPort(port);
+// receiver.setName(name + "-receiver");
+// if (decoderClass != null && !decoderClass.equals("")) {
+// receiver.setDecoder(decoderClass);
+// }
+// return receiver;
+// }
+//
+// //not recognized
+// LogLog.debug("Unable to find receiver for appender with service name: " + zone);
+// return null;
+// }
+//
+// /**
+// * Finds the matching JMenuItem based on name, may return null if there is no match.
+// *
+// * @param name
+// * @return
+// */
+// private JMenuItem locateMatchingMenuItem(String name) {
+// Component[] menuComponents = connectToMenu.getMenuComponents();
+// for (Component c : menuComponents) {
+// if (!(c instanceof JPopupMenu.Separator)) {
+// JMenuItem item = (JMenuItem) c;
+// if (item.getText().compareToIgnoreCase(name) == 0) {
+// return item;
+// }
+// }
+// }
+// return null;
+// }
+//
+// public static void main(String[] args) {
+//
+// BasicConfigurator.resetConfiguration();
+// BasicConfigurator.configure();
+//
+// final ZeroConfPlugin plugin = new ZeroConfPlugin();
+//
+//
+// JFrame frame = new JFrame();
+// frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+//
+// frame.getContentPane().setLayout(new BorderLayout());
+// frame.getContentPane().add(plugin, BorderLayout.CENTER);
+//
+// // needs to be activated after being added to the JFrame for Menu injection to work
+// plugin.activateOptions();
+//
+// frame.pack();
+// frame.setVisible(true);
+//
+// Thread thread = new Thread(plugin::shutdown);
+// Runtime.getRuntime().addShutdownHook(thread);
+// }
+//
+//}
diff --git a/src/main/java/org/apache/log4j/db/CustomSQLDBReceiver.java b/src/main/java/org/apache/log4j/db/CustomSQLDBReceiver.java
index 47ad2ab..d8463c0 100644
--- a/src/main/java/org/apache/log4j/db/CustomSQLDBReceiver.java
+++ b/src/main/java/org/apache/log4j/db/CustomSQLDBReceiver.java
@@ -1,465 +1,465 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.db;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.plugins.Pauseable;
-import org.apache.log4j.plugins.Receiver;
-import org.apache.log4j.scheduler.Job;
-import org.apache.log4j.scheduler.Scheduler;
-import org.apache.log4j.spi.LocationInfo;
-import org.apache.log4j.spi.LoggerRepositoryEx;
-import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.spi.ThrowableInformation;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.apache.log4j.xml.UnrecognizedElementHandler;
-import org.w3c.dom.Element;
-
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Hashtable;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-/**
- * Converts log data stored in a database into LoggingEvents.
- * <p>
- * <b>NOTE:</b> This receiver cannot yet be created through Chainsaw's receiver panel.
- * It must be created through an XML configuration file.
- * <p>
- * This receiver supports database configuration via ConnectionSource, in the
- * org.apache.log4j.db package: DriverManagerConnectionSource,
- * DataSourceConnectionSource, JNDIConnectionSource
- * <p>
- * This database receiver differs from DBReceiver in that this receiver relies
- * on custom SQL to retrieve logging event data, where DBReceiver requires the
- * use of a log4j-defined schema.
- * <p>
- * A 'refreshMillis' int parameter controls SQL execution. If 'refreshMillis' is
- * zero (the default), the receiver will run only one time. If it is set to any
- * other numeric value, the SQL will be executed on a recurring basis every
- * 'refreshMillis' milliseconds.
- * <p>
- * The receiver closes the connection and acquires a new connection on each
- * execution of the SQL (use pooled connections if possible).
- * <p>
- * If the SQL will be executing on a recurring basis, specify the IDField param -
- * the column name holding the unique identifier (int) representing the logging
- * event.
- * <p>
- * As events are retrieved, the column represented by IDField is examined and
- * the largest value is held and used by the next execution of the SQL statement
- * to avoid retrieving previously processed events.
- * <p>
- * As an example, the IDField references a 'COUNTER' (int, auto-increment,
- * unique) column. The first execution of the SQL statement returns 500 rows,
- * with a final value in the COUNTER field of 500.
- * <p>
- * The SQL statement is manipulated prior to the next execution, adding ' WHERE
- * COUNTER > 500' to the statement to avoid retrieval of previously processed
- * events.
- * <p>
- * The select statement must provide ALL fields which define a LoggingEvent.
- * <p>
- * The SQL statement MUST include the columns: LOGGER, TIMESTAMP, LEVEL, THREAD,
- * MESSAGE, NDC, MDC, CLASS, METHOD, FILE, LINE, PROPERTIES, THROWABLE
- * <p>
- * Use ' AS ' in the SQL statement to alias the SQL's column names to match your
- * database schema. (see example below).
- * <p>
- * Include all fields in the SQL statement, even if you don't have data for the
- * field (specify an empty string as the value for columns which you don't have
- * data).
- * <p>
- * The TIMESTAMP column must be a datetime.
- * <p>
- * Both a PROPERTIES column and an MDC column are supported. These fields
- * represent Maps on the logging event, but require the use of string
- * concatenation database functions to hold the (possibly multiple) name/value
- * pairs in the column.
- * <p>
- * For example, to include both 'userid' and 'lastname' properties in the
- * logging event (from either the PROPERTIES or MDC columns), the name/value
- * pairs must be concatenated together by your database.
- * <p>
- * The resulting PROPERTIES or MDC column must have data in this format: {{name,
- * value, name2, value2}}
- * <p>
- * The resulting PROPERTIES column would contain this text: {{userid, someone,
- * lastname, mylastname}}
- * <p>
- * Here is an example of concatenating a PROPERTIES or MDC column using MySQL's
- * concat function, where the 'application' and 'hostname' parameters were fixed
- * text, but the 'log4jid' key's value is the value of the COUNTER column:
- * <p>
- * concat("{{application,databaselogs,hostname,mymachine,log4jid,", COUNTER,
- * "}}") as PROPERTIES
- * <p>
- * log4jid is a special property that is used by Chainsaw to represent an 'ID'
- * field. Specify this property to ensure you can map events in Chainsaw to
- * events in the database if you need to go back and view events at a later time
- * or save the events to XML for later analysis.
- * <p>
- * Here is a complete MySQL SQL statement which can be used to provide events to
- * Chainsaw (note how in the example below, there is no column in logtable representing the throwable, so an
- * empty string is passed in and an ALIAS is still defined):
- * <p>
- * select myloggercolumn as LOGGER, mytimestampcolumn as TIMESTAMP, mylevelcolumn as LEVEL, mythreadcolumn as
- * THREAD, mymessagecolumn as MESSAGE, myndccolumn as NDC, mymdccolumn as MDC, myclasscolumn as CLASS, mymethodcolumn as
- * METHOD, myfilecolumn as FILE, mylinecolumn as LINE,
- * concat("{{application,databaselogs,hostname,mymachine, log4jid,",
- * COUNTER,"}}") as PROPERTIES, "" as THROWABLE from logtable
- * <p>
- *
- * @author Scott Deboy <sdeboy@apache.org>
- * <p>
- */
-public class CustomSQLDBReceiver extends Receiver implements Pauseable, UnrecognizedElementHandler {
-
- protected volatile Connection connection = null;
-
- protected String sqlStatement = "";
-
- /**
- * By default we refresh data every 1000 milliseconds.
- *
- * @see #setRefreshMillis
- */
- static int DEFAULT_REFRESH_MILLIS = 1000;
-
- int refreshMillis = DEFAULT_REFRESH_MILLIS;
-
- protected String idField = null;
-
- int lastID = -1;
-
- private static final String WHERE_CLAUSE = " WHERE ";
-
- private static final String AND_CLAUSE = " AND ";
-
- private boolean whereExists = false;
-
- private boolean paused = false;
-
- private ConnectionSource connectionSource;
-
- public static final String LOG4J_ID_KEY = "log4jid";
-
- private Job customReceiverJob;
-
- public void activateOptions() {
-
- if (connectionSource == null) {
- throw new IllegalStateException(
- "CustomSQLDBReceiver cannot function without a connection source");
- }
- whereExists = (sqlStatement.toUpperCase().contains(WHERE_CLAUSE));
-
- customReceiverJob = new CustomReceiverJob();
-
- if (this.repository == null) {
- throw new IllegalStateException(
- "CustomSQLDBReceiver cannot function without a reference to its owning repository");
- }
-
-
- if (repository instanceof LoggerRepositoryEx) {
- Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
-
- scheduler.schedule(
- customReceiverJob, System.currentTimeMillis() + 500, refreshMillis);
- }
-
- }
-
- void closeConnection() {
- if (connection != null) {
- try {
- // LogLog.warn("closing the connection. ", new Exception("x"));
- connection.close();
- } catch (SQLException sqle) {
- // nothing we can do here
- }
- }
- }
-
- public void setRefreshMillis(int refreshMillis) {
- this.refreshMillis = refreshMillis;
- }
-
- public int getRefreshMillis() {
- return refreshMillis;
- }
-
- /**
- * @return Returns the connectionSource.
- */
- public ConnectionSource getConnectionSource() {
- return connectionSource;
- }
-
- /**
- * @param connectionSource The connectionSource to set.
- */
- public void setConnectionSource(ConnectionSource connectionSource) {
- this.connectionSource = connectionSource;
- }
-
- public void close() {
- try {
- if ((connection != null) && !connection.isClosed()) {
- connection.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- } finally {
- connection = null;
- }
- }
-
- public void finalize() throws Throwable {
- super.finalize();
- close();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.log4j.plugins.Plugin#shutdown()
- */
- public void shutdown() {
- getLogger().info("removing receiverJob from the Scheduler.");
-
- if (this.repository instanceof LoggerRepositoryEx) {
- Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
- scheduler.delete(customReceiverJob);
- }
-
- lastID = -1;
- }
-
- public void setSql(String s) {
- sqlStatement = s;
- }
-
- public String getSql() {
- return sqlStatement;
- }
-
- public void setIDField(String id) {
- idField = id;
- }
-
- public String getIDField() {
- return idField;
- }
-
- public synchronized void setPaused(boolean p) {
- paused = p;
- }
-
- public synchronized boolean isPaused() {
- return paused;
- }
-
- class CustomReceiverJob implements Job {
- public void execute() {
- int oldLastID = lastID;
- try {
- connection = connectionSource.getConnection();
- Statement statement = connection.createStatement();
-
- Logger eventLogger;
- long timeStamp;
- String level;
- String threadName;
- Object message;
- String ndc;
- Hashtable<String, String> mdc;
- String[] throwable;
- String className;
- String methodName;
- String fileName;
- String lineNumber;
- Hashtable<String, String> properties;
-
- String currentSQLStatement;
- if (whereExists) {
- currentSQLStatement = sqlStatement + AND_CLAUSE + idField
- + " > " + lastID;
- } else {
- currentSQLStatement = sqlStatement + WHERE_CLAUSE + idField
- + " > " + lastID;
- }
-
- ResultSet rs = statement.executeQuery(currentSQLStatement);
-
- int i = 0;
- while (rs.next()) {
- // add a small break every 1000 received events
- if (++i == 1000) {
- synchronized (this) {
- try {
- // add a delay
- wait(300);
- } catch (InterruptedException ie) {
- }
- i = 0;
- }
- }
- eventLogger = Logger.getLogger(rs.getString("LOGGER"));
- timeStamp = rs.getTimestamp("TIMESTAMP").getTime();
-
- level = rs.getString("LEVEL");
- threadName = rs.getString("THREAD");
- message = rs.getString("MESSAGE");
- ndc = rs.getString("NDC");
-
- String mdcString = rs.getString("MDC");
- mdc = new Hashtable<>();
-
- if (mdcString != null) {
- // support MDC being wrapped in {{name, value}}
- // or
- // just name, value
- if ((mdcString.contains("{{"))
- && (mdcString.contains("}}"))) {
- mdcString = mdcString
- .substring(mdcString.indexOf("{{") + 2,
- mdcString.indexOf("}}"));
- }
-
- StringTokenizer tok = new StringTokenizer(mdcString,
- ",");
-
- while (tok.countTokens() > 1) {
- mdc.put(tok.nextToken(), tok.nextToken());
- }
- }
-
- throwable = new String[]{rs.getString("THROWABLE")};
- className = rs.getString("CLASS");
- methodName = rs.getString("METHOD");
- fileName = rs.getString("FILE");
- lineNumber = rs.getString("LINE");
-
- // if properties are provided in the
- // SQL they can be used here (for example, to route
- // events to a unique tab in
- // Chainsaw if the machinename and/or appname
- // property
- // are set)
- String propertiesString = rs.getString("PROPERTIES");
- properties = new Hashtable<>();
-
- if (propertiesString != null) {
- // support properties being wrapped in {{name,
- // value}} or just name, value
- if ((propertiesString.contains("{{"))
- && (propertiesString.contains("}}"))) {
- propertiesString = propertiesString.substring(
- propertiesString.indexOf("{{") + 2,
- propertiesString.indexOf("}}"));
- }
-
- StringTokenizer tok2 = new StringTokenizer(
- propertiesString, ",");
- while (tok2.countTokens() > 1) {
- String tokenName = tok2.nextToken();
- String value = tok2.nextToken();
- if (tokenName.equals(LOG4J_ID_KEY)) {
- try {
- int thisInt = Integer.parseInt(value);
- value = String.valueOf(thisInt);
- if (thisInt > lastID) {
- lastID = thisInt;
- }
- } catch (Exception e) {
- }
- }
- properties.put(tokenName, value);
- }
- }
-
- Level levelImpl = Level.toLevel(level);
-
-
- LocationInfo locationInfo = new LocationInfo(fileName,
- className, methodName, lineNumber);
-
- ThrowableInformation throwableInfo = new ThrowableInformation(
- throwable);
-
- properties.putAll(mdc);
-
- LoggingEvent event = new LoggingEvent(eventLogger.getName(),
- eventLogger, timeStamp, levelImpl, message,
- threadName,
- throwableInfo,
- ndc,
- locationInfo,
- properties);
-
- doPost(event);
- }
- //log when rows are retrieved
- if (lastID != oldLastID) {
- getLogger().debug("lastID: " + lastID);
- }
-
- statement.close();
- } catch (SQLException sqle) {
- getLogger()
- .error("*************Problem receiving events", sqle);
- } finally {
- closeConnection();
- }
-
- // if paused, loop prior to executing sql query
- synchronized (this) {
- while (isPaused()) {
- try {
- wait(1000);
- } catch (InterruptedException ie) {
- }
- }
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
- if ("connectionSource".equals(element.getNodeName())) {
- Object instance =
- DOMConfigurator.parseElement(element, props, ConnectionSource.class);
- if (instance instanceof ConnectionSource) {
- ConnectionSource source = (ConnectionSource) instance;
- source.activateOptions();
- setConnectionSource(source);
- }
- return true;
- }
- return false;
- }
-
-}
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one or more
+// * contributor license agreements. See the NOTICE file distributed with
+// * this work for additional information regarding copyright ownership.
+// * The ASF licenses this file to You under the Apache License, Version 2.0
+// * (the "License"); you may not use this file except in compliance with
+// * the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// */
+//
+//package org.apache.log4j.db;
+//
+//import org.apache.log4j.Level;
+//import org.apache.log4j.Logger;
+//import org.apache.log4j.plugins.Pauseable;
+//import org.apache.log4j.plugins.Receiver;
+//import org.apache.log4j.scheduler.Job;
+//import org.apache.log4j.scheduler.Scheduler;
+//import org.apache.log4j.spi.LocationInfo;
+//import org.apache.log4j.spi.LoggerRepositoryEx;
+//import org.apache.log4j.spi.LoggingEvent;
+//import org.apache.log4j.spi.ThrowableInformation;
+//import org.apache.log4j.xml.DOMConfigurator;
+//import org.apache.log4j.xml.UnrecognizedElementHandler;
+//import org.w3c.dom.Element;
+//
+//import java.sql.Connection;
+//import java.sql.ResultSet;
+//import java.sql.SQLException;
+//import java.sql.Statement;
+//import java.util.Hashtable;
+//import java.util.Properties;
+//import java.util.StringTokenizer;
+//
+///**
+// * Converts log data stored in a database into LoggingEvents.
+// * <p>
+// * <b>NOTE:</b> This receiver cannot yet be created through Chainsaw's receiver panel.
+// * It must be created through an XML configuration file.
+// * <p>
+// * This receiver supports database configuration via ConnectionSource, in the
+// * org.apache.log4j.db package: DriverManagerConnectionSource,
+// * DataSourceConnectionSource, JNDIConnectionSource
+// * <p>
+// * This database receiver differs from DBReceiver in that this receiver relies
+// * on custom SQL to retrieve logging event data, where DBReceiver requires the
+// * use of a log4j-defined schema.
+// * <p>
+// * A 'refreshMillis' int parameter controls SQL execution. If 'refreshMillis' is
+// * zero (the default), the receiver will run only one time. If it is set to any
+// * other numeric value, the SQL will be executed on a recurring basis every
+// * 'refreshMillis' milliseconds.
+// * <p>
+// * The receiver closes the connection and acquires a new connection on each
+// * execution of the SQL (use pooled connections if possible).
+// * <p>
+// * If the SQL will be executing on a recurring basis, specify the IDField param -
+// * the column name holding the unique identifier (int) representing the logging
+// * event.
+// * <p>
+// * As events are retrieved, the column represented by IDField is examined and
+// * the largest value is held and used by the next execution of the SQL statement
+// * to avoid retrieving previously processed events.
+// * <p>
+// * As an example, the IDField references a 'COUNTER' (int, auto-increment,
+// * unique) column. The first execution of the SQL statement returns 500 rows,
+// * with a final value in the COUNTER field of 500.
+// * <p>
+// * The SQL statement is manipulated prior to the next execution, adding ' WHERE
+// * COUNTER > 500' to the statement to avoid retrieval of previously processed
+// * events.
+// * <p>
+// * The select statement must provide ALL fields which define a LoggingEvent.
+// * <p>
+// * The SQL statement MUST include the columns: LOGGER, TIMESTAMP, LEVEL, THREAD,
+// * MESSAGE, NDC, MDC, CLASS, METHOD, FILE, LINE, PROPERTIES, THROWABLE
+// * <p>
+// * Use ' AS ' in the SQL statement to alias the SQL's column names to match your
+// * database schema. (see example below).
+// * <p>
+// * Include all fields in the SQL statement, even if you don't have data for the
+// * field (specify an empty string as the value for columns which you don't have
+// * data).
+// * <p>
+// * The TIMESTAMP column must be a datetime.
+// * <p>
+// * Both a PROPERTIES column and an MDC column are supported. These fields
+// * represent Maps on the logging event, but require the use of string
+// * concatenation database functions to hold the (possibly multiple) name/value
+// * pairs in the column.
+// * <p>
+// * For example, to include both 'userid' and 'lastname' properties in the
+// * logging event (from either the PROPERTIES or MDC columns), the name/value
+// * pairs must be concatenated together by your database.
+// * <p>
+// * The resulting PROPERTIES or MDC column must have data in this format: {{name,
+// * value, name2, value2}}
+// * <p>
+// * The resulting PROPERTIES column would contain this text: {{userid, someone,
+// * lastname, mylastname}}
+// * <p>
+// * Here is an example of concatenating a PROPERTIES or MDC column using MySQL's
+// * concat function, where the 'application' and 'hostname' parameters were fixed
+// * text, but the 'log4jid' key's value is the value of the COUNTER column:
+// * <p>
+// * concat("{{application,databaselogs,hostname,mymachine,log4jid,", COUNTER,
+// * "}}") as PROPERTIES
+// * <p>
+// * log4jid is a special property that is used by Chainsaw to represent an 'ID'
+// * field. Specify this property to ensure you can map events in Chainsaw to
+// * events in the database if you need to go back and view events at a later time
+// * or save the events to XML for later analysis.
+// * <p>
+// * Here is a complete MySQL SQL statement which can be used to provide events to
+// * Chainsaw (note how in the example below, there is no column in logtable representing the throwable, so an
+// * empty string is passed in and an ALIAS is still defined):
+// * <p>
+// * select myloggercolumn as LOGGER, mytimestampcolumn as TIMESTAMP, mylevelcolumn as LEVEL, mythreadcolumn as
+// * THREAD, mymessagecolumn as MESSAGE, myndccolumn as NDC, mymdccolumn as MDC, myclasscolumn as CLASS, mymethodcolumn as
+// * METHOD, myfilecolumn as FILE, mylinecolumn as LINE,
+// * concat("{{application,databaselogs,hostname,mymachine, log4jid,",
+// * COUNTER,"}}") as PROPERTIES, "" as THROWABLE from logtable
+// * <p>
+// *
+// * @author Scott Deboy <sdeboy@apache.org>
+// * <p>
+// */
+//public class CustomSQLDBReceiver extends Receiver implements Pauseable, UnrecognizedElementHandler {
+//
+// protected volatile Connection connection = null;
+//
+// protected String sqlStatement = "";
+//
+// /**
+// * By default we refresh data every 1000 milliseconds.
+// *
+// * @see #setRefreshMillis
+// */
+// static int DEFAULT_REFRESH_MILLIS = 1000;
+//
+// int refreshMillis = DEFAULT_REFRESH_MILLIS;
+//
+// protected String idField = null;
+//
+// int lastID = -1;
+//
+// private static final String WHERE_CLAUSE = " WHERE ";
+//
+// private static final String AND_CLAUSE = " AND ";
+//
+// private boolean whereExists = false;
+//
+// private boolean paused = false;
+//
+// private ConnectionSource connectionSource;
+//
+// public static final String LOG4J_ID_KEY = "log4jid";
+//
+// private Job customReceiverJob;
+//
+// public void activateOptions() {
+//
+// if (connectionSource == null) {
+// throw new IllegalStateException(
+// "CustomSQLDBReceiver cannot function without a connection source");
+// }
+// whereExists = (sqlStatement.toUpperCase().contains(WHERE_CLAUSE));
+//
+// customReceiverJob = new CustomReceiverJob();
+//
+// if (this.repository == null) {
+// throw new IllegalStateException(
+// "CustomSQLDBReceiver cannot function without a reference to its owning repository");
+// }
+//
+//
+// if (repository instanceof LoggerRepositoryEx) {
+// Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+//
+// scheduler.schedule(
+// customReceiverJob, System.currentTimeMillis() + 500, refreshMillis);
+// }
+//
+// }
+//
+// void closeConnection() {
+// if (connection != null) {
+// try {
+// // LogLog.warn("closing the connection. ", new Exception("x"));
+// connection.close();
+// } catch (SQLException sqle) {
+// // nothing we can do here
+// }
+// }
+// }
+//
+// public void setRefreshMillis(int refreshMillis) {
+// this.refreshMillis = refreshMillis;
+// }
+//
+// public int getRefreshMillis() {
+// return refreshMillis;
+// }
+//
+// /**
+// * @return Returns the connectionSource.
+// */
+// public ConnectionSource getConnectionSource() {
+// return connectionSource;
+// }
+//
+// /**
+// * @param connectionSource The connectionSource to set.
+// */
+// public void setConnectionSource(ConnectionSource connectionSource) {
+// this.connectionSource = connectionSource;
+// }
+//
+// public void close() {
+// try {
+// if ((connection != null) && !connection.isClosed()) {
+// connection.close();
+// }
+// } catch (SQLException e) {
+// e.printStackTrace();
+// } finally {
+// connection = null;
+// }
+// }
+//
+// public void finalize() throws Throwable {
+// super.finalize();
+// close();
+// }
+//
+// /*
+// * (non-Javadoc)
+// *
+// * @see org.apache.log4j.plugins.Plugin#shutdown()
+// */
+// public void shutdown() {
+// getLogger().info("removing receiverJob from the Scheduler.");
+//
+// if (this.repository instanceof LoggerRepositoryEx) {
+// Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+// scheduler.delete(customReceiverJob);
+// }
+//
+// lastID = -1;
+// }
+//
+// public void setSql(String s) {
+// sqlStatement = s;
+// }
+//
+// public String getSql() {
+// return sqlStatement;
+// }
+//
+// public void setIDField(String id) {
+// idField = id;
+// }
+//
+// public String getIDField() {
+// return idField;
+// }
+//
+// public synchronized void setPaused(boolean p) {
+// paused = p;
+// }
+//
+// public synchronized boolean isPaused() {
+// return paused;
+// }
+//
+// class CustomReceiverJob implements Job {
+// public void execute() {
+// int oldLastID = lastID;
+// try {
+// connection = connectionSource.getConnection();
+// Statement statement = connection.createStatement();
+//
+// Logger eventLogger;
+// long timeStamp;
+// String level;
+// String threadName;
+// Object message;
+// String ndc;
+// Hashtable<String, String> mdc;
+// String[] throwable;
+// String className;
+// String methodName;
+// String fileName;
+// String lineNumber;
+// Hashtable<String, String> properties;
+//
+// String currentSQLStatement;
+// if (whereExists) {
+// currentSQLStatement = sqlStatement + AND_CLAUSE + idField
+// + " > " + lastID;
+// } else {
+// currentSQLStatement = sqlStatement + WHERE_CLAUSE + idField
+// + " > " + lastID;
+// }
+//
+// ResultSet rs = statement.executeQuery(currentSQLStatement);
+//
+// int i = 0;
+// while (rs.next()) {
+// // add a small break every 1000 received events
+// if (++i == 1000) {
+// synchronized (this) {
+// try {
+// // add a delay
+// wait(300);
+// } catch (InterruptedException ie) {
+// }
+// i = 0;
+// }
+// }
+// eventLogger = Logger.getLogger(rs.getString("LOGGER"));
+// timeStamp = rs.getTimestamp("TIMESTAMP").getTime();
+//
+// level = rs.getString("LEVEL");
+// threadName = rs.getString("THREAD");
+// message = rs.getString("MESSAGE");
+// ndc = rs.getString("NDC");
+//
+// String mdcString = rs.getString("MDC");
+// mdc = new Hashtable<>();
+//
+// if (mdcString != null) {
+// // support MDC being wrapped in {{name, value}}
+// // or
+// // just name, value
+// if ((mdcString.contains("{{"))
+// && (mdcString.contains("}}"))) {
+// mdcString = mdcString
+// .substring(mdcString.indexOf("{{") + 2,
+// mdcString.indexOf("}}"));
+// }
+//
+// StringTokenizer tok = new StringTokenizer(mdcString,
+// ",");
+//
+// while (tok.countTokens() > 1) {
+// mdc.put(tok.nextToken(), tok.nextToken());
+// }
+// }
+//
+// throwable = new String[]{rs.getString("THROWABLE")};
+// className = rs.getString("CLASS");
+// methodName = rs.getString("METHOD");
+// fileName = rs.getString("FILE");
+// lineNumber = rs.getString("LINE");
+//
+// // if properties are provided in the
+// // SQL they can be used here (for example, to route
+// // events to a unique tab in
+// // Chainsaw if the machinename and/or appname
+// // property
+// // are set)
+// String propertiesString = rs.getString("PROPERTIES");
+// properties = new Hashtable<>();
+//
+// if (propertiesString != null) {
+// // support properties being wrapped in {{name,
+// // value}} or just name, value
+// if ((propertiesString.contains("{{"))
+// && (propertiesString.contains("}}"))) {
+// propertiesString = propertiesString.substring(
+// propertiesString.indexOf("{{") + 2,
+// propertiesString.indexOf("}}"));
+// }
+//
+// StringTokenizer tok2 = new StringTokenizer(
+// propertiesString, ",");
+// while (tok2.countTokens() > 1) {
+// String tokenName = tok2.nextToken();
+// String value = tok2.nextToken();
+// if (tokenName.equals(LOG4J_ID_KEY)) {
+// try {
+// int thisInt = Integer.parseInt(value);
+// value = String.valueOf(thisInt);
+// if (thisInt > lastID) {
+// lastID = thisInt;
+// }
+// } catch (Exception e) {
+// }
+// }
+// properties.put(tokenName, value);
+// }
+// }
+//
+// Level levelImpl = Level.toLevel(level);
+//
+//
+// LocationInfo locationInfo = new LocationInfo(fileName,
+// className, methodName, lineNumber);
+//
+// ThrowableInformation throwableInfo = new ThrowableInformation(
+// throwable);
+//
+// properties.putAll(mdc);
+//
+// LoggingEvent event = new LoggingEvent(eventLogger.getName(),
+// eventLogger, timeStamp, levelImpl, message,
+// threadName,
+// throwableInfo,
+// ndc,
+// locationInfo,
+// properties);
+//
+// doPost(event);
+// }
+// //log when rows are retrieved
+// if (lastID != oldLastID) {
+// getLogger().debug("lastID: " + lastID);
+// }
+//
+// statement.close();
+// } catch (SQLException sqle) {
+// getLogger()
+// .error("*************Problem receiving events", sqle);
+// } finally {
+// closeConnection();
+// }
+//
+// // if paused, loop prior to executing sql query
+// synchronized (this) {
+// while (isPaused()) {
+// try {
+// wait(1000);
+// } catch (InterruptedException ie) {
+// }
+// }
+// }
+// }
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
+// if ("connectionSource".equals(element.getNodeName())) {
+// Object instance =
+// DOMConfigurator.parseElement(element, props, ConnectionSource.class);
+// if (instance instanceof ConnectionSource) {
+// ConnectionSource source = (ConnectionSource) instance;
+// source.activateOptions();
+// setConnectionSource(source);
+// }
+// return true;
+// }
+// return false;
+// }
+//
+//}
diff --git a/src/main/java/org/apache/log4j/db/DBReceiver.java b/src/main/java/org/apache/log4j/db/DBReceiver.java
index bcb66e1..e40e808 100644
--- a/src/main/java/org/apache/log4j/db/DBReceiver.java
+++ b/src/main/java/org/apache/log4j/db/DBReceiver.java
@@ -1,139 +1,139 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.db;
-
-import org.apache.log4j.plugins.Pauseable;
-import org.apache.log4j.plugins.Receiver;
-import org.apache.log4j.scheduler.Scheduler;
-import org.apache.log4j.spi.LoggerRepositoryEx;
-import org.apache.log4j.xml.DOMConfigurator;
-import org.apache.log4j.xml.UnrecognizedElementHandler;
-import org.w3c.dom.Element;
-
-import java.util.Properties;
-
-/**
- * @author Scott Deboy <sdeboy@apache.org>
- * @author Ceki Gülcü
- */
-public class DBReceiver extends Receiver implements Pauseable, UnrecognizedElementHandler {
- /**
- * By default we refresh data every 1000 milliseconds.
- *
- * @see #setRefreshMillis
- */
- static int DEFAULT_REFRESH_MILLIS = 1000;
- ConnectionSource connectionSource;
- int refreshMillis = DEFAULT_REFRESH_MILLIS;
- DBReceiverJob receiverJob;
- boolean paused = false;
-
- public void activateOptions() {
-
- if (connectionSource == null) {
- throw new IllegalStateException(
- "DBAppender cannot function without a connection source");
- }
-
- receiverJob = new DBReceiverJob(this);
- receiverJob.setLoggerRepository(repository);
-
- if (this.repository == null) {
- throw new IllegalStateException(
- "DBAppender cannot function without a reference to its owning repository");
- }
-
- if (repository instanceof LoggerRepositoryEx) {
- Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
-
- scheduler.schedule(
- receiverJob, System.currentTimeMillis() + 500, refreshMillis);
- }
-
- }
-
- public void setRefreshMillis(int refreshMillis) {
- this.refreshMillis = refreshMillis;
- }
-
- public int getRefreshMillis() {
- return refreshMillis;
- }
-
-
- /**
- * @return Returns the connectionSource.
- */
- public ConnectionSource getConnectionSource() {
- return connectionSource;
- }
-
-
- /**
- * @param connectionSource The connectionSource to set.
- */
- public void setConnectionSource(ConnectionSource connectionSource) {
- this.connectionSource = connectionSource;
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Plugin#shutdown()
- */
- public void shutdown() {
- getLogger().info("removing receiverJob from the Scheduler.");
-
- if (this.repository instanceof LoggerRepositoryEx) {
- Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
- scheduler.delete(receiverJob);
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Pauseable#setPaused(boolean)
- */
- public void setPaused(boolean paused) {
- this.paused = paused;
- }
-
- /* (non-Javadoc)
- * @see org.apache.log4j.plugins.Pauseable#isPaused()
- */
- public boolean isPaused() {
- return paused;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
- if ("connectionSource".equals(element.getNodeName())) {
- Object instance =
- DOMConfigurator.parseElement(element, props, ConnectionSource.class);
- if (instance instanceof ConnectionSource) {
- ConnectionSource source = (ConnectionSource) instance;
- source.activateOptions();
- setConnectionSource(source);
- }
- return true;
- }
- return false;
- }
-
-}
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one or more
+// * contributor license agreements. See the NOTICE file distributed with
+// * this work for additional information regarding copyright ownership.
+// * The ASF licenses this file to You under the Apache License, Version 2.0
+// * (the "License"); you may not use this file except in compliance with
+// * the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// */
+//
+//package org.apache.log4j.db;
+//
+//import org.apache.log4j.plugins.Pauseable;
+//import org.apache.log4j.plugins.Receiver;
+//import org.apache.log4j.scheduler.Scheduler;
+//import org.apache.log4j.spi.LoggerRepositoryEx;
+//import org.apache.log4j.xml.DOMConfigurator;
+//import org.apache.log4j.xml.UnrecognizedElementHandler;
+//import org.w3c.dom.Element;
+//
+//import java.util.Properties;
+//
+///**
+// * @author Scott Deboy <sdeboy@apache.org>
+// * @author Ceki Gülcü
+// */
+//public class DBReceiver extends Receiver implements Pauseable, UnrecognizedElementHandler {
+// /**
+// * By default we refresh data every 1000 milliseconds.
+// *
+// * @see #setRefreshMillis
+// */
+// static int DEFAULT_REFRESH_MILLIS = 1000;
+// ConnectionSource connectionSource;
+// int refreshMillis = DEFAULT_REFRESH_MILLIS;
+// DBReceiverJob receiverJob;
+// boolean paused = false;
+//
+// public void activateOptions() {
+//
+// if (connectionSource == null) {
+// throw new IllegalStateException(
+// "DBAppender cannot function without a connection source");
+// }
+//
+// receiverJob = new DBReceiverJob(this);
+// receiverJob.setLoggerRepository(repository);
+//
+// if (this.repository == null) {
+// throw new IllegalStateException(
+// "DBAppender cannot function without a reference to its owning repository");
+// }
+//
+// if (repository instanceof LoggerRepositoryEx) {
+// Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+//
+// scheduler.schedule(
+// receiverJob, System.currentTimeMillis() + 500, refreshMillis);
+// }
+//
+// }
+//
+// public void setRefreshMillis(int refreshMillis) {
+// this.refreshMillis = refreshMillis;
+// }
+//
+// public int getRefreshMillis() {
+// return refreshMillis;
+// }
+//
+//
+// /**
+// * @return Returns the connectionSource.
+// */
+// public ConnectionSource getConnectionSource() {
+// return connectionSource;
+// }
+//
+//
+// /**
+// * @param connectionSource The connectionSource to set.
+// */
+// public void setConnectionSource(ConnectionSource connectionSource) {
+// this.connectionSource = connectionSource;
+// }
+//
+//
+// /* (non-Javadoc)
+// * @see org.apache.log4j.plugins.Plugin#shutdown()
+// */
+// public void shutdown() {
+// getLogger().info("removing receiverJob from the Scheduler.");
+//
+// if (this.repository instanceof LoggerRepositoryEx) {
+// Scheduler scheduler = ((LoggerRepositoryEx) repository).getScheduler();
+// scheduler.delete(receiverJob);
+// }
+// }
+//
+//
+// /* (non-Javadoc)
+// * @see org.apache.log4j.plugins.Pauseable#setPaused(boolean)
+// */
+// public void setPaused(boolean paused) {
+// this.paused = paused;
+// }
+//
+// /* (non-Javadoc)
+// * @see org.apache.log4j.plugins.Pauseable#isPaused()
+// */
+// public boolean isPaused() {
+// return paused;
+// }
+//
+// /**
+// * {@inheritDoc}
+// */
+// public boolean parseUnrecognizedElement(Element element, Properties props) throws Exception {
+// if ("connectionSource".equals(element.getNodeName())) {
+// Object instance =
+// DOMConfigurator.parseElement(element, props, ConnectionSource.class);
+// if (instance instanceof ConnectionSource) {
+// ConnectionSource source = (ConnectionSource) instance;
+// source.activateOptions();
+// setConnectionSource(source);
+// }
+// return true;
+// }
+// return false;
+// }
+//
+//}
diff --git a/src/main/java/org/apache/log4j/db/DBReceiverJob.java b/src/main/java/org/apache/log4j/db/DBReceiverJob.java
index 30091cd..45233fc 100644
--- a/src/main/java/org/apache/log4j/db/DBReceiverJob.java
+++ b/src/main/java/org/apache/log4j/db/DBReceiverJob.java
@@ -1,224 +1,224 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.db;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.scheduler.Job;
-import org.apache.log4j.spi.ComponentBase;
-import org.apache.log4j.spi.LocationInfo;
-import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.spi.ThrowableInformation;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Hashtable;
-import java.util.Vector;
-
-/**
- * Actual retrieval of data is made by the instance of DBReceiverJob associated
- * with DBReceiver.
- *
- * @author Ceki Gülcü
- */
-class DBReceiverJob extends ComponentBase implements Job {
-
- String sqlException = "SELECT trace_line FROM logging_event_exception where event_id=? ORDER by i ASC";
- String sqlProperties = "SELECT mapped_key, mapped_value FROM logging_event_property WHERE event_id=?";
- String sqlSelect =
- "SELECT " +
- "sequence_number, timestamp, rendered_message, logger_name, " +
- "level_string, ndc, thread_name, reference_flag, " +
- "caller_filename, caller_class, caller_method, caller_line, " +
- "event_id " +
- "FROM logging_event " +
- "WHERE event_id > ? ORDER BY event_id ASC";
-
-
- long lastId = Short.MIN_VALUE;
-
- DBReceiver parentDBReceiver;
-
- DBReceiverJob(DBReceiver parent) {
- parentDBReceiver = parent;
- }
-
- public void execute() {
- getLogger().debug("DBReceiverJob.execute() called");
-
- Connection connection = null;
-
- try {
- connection = parentDBReceiver.connectionSource.getConnection();
- PreparedStatement statement = connection.prepareStatement(sqlSelect);
- statement.setLong(1, lastId);
- ResultSet rs = statement.executeQuery();
- //rs.beforeFirst();
-
- while (rs.next()) {
- Logger logger;
- long timeStamp;
- String level;
- String threadName;
- Object message;
- String ndc;
- String className;
- String methodName;
- String fileName;
- String lineNumber;
- Hashtable properties = new Hashtable();
-
-
- //event.setSequenceNumber(rs.getLong(1));
- timeStamp = rs.getLong(2);
- message = rs.getString(3);
- logger = Logger.getLogger(rs.getString(4));
- level = rs.getString(5);
- Level levelImpl = Level.toLevel(level.trim());
-
- ndc = rs.getString(6);
- threadName = rs.getString(7);
-
- short mask = rs.getShort(8);
-
- fileName = rs.getString(9);
- className = rs.getString(10);
- methodName = rs.getString(11);
- lineNumber = rs.getString(12).trim();
-
- LocationInfo locationInfo;
- if (fileName.equals(LocationInfo.NA)) {
- locationInfo = LocationInfo.NA_LOCATION_INFO;
- } else {
- locationInfo = new LocationInfo(fileName, className,
- methodName, lineNumber);
- }
-
- long id = rs.getLong(13);
- //LogLog.info("Received event with id=" + id);
- lastId = id;
-
- ThrowableInformation throwableInfo = null;
- if ((mask & DBHelper.EXCEPTION_EXISTS) != 0) {
- throwableInfo = getException(connection, id);
- }
-
- LoggingEvent event = new LoggingEvent(logger.getName(),
- logger, timeStamp, levelImpl, message,
- threadName,
- throwableInfo,
- ndc,
- locationInfo,
- properties);
-
-
- // Scott asked for this info to be
- event.setProperty("log4jid", Long.toString(id));
-
- if ((mask & DBHelper.PROPERTIES_EXIST) != 0) {
- getProperties(connection, id, event);
- }
-
-
- if (!parentDBReceiver.isPaused()) {
- parentDBReceiver.doPost(event);
- }
- } // while
- statement.close();
- } catch (SQLException sqle) {
- getLogger().error("Problem receiving events", sqle);
- } finally {
- closeConnection(connection);
- }
- }
-
- void closeConnection(Connection connection) {
- if (connection != null) {
- try {
- //LogLog.warn("closing the connection. ", new Exception("x"));
- connection.close();
- } catch (SQLException sqle) {
- // nothing we can do here
- }
- }
- }
-
- /**
- * Retrieve the event properties from the logging_event_property table.
- *
- * @param connection
- * @param id
- * @param event
- * @throws SQLException
- */
- void getProperties(Connection connection, long id, LoggingEvent event)
- throws SQLException {
-
- try (PreparedStatement statement = connection.prepareStatement(sqlProperties)) {
- statement.setLong(1, id);
- ResultSet rs = statement.executeQuery();
-
- while (rs.next()) {
- String key = rs.getString(1);
- String value = rs.getString(2);
- event.setProperty(key, value);
- }
- }
- }
-
- /**
- * Retrieve the exception string representation from the
- * logging_event_exception table.
- *
- * @param connection
- * @param id
- * @throws SQLException
- */
- ThrowableInformation getException(Connection connection, long id)
- throws SQLException {
-
- PreparedStatement statement = null;
-
- try {
- statement = connection.prepareStatement(sqlException);
- statement.setLong(1, id);
- ResultSet rs = statement.executeQuery();
-
- Vector<String> v = new Vector<>();
-
- while (rs.next()) {
- //int i = rs.getShort(1);
- v.add(rs.getString(1));
- }
-
- int len = v.size();
- String[] strRep = new String[len];
- for (int i = 0; i < len; i++) {
- strRep[i] = v.get(i);
- }
- // we've filled strRep, we now attach it to the event
- return new ThrowableInformation(strRep);
- } finally {
- if (statement != null) {
- statement.close();
- }
- }
- }
-}
+///*
+// * Licensed to the Apache Software Foundation (ASF) under one or more
+// * contributor license agreements. See the NOTICE file distributed with
+// * this work for additional information regarding copyright ownership.
+// * The ASF licenses this file to You under the Apache License, Version 2.0
+// * (the "License"); you may not use this file except in compliance with
+// * the License. You may obtain a copy of the License at
+// *
+// * http://www.apache.org/licenses/LICENSE-2.0
+// *
+// * Unless required by applicable law or agreed to in writing, software
+// * distributed under the License is distributed on an "AS IS" BASIS,
+// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// * See the License for the specific language governing permissions and
+// * limitations under the License.
+// */
+//
+//package org.apache.log4j.db;
+//
+//import org.apache.log4j.Level;
+//import org.apache.log4j.Logger;
+//import org.apache.log4j.scheduler.Job;
+//import org.apache.log4j.spi.ComponentBase;
+//import org.apache.log4j.spi.LocationInfo;
+//import org.apache.log4j.spi.LoggingEvent;
+//import org.apache.log4j.spi.ThrowableInformation;
+//
+//import java.sql.Connection;
+//import java.sql.PreparedStatement;
+//import java.sql.ResultSet;
+//import java.sql.SQLException;
+//import java.util.Hashtable;
+//import java.util.Vector;
+//
+///**
+// * Actual retrieval of data is made by the instance of DBReceiverJob associated
+// * with DBReceiver.
+// *
+// * @author Ceki Gülcü
+// */
+//class DBReceiverJob extends ComponentBase implements Job {
+//
+// String sqlException = "SELECT trace_line FROM logging_event_exception where event_id=? ORDER by i ASC";
+// String sqlProperties = "SELECT mapped_key, mapped_value FROM logging_event_property WHERE event_id=?";
+// String sqlSelect =
+// "SELECT " +
+// "sequence_number, timestamp, rendered_message, logger_name, " +
+// "level_string, ndc, thread_name, reference_flag, " +
+// "caller_filename, caller_class, caller_method, caller_line, " +
+// "event_id " +
+// "FROM logging_event " +
+// "WHERE event_id > ? ORDER BY event_id ASC";
+//
+//
+// long lastId = Short.MIN_VALUE;
+//
+// DBReceiver parentDBReceiver;
+//
+// DBReceiverJob(DBReceiver parent) {
+// parentDBReceiver = parent;
+// }
+//
+// public void execute() {
+// getLogger().debug("DBReceiverJob.execute() called");
+//
+// Connection connection = null;
+//
+// try {
+// connection = parentDBReceiver.connectionSource.getConnection();
+// PreparedStatement statement = connection.prepareStatement(sqlSelect);
+// statement.setLong(1, lastId);
+// ResultSet rs = statement.executeQuery();
+// //rs.beforeFirst();
+//
+// while (rs.next()) {
+// Logger logger;
+// long timeStamp;
+// String level;
+// String threadName;
+// Object message;
+// String ndc;
+// String className;
+// String methodName;
+// String fileName;
+// String lineNumber;
+// Hashtable properties = new Hashtable();
+//
+//
+// //event.setSequenceNumber(rs.getLong(1));
+// timeStamp = rs.getLong(2);
+// message = rs.getString(3);
+// logger = Logger.getLogger(rs.getString(4));
+// level = rs.getString(5);
+// Level levelImpl = Level.toLevel(level.trim());
+//
+// ndc = rs.getString(6);
+// threadName = rs.getString(7);
+//
+// short mask = rs.getShort(8);
+//
+// fileName = rs.getString(9);
+// className = rs.getString(10);
+// methodName = rs.getString(11);
+// lineNumber = rs.getString(12).trim();
+//
+// LocationInfo locationInfo;
+// if (fileName.equals(LocationInfo.NA)) {
+// locationInfo = LocationInfo.NA_LOCATION_INFO;
+// } else {
+// locationInfo = new LocationInfo(fileName, className,
+// methodName, lineNumber);
+// }
+//
+// long id = rs.getLong(13);
+// //LogLog.info("Received event with id=" + id);
+// lastId = id;
+//
+// ThrowableInformation throwableInfo = null;
+// if ((mask & DBHelper.EXCEPTION_EXISTS) != 0) {
+// throwableInfo = getException(connection, id);
+// }
+//
+// LoggingEvent event = new LoggingEvent(logger.getName(),
+// logger, timeStamp, levelImpl, message,
+// threadName,
+// throwableInfo,
+// ndc,
+// locationInfo,
+// properties);
+//
+//
+// // Scott asked for this info to be
+// event.setProperty("log4jid", Long.toString(id));
+//
+// if ((mask & DBHelper.PROPERTIES_EXIST) != 0) {
+// getProperties(connection, id, event);
+// }
+//
+//
+// if (!parentDBReceiver.isPaused()) {
+// parentDBReceiver.doPost(event);
+// }
+// } // while
+// statement.close();
+// } catch (SQLException sqle) {
+// getLogger().error("Problem receiving events", sqle);
+// } finally {
+// closeConnection(connection);
+// }
+// }
+//
+// void closeConnection(Connection connection) {
+// if (connection != null) {
+// try {
+// //LogLog.warn("closing the connection. ", new Exception("x"));
+// connection.close();
+// } catch (SQLException sqle) {
+// // nothing we can do here
+// }
+// }
+// }
+//
+// /**
+// * Retrieve the event properties from the logging_event_property table.
+// *
+// * @param connection
+// * @param id
+// * @param event
+// * @throws SQLException
+// */
+// void getProperties(Connection connection, long id, LoggingEvent event)
+// throws SQLException {
+//
+// try (PreparedStatement statement = connection.prepareStatement(sqlProperties)) {
+// statement.setLong(1, id);
+// ResultSet rs = statement.executeQuery();
+//
+// while (rs.next()) {
+// String key = rs.getString(1);
+// String value = rs.getString(2);
+// event.setProperty(key, value);
+// }
+// }
+// }
+//
+// /**
+// * Retrieve the exception string representation from the
+// * logging_event_exception table.
+// *
+// * @param connection
+// * @param id
+// * @throws SQLException
+// */
+// ThrowableInformation getException(Connection connection, long id)
+// throws SQLException {
+//
+// PreparedStatement statement = null;
+//
+// try {
+// statement = connection.prepareStatement(sqlException);
+// statement.setLong(1, id);
+// ResultSet rs = statement.executeQuery();
+//
+// Vector<String> v = new Vector<>();
+//
+// while (rs.next()) {
+// //int i = rs.getShort(1);
+// v.add(rs.getString(1));
+// }
+//
+// int len = v.size();
+// String[] strRep = new String[len];
+// for (int i = 0; i < len; i++) {
+// strRep[i] = v.get(i);
+// }
+// // we've filled strRep, we now attach it to the event
+// return new ThrowableInformation(strRep);
+// } finally {
+// if (statement != null) {
+// statement.close();
+// }
+// }
+// }
+//}
diff --git a/src/main/java/org/apache/log4j/net/MulticastReceiver.java b/src/main/java/org/apache/log4j/net/MulticastReceiver.java
index c732d0c..eb911e7 100644
--- a/src/main/java/org/apache/log4j/net/MulticastReceiver.java
+++ b/src/main/java/org/apache/log4j/net/MulticastReceiver.java
@@ -17,8 +17,6 @@
package org.apache.log4j.net;
-import org.apache.log4j.plugins.Pauseable;
-import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.spi.Decoder;
import java.io.IOException;
diff --git a/src/main/java/org/apache/log4j/plugins/Pauseable.java b/src/main/java/org/apache/log4j/plugins/Pauseable.java
deleted file mode 100644
index 8158e40..0000000
--- a/src/main/java/org/apache/log4j/plugins/Pauseable.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.plugins;
-
-
-/**
- * Instances of this interface can be paused, and resumed.
- *
- * @author Paul Smith (psmith@apache.org)
- */
-public interface Pauseable {
- /**
- * Set paused state.
- *
- * @param paused new value
- */
- void setPaused(boolean paused);
-
- /**
- * Get paused state.
- *
- * @return paused state.
- */
- boolean isPaused();
-}
diff --git a/src/main/java/org/apache/log4j/plugins/Plugin.java b/src/main/java/org/apache/log4j/plugins/Plugin.java
deleted file mode 100644
index 90df955..0000000
--- a/src/main/java/org/apache/log4j/plugins/Plugin.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.plugins;
-
-import org.apache.log4j.spi.LoggerRepository;
-import org.apache.log4j.spi.OptionHandler;
-
-import java.beans.PropertyChangeListener;
-
-
-/**
- * Defines the required interface for all Plugin objects.
- * <p>
- * <p>A plugin implements some specific functionality to extend
- * the log4j framework. Each plugin is associated with a specific
- * LoggerRepository, which it then uses/acts upon. The functionality
- * of the plugin is up to the developer.</p>
- * <p>
- * <p>Examples of plugins are Receiver and Watchdog. Receiver plugins
- * allow for remote logging events to be received and processed by
- * a repository as if the event was sent locally. Watchdog plugins
- * allow for a repository to be reconfigured when some "watched"
- * configuration data changes.</p>
- *
- * @author Mark Womack (mwomack@apache.org)
- * @author Nicko Cadell
- * @author Paul Smith (psmith@apache.org)
- */
-public interface Plugin extends OptionHandler {
- /**
- * Gets the name of the plugin.
- *
- * @return String the name of the plugin.
- */
- String getName();
-
- /**
- * Sets the name of the plugin.
- *
- * @param name the name of the plugin.
- */
- void setName(String name);
-
- /**
- * Gets the logger repository for this plugin.
- *
- * @return the logger repository to which this plugin is attached.
- */
- LoggerRepository getLoggerRepository();
-
- /**
- * Sets the logger repository used by this plugin. This
- * repository will be used by the plugin functionality.
- *
- * @param repository the logger repository to attach this plugin to.
- */
- void setLoggerRepository(LoggerRepository repository);
-
- /**
- * Adds a PropertyChangeListener to this instance which is
- * notified only by changes of the property with name propertyName.
- *
- * @param propertyName the name of the property in standard JavaBean syntax
- * (e.g. for setName(), property="name")
- * @param l listener
- */
- void addPropertyChangeListener(
- String propertyName, PropertyChangeListener l);
-
- /**
- * Adds a PropertyChangeListener that will be notified of all property
- * changes.
- *
- * @param l The listener to add.
- */
- void addPropertyChangeListener(PropertyChangeListener l);
-
- /**
- * Removes a specific PropertyChangeListener from this instances
- * registry that has been mapped to be notified of all property
- * changes.
- *
- * @param l The listener to remove.
- */
- void removePropertyChangeListener(PropertyChangeListener l);
-
- /**
- * Removes a specific PropertyChangeListener from this instance's
- * registry which has been previously registered to be notified
- * of only a specific property change.
- *
- * @param propertyName property name, may not be null.
- * @param l listener to be removed.
- */
- void removePropertyChangeListener(
- String propertyName, PropertyChangeListener l);
-
- /**
- * True if the plugin is active and running.
- *
- * @return boolean true if the plugin is currently active.
- */
- boolean isActive();
-
- /**
- * Returns true if the testPlugin is considered to be "equivalent" to the
- * this plugin.
- * <p>
- * <p>The equivalency test is at the discretion of the plugin
- * implementation. The PluginRegistry will use this method when starting
- * new plugins to see if a given plugin is considered equivalent to an
- * already running plugin with the same name. If they are considered to
- * be equivalent, the currently running plugin will be left in place, and
- * the new plugin will not be started.</p>
- * <p>
- * <p>It is possible to override the equals() method, however this has
- * more meaning than is required for this simple test and would also
- * require the overriding of the hashCode() method as well. All of this
- * is more work than is needed, so this simple method is used instead.</p>
- *
- * @param testPlugin The plugin to test equivalency against.
- * @return Returns true if testPlugin is considered to be equivelent.
- */
- boolean isEquivalent(Plugin testPlugin);
-
- /**
- * Call when the plugin should be stopped.
- */
- void shutdown();
-}
diff --git a/src/main/java/org/apache/log4j/plugins/PluginEvent.java b/src/main/java/org/apache/log4j/plugins/PluginEvent.java
deleted file mode 100644
index d1928d6..0000000
--- a/src/main/java/org/apache/log4j/plugins/PluginEvent.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.plugins;
-
-import java.util.EventObject;
-
-
-/**
- * All Plugin events are encapsulated in this class, which
- * simply contains the source Plugin, but may in future include more
- * information.
- *
- * @author Paul Smith
- */
-public class PluginEvent extends EventObject {
- /**
- * @param source The source plugin of the event
- */
- PluginEvent(final Plugin source) {
- super(source);
- }
-
- /**
- * Returns the source Plugin of this event, which is simple
- * the getSource() method casted to Plugin for convenience.
- *
- * @return Plugin source of this event
- */
- public Plugin getPlugin() {
- return (Plugin) getSource();
- }
-}
diff --git a/src/main/java/org/apache/log4j/plugins/PluginListener.java b/src/main/java/org/apache/log4j/plugins/PluginListener.java
deleted file mode 100644
index 59a6a7e..0000000
--- a/src/main/java/org/apache/log4j/plugins/PluginListener.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- */
-package org.apache.log4j.plugins;
-
-import java.util.EventListener;
-
-
-/**
- * PluginListeners are notified when plugins are started or stopped
- * by the PluginRegistry.
- *
- * @author Paul Smith (psmith@apache.org)
- */
-public interface PluginListener extends EventListener {
- /**
- * Notification that plugin has started.
- *
- * @param e event
- */
- void pluginStarted(PluginEvent e);
-
- /**
- * Notification that plugin has stopped.
- *
- * @param e event
- */
- void pluginStopped(PluginEvent e);
-}
diff --git a/src/main/java/org/apache/log4j/plugins/PluginRegistry.java b/src/main/java/org/apache/log4j/plugins/PluginRegistry.java
deleted file mode 100644
index feaae6b..0000000
--- a/src/main/java/org/apache/log4j/plugins/PluginRegistry.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.log4j.plugins;
-
-import org.apache.log4j.spi.LoggerRepository;
-import org.apache.log4j.spi.LoggerRepositoryEventListener;
-import org.apache.log4j.spi.LoggerRepositoryEx;
-
-import java.util.*;
-
-
-/**
- * This is a registry for Plugin instances. It provides methods to
- * start and stop plugin objects individually and to stop all
- * plugins for a repository.
- *
- * @author Mark Womack
- * @author Paul Smith
- */
-public final class PluginRegistry {
- /**
- * The pluginMap is keyed by plugin name and contains plugins as values.
- * key=plugin.getName, value=plugin
- */
- private final Map<String, Plugin> pluginMap;
- /**
- * Logger repository.
- */
- private final LoggerRepositoryEx loggerRepository;
-
- /**
- * the listener used to listen for repository events.
- */
- private final RepositoryListener listener = new RepositoryListener();
- /**
- * List of listeners.
- */
- private final List listenerList =
- Collections.synchronizedList(new ArrayList());
-
- /**
- * Creates a new instance.
- *
- * @param repository logger repository.
- */
- public PluginRegistry(final LoggerRepositoryEx repository) {
- super();
- pluginMap = new HashMap<>();
- this.loggerRepository = repository;
- this.loggerRepository.addLoggerRepositoryEventListener(listener);
- }
-
- /**
- * Get logger repository.
- *
- * @return logger repository.
- */
- public LoggerRepositoryEx getLoggerRepository() {
- return loggerRepository;
- }
-
-
- /**
- * Returns true if the specified name is already taken by
- * an existing Plugin registered within the scope of the specified
- * LoggerRepository.
- *
- * @param name The name to check the repository for
- * @return true if the name is already in use, otherwise false
- */
- public boolean pluginNameExists(final String name) {
- synchronized (pluginMap) {
- return pluginMap.containsKey(name);
- }
- }
-
-
- /**
- * Adds a plugin to the plugin registry.
- * If a plugin with the same name exists
- * already, it is shutdown and removed.
- *
- * @param plugin the plugin to add.
- */
- public void addPlugin(final Plugin plugin) {
- // put plugin into the repository's reciever map
- synchronized (pluginMap) {
- String name = plugin.getName();
-
- // make sure the plugin has reference to repository
- plugin.setLoggerRepository(getLoggerRepository());
-
- Plugin existingPlugin = pluginMap.get(name);
- if (existingPlugin != null) {
- existingPlugin.shutdown();
- }
-
- // put the new plugin into the map
- pluginMap.put(name, plugin);
- firePluginStarted(plugin);
- }
- }
-
-
- /**
- * Calls the pluginStarted method on every registered PluginListener.
- *
- * @param plugin The plugin that has been started.
- */
- private void firePluginStarted(final Plugin plugin) {
- PluginEvent e = null;
- synchronized (listenerList) {
- for (Object aListenerList : listenerList) {
- PluginListener l = (PluginListener) aListenerList;
- if (e == null) {
- e = new PluginEvent(plugin);
- }
- l.pluginStarted(e);
- }
- }
- }
-
-
- /**
- * Calls the pluginStopped method for every registered PluginListner.
- *
- * @param plugin The plugin that has been stopped.
- */
- private void firePluginStopped(final Plugin plugin) {
- PluginEvent e = null;
- synchronized (listenerList) {
- for (Object aListenerList : listenerList) {
- PluginListener l = (PluginListener) aListenerList;
- if (e == null) {
- e = new PluginEvent(plugin);
- }
- l.pluginStopped(e);
- }
- }
- }
-
-
- /**
- * Returns all the plugins for a given repository.
- *
- * @return List list of plugins from the repository.
- */
- public List<Plugin> getPlugins() {
- synchronized (pluginMap) {
- List<Plugin> pluginList = new ArrayList<>(pluginMap.size());
-
- pluginList.addAll(pluginMap.values());
- return pluginList;
- }
- }
-
-
- /**
- * Returns all the plugins for a given repository that are instances
- * of a certain class.
- *
- * @param pluginClass the class the plugin must implement to be selected.
- * @return List list of plugins from the repository.
- */
- public List getPlugins(final Class pluginClass) {
- synchronized (pluginMap) {
- List pluginList = new ArrayList(pluginMap.size());
-
- for (Object plugin : pluginMap.values()) {
- if (pluginClass.isInstance(plugin)) {
- pluginList.add(plugin);
- }
- }
- return pluginList;
- }
- }
-
-
- /**
- * Stops a plugin by plugin name and repository.
- *
- * @param pluginName the name of the plugin to stop.
- * @return Plugin the plugin, if stopped, or null if the
- * the plugin was not found in the registry.
- */
- public Plugin stopPlugin(final String pluginName) {
- synchronized (pluginMap) {
- Plugin plugin = pluginMap.get(pluginName);
-
- if (plugin == null) {
- return null;
- }
-
- // shutdown the plugin
- plugin.shutdown();
-
- // remove it from the plugin map
- pluginMap.remove(pluginName);
- firePluginStopped(plugin);
-
- // return it for future use
- return plugin;
- }
- }
-
- /**
- * Stops all plugins in the given logger repository.
- */
- public void stopAllPlugins() {
- synchronized (pluginMap) {
- // remove the listener for this repository
- loggerRepository.removeLoggerRepositoryEventListener(listener);
-
- for (Object o : pluginMap.values()) {
- Plugin plugin = (Plugin) o;
- plugin.shutdown();
- firePluginStopped(plugin);
- }
- }
- }
-
-
- /**
- * Adds a PluginListener to this registry to be notified
- * of PluginEvents.
- *
- * @param l PluginListener to add to this registry
- */
- public void addPluginListener(final PluginListener l) {
- listenerList.add(l);
- }
-
-
- /**
- * Removes a particular PluginListener from this registry
- * such that it will no longer be notified of PluginEvents.
- *
- * @param l PluginListener to remove
- */
- public void removePluginListener(final PluginListener l) {
- listenerList.remove(l);
- }
-
- /**
- * Internal class used to handle listener events from repositories.
- */
- private class RepositoryListener implements LoggerRepositoryEventListener {
- /**
- * Stops all plugins associated with the repository being reset.
- *
- * @param repository the repository that was reset.
- */
- public void configurationResetEvent(final LoggerRepository repository) {
- PluginRegistry.this.stopAllPlugins();
- }
-
-
- /**
- * Called when the repository configuration is changed.
- *
- * @param repository the repository that was changed.
- */
- public void configurationChangedEvent(
- final LoggerRepository repository) {
- // do nothing with this event
- }
-
-
- /**
- * Stops all plugins associated with the repository being shutdown.
- *
- * @param repository the repository being shutdown.
- */
- public void shutdownEvent(final LoggerRepository repository) {
- PluginRegistry.this.stopAllPlugins();
- }
- }
-}
diff --git a/src/main/java/org/apache/log4j/plugins/PluginSkeleton.java b/src/main/java/org/apache/log4j/plugins/PluginSkeleton.java
deleted file mode 100644
index 50b0143..0000000
--- a/src/main/java/org/apache/log4j/plugins/PluginSkeleton.java
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.plugins;
-
-import org.apache.log4j.spi.ComponentBase;
-import org.apache.log4j.spi.LoggerRepository;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-
-/**
- * A convienent abstract class for plugin subclasses that implements
- * the basic methods of the Plugin interface. Subclasses are required
- * to implement the isActive(), activateOptions(), and shutdown()
- * methods.
- * <p></p>
- * <p>Developers are not required to subclass PluginSkeleton to
- * develop their own plugins (they are only required to implement the
- * Plugin interface), but it provides a convenient base class to start
- * from.
- * <p></p>
- * Contributors: Nicko Cadell
- *
- * @author Mark Womack (mwomack@apache.org)
- * @author Paul Smith (psmith@apache.org)
- */
-public abstract class PluginSkeleton extends ComponentBase implements Plugin {
- /**
- * Name of this plugin.
- */
- protected String name = "plugin";
-
- /**
- * Active state of plugin.
- */
- protected boolean active;
-
- /**
- * This is a delegate that does all the PropertyChangeListener
- * support.
- */
- private PropertyChangeSupport propertySupport =
- new PropertyChangeSupport(this);
-
- /**
- * Construct new instance.
- */
- protected PluginSkeleton() {
- super();
- }
-
- /**
- * Gets the name of the plugin.
- *
- * @return String the name of the plugin.
- */
- public String getName() {
- return name;
- }
-
- /**
- * Sets the name of the plugin and notifies
- * PropertyChangeListeners of the change.
- *
- * @param newName the name of the plugin to set.
- */
- public void setName(final String newName) {
- String oldName = this.name;
- this.name = newName;
- propertySupport.firePropertyChange("name", oldName, this.name);
- }
-
- /**
- * Gets the logger repository for this plugin.
- *
- * @return LoggerRepository the logger repository this plugin will affect.
- */
- public LoggerRepository getLoggerRepository() {
- return repository;
- }
-
- /**
- * Sets the logger repository used by this plugin and notifies a
- * relevant PropertyChangeListeners registered. This
- * repository will be used by the plugin functionality.
- *
- * @param repository the logger repository that this plugin should affect.
- */
- public void setLoggerRepository(final LoggerRepository repository) {
- Object oldValue = this.repository;
- this.repository = repository;
- firePropertyChange("loggerRepository", oldValue, this.repository);
- }
-
- /**
- * Returns whether this plugin is Active or not.
- *
- * @return true/false
- */
- public synchronized boolean isActive() {
- return active;
- }
-
- /**
- * Returns true if the plugin has the same name and logger repository as the
- * testPlugin passed in.
- *
- * @param testPlugin The plugin to test equivalency against.
- * @return Returns true if testPlugin is considered to be equivalent.
- */
- public boolean isEquivalent(final Plugin testPlugin) {
- return (repository == testPlugin.getLoggerRepository())
- && ((this.name == null && testPlugin.getName() == null)
- || (this.name != null
- && name.equals(testPlugin.getName())))
- && this.getClass().equals(testPlugin.getClass());
- }
-
- /**
- * Add property change listener.
- *
- * @param listener listener.
- */
- public final void addPropertyChangeListener(
- final PropertyChangeListener listener) {
- propertySupport.addPropertyChangeListener(listener);
- }
-
- /**
- * Add property change listener for one property only.
- *
- * @param propertyName property name.
- * @param listener listener.
- */
- public final void addPropertyChangeListener(
- final String propertyName,
- final PropertyChangeListener listener) {
- propertySupport.addPropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Remove property change listener.
- *
- * @param listener listener.
- */
- public final void removePropertyChangeListener(
- final PropertyChangeListener listener) {
- propertySupport.removePropertyChangeListener(listener);
- }
-
- /**
- * Remove property change listener on a specific property.
- *
- * @param propertyName property name.
- * @param listener listener.
- */
- public final void removePropertyChangeListener(
- final String propertyName,
- final PropertyChangeListener listener) {
- propertySupport.removePropertyChangeListener(propertyName, listener);
- }
-
- /**
- * Fire a property change event to appropriate listeners.
- *
- * @param evt change event.
- */
- protected final void firePropertyChange(
- final PropertyChangeEvent evt) {
- propertySupport.firePropertyChange(evt);
- }
-
- /**
- * Fire property change event to appropriate listeners.
- *
- * @param propertyName property name.
- * @param oldValue old value.
- * @param newValue new value.
- */
- protected final void firePropertyChange(
- final String propertyName,
- final boolean oldValue,
- final boolean newValue) {
- propertySupport.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- /**
- * Fire property change event to appropriate listeners.
- *
- * @param propertyName property name.
- * @param oldValue old value.
- * @param newValue new value.
- */
- protected final void firePropertyChange(
- final String propertyName,
- final int oldValue, final int newValue) {
- propertySupport.firePropertyChange(propertyName, oldValue, newValue);
- }
-
- /**
- * Fire property change event to appropriate listeners.
- *
- * @param propertyName property name.
- * @param oldValue old value.
- * @param newValue new value.
- */
- protected final void firePropertyChange(
- final String propertyName,
- final Object oldValue,
- final Object newValue) {
- propertySupport.firePropertyChange(propertyName, oldValue, newValue);
- }
-}
diff --git a/src/main/java/org/apache/log4j/plugins/Receiver.java b/src/main/java/org/apache/log4j/plugins/Receiver.java
deleted file mode 100644
index 5e54221..0000000
--- a/src/main/java/org/apache/log4j/plugins/Receiver.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.log4j.plugins;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.apache.log4j.chainsaw.ChainsawEventBatchListener;
-import org.apache.log4j.chainsaw.logevents.ChainsawLoggingEvent;
-import org.apache.log4j.spi.LoggingEvent;
-import org.apache.log4j.spi.Thresholdable;
-
-
-/**
- * Defines the base class for Receiver plugins.
- * <p></p>
- * <p>Just as Appenders send logging events outside of the log4j
- * environment (to files, to smtp, to sockets, etc), Receivers bring
- * logging events inside the log4j environment.
- * <p></p>
- * <p>Receivers are meant to support the receiving of
- * remote logging events from another process.
- * <p></p>
- * <p>Receivers can also be used to "import" log messages from other
- * logging packages into the log4j environment.
- * <p></p>
- * <p>Receivers can be configured to post events to a given
- * LoggerRepository.
- * <p></p>
- * <p>Subclasses of Receiver must implement the isActive(),
- * activateOptions(), and shutdown() methods. The doPost() method
- * is provided to standardize the "import" of remote events into
- * the repository.
- *
- * @author Mark Womack
- * @author Ceki Gülcü
- * @author Paul Smith (psmith@apache.org)
- */
-public abstract class Receiver extends PluginSkeleton implements Thresholdable {
- /**
- * Threshold level.
- */
- protected Level thresholdLevel;
-
- private List<ChainsawEventBatchListener> m_eventListeners;
- private WorkQueue m_worker;
- private final Object mutex = new Object();
- private int m_sleepInterval = 1000;
-
- /**
- * Create new instance.
- */
- protected Receiver() {
- super();
- m_eventListeners = new ArrayList<>();
- m_worker = new WorkQueue();
- }
-
- /**
- * Sets the receiver theshold to the given level.
- *
- * @param level The threshold level events must equal or be greater
- * than before further processing can be done.
- */
- public void setThreshold(final Level level) {
- Level oldValue = this.thresholdLevel;
- thresholdLevel = level;
- firePropertyChange("threshold", oldValue, this.thresholdLevel);
- }
-
- /**
- * Gets the current threshold setting of the receiver.
- *
- * @return Level The current threshold level of the receiver.
- */
- public Level getThreshold() {
- return thresholdLevel;
- }
-
- /**
- * Returns true if the given level is equals or greater than the current
- * threshold value of the receiver.
- *
- * @param level The level to test against the receiver threshold.
- * @return boolean True if level is equal or greater than the
- * receiver threshold.
- */
- public boolean isAsSevereAsThreshold(final Level level) {
- return ((thresholdLevel == null)
- || level.isGreaterOrEqual(thresholdLevel));
- }
-
- public void addChainsawEventBatchListener( ChainsawEventBatchListener listen ){
- if( listen != null ){
- m_eventListeners.add( listen );
- }
- }
-
- public void removeEventBatchListener( ChainsawEventBatchListener listen ){
- if( listen != null ){
- m_eventListeners.remove( listen );
- }
- }
-
- public void append(final ChainsawLoggingEvent event){
- m_worker.enqueue(event);
- }
-
- /**
- * Posts the logging event to a logger in the configured logger
- * repository.
- *
- * @param event the log event to post to the local log4j environment.
- */
- public void doPost(final LoggingEvent event) {
- // if event does not meet threshold, exit now
- if (!isAsSevereAsThreshold(event.getLevel())) {
- return;
- }
-
- // get the "local" logger for this event from the
- // configured repository.
- Logger localLogger =
- getLoggerRepository().getLogger(event.getLoggerName());
-
- // if the logger level is greater or equal to the level
- // of the event, use the logger to append the event.
- if (event.getLevel()
- .isGreaterOrEqual(localLogger.getEffectiveLevel())) {
- // call the loggers appenders to process the event
- localLogger.callAppenders(event);
- }
- }
-
- public int getQueueInterval() {
- return m_sleepInterval;
- }
-
- public void setQueueInterval(int interval) {
- m_sleepInterval = interval;
- }
-
- /**
- * Queue of Events are placed in here, which are picked up by an asychronous
- * thread. The WorkerThread looks for events once a second and processes all
- * events accumulated during that time..
- */
- class WorkQueue {
- final ArrayList<ChainsawLoggingEvent> queue = new ArrayList<>();
- Thread workerThread;
-
- protected WorkQueue() {
- workerThread = new WorkerThread();
- workerThread.start();
- }
-
- public final void enqueue(ChainsawLoggingEvent event) {
- synchronized (mutex) {
- queue.add(event);
- mutex.notify();
- }
- }
-
- public final void stop() {
- synchronized (mutex) {
- workerThread.interrupt();
- }
- }
-
- /**
- * The worker thread converts each queued event to a vector and forwards the
- * vector on to the UI.
- */
- private class WorkerThread extends Thread {
- public WorkerThread() {
- super("Chainsaw-WorkerThread");
- setDaemon(true);
- setPriority(Thread.NORM_PRIORITY - 1);
- }
-
- public void run() {
- while (true) {
- List<ChainsawLoggingEvent> innerList = new ArrayList<>();
- synchronized (mutex) {
- try {
- while ((queue.size() == 0)) {
-// setDataRate(0);
- mutex.wait();
- }
- if (queue.size() > 0) {
- innerList.addAll(queue);
- queue.clear();
- }
- } catch (InterruptedException ie) {
- }
- }
-
- for( ChainsawEventBatchListener evtListner : m_eventListeners ){
- evtListner.receiveChainsawEventBatch(innerList);
- }
-
- if (getQueueInterval() > 1000) {
- try {
- synchronized (this) {
- wait(getQueueInterval());
- }
- } catch (InterruptedException ie) {
- }
- } else {
- Thread.yield();
- }
-// if (size == 0) {
-// setDataRate(0.0);
-// } else {
-// long timeEnd = System.currentTimeMillis();
-// long diffInSeconds = (timeEnd - timeStart) / 1000;
-// double rate = (((double) size) / diffInSeconds);
-// setDataRate(rate);
-// }
- }
- }
- }
- }
-}
diff --git a/src/main/java/org/apache/log4j/spi/LoggerRepositoryEx.java b/src/main/java/org/apache/log4j/spi/LoggerRepositoryEx.java
index 5967e21..ee8d430 100644
--- a/src/main/java/org/apache/log4j/spi/LoggerRepositoryEx.java
+++ b/src/main/java/org/apache/log4j/spi/LoggerRepositoryEx.java
@@ -20,7 +20,6 @@
import org.apache.log4j.Appender;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
-import org.apache.log4j.plugins.PluginRegistry;
import org.apache.log4j.scheduler.Scheduler;
import java.util.List;
@@ -132,7 +131,7 @@
*
* @return plug in registry.
*/
- PluginRegistry getPluginRegistry();
+// PluginRegistry getPluginRegistry();
/**
* Return the {@link Scheduler} for this LoggerRepository.
diff --git a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
index 773c644..52f05e2 100644
--- a/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
+++ b/src/main/java/org/apache/log4j/varia/LogFilePatternReceiver.java
@@ -18,7 +18,6 @@
package org.apache.log4j.varia;
import org.apache.log4j.helpers.Constants;
-import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.rule.ExpressionRule;
import org.apache.log4j.rule.Rule;
import org.apache.log4j.spi.ThrowableInformation;
diff --git a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
index 8011c9d..4d7ee8b 100644
--- a/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
+++ b/src/main/java/org/apache/log4j/xml/LogFileXMLReceiver.java
@@ -18,7 +18,6 @@
package org.apache.log4j.xml;
import org.apache.log4j.helpers.Constants;
-import org.apache.log4j.plugins.Receiver;
import org.apache.log4j.rule.ExpressionRule;
import org.apache.log4j.rule.Rule;
import org.apache.log4j.spi.Decoder;