Пример #1
0
  /**
   * Initialise the service. The service will first create a Mule UMO from the UMODescriptor and
   * then initialise a pool based on the attributes in the UMODescriptor.
   *
   * @throws org.mule.api.lifecycle.InitialisationException if the service fails to initialise
   */
  public final synchronized void initialise() throws InitialisationException {
    if (initialised.get()) {
      throw new InitialisationException(
          CoreMessages.objectAlreadyInitialised("Service '" + name + "'"), this);
    }
    // Ensure Component has service instance and is initialised. If the component
    // was configured with spring and is therefore in the registry it will get
    // started automatically, if it was set on the service directly then it won't
    // be started automatically. So to be sure we start it here.
    component.setService(this);
    component.initialise();

    if (inboundRouter == null) {
      // Create Default routes that route to the default inbound and
      // outbound endpoints
      inboundRouter = new DefaultInboundRouterCollection();
      // TODO MULE-2102 This should be configured in the default template.
      inboundRouter.addRouter(new InboundPassThroughRouter());
    }
    if (outboundRouter == null) {
      outboundRouter = new DefaultOutboundRouterCollection();
      // TODO MULE-2102 This should be configured in the default template.
      outboundRouter.addRouter(new OutboundPassThroughRouter());
    }
    if (responseRouter == null) {
      responseRouter = new DefaultResponseRouterCollection();
    }

    if (exceptionListener == null) {
      // By default us the model Exception Listener
      exceptionListener = getModel().getExceptionListener();
      //            // TODO MULE-2102 This should be configured in the default template.
      //            exceptionListener = new DefaultServiceExceptionStrategy(this);
      //            ((MuleContextAware) exceptionListener).setMuleContext(muleContext);
      //            ((Initialisable) exceptionListener).initialise();
    }

    doInitialise();

    // initialise statistics
    stats = createStatistics();

    stats.setEnabled(muleContext.getStatistics().isEnabled());
    muleContext.getStatistics().add(stats);
    stats.setOutboundRouterStat(outboundRouter.getStatistics());
    stats.setInboundRouterStat(inboundRouter.getStatistics());
    stats.setComponentStat(component.getStatistics());

    initialised.set(true);
    fireServiceNotification(ServiceNotification.SERVICE_INITIALISED);
  }
Пример #2
0
  /**
   * Initialise the service. The service will first create a component from the ServiceDescriptor
   * and then initialise a pool based on the attributes in the ServiceDescriptor .
   *
   * @see org.mule.api.registry.ServiceDescriptor
   * @throws org.mule.api.lifecycle.InitialisationException if the service fails to initialise
   */
  public final synchronized void initialise() throws InitialisationException {
    if (inboundRouter == null) {
      // Create Default routes that route to the default inbound and
      // outbound endpoints
      inboundRouter = new DefaultInboundRouterCollection();
      // TODO MULE-2102 This should be configured in the default template.
      inboundRouter.addRouter(new InboundPassThroughRouter());
    }
    if (outboundRouter == null) {
      outboundRouter = new DefaultOutboundRouterCollection();
      // TODO MULE-2102 This should be configured in the default template.
      outboundRouter.addRouter(new OutboundPassThroughRouter());
    }
    if (responseRouter == null) {
      responseRouter = new DefaultResponseRouterCollection();
    }

    if (exceptionListener == null) {
      // By default us the model Exception Listener
      exceptionListener = getModel().getExceptionListener();
      //            // TODO MULE-2102 This should be configured in the default template.
      //            exceptionListener = new DefaultServiceExceptionStrategy(this);
      //            ((MuleContextAware) exceptionListener).setMuleContext(muleContext);
      //            ((Initialisable) exceptionListener).initialise();
    }

    try {
      lifecycleManager.fireLifecycle(Initialisable.PHASE_NAME);
    } catch (LifecycleException e) {
      throw new InitialisationException(e, this);
    }
    // Ensure Component has service instance and is initialised. If the component
    // was configured with spring and is therefore in the registry it will get
    // started automatically, if it was set on the service directly then it won't
    // be started automatically. So to be sure we start it here.
    component.setService(this);
    component.initialise();

    // initialise statistics
    stats = createStatistics();

    stats.setEnabled(muleContext.getStatistics().isEnabled());
    muleContext.getStatistics().add(stats);
    stats.setOutboundRouterStat(outboundRouter.getStatistics());
    stats.setInboundRouterStat(inboundRouter.getStatistics());
    stats.setComponentStat(component.getStatistics());
  }