protected Object createBean() throws ClassNotFoundException, InstantiationException, IllegalAccessException { if (beanType == null && beanClassName != null) { beanType = Class.forName(beanClassName, true, getServiceUnit().getConfigurationClassLoader()); } if (beanName == null && beanType == null) { throw new IllegalArgumentException("Property 'bean', 'beanName' or 'beanClassName' has not been set!"); } if (beanName != null && applicationContext == null) { throw new IllegalArgumentException("Property 'beanName' specified, but no BeanFactory set!"); } if (beanType != null) { return beanType.newInstance(); } else { Object answer = applicationContext.getBean(beanName); if (answer == null) { throw new NoSuchBeanException(beanName, this); } return answer; } }
public synchronized void shutDown(String serviceUnitName) throws DeploymentException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { logger.debug("Shutting down service unit"); if (serviceUnitName == null || serviceUnitName.length() == 0) { throw new IllegalArgumentException("serviceUnitName should be non null and non empty"); } ServiceUnit su = getServiceUnit(serviceUnitName); if (su == null) { throw failure("shutDown", "Service Unit '" + serviceUnitName + "' is not deployed", null); } if (!LifeCycleMBean.STOPPED.equals(su.getCurrentState())) { throw failure("shutDown", "ServiceUnit should be in a STOPPED state", null); } Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); su.shutDown(); logger.debug("Service unit shut down"); } catch (DeploymentException e) { throw e; } catch (Exception e) { throw failure("shutDown", "Unable to shutdown service unit", e); } finally { Thread.currentThread().setContextClassLoader(cl); } }
public synchronized void stop(String serviceUnitName) throws DeploymentException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { logger.debug("Stopping service unit"); if (serviceUnitName == null || serviceUnitName.length() == 0) { throw new IllegalArgumentException("serviceUnitName should be non null and non empty"); } ServiceUnit su = getServiceUnit(serviceUnitName); if (su == null) { throw failure("stop", "Service Unit '" + serviceUnitName + "' is not deployed", null); } if (!LifeCycleMBean.STARTED.equals(su.getCurrentState())) { throw failure("stop", "ServiceUnit should be in a STARTED state", null); } Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); su.stop(); logger.debug("Service unit stopped"); } catch (DeploymentException e) { throw e; } catch (Exception e) { throw failure("stop", "Unable to stop service unit", e); } finally { Thread.currentThread().setContextClassLoader(cl); } }
public synchronized void start(String serviceUnitName) throws DeploymentException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { logger.debug("Starting service unit"); if (serviceUnitName == null || serviceUnitName.length() == 0) { throw new IllegalArgumentException("serviceUnitName should be non null and non empty"); } ServiceUnit su = (ServiceUnit) getServiceUnit(serviceUnitName); if (su == null) { throw failure("start", "Service Unit '" + serviceUnitName + "' is not deployed", null); } if (!LifeCycleMBean.STOPPED.equals(su.getCurrentState())) { throw failure("start", "ServiceUnit should be in a STOPPED state", null); } Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); su.start(); logger.debug("Service unit started"); } catch (DeploymentException e) { throw e; } catch (Exception e) { throw failure("start", "Unable to start service unit", e); } finally { Thread.currentThread().setContextClassLoader(cl); } }
public void start() throws Exception { super.start(); try { // lazy instatiation this.manager = new ScriptEngineManager(serviceUnit.getConfigurationClassLoader()); if (script == null) { throw new IllegalArgumentException("Property script must be set"); } else { // initialize the script engine if (this.language.equalsIgnoreCase(LANGUAGE_AUTODETECT)) { // detect language by file extension this.engine = this.manager.getEngineByExtension(getExtension(script.getFilename())); if (this.engine == null) { throw new RuntimeException("There is no script engine registered for extension " + getExtension(script.getFilename())); } } else { // use predefined language from xbean this.engine = this.manager.getEngineByName(this.language); if (this.engine == null) { throw new RuntimeException("There is no script engine for language " + this.language); } } } // do custom startup logic marshaler.onStartup(this); } catch (Exception ex) { throw new JBIException(ex); } }
public synchronized String undeploy(String serviceUnitName, String serviceUnitRootPath) throws DeploymentException { ClassLoader cl = Thread.currentThread().getContextClassLoader(); try { logger.debug("Undeploying service unit"); logger.debug("Shutting down service unit"); if (serviceUnitName == null || serviceUnitName.length() == 0) { throw new IllegalArgumentException("serviceUnitName should be non null and non empty"); } ServiceUnit su = getServiceUnit(serviceUnitName); if (su == null) { throw failure("undeploy", "Service Unit '" + serviceUnitName + "' is not deployed", null); } if (!LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) { throw failure("undeploy", "ServiceUnit should be in a SHUTDOWN state", null); } Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); if (serviceUnitRootPath != null) { doUndeploy(su); } component.getRegistry().unregisterServiceUnit(su); logger.debug("Service unit undeployed"); return createSuccessMessage("undeploy"); } catch (DeploymentException e) { throw e; } catch (Exception e) { throw failure("undeploy", "Unable to undeploy service unit", e); } finally { Thread.currentThread().setContextClassLoader(cl); } }
throw failure("init", "ServiceUnit should be in a SHUTDOWN state", null); Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); su.init(); logger.debug("Service unit initialized");
boolean processed = false; try { ClassLoader cl = (ep != null) ? ep.getServiceUnit().getConfigurationClassLoader() : null; if (cl != null) { Thread.currentThread().setContextClassLoader(cl);
throw new IllegalArgumentException("Endpoint must have a non-null pojo or a pojoClass"); Class cl = Class.forName(pojoClass, true, getServiceUnit().getConfigurationClassLoader()); pojo = cl.newInstance(); Class serviceClass = pojo.getClass(); if (serviceInterface != null) { serviceClass = Class.forName(serviceInterface, true, getServiceUnit().getConfigurationClassLoader());