1 31 32 package org.objectweb.proactive.examples.nfe; 33 34 import org.objectweb.proactive.ProActive; 35 import org.objectweb.proactive.core.config.ProActiveConfiguration; 36 import org.objectweb.proactive.core.exceptions.NonFunctionalException; 37 import org.objectweb.proactive.core.exceptions.communication.ProActiveCommunicationException; 38 import org.objectweb.proactive.core.exceptions.communication.SendRequestCommunicationException; 39 import org.objectweb.proactive.core.exceptions.handler.HandlerNonFunctionalException; 40 import org.objectweb.proactive.core.exceptions.handler.IHandler; 41 42 43 46 public class TestNFE { 47 48 51 public static void raiseException(Class classOfException) throws NonFunctionalException { 52 53 System.out.println("*** RAISE " + classOfException.getName()); 54 55 NonFunctionalException ex = null; 57 try { 58 ex = (NonFunctionalException) classOfException.getConstructor(new Class [] {String .class, Throwable .class}).newInstance(new Object [] {classOfException.getName(), null}); 59 } catch (Exception e) { 60 if (e instanceof ClassNotFoundException ) 61 System.out.println("*** ERROR : cannot find class " + ex); 62 else 63 e.printStackTrace(); 64 } 65 66 throw ex; 68 } 69 70 71 public static void main(String [] args) { 73 ProActiveConfiguration.load(); 74 75 ProActiveConfiguration.load(); 76 if (args.length != 1) { 78 System.out.println("Usage : java org.objectweb.proactive.examples.nfeCreation NFE"); 79 System.exit(0); 80 } 81 82 NonFunctionalException ex = null; 84 85 try { 87 ex = (NonFunctionalException) Class.forName(args[0]).getConstructor(new Class [] {String .class, Throwable .class}).newInstance(new Object [] {args[0], null}); 88 } catch (ClassNotFoundException e) { 89 System.out.println("Class " + args[0] + " is not a valid NFE"); 90 System.exit(0); 91 } catch (InstantiationException e) { 92 System.out.println("Problems occurs when instantiating " + args[0]); 93 e.printStackTrace(); 94 System.exit(0); 95 } catch (Exception e) { 96 e.printStackTrace(); 97 System.exit(0); 98 } 99 100 System.out.println("PARAMETER : " + ex.getDescription() + ex.getMessage()); 102 103 System.out.println(); 105 ProActive.setExceptionHandler(IHandler.ID_defaultLevel, null, HandlerNonFunctionalException.class, NonFunctionalException.class); 106 ProActive.unsetExceptionHandler(IHandler.ID_defaultLevel, null, HandlerNonFunctionalException.class); 107 ProActive.setExceptionHandler(IHandler.ID_VMLevel, null, HandlerNonFunctionalException.class, NonFunctionalException.class); 108 ProActive.unsetExceptionHandler(IHandler.ID_VMLevel, null, NonFunctionalException.class); 109 110 System.out.println(); 112 try { 113 raiseException(ProActiveCommunicationException.class); 114 } catch (NonFunctionalException nfe) { 115 IHandler handler = ProActive.searchExceptionHandler(nfe); 116 if (handler != null) handler.handle(nfe); 117 } 118 119 System.out.println(); 121 try { 122 raiseException(SendRequestCommunicationException.class); 123 } catch (NonFunctionalException nfe) { 124 IHandler handler = ProActive.searchExceptionHandler(nfe); 125 if (handler != null) handler.handle(nfe); 126 } 127 128 System.exit(0); 130 } 131 } | Popular Tags |