00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
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
00098 logger.warn("NFE in a Body", nfe);
00099
00100
00101 }
00102 }
00103 }