01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) The JacORB project, 1997-2006.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * version 2 of the License, or (at your option) any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Library General Public License for more details.
15: *
16: * You should have received a copy of the GNU Library General Public
17: * License along with this library; if not, write to the Free
18: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19: */
20:
21: package org.jacorb.orb.listener;
22:
23: import org.apache.avalon.framework.configuration.Configurable;
24: import org.apache.avalon.framework.configuration.Configuration;
25: import org.apache.avalon.framework.configuration.ConfigurationException;
26: import org.apache.avalon.framework.logger.Logger;
27: import org.jacorb.orb.iiop.IIOPListener;
28: import org.jacorb.util.ObjectUtil;
29:
30: /**
31: * The JacORB default implementation of interface
32: * <code>AcceptorExceptionListener</code>. It will shutdown the ORB on all
33: * Errors and for SSLExceptions that are thrown on the first loop.
34: *
35: * @author Nick Cross
36: * @version $Id: DefaultAcceptorExceptionListener.java,v 1.2 2006/06/29 13:20:58 alphonse.bendt Exp $
37: */
38: public class DefaultAcceptorExceptionListener implements
39: AcceptorExceptionListener, Configurable {
40: /**
41: * <code>sslException</code> is a cached class name for ssl exceptions.
42: */
43: private Class sslException;
44:
45: /**
46: * <code>logger</code> is the logger.
47: */
48: private Logger logger;
49:
50: /**
51: * Creates a new <code>DefaultAcceptorExceptionListener</code> instance.
52: *
53: */
54: public void configure(Configuration configuration) {
55: try {
56: String exceptionClass = configuration
57: .getAttribute("javax.net.ssl.SSLException");
58: sslException = ObjectUtil.classForName(exceptionClass);
59: } catch (ClassNotFoundException e) {
60: } catch (ConfigurationException e) {
61: sslException = null;
62: }
63: {
64: sslException = null;
65: }
66:
67: logger = ((org.jacorb.config.Configuration) configuration)
68: .getNamedLogger("jacorb.orb.iiop");
69: }
70:
71: /**
72: * Throwable <code>th</code> has been caught by the acceptor thread.
73: *
74: * @param e an <code>AcceptorExceptionEvent</code> value
75: */
76: public void exceptionCaught(AcceptorExceptionEvent e) {
77: if (logger.isDebugEnabled()) {
78: logger.debug("Caught acceptor event: " + e);
79: }
80:
81: if ((e.getException() instanceof Error)
82: || (!((IIOPListener.Acceptor) e.getSource())
83: .getAcceptorSocketLoop() && (sslException != null && sslException
84: .isInstance(e.getException())))) {
85: logger.fatalError("fatal exception. will shutdown orb", e
86: .getException());
87:
88: e.getORB().shutdown(true);
89: }
90: }
91: }
|