1 package org.codehaus.spice.netserve.connection.impl; 2 3 import java.io.IOException; 4 import java.net.ServerSocket; 5 6 /*** 7 * An abstract monitor that writes out messages 8 * for acceptor events. Need to subclass and implement 9 * methods to write out log messages. 10 */ 11 public abstract class AbstractLoggingAcceptorMonitor 12 implements AcceptorMonitor 13 { 14 /*** 15 * @see AcceptorMonitor#acceptorCreated 16 */ 17 public void acceptorCreated( final String name, 18 final ServerSocket serverSocket ) 19 { 20 final String message = 21 "Creating Acceptor " + name + " on " + 22 serverSocket.getInetAddress().getHostAddress() + ":" + 23 serverSocket.getLocalPort() + "."; 24 info( message ); 25 } 26 27 /*** 28 * @see AcceptorMonitor#acceptorClosing 29 */ 30 public void acceptorClosing( final String name, 31 final ServerSocket serverSocket ) 32 { 33 final String message = "Closing Acceptor " + name + "."; 34 info( message ); 35 } 36 37 /*** 38 * @see AcceptorMonitor#serverSocketListening 39 */ 40 public void serverSocketListening( final String name, 41 final ServerSocket serverSocket ) 42 { 43 if ( isDebugEnabled() ) 44 { 45 final String message = 46 "About to call accept() on ServerSocket '" + name + "'."; 47 debug( message ); 48 } 49 } 50 51 /*** 52 * @see AcceptorMonitor#errorAcceptingConnection 53 */ 54 public void errorAcceptingConnection( final String name, 55 final IOException ioe ) 56 { 57 warn( "Error Accepting connection on " + name, ioe ); 58 } 59 60 /*** 61 * @see AcceptorMonitor#errorClosingServerSocket 62 */ 63 public void errorClosingServerSocket( final String name, 64 final IOException ioe ) 65 { 66 warn( "Error Closing Server Socket " + name, ioe ); 67 } 68 69 /*** 70 * Return true if debug logging enabled. 71 * 72 * @return true if debug logging enabled. 73 */ 74 protected abstract boolean isDebugEnabled(); 75 76 /*** 77 * Write out debug message. 78 * 79 * @param message the message 80 */ 81 protected abstract void debug( String message ); 82 83 /*** 84 * Write out info message. 85 * 86 * @param message the message 87 */ 88 protected abstract void info( String message ); 89 90 /*** 91 * Write out warn message. 92 * 93 * @param message the message 94 * @param e the warnings cause 95 */ 96 protected abstract void warn( String message, Exception e ); 97 }