/** * <p> * Associates an endpoint with a service unit. The service unit is used by the container to manage the endpoint's lifecycle. * </p> * * @param serviceUnit a <code>ServiceUnit</code> to which the endpoint will be associated * @org.apache.xbean.Property description="the service unit responsible for the endpoint" hidden="true */ public void setServiceUnit(ServiceUnit serviceUnit) { this.serviceUnit = serviceUnit; this.logger = serviceUnit.getComponent().getLogger(); }
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 Map<String, String> getServiceUnits() { if (endpointRegistrations == null) { throw new IllegalStateException("Service assembly has not been deployed"); } Map<String, String> sus = new HashMap<String, String>(); for (Endpoint ep : getEndpoints()) { if (ep.getServiceUnit() == null) { // This should not happen, as we only register the SA after all endpoints have been deployed throw new IllegalStateException("Endpoint has not been initialized. Check that the component is installed."); } sus.put(ep.getServiceUnit().getName(), ep.getServiceUnit().getComponent().getComponentName()); } return sus; }
public void unregisterServiceUnit(ServiceUnit su) { this.serviceUnits.remove(su.getName()); Collection<Endpoint> endpoints = su.getEndpoints(); for (Endpoint endpoint : endpoints) { unregisterEndpoint(endpoint); } }
protected void doUndeploy(ServiceUnit su) throws Exception { for (int i = 0; i < deployers.length; i++) { if (deployers[i].canDeploy(su.getName(), su.getRootPath())) { deployers[i].undeploy(su); return; } } throw failure("undeploy", "Unable to find suitable deployer for Service Unit '" + su.getName() + "'", null); }
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 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 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); } }
if (!LifeCycleMBean.SHUTDOWN.equals(su.getCurrentState())) { throw failure("init", "ServiceUnit should be in a SHUTDOWN state", null); Thread.currentThread().setContextClassLoader(su.getConfigurationClassLoader()); su.init(); logger.debug("Service unit initialized"); } catch (DeploymentException e) {
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); } }
public boolean isRegistered(ServiceUnit su) { return isServiceUnitRegistered(su.getName()); }
/** * Dynamically adds a new endpoint */ public synchronized void addEndpoint(Endpoint endpoint) throws Exception { endpoint.setServiceUnit(serviceUnit); validateEndpoint(endpoint); endpoint.validate(); registry.registerEndpoint(endpoint); serviceUnit.addEndpoint(endpoint); }
public void registerServiceUnit(ServiceUnit su) { this.serviceUnits.put(su.getName(), su); Collection<Endpoint> endpoints = su.getEndpoints(); for (Endpoint endpoint : endpoints) { registerEndpoint(endpoint); } }
public void undeploy(ServiceUnit su) throws DeploymentException { // Remove the jbiComponent form CamelJbiComponent component.removeJbiComponent(su.getName()); super.undeploy(su); }
ep.setInterfaceName(binding.getPortType().getQName()); validate(ep); su.addEndpoint(ep);
public AbstractEndpoint(ServiceUnit serviceUnit, QName service, String endpoint) { this.serviceUnit = serviceUnit; this.logger = serviceUnit.getComponent().getLogger(); this.service = service; this.endpoint = endpoint; }
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 XFire getXFire() { Jsr181Component component = (Jsr181Component) this.serviceUnit.getComponent(); return component.getXFire(); }
boolean processed = false; try { ClassLoader cl = (ep != null) ? ep.getServiceUnit().getConfigurationClassLoader() : null; if (cl != null) { Thread.currentThread().setContextClassLoader(cl);
protected Container getContainer() { try { ComponentContext ctx = getServiceUnit().getComponent().getComponentContext(); Field field = ctx.getClass().getDeclaredField("container"); field.setAccessible(true); return (Container) field.get(ctx); } catch (Exception e) { logger.debug("Unable to retrieve JBIContainer: {}", e.getMessage()); return null; } }