public final void initialise() throws InitialisationException {
    if (flowConstruct == null) {
      throw new InitialisationException(
          MessageFactory.createStaticMessage(
              "Component has not been initialized properly, no flow constuct."),
          this);
    }

    lifecycleManager.fireInitialisePhase(
        new LifecycleCallback<Component>() {
          public void onTransition(String phaseName, Component object) throws MuleException {
            DefaultMessageProcessorChainBuilder chainBuilder =
                new DefaultMessageProcessorChainBuilder(flowConstruct);
            chainBuilder.setName("Component interceptor processor chain for :" + getName());
            for (Interceptor interceptor : interceptors) {
              chainBuilder.chain(interceptor);
            }
            chainBuilder.chain(
                new MessageProcessor() {
                  public MuleEvent process(MuleEvent event) throws MuleException {
                    return invokeInternal(event);
                  }
                });

            interceptorChain = chainBuilder.build();
            if (interceptorChain instanceof MuleContextAware) {
              ((MuleContextAware) interceptorChain).setMuleContext(muleContext);
            }
            if (interceptorChain instanceof Initialisable) {
              ((Initialisable) interceptorChain).initialise();
            }
            doInitialise();
          }
        });
  }
 public void dispose() {
   lifecycleManager.fireDisposePhase(
       new LifecycleCallback<Component>() {
         public void onTransition(String phaseName, Component object) throws MuleException {
           doDispose();
         }
       });
 }
  private MuleEvent invokeInternal(MuleEvent event) throws MuleException {
    // Ensure we have event in ThreadLocal
    OptimizedRequestContext.unsafeSetEvent(event);

    if (logger.isTraceEnabled()) {
      logger.trace(
          String.format(
              "Invoking %s component for service %s",
              this.getClass().getName(), flowConstruct.getName()));
    }

    if (!lifecycleManager.getState().isStarted() || lifecycleManager.getState().isStopping()) {
      throw new LifecycleException(CoreMessages.isStopped(flowConstruct.getName()), this);
    }

    // Invoke component implementation and gather statistics
    try {
      fireComponentNotification(
          event.getMessage(), ComponentMessageNotification.COMPONENT_PRE_INVOKE);

      long startTime = 0;
      if (statistics.isEnabled()) {
        startTime = System.currentTimeMillis();
      }

      Object result = doInvoke(event);

      if (statistics.isEnabled()) {
        statistics.addExecutionTime(System.currentTimeMillis() - startTime);
      }

      MuleEvent resultEvent = createResultEvent(event, result);
      // Components only have access to the original event, so propogate the
      // stop further processing
      resultEvent.setStopFurtherProcessing(event.isStopFurtherProcessing());
      fireComponentNotification(
          resultEvent.getMessage(), ComponentMessageNotification.COMPONENT_POST_INVOKE);

      return resultEvent;
    } catch (MuleException me) {
      throw me;
    } catch (Exception e) {
      throw new ComponentException(CoreMessages.failedToInvoke(this.toString()), event, this, e);
    }
  }
 public void start() throws MuleException {
   lifecycleManager.fireStartPhase(
       new LifecycleCallback<Component>() {
         public void onTransition(String phaseName, Component object) throws MuleException {
           notificationHandler =
               new OptimisedNotificationHandler(
                   muleContext.getNotificationManager(), ComponentMessageNotification.class);
           doStart();
         }
       });
 }
 public void stop() throws MuleException {
   try {
     lifecycleManager.fireStopPhase(
         new LifecycleCallback<Component>() {
           public void onTransition(String phaseName, Component object) throws MuleException {
             doStop();
           }
         });
   } catch (MuleException e) {
     e.printStackTrace();
     throw e;
   }
 }