use of com.yahoo.logserver.handlers.LogHandler in project vespa by vespa-engine.
the class LogDispatcherTestCase method testTestLogHandlerRegistration.
@Test
public void testTestLogHandlerRegistration() {
MockHandler handler = new MockHandler();
LogDispatcher dispatcher = new LogDispatcher();
dispatcher.registerLogHandler(handler);
assertNotNull(dispatcher.getLogHandlers());
LogHandler[] handlers = dispatcher.getLogHandlers();
assertNotNull(handlers);
assertEquals(1, handlers.length);
assertTrue(handler == handlers[0]);
}
use of com.yahoo.logserver.handlers.LogHandler in project vespa by vespa-engine.
the class ServerTestCase method testStartupAndRegHandlers.
@Test
public void testStartupAndRegHandlers() throws IOException, InterruptedException {
Server.help();
Server server = Server.getInstance();
server.initialize(18322);
LogSetup.clearHandlers();
Thread serverThread = new Thread(server);
serverThread.start();
assertTrue(serverThread.isAlive());
LogHandler handler = new LogDispatcherTestCase.MockHandler();
server.registerLogHandler(handler, "foo");
assertEquals(Server.threadNameForHandler().get(handler), "foo");
server.unregisterLogHandler(handler);
assertEquals(Server.threadNameForHandler().get(handler), null);
serverThread.interrupt();
try {
serverThread.join();
assertTrue(true);
} catch (InterruptedException e) {
fail();
}
}
use of com.yahoo.logserver.handlers.LogHandler in project vespa by vespa-engine.
the class LogDispatcher method close.
public void close() {
if (hasBeenShutDown.getAndSet(true)) {
throw new IllegalStateException("Shutdown already in progress");
}
for (LogHandler ht : handlers) {
if (ht instanceof Thread) {
log.fine("Stopping " + ht);
// Todo: Very bad, never do....
((Thread) ht).interrupt();
}
}
handlers.clear();
log.log(LogLevel.DEBUG, "Logdispatcher shut down. Handled " + messageCount + " messages");
}
use of com.yahoo.logserver.handlers.LogHandler in project vespa by vespa-engine.
the class Flusher method run.
public synchronized void run() {
try {
while (!isInterrupted()) {
Thread.sleep(2000);
Iterator<WeakReference<LogHandler>> it = logHandlers.iterator();
while (it.hasNext()) {
WeakReference<LogHandler> r = it.next();
LogHandler h = r.get();
if (h == null) {
it.remove();
} else {
h.flush();
}
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Flushing " + h);
}
}
}
} catch (InterruptedException e) {
log.log(LogLevel.WARNING, "flusher was interrupted", e);
}
}
Aggregations