org/objectweb/proactive/core/exceptions/manager/NFEManager.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.exceptions.manager;
00032 
00033 import org.apache.log4j.Logger;
00034 import org.objectweb.proactive.core.body.UniversalBody;
00035 import org.objectweb.proactive.core.body.proxy.AbstractProxy;
00036 import org.objectweb.proactive.core.exceptions.NonFunctionalException;
00037 import org.objectweb.proactive.core.exceptions.body.BodyNonFunctionalException;
00038 import org.objectweb.proactive.core.exceptions.proxy.ProxyNonFunctionalException;
00039 import org.objectweb.proactive.core.util.log.Loggers;
00040 import org.objectweb.proactive.core.util.log.ProActiveLogger;
00041 
00042 
00043 public class NFEManager {
00044     // NFEProducer implementation
00045     private static NFEListenerList nfeListeners = null;
00046     private static Logger logger = ProActiveLogger.getLogger(Loggers.NFE);
00047 
00048     public static void addNFEListener(NFEListener listener) {
00049         if (nfeListeners == null) {
00050             nfeListeners = new NFEListenerList();
00051         }
00052         nfeListeners.addNFEListener(listener);
00053     }
00054 
00055     public static void removeNFEListener(NFEListener listener) {
00056         if (nfeListeners != null) {
00057             nfeListeners.removeNFEListener(listener);
00058         }
00059     }
00060 
00061     public static int fireNFE(BodyNonFunctionalException e, UniversalBody body) {
00062         return fireNFE(e, body, null);
00063     }
00064 
00065     public static int fireNFE(ProxyNonFunctionalException e, AbstractProxy proxy) {
00066         return fireNFE(e, null, proxy);
00067     }
00068 
00069     private static int fireNFE(NonFunctionalException e, UniversalBody body,
00070         AbstractProxy proxy) {
00071         int nbListeners = 0;
00072 
00073         if (body != null) {
00074             nbListeners += body.fireNFE(e);
00075         }
00076 
00077         if (proxy != null) {
00078             nbListeners += proxy.fireNFE(e);
00079         }
00080 
00081         if (nfeListeners != null) {
00082             nbListeners += nfeListeners.fireNFE(e);
00083         }
00084 
00085         if (nbListeners == 0) {
00086             defaultNFEHandler(e);
00087         }
00088 
00089         return nbListeners;
00090     }
00091 
00092     public static void defaultNFEHandler(NonFunctionalException nfe) {
00093         try {
00094             throw nfe;
00095         } catch (BodyNonFunctionalException bnfe) {
00096 
00097             /* Avoid killing an AO */
00098             logger.warn("NFE in a Body", nfe);
00099 
00100             /* But the exception will be thrown if it's on the proxy */
00101         }
00102     }
00103 }

Generated on Mon Jan 22 15:16:08 2007 for ProActive by  doxygen 1.5.1