Search in sources :

Example 1 with LogHandler

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]);
}
Also used : LogHandler(com.yahoo.logserver.handlers.LogHandler) LogDispatcher(com.yahoo.logserver.LogDispatcher)

Example 2 with LogHandler

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();
    }
}
Also used : LogHandler(com.yahoo.logserver.handlers.LogHandler)

Example 3 with LogHandler

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");
}
Also used : LogHandler(com.yahoo.logserver.handlers.LogHandler)

Example 4 with LogHandler

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);
    }
}
Also used : LogHandler(com.yahoo.logserver.handlers.LogHandler) WeakReference(java.lang.ref.WeakReference)

Aggregations

LogHandler (com.yahoo.logserver.handlers.LogHandler)4 LogDispatcher (com.yahoo.logserver.LogDispatcher)1 WeakReference (java.lang.ref.WeakReference)1