/** {@inheritDoc} */ @Override public void start() throws GridException { if (ctx.isEnterprise()) { Package pkg = getClass().getPackage(); if (pkg == null) throw new GridException( "Internal error (package object was not found) for: " + getClass().getName()); if (ctx.isEnterprise()) { try { Class<?> cls = Class.forName(pkg.getName() + ".GridEnterpriseSecureSessionHandler"); sesHnd = (GridSecureSessionHandler) cls.getConstructor(GridSecureSessionSpi[].class) .newInstance(new Object[] {getProxies()}); } catch (ClassNotFoundException e) { throw new GridException( "Failed to create enterprise secure session handler (implementing class " + "was not found)", e); } catch (InvocationTargetException e) { throw new GridException( "Failed to create enterprise secure session handler (target constructor " + "has thrown an exception", e.getCause()); } catch (InstantiationException e) { throw new GridException( "Failed to create enterprise secure session handler (object cannot be " + "instantiated)", e); } catch (NoSuchMethodException e) { throw new GridException( "Failed to create enterprise secure session handler (target constructor " + "could not be found)", e); } catch (IllegalAccessException e) { throw new GridException( "Failed to create enterprise secure session handler (object access is not" + " allowed)", e); } } } else sesHnd = new GridCommunitySecureSessionHandler(); startSpi(); if (log.isDebugEnabled()) log.debug(startInfo()); }
/** * Provides default implementation for execution of grid-enabled methods. This method assumes that * argument passed in is of {@link GridifyArgument} type. It attempts to reflectively execute a * method based on information provided in the argument and returns the return value of the * method. * * <p>If some exception occurred during execution, then it will be thrown out of this method. * * @return {@inheritDoc} * @throws GridException {@inheritDoc} */ @Override public Object execute() throws GridException { GridifyArgument arg = argument(0); try { // Get public, package, protected, or private method. Method mtd = arg.getMethodClass() .getDeclaredMethod(arg.getMethodName(), arg.getMethodParameterTypes()); // Attempt to soften access control in case we grid-enabling // non-accessible method. Subject to security manager setting. if (!mtd.isAccessible()) try { mtd.setAccessible(true); } catch (SecurityException e) { throw new GridException( "Got security exception when attempting to soften access control for " + "@Gridify method: " + mtd, e); } Object obj = null; // No need to create an instance for static methods. if (!Modifier.isStatic(mtd.getModifiers())) // Obtain instance to execute method on. obj = arg.getTarget(); return mtd.invoke(obj, arg.getMethodParameters()); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof GridException) throw (GridException) e.getTargetException(); throw new GridException( "Failed to invoke a method due to user exception.", e.getTargetException()); } catch (IllegalAccessException e) { throw new GridException("Failed to access method for execution.", e); } catch (NoSuchMethodException e) { throw new GridException("Failed to find method for execution.", e); } }