1 8 package org.jivesoftware.util.log.output; 9 10 import org.jivesoftware.util.log.ErrorAware; 11 import org.jivesoftware.util.log.ErrorHandler; 12 import org.jivesoftware.util.log.LogEvent; 13 import org.jivesoftware.util.log.LogTarget; 14 15 20 public abstract class AbstractTarget implements LogTarget, ErrorAware { 21 22 private ErrorHandler m_errorHandler; 24 25 private boolean m_isOpen; 27 28 33 public synchronized void setErrorHandler(final ErrorHandler errorHandler) { 34 m_errorHandler = errorHandler; 35 } 36 37 protected synchronized boolean isOpen() { 38 return m_isOpen; 39 } 40 41 44 protected synchronized void open() { 45 if (!isOpen()) { 46 m_isOpen = true; 47 } 48 } 49 50 55 public synchronized void processEvent(final LogEvent event) { 56 if (!isOpen()) { 57 getErrorHandler().error("Writing event to closed stream.", null, event); 58 return; 59 } 60 61 try { 62 doProcessEvent(event); 63 } 64 catch (final Throwable throwable) { 65 getErrorHandler().error("Unknown error writing event.", throwable, event); 66 } 67 } 68 69 75 protected abstract void doProcessEvent(LogEvent event) 76 throws Exception ; 77 78 82 public synchronized void close() { 83 if (isOpen()) { 84 m_isOpen = false; 85 } 86 } 87 88 93 protected final ErrorHandler getErrorHandler() { 94 return m_errorHandler; 95 } 96 97 104 protected final void error(final String message, final Throwable throwable) { 105 getErrorHandler().error(message, throwable, null); 106 } 107 } 108 | Popular Tags |