1 17 package org.apache.log.output.jms; 18 19 import javax.jms.Message ; 20 import javax.jms.Session ; 21 22 import org.apache.log.ErrorHandler; 23 import org.apache.log.LogEvent; 24 import org.apache.log.output.AbstractTarget; 25 26 31 public abstract class AbstractJMSTarget 32 extends AbstractTarget 33 { 34 private MessageBuilder m_builder; 36 37 public AbstractJMSTarget( final MessageBuilder builder ) 38 { 39 m_builder = builder; 40 } 41 42 public AbstractJMSTarget( final MessageBuilder builder, 43 final ErrorHandler errorHandler ) 44 { 45 super( errorHandler ); 46 m_builder = builder; 47 } 48 49 protected abstract void send( Message message ); 50 51 protected abstract Session getSession(); 52 53 58 protected void doProcessEvent( final LogEvent event ) 59 throws Exception 60 { 61 final Message message = 62 m_builder.buildMessage( getSession(), event ); 63 send( message ); 64 } 65 66 70 protected synchronized void open() 71 { 72 if( !isOpen() ) 73 { 74 super.open(); 75 openConnection(); 76 } 77 } 78 79 84 public synchronized void close() 85 { 86 if( isOpen() ) 87 { 88 closeConnection(); 89 super.close(); 90 } 91 } 92 93 protected abstract void openConnection(); 94 95 protected abstract void closeConnection(); 96 } 97 | Popular Tags |