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