diff options
author | Harald Musum <musum@yahoo-inc.com> | 2017-05-24 08:20:38 +0200 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2017-05-24 08:20:38 +0200 |
commit | 08f088a3b8ec618b0d94ea13d6639bc9ff044ff6 (patch) | |
tree | daa05b4ef4855022f4b35101b0c46b44a44ce644 /logserver/src/main | |
parent | 0e84e9bbaf713ee446af28e029bfc0dbec367df3 (diff) |
Reindent and minor cleanups, no functional changes
Diffstat (limited to 'logserver/src/main')
37 files changed, 559 insertions, 600 deletions
diff --git a/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java index 6d215b9e831..2b49abd1ff4 100644 --- a/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/AbstractPluginLoader.java @@ -10,37 +10,37 @@ import java.util.logging.Logger; /** * TODO: describe class * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ public abstract class AbstractPluginLoader implements PluginLoader { - private static final Logger log = Logger.getLogger(AbstractPluginLoader.class.getName()); + private static final Logger log = Logger.getLogger(AbstractPluginLoader.class.getName()); - public abstract void loadPlugins(); + public abstract void loadPlugins(); - protected void loadFromClass (Class<? extends Plugin> pluginClass) { - Plugin plugin; - try { - plugin = (Plugin)pluginClass.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - log.log(LogLevel.ERROR, pluginClass.getName() + ": load failed: " + e); - throw new RuntimeException(e); - } + protected void loadFromClass(Class<? extends Plugin> pluginClass) { + Plugin plugin; + try { + plugin = (Plugin) pluginClass.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + log.log(LogLevel.ERROR, pluginClass.getName() + ": load failed: " + e); + throw new RuntimeException(e); + } String pname = plugin.getPluginName(); - String prefix = Server.APPNAME + "." + pname + "."; - SystemPropertyConfig config = new SystemPropertyConfig(prefix); - String enable = config.get("enable", "true"); - - if (!enable.equals("true")) { - log.log(LogLevel.INFO, pname + ": plugin disabled by config"); - return; - } - - try { - plugin.initPlugin(config); - log.log(LogLevel.DEBUG, pname + ": plugin loaded"); - } catch (Exception e) { + String prefix = Server.APPNAME + "." + pname + "."; + SystemPropertyConfig config = new SystemPropertyConfig(prefix); + String enable = config.get("enable", "true"); + + if (! enable.equals("true")) { + log.log(LogLevel.INFO, pname + ": plugin disabled by config"); + return; + } + + try { + plugin.initPlugin(config); + log.log(LogLevel.DEBUG, pname + ": plugin loaded"); + } catch (Exception e) { log.log(LogLevel.ERROR, pname + ": init failed", e); } - } + } } diff --git a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java index f2ef60267fe..5f8230bd246 100644 --- a/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/BuiltinPluginLoader.java @@ -12,7 +12,7 @@ import com.yahoo.logserver.handlers.replicator.ReplicatorPlugin; /** * Load a set of builtin plugins * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ public class BuiltinPluginLoader extends AbstractPluginLoader { private static final Logger log = Logger.getLogger(BuiltinPluginLoader.class.getName()); diff --git a/logserver/src/main/java/com/yahoo/logserver/Flusher.java b/logserver/src/main/java/com/yahoo/logserver/Flusher.java index ee2b317f573..19b06c15f85 100644 --- a/logserver/src/main/java/com/yahoo/logserver/Flusher.java +++ b/logserver/src/main/java/com/yahoo/logserver/Flusher.java @@ -11,7 +11,7 @@ import com.yahoo.log.LogLevel; import com.yahoo.logserver.handlers.LogHandler; /** - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class Flusher extends Thread { private static final Logger log = Logger.getLogger(Flusher.class.getName()); @@ -29,7 +29,7 @@ public class Flusher extends Thread { } public static synchronized void register(LogHandler logHandler) { - logHandlers.add(new WeakReference<LogHandler>(logHandler)); + logHandlers.add(new WeakReference<>(logHandler)); } public synchronized void run() { diff --git a/logserver/src/main/java/com/yahoo/logserver/LogDispatcher.java b/logserver/src/main/java/com/yahoo/logserver/LogDispatcher.java index 6de34d4a899..f7828b4dc9f 100644 --- a/logserver/src/main/java/com/yahoo/logserver/LogDispatcher.java +++ b/logserver/src/main/java/com/yahoo/logserver/LogDispatcher.java @@ -15,24 +15,22 @@ import com.yahoo.logserver.handlers.LogHandler; * This is the central point from which LogMessage objects are * propagated throughout the logserver architecture. * - * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ -public class LogDispatcher implements LogHandler, SelectLoopHook -{ +public class LogDispatcher implements LogHandler, SelectLoopHook { private static final Logger log = Logger.getLogger(LogDispatcher.class.getName()); - private final List<LogHandler> handlers = new ArrayList<LogHandler>(); - private int messageCount = 0; + private final List<LogHandler> handlers = new ArrayList<>(); + private int messageCount = 0; private boolean hasBeenShutDown = false; private boolean batchedMode = false; private final int batchSize = 5000; private List<LogMessage> currentBatchList; private int roundCount = 0; @SuppressWarnings("unused") - private int lastRoundCount = 0; + private int lastRoundCount = 0; - public LogDispatcher () { + public LogDispatcher() { } /** @@ -43,7 +41,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook * @param msg The LogMessage instance we wish to dispatch to the * plugins */ - public synchronized void handle (LogMessage msg) { + public synchronized void handle(LogMessage msg) { if (msg == null) { throw new NullPointerException("LogMessage was null"); } @@ -51,14 +49,14 @@ public class LogDispatcher implements LogHandler, SelectLoopHook if (batchedMode) { addToBatch(msg); } else { - for (LogHandler h : handlers) { + for (LogHandler h : handlers) { h.handle(msg); } } messageCount++; } - private void addToBatch (LogMessage msg) { + private void addToBatch(LogMessage msg) { if (currentBatchList == null) { currentBatchList = new ArrayList<LogMessage>(batchSize); currentBatchList.add(msg); @@ -72,7 +70,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook } } - private void flushBatch () { + private void flushBatch() { if (currentBatchList == null) { return; } @@ -84,7 +82,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook } - public void handle (List<LogMessage> messages) { + public void handle(List<LogMessage> messages) { throw new IllegalStateException("method not supported"); } @@ -95,11 +93,11 @@ public class LogDispatcher implements LogHandler, SelectLoopHook * dispatcher will not enqueue single LogMessage instances * but lists of same. */ - public void setBatchedMode (boolean batchedMode) { + public void setBatchedMode(boolean batchedMode) { this.batchedMode = batchedMode; } - public synchronized void flush () { + public synchronized void flush() { if (batchedMode) { flushBatch(); } @@ -112,7 +110,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook } } - public synchronized void close () { + public synchronized void close() { if (hasBeenShutDown) { throw new IllegalStateException("Shutdown already in progress"); } @@ -121,7 +119,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook for (LogHandler ht : handlers) { if (ht instanceof Thread) { log.fine("Stopping " + ht); - ((Thread)ht).interrupt(); + ((Thread) ht).interrupt(); } } handlers.clear(); @@ -133,15 +131,14 @@ public class LogDispatcher implements LogHandler, SelectLoopHook * Register handler thread with the dispatcher. If the handler * thread has already been registered, we log a warning and * just do nothing. - * - * <P> + * <p> + * <p> * If the thread is not alive it will be start()'ed. - * */ - public synchronized void registerLogHandler (LogHandler ht) { + public synchronized void registerLogHandler(LogHandler ht) { if (hasBeenShutDown) { - throw new IllegalStateException("Tried to register LogHandler on"+ - " LogDispatcher which was shut down"); + throw new IllegalStateException("Tried to register LogHandler on" + + " LogDispatcher which was shut down"); } if (handlers.contains(ht)) { @@ -150,8 +147,8 @@ public class LogDispatcher implements LogHandler, SelectLoopHook } handlers.add(ht); - if ((ht instanceof Thread) && (! ((Thread)ht).isAlive())) { - ((Thread)ht).start(); + if ((ht instanceof Thread) && (! ((Thread) ht).isAlive())) { + ((Thread) ht).start(); } log.fine("Added (and possibly started) LogHandler " + ht); @@ -160,7 +157,7 @@ public class LogDispatcher implements LogHandler, SelectLoopHook /** * Make defensive copy and return array of LogHandlers. */ - public LogHandler[] getLogHandlers () { + public LogHandler[] getLogHandlers() { LogHandler[] h = new LogHandler[handlers.size()]; return handlers.toArray(h); } @@ -170,14 +167,14 @@ public class LogDispatcher implements LogHandler, SelectLoopHook * * @return Returns the number of messages that we have seen. */ - public synchronized int getMessageCount () { + public synchronized int getMessageCount() { return messageCount; } /** * Hook which is called when the select loop has finished. */ - public void selectLoopHook (boolean before) { + public void selectLoopHook(boolean before) { if (batchedMode) { flushBatch(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/PluginLoader.java b/logserver/src/main/java/com/yahoo/logserver/PluginLoader.java index 2357eefb804..6347226f5de 100644 --- a/logserver/src/main/java/com/yahoo/logserver/PluginLoader.java +++ b/logserver/src/main/java/com/yahoo/logserver/PluginLoader.java @@ -7,16 +7,15 @@ package com.yahoo.logserver; * all of its knows plugins. In addition, if a plugin loader's * canReload() method returns <code>true</code>, plugins may be loaded * again after they are unloaded. - * + * <p> * <p> Plugins loaded through such reload-capable plugin loaders may * be upgraded without restarting the server. * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ -public interface PluginLoader -{ +public interface PluginLoader { /** * Load all plugins known to this loader. */ - public void loadPlugins(); + void loadPlugins(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/Server.java b/logserver/src/main/java/com/yahoo/logserver/Server.java index d09ae305dc2..dbfd7e028c1 100644 --- a/logserver/src/main/java/com/yahoo/logserver/Server.java +++ b/logserver/src/main/java/com/yahoo/logserver/Server.java @@ -11,6 +11,7 @@ import com.yahoo.logserver.handlers.LogHandler; import com.yahoo.logserver.net.LogConnectionFactory; import com.yahoo.logserver.net.control.Levels; import com.yahoo.system.CatchSigTerm; + import java.io.IOException; import java.util.HashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -22,21 +23,18 @@ import java.util.logging.Logger; * no runtime configuration; the server starts up, binds port 19081 * and loads builtin plugins. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Bjorn Borud + * @author Stig Bakken */ public class Server implements Runnable { private final AtomicBoolean signalCaught = new AtomicBoolean(false); - public static final String APPNAME = "logserver"; + static final String APPNAME = "logserver"; private static final Server instance = new Server(); private static final Logger log = Logger.getLogger(Server.class.getName()); - private static final FatalErrorHandler fatalErrorHandler = - new FatalErrorHandler(); - private static final HashMap<String,HandlerThread> handlerThreads = - new HashMap<String,HandlerThread>(); - private static final HashMap<LogHandler,String> threadNameForHandler = - new HashMap<LogHandler,String>(); + private static final FatalErrorHandler fatalErrorHandler = new FatalErrorHandler(); + private static final HashMap<String, HandlerThread> handlerThreads = new HashMap<>(); + private static final HashMap<LogHandler, String> threadNameForHandler = new HashMap<>(); static { LogSetup.initVespaLogging("ADM"); @@ -44,7 +42,7 @@ public class Server implements Runnable { // the port is a String because we want to use it as the default // value of a System.getProperty(). - private static final String LISTEN_PORT = "19081"; + private static final String LISTEN_PORT = "19081"; private int listenPort; private Listener listener; @@ -55,17 +53,17 @@ public class Server implements Runnable { /** * Server constructor */ - private Server () { + private Server() { dispatch = new LogDispatcher(); dispatch.setBatchedMode(true); isInitialized = false; } - public static Server getInstance () { + public static Server getInstance() { return instance; } - private HandlerThread getHandlerThread (String threadName) { + private HandlerThread getHandlerThread(String threadName) { threadName += " handler thread"; HandlerThread ht = handlerThreads.get(threadName); if (ht == null) { @@ -77,33 +75,35 @@ public class Server implements Runnable { return ht; } - public void registerPluginLoader (PluginLoader loader) { + public void registerPluginLoader(PluginLoader loader) { loader.loadPlugins(); } - public void registerLogHandler (LogHandler lh, String threadName) { + public void registerLogHandler(LogHandler lh, String threadName) { HandlerThread ht = getHandlerThread(threadName); ht.registerHandler(lh); threadNameForHandler.put(lh, threadName); } - public void unregisterLogHandler (LogHandler lh) { + public void unregisterLogHandler(LogHandler lh) { String threadName = threadNameForHandler.get(lh); unregisterLogHandler(lh, threadName); } - public void unregisterLogHandler (LogHandler lh, String threadName) { + public void unregisterLogHandler(LogHandler lh, String threadName) { HandlerThread ht = getHandlerThread(threadName); ht.unregisterHandler(lh); threadNameForHandler.remove(lh); } - public void registerFlusher (LogHandler lh) { + public void registerFlusher(LogHandler lh) { Flusher.register(lh); } - /** Included only for consistency */ - public void unregisterFlusher (LogHandler lh) { + /** + * Included only for consistency + */ + public void unregisterFlusher(LogHandler lh) { /* NOP */ } @@ -113,7 +113,7 @@ public class Server implements Runnable { * @param listenPort The port on which the logserver accepts log * messages. */ - public void initialize (int listenPort) { + public void initialize(int listenPort) { if (isInitialized) { throw new IllegalStateException(APPNAME + " already initialized"); } @@ -148,18 +148,18 @@ public class Server implements Runnable { try { listener.join(); log.fine("listener thread exited"); - } - catch (InterruptedException e) { + } catch (InterruptedException e) { log.log(Level.WARNING, "Server was interrupted", e); } } + private void setupSigTermHandler() { CatchSigTerm.setup(signalCaught); // catch termination signal } private void waitForShutdown() { synchronized (signalCaught) { - while (!signalCaught.get()) { + while (! signalCaught.get()) { try { signalCaught.wait(); } catch (InterruptedException e) { @@ -173,24 +173,20 @@ public class Server implements Runnable { System.exit(0); } - public static HashMap<LogHandler, String> threadNameForHandler() { + static HashMap<LogHandler, String> threadNameForHandler() { return threadNameForHandler; } - - public static void help () { + + static void help() { System.out.println(); System.out.println("System properties:"); System.out.println(" - " + APPNAME + ".listenport (" + LISTEN_PORT + ")"); - System.out.println(" - " + APPNAME + ".queue.size (" - + HandlerThread.DEFAULT_QUEUESIZE - + ")"); - System.out.println(" - logserver.default.loglevels (" - + (new Levels()).toString() - + ")"); + System.out.println(" - " + APPNAME + ".queue.size (" + HandlerThread.DEFAULT_QUEUESIZE + ")"); + System.out.println(" - logserver.default.loglevels (" + (new Levels()).toString() + ")"); System.out.println(); } - public static void main (String[] args) { + public static void main(String[] args) { if (args.length > 0 && "-help".equals(args[0])) { help(); System.exit(0); diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/LevelFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/LevelFilter.java index b229af522ab..1d4a817b4c4 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/LevelFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/LevelFilter.java @@ -2,29 +2,30 @@ package com.yahoo.logserver.filter; import com.yahoo.log.LogMessage; + import java.util.Set; import java.util.HashSet; import java.util.logging.Level; + /** - * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class LevelFilter implements LogFilter { private final Set<Level> levels = new HashSet<Level>(); - public void addLevel (Level level) { + public void addLevel(Level level) { levels.add(level); } - public void removeLevel (Level level) { + public void removeLevel(Level level) { levels.remove(level); } - public boolean isLoggable (LogMessage msg) { + public boolean isLoggable(LogMessage msg) { return levels.contains(msg.getLevel()); } - public String description () { + public String description() { return "Match specific log levels"; } } diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/LogFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/LogFilter.java index 8c4c3911c9e..51bd9adc03e 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/LogFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/LogFilter.java @@ -9,15 +9,15 @@ import com.yahoo.log.LogMessage; * <b>stateless/immutable if possible so filters can be * shared</b>. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public interface LogFilter { /** * Determine if this log message is loggable. * * @param msg The log message - * */ - public boolean isLoggable (LogMessage msg); - public String description (); + public boolean isLoggable(LogMessage msg); + + public String description(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/LogFilterManager.java b/logserver/src/main/java/com/yahoo/logserver/filter/LogFilterManager.java index a68aff86e10..d608c7871f0 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/LogFilterManager.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/LogFilterManager.java @@ -12,9 +12,8 @@ import com.yahoo.log.LogLevel; * is truly global. It also manages the LogFilter namespace * to ensure that system-defined filters are not tampered with. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ - public class LogFilterManager { private static final LogFilterManager instance; @@ -30,20 +29,20 @@ public class LogFilterManager { instance.addLogFilterInternal("system.mute", MuteFilter.getInstance()); } - private final Map<String,LogFilter> filters = new HashMap<String,LogFilter>(); + private final Map<String, LogFilter> filters = new HashMap<String, LogFilter>(); - private LogFilterManager () { + private LogFilterManager() { } /** * Public interface for adding a name-logfilter mapping. If * there exists a mapping already the old mapping is replaced * with the new mapping. - * + * <p> * If the name is within the namespace reserved for internal * built-in filters it will throw an exception */ - public static void addLogFilter (String name, LogFilter filter) { + public static void addLogFilter(String name, LogFilter filter) { if (filter == null) { throw new NullPointerException("filter cannot be null"); } @@ -66,9 +65,9 @@ public class LogFilterManager { * * @param name The name of the LogFilter to be looked up. * @return Returns the LogFilter associated with this name or - * <code>null</code> if not found. + * <code>null</code> if not found. */ - public static LogFilter getLogFilter (String name) { + public static LogFilter getLogFilter(String name) { return instance.filters.get(name); } @@ -77,12 +76,11 @@ public class LogFilterManager { * Get the names of the defined filters. * * @return Returns an array containing the names of filters that - * have been registered. - * + * have been registered. */ - public static String[] getFilterNames () { - synchronized(instance.filters) { - String[] filterNames= new String[instance.filters.keySet().size()]; + public static String[] getFilterNames() { + synchronized (instance.filters) { + String[] filterNames = new String[instance.filters.keySet().size()]; instance.filters.keySet().toArray(filterNames); return filterNames; } @@ -93,7 +91,7 @@ public class LogFilterManager { * LogFilter mappings but doesn't perform any of the checks * performed by the public method for adding mappings. */ - private void addLogFilterInternal (String name, LogFilter filter) { + private void addLogFilterInternal(String name, LogFilter filter) { filters.put(name, filter); } } diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/MetricsFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/MetricsFilter.java index fa626de1d08..3f9ae20dc3b 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/MetricsFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/MetricsFilter.java @@ -15,7 +15,7 @@ import com.yahoo.log.LogMessage; * This filter matches events that are used for monitoring, specificly * the Count and Value events. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class MetricsFilter implements LogFilter { public boolean isLoggable (LogMessage msg) { diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/MuteFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/MuteFilter.java index a360cba6b8f..45071b7344c 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/MuteFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/MuteFilter.java @@ -6,7 +6,7 @@ import com.yahoo.log.LogMessage; /** * Filter which always returns false. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class MuteFilter implements LogFilter { private static final MuteFilter instance = new MuteFilter(); @@ -14,17 +14,17 @@ public class MuteFilter implements LogFilter { /** * Singleton, private constructor. */ - private MuteFilter () {} + private MuteFilter() {} public static MuteFilter getInstance() { return instance; } - public boolean isLoggable (LogMessage msg) { + public boolean isLoggable(LogMessage msg) { return false; } - public String description () { + public String description() { return "Matches no messages. Mute."; } } diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/NoMetricsFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/NoMetricsFilter.java index 5621ea60d0c..4185f318ced 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/NoMetricsFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/NoMetricsFilter.java @@ -6,10 +6,10 @@ import com.yahoo.log.LogMessage; /** * This filter is the complement of MetricsFilter * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class NoMetricsFilter implements LogFilter { - final MetricsFilter filter = new MetricsFilter(); + private final MetricsFilter filter = new MetricsFilter(); public boolean isLoggable (LogMessage msg) { return (! filter.isLoggable(msg)); diff --git a/logserver/src/main/java/com/yahoo/logserver/filter/NullFilter.java b/logserver/src/main/java/com/yahoo/logserver/filter/NullFilter.java index a62b2f7171b..9698a02f4f8 100644 --- a/logserver/src/main/java/com/yahoo/logserver/filter/NullFilter.java +++ b/logserver/src/main/java/com/yahoo/logserver/filter/NullFilter.java @@ -4,16 +4,14 @@ package com.yahoo.logserver.filter; import com.yahoo.log.LogMessage; /** - * - * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class NullFilter implements LogFilter { - public boolean isLoggable (LogMessage msg) { + public boolean isLoggable(LogMessage msg) { return true; } - public String description () { + public String description() { return "Match all log messages"; } } diff --git a/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatter.java b/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatter.java index ae217634e1c..ef42a915e24 100644 --- a/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatter.java +++ b/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatter.java @@ -10,19 +10,18 @@ import com.yahoo.log.LogMessage; * shared</b>. If it does have state it must not prevent * concurrent use. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public interface LogFormatter { /** * Format log message as a string. * * @param msg The log message - * */ - public String format (LogMessage msg); + String format(LogMessage msg); /** * Returns a textual description of the formatter */ - public String description (); + String description(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatterManager.java b/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatterManager.java index fb81b35dcf0..7fe6c6d17d5 100644 --- a/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatterManager.java +++ b/logserver/src/main/java/com/yahoo/logserver/formatter/LogFormatterManager.java @@ -13,30 +13,30 @@ import java.util.Map; * This singleton class implements a central registry of LogFormatter * instances. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class LogFormatterManager { private static final LogFormatterManager instance; + static { instance = new LogFormatterManager(); instance.addLogFormatterInternal("system.textformatter", new TextFormatter()); instance.addLogFormatterInternal("system.nullformatter", new NullFormatter()); } - private final Map<String,LogFormatter> logFormatters = - new HashMap<String,LogFormatter>(); + private final Map<String, LogFormatter> logFormatters = new HashMap<String, LogFormatter>(); - private LogFormatterManager () {} + private LogFormatterManager() {} /** * LogFormatter lookup function * * @param name The name of the LogFormatter to be looked up. * @return Returns the LogFormatter associated with this name or - * <code>null</code> if not found. + * <code>null</code> if not found. */ - public static LogFormatter getLogFormatter (String name) { - synchronized(instance.logFormatters) { + public static LogFormatter getLogFormatter(String name) { + synchronized (instance.logFormatters) { return instance.logFormatters.get(name); } } @@ -45,11 +45,10 @@ public class LogFormatterManager { * Get the names of the defined formatters. * * @return Returns an array containing the names of formatters that - * have been registered. - * + * have been registered. */ - public static String[] getFormatterNames () { - synchronized(instance.logFormatters) { + public static String[] getFormatterNames() { + synchronized (instance.logFormatters) { String[] formatterNames = new String[instance.logFormatters.keySet().size()]; instance.logFormatters.keySet().toArray(formatterNames); return formatterNames; @@ -61,8 +60,8 @@ public class LogFormatterManager { * LogFormatter mappings but doesn't perform any of the checks * performed by the public method for adding mappings. */ - private void addLogFormatterInternal (String name, LogFormatter logFormatter) { - synchronized(logFormatters) { + private void addLogFormatterInternal(String name, LogFormatter logFormatter) { + synchronized (logFormatters) { logFormatters.put(name, logFormatter); } } diff --git a/logserver/src/main/java/com/yahoo/logserver/formatter/NullFormatter.java b/logserver/src/main/java/com/yahoo/logserver/formatter/NullFormatter.java index 646ab0ce423..4bff6454239 100644 --- a/logserver/src/main/java/com/yahoo/logserver/formatter/NullFormatter.java +++ b/logserver/src/main/java/com/yahoo/logserver/formatter/NullFormatter.java @@ -14,11 +14,11 @@ import com.yahoo.log.LogMessage; * pointless and silly, but we include it for symmetry... * or completeness....or...whatever. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class NullFormatter implements LogFormatter { - public String format (LogMessage msg) { + public String format(LogMessage msg) { return msg.toString(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/formatter/TextFormatter.java b/logserver/src/main/java/com/yahoo/logserver/formatter/TextFormatter.java index d94dcceaf29..ff1a4742e67 100644 --- a/logserver/src/main/java/com/yahoo/logserver/formatter/TextFormatter.java +++ b/logserver/src/main/java/com/yahoo/logserver/formatter/TextFormatter.java @@ -15,7 +15,7 @@ import com.yahoo.log.LogMessage; /** * Creates human-readable text representation of log message. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class TextFormatter implements LogFormatter { static final SimpleDateFormat dateFormat; @@ -25,7 +25,7 @@ public class TextFormatter implements LogFormatter { dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); } - public String format (LogMessage msg) { + public String format(LogMessage msg) { StringBuffer sbuf = new StringBuffer(150); sbuf.append(dateFormat.format(new Date(msg.getTime()))) .append(" ") diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/AbstractLogHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/AbstractLogHandler.java index f498568e7f2..a2da987f802 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/AbstractLogHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/AbstractLogHandler.java @@ -1,7 +1,6 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.logserver.handlers; -import java.io.PrintWriter; import java.util.Iterator; import java.util.List; @@ -14,11 +13,11 @@ import com.yahoo.logserver.filter.LogFilter; * of quite a bit of tedious work for you (log message counting, * handling of lists of messages versus single instances etc). * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public abstract class AbstractLogHandler implements LogHandler { - private long count = 0; - private long filtered = 0; + private long count = 0; + private long filtered = 0; private LogFilter filter = null; private String name; @@ -29,7 +28,7 @@ public abstract class AbstractLogHandler implements LogHandler { * * @param msg The message we are about to handle */ - public final void handle (LogMessage msg) { + public final void handle(LogMessage msg) { if ((filter != null) && (! filter.isLoggable(msg))) { filtered++; return; @@ -45,7 +44,7 @@ public abstract class AbstractLogHandler implements LogHandler { * * @param messages List of LogMessage instances. */ - public final void handle (List<LogMessage> messages) { + public final void handle(List<LogMessage> messages) { Iterator<LogMessage> it = messages.iterator(); while (it.hasNext()) { handle(it.next()); @@ -58,17 +57,16 @@ public abstract class AbstractLogHandler implements LogHandler { * off. * * @param filter The filter to be used for this handler - * */ - public void setLogFilter (LogFilter filter) { + public void setLogFilter(LogFilter filter) { this.filter = filter; } /** * @return Returns the log filter for this handler or - * <code>null</code> if no filter is in effect. + * <code>null</code> if no filter is in effect. */ - public LogFilter getLogFilter () { + public LogFilter getLogFilter() { return filter; } @@ -78,23 +76,23 @@ public abstract class AbstractLogHandler implements LogHandler { * * @return Returns the number of times doHandle has been called. */ - public final long getCount () { + public final long getCount() { return count; } - public String getName () { + public String getName() { if (name == null) { String n = this.getClass().getName(); int x = n.lastIndexOf('.'); - if (x != -1) { - n = n.substring(x+1); + if (x != - 1) { + n = n.substring(x + 1); } name = n; } return name; } - public void setName (String name) { + public void setName(String name) { this.name = name; } @@ -102,8 +100,8 @@ public abstract class AbstractLogHandler implements LogHandler { * The method which actually handles the log message and * does something to it. This is the one you wish to * override when you write a new handler. - * - * <P> + * <p> + * <p> * <em> * If your handle method is slow you should document this fact * so that decisions can be made with regard to configuration. @@ -111,24 +109,24 @@ public abstract class AbstractLogHandler implements LogHandler { * * @param msg The LogMessage we are about to handle * @return Returns <code>true</code> if the message was - * handled and <code>false</code> if it was ignored. + * handled and <code>false</code> if it was ignored. */ - public abstract boolean doHandle (LogMessage msg); + public abstract boolean doHandle(LogMessage msg); /** * Flush LogMessages. */ - public abstract void flush (); + public abstract void flush(); /** * Close this loghandler. After a loghandler is closed calling * the #handle() has undefined behavior, but it should be assumed * that log messages will be silently dropped. - * - * <P> + * <p> + * <p> * #close() usually implies #flush() but don't bet on it. */ - public abstract void close (); + public abstract void close(); /** * Force implementation of (hopefully meaningful) toString() diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/HandlerThread.java b/logserver/src/main/java/com/yahoo/logserver/handlers/HandlerThread.java index 15c44d6e197..d6e8f30298a 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/HandlerThread.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/HandlerThread.java @@ -18,11 +18,10 @@ import java.util.concurrent.LinkedBlockingQueue; * thread. The purpose of this handler is to isolate execution * of handlers from the main server IO threads. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ -public class HandlerThread extends Thread implements LogHandler -{ +public class HandlerThread extends Thread implements LogHandler { private static final Logger log = Logger.getLogger(HandlerThread.class.getName()); // default queue size is 200 @@ -49,16 +48,19 @@ public class HandlerThread extends Thread implements LogHandler private static class ItemOrList { final LogMessage item; final List<LogMessage> list; + ItemOrList(LogMessage i) { this.item = i; this.list = null; } + ItemOrList(List<LogMessage> l) { this.item = null; this.list = l; } + public String toString() { - return "item="+item+", list="+list; + return "item=" + item + ", list=" + list; } } @@ -66,15 +68,15 @@ public class HandlerThread extends Thread implements LogHandler private final List<LogHandler> handlers = new ArrayList<LogHandler>(); private long count; @SuppressWarnings("unused") - private long droppedCount = 0; + private long droppedCount = 0; @SuppressWarnings("unused") - private boolean queueWasFull = false; + private boolean queueWasFull = false; @SuppressWarnings("unused") - private long lastDropLogMessage = 0; + private long lastDropLogMessage = 0; @SuppressWarnings("unused") - private long lastAcceptingLogMessage = 0; + private long lastAcceptingLogMessage = 0; - public HandlerThread (String name) { + public HandlerThread(String name) { super(name); queue = new LinkedBlockingQueue<>(queueSize); log.log(LogLevel.CONFIG, "logserver.queue.size=" + queueSize); @@ -85,7 +87,7 @@ public class HandlerThread extends Thread implements LogHandler * * @param f The FatalErrorHandler instance to be registered */ - public synchronized void setFatalErrorHandler (FatalErrorHandler f) { + public synchronized void setFatalErrorHandler(FatalErrorHandler f) { fatalErrorHandler = f; } @@ -95,7 +97,7 @@ public class HandlerThread extends Thread implements LogHandler * @param message The LogMessage we wish to dispatch to this * handler thread. */ - public void handle (LogMessage message) { + public void handle(LogMessage message) { handleInternal(new ItemOrList(message)); } @@ -103,24 +105,23 @@ public class HandlerThread extends Thread implements LogHandler * Called by the LogDispatch to put a list of LogMessage * instances onto the Queue. */ - public void handle (List<LogMessage> messages) { + public void handle(List<LogMessage> messages) { handleInternal(new ItemOrList(messages)); } - private void handleInternal (ItemOrList o) { + private void handleInternal(ItemOrList o) { boolean done = false; while (! done) { try { queue.put(o); done = true; - } - catch (InterruptedException e) { + } catch (InterruptedException e) { // NOP } } } - public void flush () { + public void flush() { Iterator<LogHandler> it = handlers.iterator(); while (it.hasNext()) { LogHandler handler = it.next(); @@ -128,7 +129,7 @@ public class HandlerThread extends Thread implements LogHandler } } - public void close () { + public void close() { Iterator<LogHandler> it = handlers.iterator(); while (it.hasNext()) { LogHandler handler = it.next(); @@ -136,14 +137,14 @@ public class HandlerThread extends Thread implements LogHandler } } - public long getCount () { + public long getCount() { return count; } /** * Register a LogHandler */ - public synchronized void registerHandler (LogHandler handler) { + public synchronized void registerHandler(LogHandler handler) { log.fine("Registering handler " + handler); handlers.add(handler); } @@ -151,15 +152,15 @@ public class HandlerThread extends Thread implements LogHandler /** * Unregister a Loghandler */ - public synchronized void unregisterHandler (LogHandler handler) { - int idx; - while ((idx = handlers.indexOf(handler)) != -1) { - try { - handlers.remove(idx); - } catch (IndexOutOfBoundsException e) { - throw new RuntimeException(e); - } - } + public synchronized void unregisterHandler(LogHandler handler) { + int idx; + while ((idx = handlers.indexOf(handler)) != - 1) { + try { + handlers.remove(idx); + } catch (IndexOutOfBoundsException e) { + throw new RuntimeException(e); + } + } } /** @@ -167,7 +168,7 @@ public class HandlerThread extends Thread implements LogHandler * * @return Returns an array of the handlers registered */ - public LogHandler[] getHandlers () { + public LogHandler[] getHandlers() { LogHandler[] h = new LogHandler[handlers.size()]; return handlers.toArray(h); } @@ -177,7 +178,7 @@ public class HandlerThread extends Thread implements LogHandler * Return the underlying queue used to send LogMessage instances * to this handler thread. */ - public BlockingQueue<ItemOrList> getQueue () { + public BlockingQueue<ItemOrList> getQueue() { return queue; } @@ -185,15 +186,15 @@ public class HandlerThread extends Thread implements LogHandler * Consume messages from the incoming queue and hand * them off to the handlers. */ - public void run () { + public void run() { if (queue == null) { throw new NullPointerException("channel is not allowed to be null"); } - // TODO: Make the legmessage elements some kind of composite structure to handle both individual messages and lists uniformly. + // TODO: Make the legmessage elements some kind of composite structure to handle both individual messages and lists uniformly. List<ItemOrList> drainList = new ArrayList<ItemOrList>(queue.size() + 1); try { - for (;;) { + for (; ; ) { drainList.clear(); // block in take(), then see if there is more // to be had with drainTo() @@ -206,15 +207,15 @@ public class HandlerThread extends Thread implements LogHandler // handle them accordingly. if (o.item != null) { - for (LogHandler handler : handlers) { + for (LogHandler handler : handlers) { handler.handle(o.item); } } else if (o.list != null) { - for (LogHandler handler : handlers) { + for (LogHandler handler : handlers) { handler.handle(o.list); } } else { - throw new IllegalArgumentException("not LogMessage or List: " + o); + throw new IllegalArgumentException("not LogMessage or List: " + o); } count++; } @@ -227,8 +228,8 @@ public class HandlerThread extends Thread implements LogHandler } } finally { log.fine("Handler thread " - + getName() - + " exiting, removing handlers"); + + getName() + + " exiting, removing handlers"); for (LogHandler handler : handlers) { log.fine("Removing handler " + handler); handler.close(); diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/LogHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/LogHandler.java index 6fb009fcda2..c613a04b75b 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/LogHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/LogHandler.java @@ -2,13 +2,14 @@ package com.yahoo.logserver.handlers; import com.yahoo.log.LogMessage; + import java.util.List; /** * The LogHandler interface defines the interface used for all * parts of the logserver which consume log messages. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public interface LogHandler { /** @@ -19,7 +20,7 @@ public interface LogHandler { * * @param msg The log message */ - public void handle (LogMessage msg); + void handle(LogMessage msg); /** * Instead of taking a single log message, this method can take @@ -27,25 +28,24 @@ public interface LogHandler { * order needs to be preserved. * * @param messages a List containing zero or more LogMessage - * instances. + * instances. */ - public void handle (List<LogMessage> messages); + void handle(List<LogMessage> messages); /** * Any log messages received so far should be dealt with * before this method returns -- within reason ,of course. * (<em>Within reason is loosely defined to be 2-5 seconds</em>) */ - public void flush (); + void flush(); /** * Signals that we want to end logging and should close down the - * unerlying logging mechanism -- whatever this maps to + * underlying logging mechanism -- whatever this maps to * semantically for the underlying implementation. After this * method has been called it is considered an error to submit more * log messages to the handle() methods and an implementation * may elect to throw runtime exceptions. - * */ - public void close (); + void close(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java index 06bf5183005..d2a3d566c38 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverHandler.java @@ -24,56 +24,65 @@ import com.yahoo.logserver.handlers.AbstractLogHandler; * messages based on their timestamp. The goal of this archiver * is to make it easy to locate messages in a time interval, while * ensuring that no log file exceeds the maximum allowed size. - * + * <p> * <p> * This class is not thread safe. * </p> - * + * <p> * <p> * TODO: * </p> * <ul> - * <li> Add file locking support in order to make it - * possible to do concurrent compression of log - * files. - * - * <li> Add support for disk monitoring. Should have - * high/low watermark mechanism and three modes - * of operation: normal, tight and full. In - * "tight" mode disk is running low and compression - * and cleanup should possibly be more frequent. - * - * <li> Add compression task which periodically scans - * the log directory looking for uncompressed - * candidate log files. - * + * <li> Add file locking support in order to make it + * possible to do concurrent compression of log + * files. + * <p> + * <li> Add support for disk monitoring. Should have + * high/low watermark mechanism and three modes + * of operation: normal, tight and full. In + * "tight" mode disk is running low and compression + * and cleanup should possibly be more frequent. + * <p> + * <li> Add compression task which periodically scans + * the log directory looking for uncompressed + * candidate log files. + * <p> * </ul> - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * + * @author Bjorn Borud */ -public class ArchiverHandler extends AbstractLogHandler -{ - private static final Logger log - = Logger.getLogger(ArchiverHandler.class.getName()); +public class ArchiverHandler extends AbstractLogHandler { + private static final Logger log = Logger.getLogger(ArchiverHandler.class.getName()); - /** File instance representing root directory for logging */ + /** + * File instance representing root directory for logging + */ private File root; - /** Root directory for logging */ + /** + * Root directory for logging + */ private String absoluteRootDir; - /** Max number of log files open at any given time */ + /** + * Max number of log files open at any given time + */ private final int maxFilesOpen = 100; /** - *The maximum number of bytes we allow a file to grow to + * The maximum number of bytes we allow a file to grow to * before we rotate it */ private int maxFileSize; - /** Calendar instance for operating on Date objects */ + /** + * Calendar instance for operating on Date objects + */ private final Calendar calendar; - /** DateFormat instance for building filenames */ + /** + * DateFormat instance for building filenames + */ private final SimpleDateFormat dateformat; /** @@ -91,14 +100,14 @@ public class ArchiverHandler extends AbstractLogHandler * Creates an ArchiverHandler which puts files under * the given root directory. */ - public ArchiverHandler () { + public ArchiverHandler() { calendar = new GregorianCalendar(TimeZone.getTimeZone("UTC")); dateformat = new SimpleDateFormat("yyyy/MM/dd/HH"); dateformat.setTimeZone(TimeZone.getTimeZone("UTC")); // Set up filtering String archiveMetrics = System.getProperty("vespa_log_server__archive_metric"); - if ("off".equals(archiveMetrics)){ + if ("off".equals(archiveMetrics)) { filter = LogFilterManager.getLogFilter("system.nometricsevents"); } @@ -106,14 +115,14 @@ public class ArchiverHandler extends AbstractLogHandler // set up LRU for files logWriterLRUCache = new LogWriterLRUCache(maxFilesOpen, - (float)0.75); + (float) 0.75); } /** * Creates an ArchiverHandler which puts files under * the given root directory. */ - public ArchiverHandler (String rootDir, int maxFileSize) { + public ArchiverHandler(String rootDir, int maxFileSize) { this(); setRootDir(rootDir); this.maxFileSize = maxFileSize; @@ -123,8 +132,8 @@ public class ArchiverHandler extends AbstractLogHandler /** * Return the appropriate LogWriter given a log message. */ - private synchronized LogWriter getLogWriter (LogMessage m) throws IOException { - Integer slot = new Integer(dateHash(m.getTime())); + private synchronized LogWriter getLogWriter(LogMessage m) throws IOException { + Integer slot = dateHash(m.getTime()); LogWriter logWriter = logWriterLRUCache.get(slot); if (logWriter != null) { return logWriter; @@ -141,34 +150,34 @@ public class ArchiverHandler extends AbstractLogHandler * This method is just a fancy way of generating a stripped * down number representing year, month, day and hour in order * to partition logging in time. - * - * <P> + * <p> + * <p> * This method is not thread-safe. */ - public int dateHash (long time) { + public int dateHash(long time) { calendar.setTimeInMillis(time); - int year = calendar.get(Calendar.YEAR); - int month = calendar.get(Calendar.MONTH) + 1; - int day = calendar.get(Calendar.DAY_OF_MONTH); - int hour = calendar.get(Calendar.HOUR_OF_DAY); + int year = calendar.get(Calendar.YEAR); + int month = calendar.get(Calendar.MONTH) + 1; + int day = calendar.get(Calendar.DAY_OF_MONTH); + int hour = calendar.get(Calendar.HOUR_OF_DAY); return year * 1000000 - + month * 10000 - + day * 100 - + hour; + + month * 10000 + + day * 100 + + hour; } /** * Generate prefix for log filenames based on log message. - * - * <P> + * <p> + * <p> * <EM>This message is <code>public</code> only because we need * access to it in unit tests. For all practical purposes this * method does not exist to you, the application programmer, OK? :-)</EM> - * <P> + * <p> * XXX optimize! */ - public String getPrefix (LogMessage msg) { + public String getPrefix(LogMessage msg) { calendar.setTimeInMillis(msg.getTime()); /* int year = calendar.get(Calendar.YEAR); @@ -177,50 +186,47 @@ public class ArchiverHandler extends AbstractLogHandler int hour = calendar.get(Calendar.HOUR_OF_DAY); */ StringBuffer result = new StringBuffer(absoluteRootDir.length() - + 1 // slash - + 4 // year - + 1 // slash - + 2 // month - + 1 // slash - + 2 // day - + 1 // slash - + 2 // hour + + 1 // slash + + 4 // year + + 1 // slash + + 2 // month + + 1 // slash + + 2 // day + + 1 // slash + + 2 // hour ) .append(absoluteRootDir).append("/") .append(dateformat.format(calendar.getTime())); return result.toString(); } - public boolean doHandle (LogMessage msg) { + public boolean doHandle(LogMessage msg) { try { LogWriter logWriter = getLogWriter(msg); logWriter.write(msg.toString()); - } - catch (IOException e) { + } catch (IOException e) { throw new RuntimeException(e); } return true; } - public synchronized void flush () { + public synchronized void flush() { for (LogWriter l : logWriterLRUCache.values()) { try { l.flush(); - } - catch (IOException e) { + } catch (IOException e) { log.log(Level.WARNING, "Flushing failed", e); } } } - public synchronized void close () { + public synchronized void close() { Iterator<LogWriter> it = logWriterLRUCache.values().iterator(); while (it.hasNext()) { LogWriter l = it.next(); try { l.close(); - } - catch (IOException e) { + } catch (IOException e) { log.log(Level.WARNING, "Closing failed", e); } it.remove(); @@ -249,7 +255,7 @@ public class ArchiverHandler extends AbstractLogHandler } - public String toString () { + public String toString() { return ArchiverHandler.class.getName() + ": root=" + absoluteRootDir; } } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java index 0d04b4cf981..3c3bd80e607 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/ArchiverPlugin.java @@ -2,13 +2,13 @@ package com.yahoo.logserver.handlers.archive; import java.util.logging.Logger; + import com.yahoo.logserver.Server; import com.yahoo.plugin.Config; import com.yahoo.plugin.Plugin; -public class ArchiverPlugin implements Plugin -{ +public class ArchiverPlugin implements Plugin { /** * Default log archive dir (relative to current directory * at startup). @@ -21,8 +21,7 @@ public class ArchiverPlugin implements Plugin private static final String DEFAULT_MAXFILESIZE = "20971520"; private final Server server = Server.getInstance(); - private static final Logger log = - Logger.getLogger(ArchiverPlugin.class.getName()); + private static final Logger log = Logger.getLogger(ArchiverPlugin.class.getName()); private ArchiverHandler archiver; /** @@ -32,20 +31,21 @@ public class ArchiverPlugin implements Plugin return "logarchive"; } - /** Initialize the archiver plugin - * + /** + * Initialize the archiver plugin + * <p> * Config keys used: - * - * maxfilesize - * dir The root of the logarchive, make sure this does - * <b>not</b> end with a '/' character. + * <p> + * maxfilesize + * dir The root of the logarchive, make sure this does + * <b>not</b> end with a '/' character. */ public void initPlugin(Config config) { if (archiver != null) { - log.finer("ArchivePlugin doubly initialized"); + log.finer("ArchivePlugin doubly initialized"); throw new IllegalStateException("plugin already initialized: " - + getPluginName()); + + getPluginName()); } // Possible to disable logarchive for testing @@ -65,9 +65,9 @@ public class ArchiverPlugin implements Plugin public void shutdownPlugin() { if (archiver == null) { - log.finer("ArchiverPlugin shutdown before initialize"); + log.finer("ArchiverPlugin shutdown before initialize"); throw new IllegalStateException("plugin not initialized: " - + getPluginName()); + + getPluginName()); } server.unregisterLogHandler(archiver); server.unregisterFlusher(archiver); diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java index fb78e8243c3..5fa7dd7f4b6 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriter.java @@ -12,23 +12,21 @@ import com.yahoo.log.LogLevel; /** * This class is not thread-safe. * - * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ -public class LogWriter extends Writer -{ +public class LogWriter extends Writer { private static final Logger log = Logger.getLogger(LogWriter.class.getName()); - private long bytesWritten = 0; - private int generation = 0; - private int maxSize = 20 * (1024*1024); - private final int resumeLimit = 95; - private final int resumeLimitSize = (maxSize * resumeLimit / 100); + private long bytesWritten = 0; + private int generation = 0; + private int maxSize = 20 * (1024 * 1024); + private final int resumeLimit = 95; + private final int resumeLimitSize = (maxSize * resumeLimit / 100); private File currentFile; private Writer writer; private final String prefix; - public LogWriter (String prefix, int maxSize) throws IOException { + public LogWriter(String prefix, int maxSize) throws IOException { this.prefix = prefix; this.maxSize = maxSize; writer = nextWriter(); @@ -38,14 +36,13 @@ public class LogWriter extends Writer * This is called when we want to rotate the output file to * start writing the next file. There are two scenarios when * we do this: - * + * <p> * <UL> - * <LI> initial case, when we have no file - * <LI> when we have filled the file and want to rotate it + * <LI> initial case, when we have no file + * <LI> when we have filled the file and want to rotate it * </UL> - * */ - private Writer nextWriter () throws IOException { + private Writer nextWriter() throws IOException { if (writer != null) { writer.close(); @@ -64,7 +61,7 @@ public class LogWriter extends Writer // if compressed version exists we skip it if ((new File(name + ".gz").exists()) - || (new File(name + ".bz2").exists())) { + || (new File(name + ".bz2").exists())) { continue; } @@ -91,9 +88,9 @@ public class LogWriter extends Writer } else { log.fine("nextWriter, not resuming " + name - + " because it is bigger than " - + resumeLimit - + " percent of max"); + + " because it is bigger than " + + resumeLimit + + " percent of max"); } } @@ -104,13 +101,13 @@ public class LogWriter extends Writer * Note that this method should not be used directly since * that would circumvent rotation when it grows past its * maximum size. use the one that takes String instead. - * - * <P> + * <p> + * <p> * <em> * (This is a class which is only used internally anyway) * </em> */ - public void write (char[] cbuff, int offset, int len) throws IOException { + public void write(char[] cbuff, int offset, int len) throws IOException { throw new RuntimeException("This method should not be used"); } @@ -124,14 +121,14 @@ public class LogWriter extends Writer if (bytesWritten >= maxSize) { log.fine("logfile '" - + currentFile.getAbsolutePath() - + "' full, rotating"); + + currentFile.getAbsolutePath() + + "' full, rotating"); writer = nextWriter(); } } - public void flush() throws IOException{ + public void flush() throws IOException { if (writer != null) { writer.flush(); } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriterLRUCache.java b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriterLRUCache.java index d36486e0c44..0b2e3e8f1b5 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriterLRUCache.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/archive/LogWriterLRUCache.java @@ -8,23 +8,20 @@ import java.util.LinkedHashMap; import java.util.Map; /** - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ @SuppressWarnings("serial") -public class LogWriterLRUCache extends LinkedHashMap<Integer, LogWriter> -{ - private static final Logger log - = Logger.getLogger(LogWriterLRUCache.class.getName()); +public class LogWriterLRUCache extends LinkedHashMap<Integer, LogWriter> { + private static final Logger log = Logger.getLogger(LogWriterLRUCache.class.getName()); final int maxEntries = 100; - public LogWriterLRUCache(int initialCapacity, - float loadFactor) { + public LogWriterLRUCache(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor, true); } // TODO: implement unit test for this - protected boolean removeEldestEntry (Map.Entry<Integer, LogWriter> eldest) { + protected boolean removeEldestEntry(Map.Entry<Integer, LogWriter> eldest) { if (size() > maxEntries) { LogWriter logWriter = eldest.getValue(); log.fine("Closing oldest LogWriter: " + logWriter); diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java index ff587bdc396..4869896cfa6 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsHandler.java @@ -5,9 +5,7 @@ package com.yahoo.logserver.handlers.logmetrics; import java.util.Arrays; -import java.util.Iterator; import java.util.List; -import java.util.Set; import java.util.Map; import java.util.TreeMap; import java.util.ArrayList; @@ -24,25 +22,22 @@ import com.yahoo.logserver.handlers.AbstractLogHandler; * The LogMetricsHandler stores a count of the number of log messages * per level per host and sends an event count for this five minutes. * - * * @author hmusum */ -public class LogMetricsHandler extends AbstractLogHandler -{ - public static final long EVENTINTERVAL = 5 * 60; // in seconds +public class LogMetricsHandler extends AbstractLogHandler { + private static final long EVENTINTERVAL = 5 * 60; // in seconds - private static final Logger log = - Logger.getLogger(LogMetricsHandler.class.getName()); + private static final Logger log = Logger.getLogger(LogMetricsHandler.class.getName()); // A list of log metrics per host and per log level private final List<LevelCount> logMetrics = new ArrayList<LevelCount>(); // The log levels that are handled by this plugin private static final Level[] levels = {LogLevel.INFO, - LogLevel.WARNING, - LogLevel.SEVERE, - LogLevel.ERROR, - LogLevel.FATAL}; + LogLevel.WARNING, + LogLevel.SEVERE, + LogLevel.ERROR, + LogLevel.FATAL}; /** @@ -67,7 +62,7 @@ public class LogMetricsHandler extends AbstractLogHandler String host = message.getHost(); Level logLevel = message.getLevel(); - boolean found = false; + boolean found = false; if (logMetrics.size() > 0) { LevelCount count; // Loop through the list logMetrics and check if there @@ -75,19 +70,19 @@ public class LogMetricsHandler extends AbstractLogHandler for (int i = 0; i < logMetrics.size(); i++) { count = logMetrics.get(i); if (count.getHost().equals(host) && - count.getLevel().getName().equals(logLevel.getName())) { + count.getLevel().getName().equals(logLevel.getName())) { count.addCount(1); found = true; break; } } } - + // There is no element in logMetrics with the same host and // level as in the message, so create a new object and add it // to the list. - if (!found) { - for (Level level : Arrays.asList(levels)) { + if (! found) { + for (Level level : Arrays.asList(levels)) { LevelCount levelCount; if (level.getName().equals(logLevel.getName())) { levelCount = new LevelCount(host, @@ -97,29 +92,27 @@ public class LogMetricsHandler extends AbstractLogHandler levelCount = new LevelCount(host, level, 0); - + } logMetrics.add(levelCount); } - } + } return true; } /** - * * Create event count for each log level and report it. For now we * add up the numbers for all host on each level and report that. - * */ private void sendEvents() { - Map<String,Long> levelCount = getMetricsPerLevel(); - for (Map.Entry<String,Long> entry : levelCount.entrySet()) { + Map<String, Long> levelCount = getMetricsPerLevel(); + for (Map.Entry<String, Long> entry : levelCount.entrySet()) { String key = entry.getKey(); Long count = entry.getValue(); Event.count("log_message." + key.toLowerCase(), count.longValue()); } } - + public void flush() {} public void close() {} @@ -137,7 +130,7 @@ public class LogMetricsHandler extends AbstractLogHandler public long getMetricsCount() { long count = 0; for (LevelCount levelCount : logMetrics) { - count = count + levelCount.getCount(); + count = count + levelCount.getCount(); } return count; } @@ -148,18 +141,18 @@ public class LogMetricsHandler extends AbstractLogHandler * * @return A Map of log level counts */ - public Map<String,Long> getMetricsPerLevel() { + public Map<String, Long> getMetricsPerLevel() { Map<String, Long> levelCounts = new TreeMap<String, Long>(); // Loop through all levels summing the count for all hosts. for (Level level : Arrays.asList(levels)) { - String levelName = level.getName(); - long count = 0; - for (LevelCount levelCount : logMetrics) { - if (levelName.equals(levelCount.getLevel().getName())) { - count += levelCount.getCount(); - } - } - levelCounts.put(levelName, count); + String levelName = level.getName(); + long count = 0; + for (LevelCount levelCount : logMetrics) { + if (levelName.equals(levelCount.getLevel().getName())) { + count += levelCount.getCount(); + } + } + levelCounts.put(levelName, count); } return levelCounts; } @@ -167,21 +160,20 @@ public class LogMetricsHandler extends AbstractLogHandler /** * The LevelCount class represents the number (count) of log * messages with the same log level for a host. - * */ private class LevelCount { private final String host; private final Level level; private long count; - + LevelCount(String host, Level level, long count) { - this.host = host; - this.level = level; - this.count = count; + this.host = host; + this.level = level; + this.count = count; } - + LevelCount(String host, Level level) { - this(host, level, 0); + this(host, level, 0); } Level getLevel() { @@ -207,7 +199,7 @@ public class LogMetricsHandler extends AbstractLogHandler public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Host=" + host + ", level = " + level.getName() + - ",count=" + count); + ",count=" + count); return sb.toString(); } } @@ -215,7 +207,6 @@ public class LogMetricsHandler extends AbstractLogHandler /** * Implements a thread that sends events every EVENTINTERVAL * seconds. - * */ private class EventGenerator implements Runnable { public void run() { @@ -228,6 +219,6 @@ public class LogMetricsHandler extends AbstractLogHandler } sendEvents(); } - } + } } } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java index 204e35d52bb..51fac499903 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/logmetrics/LogMetricsPlugin.java @@ -11,10 +11,8 @@ import com.yahoo.plugin.Config; import com.yahoo.plugin.Plugin; -public class LogMetricsPlugin implements Plugin -{ - private static final Logger log = - Logger.getLogger(LogMetricsPlugin.class.getName()); +public class LogMetricsPlugin implements Plugin { + private static final Logger log = Logger.getLogger(LogMetricsPlugin.class.getName()); private LogMetricsHandler logMetricsHandler; private final Server server = Server.getInstance(); @@ -22,15 +20,15 @@ public class LogMetricsPlugin implements Plugin return "logmetrics"; } - /** Initialize the logmetrics plugin + /** + * Initialize the logmetrics plugin * * @param config Plugin config object, keys used: - * <code>thread</code> - name of handler thread this plugin runs in - * + * <code>thread</code> - name of handler thread this plugin runs in */ public void initPlugin(Config config) { if (logMetricsHandler != null) { - log.finer("LogMetricsPlugin doubly initialized"); + log.finer("LogMetricsPlugin doubly initialized"); throw new IllegalStateException( "plugin already initialized: " + getPluginName()); } @@ -44,9 +42,9 @@ public class LogMetricsPlugin implements Plugin */ public void shutdownPlugin() { if (logMetricsHandler == null) { - log.finer("LogMetricsPlugin shutdown before initialize"); + log.finer("LogMetricsPlugin shutdown before initialize"); throw new IllegalStateException("plugin not initialized: " + - getPluginName()); + getPluginName()); } server.unregisterLogHandler(logMetricsHandler); logMetricsHandler = null; diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/FormattedBufferCache.java b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/FormattedBufferCache.java index f20adbe3c91..284781b12bb 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/FormattedBufferCache.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/FormattedBufferCache.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.IdentityHashMap; import java.nio.ByteBuffer; import java.nio.charset.Charset; + import com.yahoo.log.LogMessage; import com.yahoo.logserver.formatter.LogFormatter; import com.yahoo.logserver.formatter.LogFormatterManager; @@ -15,16 +16,16 @@ import com.yahoo.logserver.formatter.LogFormatterManager; * is to make it easier to support multiple message formats while * still ensuring we don't format more messages than we strictly need * to and that we don't keep around more buffers that we ought to. - * - * <P> + * <p> + * <p> * This is not a general purpose class, I think, so please * refer to the source code of the Replicator class for * information on how to use this. - * - * <P> + * <p> + * <p> * This class is not threadsafe. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class FormattedBufferCache { // the documentation says " All of the methods defined in this @@ -35,7 +36,7 @@ public class FormattedBufferCache { private final IdentityHashMap<LogFormatter, ByteBuffer> buffers; - public FormattedBufferCache () { + public FormattedBufferCache() { // hope this is a good hash size int initialSize = LogFormatterManager.getFormatterNames().length * 2; buffers = new IdentityHashMap<LogFormatter, ByteBuffer>(initialSize); @@ -47,11 +48,11 @@ public class FormattedBufferCache { * exist in the cache from before, it will after this * method returns. * - * @param msg The log message you wish to format + * @param msg The log message you wish to format * @param formatter The log formatter you wish to use for formatting * @return Returns a ByteBuffer slice */ - public ByteBuffer getFormatted (LogMessage msg, LogFormatter formatter) { + public ByteBuffer getFormatted(LogMessage msg, LogFormatter formatter) { ByteBuffer bb = buffers.get(formatter); if (bb == null) { bb = charset.encode(formatter.format(msg)); @@ -65,14 +66,14 @@ public class FormattedBufferCache { * clients we clear the cache so we are ready for the next * message. */ - public void reset () { + public void reset() { buffers.clear(); } /** * This is here for test purposes. Don't get any bright ideas. */ - public Map<LogFormatter,ByteBuffer> getUnderlyingMapOnlyForTesting() { + public Map<LogFormatter, ByteBuffer> getUnderlyingMapOnlyForTesting() { return buffers; } } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/Replicator.java b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/Replicator.java index f8dc700931f..5ede34a1f79 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/Replicator.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/Replicator.java @@ -6,6 +6,7 @@ import java.nio.channels.SocketChannel; import java.util.HashSet; import java.util.Set; import java.util.logging.Logger; + import com.yahoo.io.Connection; import com.yahoo.io.ConnectionFactory; import com.yahoo.io.Listener; @@ -16,115 +17,110 @@ import com.yahoo.logserver.handlers.AbstractLogHandler; /** * The Replicator plugin is used for replicating log messages sent * to the logserver. - * - * <P> + * <p> + * <p> * Per default the replicator will start dropping messages enqueued * to a client if the outbound message queue reaches 5000 messages. * This limit can be configured by setting the system property * <code>logserver.replicator.maxqueuelength</code> to the desired * value. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ -public class Replicator extends AbstractLogHandler -implements ConnectionFactory -{ - private static final Logger log = Logger.getLogger(Replicator.class.getName()); +public class Replicator extends AbstractLogHandler implements ConnectionFactory { + private static final Logger log = Logger.getLogger(Replicator.class.getName()); - private int port; - private Listener listener; - private final Set<ReplicatorConnection> connections = new HashSet<ReplicatorConnection>(); - private final FormattedBufferCache bufferCache = new FormattedBufferCache(); + private int port; + private Listener listener; + private final Set<ReplicatorConnection> connections = new HashSet<ReplicatorConnection>(); + private final FormattedBufferCache bufferCache = new FormattedBufferCache(); - /** - * @param port The port to which the replicator listens. - * - */ - public Replicator (int port) throws IOException { - this.port = port; - listen(port); - } + /** + * @param port The port to which the replicator listens. + */ + public Replicator(int port) throws IOException { + this.port = port; + listen(port); + } - public Replicator () { - } + public Replicator() { + } - public void listen (int port) throws IOException { - if (listener != null) { - throw new IllegalStateException("already listening to port " + this.port); - } - listener = new Listener("replicator"); - listener.listen(this, port); - listener.start(); - log.log(LogLevel.CONFIG, "port=" + port); - } + public void listen(int port) throws IOException { + if (listener != null) { + throw new IllegalStateException("already listening to port " + this.port); + } + listener = new Listener("replicator"); + listener.listen(this, port); + listener.start(); + log.log(LogLevel.CONFIG, "port=" + port); + } - public synchronized boolean doHandle (LogMessage msg) { - boolean logged = false; - bufferCache.reset(); - for (ReplicatorConnection c : connections) { - try { - if (c.isLoggable(msg)) { - c.enqueue(bufferCache.getFormatted(msg, c.formatter)); - logged = true; - } - } - catch (IOException e) { - log.log(LogLevel.DEBUG, "Writing failed", e); - } - } - return logged; - } + public synchronized boolean doHandle(LogMessage msg) { + boolean logged = false; + bufferCache.reset(); + for (ReplicatorConnection c : connections) { + try { + if (c.isLoggable(msg)) { + c.enqueue(bufferCache.getFormatted(msg, c.formatter)); + logged = true; + } + } catch (IOException e) { + log.log(LogLevel.DEBUG, "Writing failed", e); + } + } + return logged; + } - public void close() { - // kill the listener thread, then wait for it to - // shut down. - try { - listener.interrupt(); - listener.join(); - log.log(LogLevel.DEBUG, "Replicator listener stopped"); - } - catch (InterruptedException e) { - log.log(LogLevel.WARNING, - "Replicator listener was interrupted", - e); - } - } + public void close() { + // kill the listener thread, then wait for it to + // shut down. + try { + listener.interrupt(); + listener.join(); + log.log(LogLevel.DEBUG, "Replicator listener stopped"); + } catch (InterruptedException e) { + log.log(LogLevel.WARNING, + "Replicator listener was interrupted", + e); + } + } - /** - * Currently a NOP, but we might want to have some best-effort - * mechanism for trying to flush all connections within some - * time-frame. - */ - public void flush() {} + /** + * Currently a NOP, but we might want to have some best-effort + * mechanism for trying to flush all connections within some + * time-frame. + */ + public void flush() {} - /** - * Factory method for wrapping new connections in the proper - * (Replicator)Connection objects. - * - * @param socket The new SocketChannel - * @param listener The Listener instance we want to use - */ - public synchronized Connection newConnection (SocketChannel socket, - Listener listener) { - if (log.isLoggable(LogLevel.DEBUG)) { - log.fine("New replicator connection: " + socket); - } - ReplicatorConnection n = - new ReplicatorConnection(socket, listener, this); - connections.add(n); - return n; - } + /** + * Factory method for wrapping new connections in the proper + * (Replicator)Connection objects. + * + * @param socket The new SocketChannel + * @param listener The Listener instance we want to use + */ + public synchronized Connection newConnection(SocketChannel socket, + Listener listener) { + if (log.isLoggable(LogLevel.DEBUG)) { + log.fine("New replicator connection: " + socket); + } + ReplicatorConnection n = + new ReplicatorConnection(socket, listener, this); + connections.add(n); + return n; + } - /** - * Removes a ReplicatorConnection from the set of active - * connections. - */ - protected synchronized void deRegisterConnection (ReplicatorConnection conn) { - connections.remove(conn); - } + /** + * Removes a ReplicatorConnection from the set of active + * connections. + */ + protected synchronized void deRegisterConnection(ReplicatorConnection conn) { + connections.remove(conn); + } - public String toString () { - return Replicator.class.getName(); - } + public String toString() { + return Replicator.class.getName(); + } } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorConnection.java b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorConnection.java index 2978f751665..003d35e96d0 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorConnection.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorConnection.java @@ -23,18 +23,22 @@ import com.yahoo.logserver.formatter.LogFormatterManager; /** * Replication client connection. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ -public class ReplicatorConnection implements Connection, LogFilter -{ - private static final Logger log - = Logger.getLogger(ReplicatorConnection.class.getName()); +public class ReplicatorConnection implements Connection, LogFilter { + private static final Logger log = Logger.getLogger(ReplicatorConnection.class.getName()); - /** The maximum number of queued messages before we start dropping */ + /** + * The maximum number of queued messages before we start dropping + */ private static final int maxQueueLength; - /** The maximum number of times we go over maxQueueLength before we log a warning */ + /** + * The maximum number of times we go over maxQueueLength before we log a warning + */ private static final int maxRetriesBeforeWarning = 10; - /** Count of how many times we have received a message while the queue is full */ + /** + * Count of how many times we have received a message while the queue is full + */ private static int queueFullCount = 0; static { @@ -64,11 +68,8 @@ public class ReplicatorConnection implements Connection, LogFilter * Constructs a ReplicatorConnection. Note that initially the * filter of this connection is set to MuteFilter, which mutes * all log messages. - * */ - public ReplicatorConnection (SocketChannel socket, - Listener listener, - Replicator replicator) { + public ReplicatorConnection(SocketChannel socket, Listener listener, Replicator replicator) { this.socket = socket; this.listener = listener; this.replicator = replicator; @@ -97,9 +98,8 @@ public class ReplicatorConnection implements Connection, LogFilter * serialize it into. * * @param msg The log message offered - * */ - public boolean isLoggable (LogMessage msg) { + public boolean isLoggable(LogMessage msg) { if (filter == null) { return true; } @@ -109,7 +109,7 @@ public class ReplicatorConnection implements Connection, LogFilter /** * Return the description of the currently active filter. */ - public String description () { + public String description() { if (filter == null) { return "No filter defined"; } @@ -124,7 +124,7 @@ public class ReplicatorConnection implements Connection, LogFilter * @param buffer the ByteBuffer into which the log message is * serialized. */ - public synchronized void enqueue (ByteBuffer buffer) throws IOException { + public synchronized void enqueue(ByteBuffer buffer) throws IOException { if (writeBuffer == null) { writeBuffer = buffer; } else { @@ -133,7 +133,7 @@ public class ReplicatorConnection implements Connection, LogFilter queueFullCount++; if (! droppingMode) { droppingMode = true; - String message = "client at " + remoteHost + " can't keep up, dropping messages"; + String message = "client at " + remoteHost + " can't keep up, dropping messages"; if (queueFullCount > maxRetriesBeforeWarning) { log.log(LogLevel.WARNING, message); queueFullCount = 0; @@ -154,38 +154,38 @@ public class ReplicatorConnection implements Connection, LogFilter } - public void read () throws IOException { + public void read() throws IOException { if (! readBuffer.hasRemaining()) { log.warning("Log message too long. Message exceeds " - + readBuffer.capacity() - + " bytes. Connection dropped."); + + readBuffer.capacity() + + " bytes. Connection dropped."); close(); return; } - int ret = socket.read(readBuffer); - if (ret == -1) { - close(); - return; - } + int ret = socket.read(readBuffer); + if (ret == - 1) { + close(); + return; + } - if (ret == 0) { - if (log.isLoggable(LogLevel.DEBUG)) { - log.fine("zero byte read occurred"); - } - } + if (ret == 0) { + if (log.isLoggable(LogLevel.DEBUG)) { + log.fine("zero byte read occurred"); + } + } - readBuffer.flip(); + readBuffer.flip(); - String s; - while ((s = ReadLine.readLine(readBuffer)) != null) { - onCommand(s); - } + String s; + while ((s = ReadLine.readLine(readBuffer)) != null) { + onCommand(s); + } } - public synchronized void write () throws IOException { + public synchronized void write() throws IOException { if (! socket.isOpen()) { // throw new IllegalStateException("SocketChannel not open in write()"); close(); @@ -218,8 +218,7 @@ public class ReplicatorConnection implements Connection, LogFilter // try { bytesWritten = socket.write(writeBuffer); - } - catch (IOException e) { + } catch (IOException e) { close(); return; } @@ -227,13 +226,13 @@ public class ReplicatorConnection implements Connection, LogFilter // buffer drained so we forget it and see what happens when we // go around. if indeed we go around - if ((writeBuffer != null) && (!writeBuffer.hasRemaining())) { + if ((writeBuffer != null) && (! writeBuffer.hasRemaining())) { writeBuffer = null; } } while (bytesWritten > 0); } - public synchronized void close () throws IOException { + public synchronized void close() throws IOException { replicator.deRegisterConnection(this); socket.close(); writeBuffer = null; @@ -241,15 +240,15 @@ public class ReplicatorConnection implements Connection, LogFilter log.log(LogLevel.DEBUG, "closing connection to " + remoteHost); } - public int selectOps () { + public int selectOps() { return SelectionKey.OP_READ; } - public SocketChannel socketChannel () { + public SocketChannel socketChannel() { return socket; } - public void connect () { + public void connect() { } @@ -257,7 +256,7 @@ public class ReplicatorConnection implements Connection, LogFilter // ==== command processing // ======================================================== - void onCommand (String s) { + void onCommand(String s) { log.log(LogLevel.DEBUG, "COMMAND: '" + s + "' from " + remoteHost); StringTokenizer st = new StringTokenizer(s.toLowerCase()); while (st.hasMoreTokens()) { @@ -308,7 +307,7 @@ public class ReplicatorConnection implements Connection, LogFilter } } - void onFormatter (String formatterName) { + void onFormatter(String formatterName) { LogFormatter newFormatter = LogFormatterManager.getLogFormatter(formatterName); if (newFormatter == null) { print("# 405 formatter not found '" + formatterName + "'\n"); @@ -319,7 +318,7 @@ public class ReplicatorConnection implements Connection, LogFilter print("# 202 using '" + formatter + "'\n"); } - void onUse (String filterName) { + void onUse(String filterName) { LogFilter newFilter = LogFilterManager.getLogFilter(filterName); if (newFilter == null) { print("# 404 filter not found '" + filterName + "'\n"); @@ -331,8 +330,7 @@ public class ReplicatorConnection implements Connection, LogFilter } - - void onList () { + void onList() { print("# 203 filter list\n"); String filterNames[] = LogFilterManager.getFilterNames(); for (int i = 0; i < filterNames.length; i++) { @@ -342,7 +340,7 @@ public class ReplicatorConnection implements Connection, LogFilter print("# 205 end filter list\n"); } - void onListFormatters () { + void onListFormatters() { print("# 206 formatter list\n"); String formatterNames[] = LogFormatterManager.getFormatterNames(); for (int i = 0; i < formatterNames.length; i++) { @@ -352,60 +350,58 @@ public class ReplicatorConnection implements Connection, LogFilter print("# 208 end formatter list\n"); } - private void print (String s) { + private void print(String s) { try { enqueue(IOUtils.utf8ByteBuffer(s)); - } - catch (IOException e) { + } catch (IOException e) { log.log(LogLevel.WARNING, "error printing", e); try { close(); - } - catch (IOException e2) { + } catch (IOException e2) { // ignore } } } - void onStats () { + void onStats() { print(new StringBuilder(80) - .append("# 206 stats start (this connection)\n") - .append("# 207 ").append(numHandled).append(" handled\n") - .append("# 208 ").append(numDropped).append(" dropped\n") - .append("# 209 ").append(numQueued) - .append(" handled and queued\n") - .append("# 210 ").append(totalBytesWritten) - .append(" total bytes written\n") - .append("# 211 stats end\n") - .toString() - ); + .append("# 206 stats start (this connection)\n") + .append("# 207 ").append(numHandled).append(" handled\n") + .append("# 208 ").append(numDropped).append(" dropped\n") + .append("# 209 ").append(numQueued) + .append(" handled and queued\n") + .append("# 210 ").append(totalBytesWritten) + .append(" total bytes written\n") + .append("# 211 stats end\n") + .toString() + ); } - public int getNumHandled () { + public int getNumHandled() { return numHandled; } - public int getNumQueued () { + public int getNumQueued() { return numQueued; } - public int getNumDropped () { + public int getNumDropped() { return numDropped; } - public long getTotalBytesWritten () { + public long getTotalBytesWritten() { return totalBytesWritten; } - public String getLogFilterName () { + public String getLogFilterName() { return filterName; } - + void setFilter(LogFilter filter) { this.filter = filter; } - + } diff --git a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorPlugin.java b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorPlugin.java index 03bc66c8262..b1fe0ce9193 100644 --- a/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorPlugin.java +++ b/logserver/src/main/java/com/yahoo/logserver/handlers/replicator/ReplicatorPlugin.java @@ -9,23 +9,21 @@ import com.yahoo.logserver.Server; import com.yahoo.plugin.Config; import com.yahoo.plugin.Plugin; -public class ReplicatorPlugin implements Plugin -{ +public class ReplicatorPlugin implements Plugin { private static final String DEFAULT_PORT = "19083"; - private static final Logger log = - Logger.getLogger(ReplicatorPlugin.class.getName()); + private static final Logger log = Logger.getLogger(ReplicatorPlugin.class.getName()); + private Replicator replicator; private final Server server = Server.getInstance(); - public String getPluginName () { + public String getPluginName() { return "replicator"; } /** * Initialize the replicator plugin */ - public void initPlugin (Config config) { - + public void initPlugin(Config config) { if (replicator != null) { throw new IllegalStateException( "plugin already initialized: " + getPluginName()); @@ -34,8 +32,7 @@ public class ReplicatorPlugin implements Plugin String threadName = config.get("thread", getPluginName()); try { replicator = new Replicator(listenPort); - } - catch (IOException e) { + } catch (IOException e) { log.log(LogLevel.WARNING, "init failed: " + e); return; } @@ -45,7 +42,7 @@ public class ReplicatorPlugin implements Plugin /** * Shut down the replicator plugin. */ - public void shutdownPlugin () { + public void shutdownPlugin() { if (replicator == null) { throw new IllegalStateException( diff --git a/logserver/src/main/java/com/yahoo/logserver/net/LogConnection.java b/logserver/src/main/java/com/yahoo/logserver/net/LogConnection.java index f9853ea03b0..be59fe5222f 100644 --- a/logserver/src/main/java/com/yahoo/logserver/net/LogConnection.java +++ b/logserver/src/main/java/com/yahoo/logserver/net/LogConnection.java @@ -31,7 +31,7 @@ import java.nio.channels.SelectionKey; * analyzed and errors can be corrected. * </UL> * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class LogConnection implements Connection { diff --git a/logserver/src/main/java/com/yahoo/logserver/net/LogConnectionFactory.java b/logserver/src/main/java/com/yahoo/logserver/net/LogConnectionFactory.java index 5d97420f30a..7f0f18a0435 100644 --- a/logserver/src/main/java/com/yahoo/logserver/net/LogConnectionFactory.java +++ b/logserver/src/main/java/com/yahoo/logserver/net/LogConnectionFactory.java @@ -13,29 +13,26 @@ import java.util.logging.Logger; import java.nio.channels.SocketChannel; /** - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ +public class LogConnectionFactory implements ConnectionFactory { + private static final Logger log = Logger.getLogger(LogConnectionFactory.class.getName()); -public class LogConnectionFactory implements ConnectionFactory -{ - private static final Logger log - = Logger.getLogger(LogConnectionFactory.class.getName()); + private final LogDispatcher dispatcher; + private final Levels defaultLogLevels; - final LogDispatcher dispatcher; - final Levels defaultLogLevels; - - public LogConnectionFactory (LogDispatcher dispatcher) { + public LogConnectionFactory(LogDispatcher dispatcher) { this.dispatcher = dispatcher; defaultLogLevels = Levels.parse(System.getProperty("logserver.default.loglevels", "")); } - public Connection newConnection (SocketChannel socket, Listener listener) { + public Connection newConnection(SocketChannel socket, Listener listener) { if (log.isLoggable(Level.FINE)) { log.fine("New connection: " + socket); } return new LogConnection(socket, listener, dispatcher, - (Levels)defaultLogLevels.clone()); + (Levels) defaultLogLevels.clone()); } } diff --git a/logserver/src/main/java/com/yahoo/logserver/net/control/Levels.java b/logserver/src/main/java/com/yahoo/logserver/net/control/Levels.java index c9b749f4417..985f7159fc4 100644 --- a/logserver/src/main/java/com/yahoo/logserver/net/control/Levels.java +++ b/logserver/src/main/java/com/yahoo/logserver/net/control/Levels.java @@ -8,7 +8,7 @@ import java.util.Map; * This class is used to represent the state of each log level * in a set of states. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class Levels implements Cloneable { private final Map<String, State> levelsMap = new LinkedHashMap<String, State>(10); diff --git a/logserver/src/main/java/com/yahoo/logserver/testutils/VerifyLogfile.java b/logserver/src/main/java/com/yahoo/logserver/testutils/VerifyLogfile.java index 623bf04aa36..d8b05555133 100644 --- a/logserver/src/main/java/com/yahoo/logserver/testutils/VerifyLogfile.java +++ b/logserver/src/main/java/com/yahoo/logserver/testutils/VerifyLogfile.java @@ -15,7 +15,7 @@ import com.yahoo.log.LogMessage; * in a log file are correct. Any incorrectly formatted log * message is output to stdout. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class VerifyLogfile { diff --git a/logserver/src/main/java/com/yahoo/plugin/Config.java b/logserver/src/main/java/com/yahoo/plugin/Config.java index a7ea2b44caf..9cae0606809 100644 --- a/logserver/src/main/java/com/yahoo/plugin/Config.java +++ b/logserver/src/main/java/com/yahoo/plugin/Config.java @@ -5,10 +5,9 @@ package com.yahoo.plugin; * This interface specifies an API for configuring runtime-loadable * server plugins. * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ -public abstract class Config -{ +public abstract class Config { /** * @return a config value for the specified key */ diff --git a/logserver/src/main/java/com/yahoo/plugin/Plugin.java b/logserver/src/main/java/com/yahoo/plugin/Plugin.java index e53bc3a1faa..ced89b7fe1a 100644 --- a/logserver/src/main/java/com/yahoo/plugin/Plugin.java +++ b/logserver/src/main/java/com/yahoo/plugin/Plugin.java @@ -8,26 +8,25 @@ package com.yahoo.plugin; * calls application-specific registration methods to connect the * plugin to the hosting application. * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ -public interface Plugin -{ +public interface Plugin { /** * @return a unique and simple name for the plugin */ - public String getPluginName(); + String getPluginName(); /** * Initialize the plugin. * * @param config Config object for this plugin */ - public void initPlugin(Config config); + void initPlugin(Config config); /** * Shut down the plugin. Must clean up all resources allocated by * initPlugin() or any of the handler methods. */ - public void shutdownPlugin(); + void shutdownPlugin(); } diff --git a/logserver/src/main/java/com/yahoo/plugin/SystemPropertyConfig.java b/logserver/src/main/java/com/yahoo/plugin/SystemPropertyConfig.java index 763dc2d1f3e..4f17678e3b9 100644 --- a/logserver/src/main/java/com/yahoo/plugin/SystemPropertyConfig.java +++ b/logserver/src/main/java/com/yahoo/plugin/SystemPropertyConfig.java @@ -8,15 +8,14 @@ package com.yahoo.plugin; * then return the contents of the "logserver.archiver.foo" system * property. * - * @author <a href="mailto:stig@yahoo-inc.com">Stig Bakken</a> + * @author Stig Bakken */ -public class SystemPropertyConfig extends Config -{ +public class SystemPropertyConfig extends Config { private final String prefix; /** * @param prefix Prefix string prepended to config keys - * as they are looked up as system properties. + * as they are looked up as system properties. */ public SystemPropertyConfig(String prefix) { this.prefix = prefix; @@ -29,7 +28,7 @@ public class SystemPropertyConfig extends Config return System.getProperty(prefix + key, defaultValue); } - public String toString () { + public String toString() { return "Prefix=" + prefix; } } |