List of usage examples for java.lang.reflect InvocationTargetException getTargetException
public Throwable getTargetException()
From source file:org.unitime.timetable.solver.jgroups.CourseSolverContainerRemote.java
@Override public Object dispatch(Address address, String user, Method method, Object[] args) throws Exception { try {/* ww w .j a va 2s . c o m*/ return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), user, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } catch (Exception e) { if ("exists".equals(method.getName()) && e instanceof SuspectedException) return false; sLog.error("Excution of " + method.getName() + " on solver " + user + " failed: " + e.getMessage(), e); throw e; } }
From source file:org.unitime.timetable.solver.jgroups.ExaminationSolverContainerRemote.java
@Override public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { try {// ww w. j ava 2 s.c o m ExamSolverProxy solver = iExamSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } finally { _RootDAO.closeCurrentThreadSessions(); } }
From source file:org.unitime.timetable.solver.jgroups.OnlineStudentSchedulingContainerRemote.java
@Override public Object invoke(String method, String sessionId, Class[] types, Object[] args) throws Exception { try {/*from w ww. ja va 2s . c om*/ OnlineSectioningServer solver = iInstances.get(Long.valueOf(sessionId)); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Server " + sessionId + " does not exist."); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } finally { _RootDAO.closeCurrentThreadSessions(); } }
From source file:org.unitime.timetable.solver.jgroups.OnlineStudentSchedulingContainerRemote.java
@Override public Object dispatch(Address address, String sessionId, Method method, Object[] args) throws Exception { try {//from w w w . ja v a 2s . c o m return iDispatcher.callRemoteMethod(address, "invoke", new Object[] { method.getName(), sessionId, method.getParameterTypes(), args }, new Class[] { String.class, String.class, Class[].class, Object[].class }, SolverServerImplementation.sFirstResponse); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } catch (Exception e) { if ("exists".equals(method.getName()) && e instanceof SuspectedException) return false; sLog.debug("Excution of " + method.getName() + " on server " + sessionId + " failed: " + e.getMessage(), e); throw e; } }
From source file:org.unitime.timetable.solver.jgroups.OnlineStudentSchedulingContainerRemote.java
@Override public Object dispatch(Collection<Address> addresses, String sessionId, Method method, Object[] args) throws Exception { try {//from w w w .j av a 2s . c o m if (addresses.size() == 1) { return dispatch(ToolBox.random(addresses), sessionId, method, args); } else { Address address = ToolBox.random(addresses); CheckMaster ch = method.getAnnotation(CheckMaster.class); if (ch == null && "execute".equals(method.getName())) ch = args[0].getClass().getAnnotation(CheckMaster.class); RspList<Boolean> ret = iDispatcher.callRemoteMethods(addresses, "hasMaster", new Object[] { sessionId }, new Class[] { String.class }, SolverServerImplementation.sAllResponses); if (ch != null && ch.value() == Master.REQUIRED) { for (Rsp<Boolean> rsp : ret) { if (rsp != null && rsp.getValue()) { address = rsp.getSender(); break; } } } else { List<Address> slaves = new ArrayList<Address>(); for (Rsp<Boolean> rsp : ret) { if (rsp != null && !rsp.getValue()) { slaves.add(rsp.getSender()); } } if (!slaves.isEmpty()) address = ToolBox.random(slaves); } return dispatch(address, sessionId, method, args); } } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } }
From source file:org.unitime.timetable.solver.jgroups.StudentSolverContainerRemote.java
@Override public Object invoke(String method, String user, Class[] types, Object[] args) throws Exception { try {/* w w w . ja v a 2s . co m*/ StudentSolverProxy solver = iStudentSolvers.get(user); if ("exists".equals(method) && types.length == 0) return solver != null; if (solver == null) throw new Exception("Solver " + user + " does not exist."); return solver.getClass().getMethod(method, types).invoke(solver, args); } catch (InvocationTargetException e) { if (e.getTargetException() != null && e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException(); else throw e; } finally { _RootDAO.closeCurrentThreadSessions(); } }
From source file:org.wso2.carbon.bridge.EquinoxFrameworkLauncher.java
/** * start is used to "start" a previously deployed OSGi framework * The default behaviour will read launcher.ini to create a set of initial properties and * use the "commandline" configuration parameter to create the equivalent command line arguments * available when starting Eclipse.//from w w w. jav a 2 s .c o m */ public synchronized void start() { platformDirectory = getCarbonComponentRepo(); if (platformDirectory == null) { throw new IllegalStateException("Could not start the Framework - (not deployed)"); } if (frameworkClassLoader != null) { context.log("Framework is already started"); return; } Map<String, String> initialPropsMap = buildInitialPropertyMap(); String[] args = getArgs(); ClassLoader original = Thread.currentThread().getContextClassLoader(); try { System.setProperty("osgi.framework.useSystemProperties", "false"); frameworkClassLoader = new ChildFirstURLClassLoader( new URL[] { new URL(initialPropsMap.get(OSGI_FRAMEWORK)) }, this.getClass().getClassLoader()); Class clazz = frameworkClassLoader.loadClass(STARTER); Method setInitialProperties = clazz.getMethod("setInitialProperties", Map.class); setInitialProperties.invoke(null, initialPropsMap); registerRestartHandler(clazz); Method runMethod = clazz.getMethod("startup", String[].class, Runnable.class); runMethod.invoke(null, args, null); frameworkContextClassLoader = Thread.currentThread().getContextClassLoader(); isRunning = true; } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t == null) { t = ite; } context.log("Error while starting Framework", t); throw new RuntimeException(t.getMessage()); } catch (Exception e) { context.log("Error while starting Framework", e); throw new RuntimeException(e.getMessage()); } finally { Thread.currentThread().setContextClassLoader(original); } }
From source file:org.wso2.carbon.bridge.EquinoxFrameworkLauncher.java
private Runnable createRestartHandler() throws ClassNotFoundException, NoSuchMethodException { Class frameworkPropertiesClazz = frameworkClassLoader.loadClass(FRAMEWORKPROPERTIES); final Method getProperty = frameworkPropertiesClazz.getMethod("getProperty", String.class); Runnable restartHandler = new Runnable() { public void run() { try { String forcedRestart = (String) getProperty.invoke(null, OSGI_FORCED_RESTART); if (Boolean.valueOf(forcedRestart).booleanValue()) { stop();/*ww w .j ava2s . c o m*/ start(); } } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t == null) { t = ite; } throw new RuntimeException(t.getMessage()); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }; return restartHandler; }
From source file:org.wso2.carbon.micro.integrator.server.Main.java
private static void startEquinox() { /**// w w w .j av a 2s .c om * Launches Equinox OSGi framework by invoking EclipseStarter.startup() method using reflection. * Creates a ChildFirstClassLoader out of the OSGi framework jar and set the classloader as the framework * classloader. */ URLClassLoader frameworkClassLoader = null; platformDirectory = Utils.getCarbonComponentRepo(); if (platformDirectory == null) { throw new IllegalStateException("Could not start the Framework - (not deployed)"); } if (frameworkClassLoader != null) { return; } final Map<String, String> initialPropsMap = buildInitialPropertyMap(); String[] args2 = Utils.getArgs(); ClassLoader original = Thread.currentThread().getContextClassLoader(); try { System.setProperty("osgi.framework.useSystemProperties", "false"); frameworkClassLoader = java.security.AccessController .doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { URLClassLoader cl = null; try { cl = new ChildFirstURLClassLoader( new URL[] { new URL(initialPropsMap.get(OSGI_FRAMEWORK)) }, null); } catch (MalformedURLException e) { log.error(e.getMessage(), e); } return cl; } }); // frameworkClassLoader = //Loads EclipseStarter class. Class clazz = frameworkClassLoader.loadClass(STARTER); //Set the propertyMap by invoking setInitialProperties method. Method setInitialProperties = clazz.getMethod("setInitialProperties", Map.class); setInitialProperties.invoke(null, initialPropsMap); //Invokes the startup method with some arguments. Method runMethod = clazz.getMethod("startup", String[].class, Runnable.class); runMethod.invoke(null, args2, null); } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t == null) { t = ite; } throw new RuntimeException(t.getMessage()); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } finally { Thread.currentThread().setContextClassLoader(original); } }
From source file:org.wso2.carbon.server.CarbonLauncher.java
/** * Launches Equinox OSGi framework by invoking EclipseStarter.startup() method using reflection. * Creates a ChildFirstClassLoader out of the OSGi framework jar and set the classloader as the framework * classloader.//from w w w . j a v a 2 s .com */ public void launch() { platformDirectory = Utils.getCarbonComponentRepo(); if (platformDirectory == null) { throw new IllegalStateException("Could not start the Framework - (not deployed)"); } if (frameworkClassLoader != null) { return; } final Map<String, String> initialPropsMap = buildInitialPropertyMap(); String[] args2 = Utils.getArgs(); ClassLoader original = Thread.currentThread().getContextClassLoader(); try { System.setProperty("osgi.framework.useSystemProperties", "false"); frameworkClassLoader = java.security.AccessController .doPrivileged(new java.security.PrivilegedAction<URLClassLoader>() { public URLClassLoader run() { URLClassLoader cl = null; try { cl = new ChildFirstURLClassLoader( new URL[] { new URL(initialPropsMap.get(OSGI_FRAMEWORK)) }, null); } catch (MalformedURLException e) { log.error(e.getMessage(), e); } return cl; } }); // frameworkClassLoader = //Loads EclipseStarter class. Class clazz = frameworkClassLoader.loadClass(STARTER); //Set the propertyMap by invoking setInitialProperties method. Method setInitialProperties = clazz.getMethod("setInitialProperties", Map.class); setInitialProperties.invoke(null, initialPropsMap); //Invokes the startup method with some arguments. Method runMethod = clazz.getMethod("startup", String[].class, Runnable.class); runMethod.invoke(null, args2, null); } catch (InvocationTargetException ite) { Throwable t = ite.getTargetException(); if (t == null) { t = ite; } throw new RuntimeException(t.getMessage()); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } finally { Thread.currentThread().setContextClassLoader(original); } }