コード例 #1
0
 /*
  * (non-Javadoc)
  *
  * @see org.mule.umo.provider.UMOConnector#registerListener(org.mule.umo.UMOSession,
  *      org.mule.umo.endpoint.UMOEndpoint)
  */
 public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint)
     throws Exception {
   if (queueEvents) {
     queueProfile.configureQueue(endpoint.getEndpointURI().getAddress());
   }
   return serviceDescriptor.createMessageReceiver(this, component, endpoint);
 }
 @Override
 protected void doSetUp() throws Exception {
   super.doSetUp();
   queueProfile = QueueProfile.newInstancePersistingToDefaultMemoryQueueStore(muleContext);
   queueStatistics = new TestQueueStatistics();
   queueTimeout = muleContext.getConfiguration().getDefaultQueueTimeout();
   lifeCycleState = new TestLifeCycleState();
   super.doSetUp();
   ((Initialisable) messageProcessor).initialise();
   ((Startable) messageProcessor).start();
   lifeCycleState.start();
 }
 @Test
 public void customQueueSize() throws Exception {
   int queueSize = 100;
   queueProfile.setMaxOutstandingMessages(queueSize);
   SedaStageInterceptingMessageProcessor mp;
   mp =
       new SedaStageInterceptingMessageProcessor(
           "name",
           "name",
           queueProfile,
           queueTimeout,
           muleContext.getDefaultThreadingProfile(),
           queueStatistics,
           muleContext);
   assertThat(mp.queueProfile.getMaxOutstandingMessages(), is(equalTo(queueSize)));
 }
コード例 #4
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
   * @see org.mule.api.UMODescriptor
   */
  protected synchronized void doInitialise() throws InitialisationException {
    MuleConfiguration config = muleContext.getConfiguration();
    if (threadingProfile == null) {
      // TODO MULE-2102 This should be configured in the default template.
      threadingProfile = muleContext.getDefaultComponentThreadingProfile();
    }
    // Create thread pool
    workManager = threadingProfile.createWorkManager(getName());

    if (queueProfile == null) {
      // TODO MULE-2102 This should be configured in the default template.
      queueProfile = ((SedaModel) model).getQueueProfile();
    }

    if (queueTimeout == null) {
      // TODO MULE-2102 This should be configured in the default template.
      setQueueTimeout(new Integer(((SedaModel) model).getQueueTimeout()));
    }

    try {
      if (name == null) {
        throw new InitialisationException(
            MessageFactory.createStaticMessage("Service has no name to identify it"), this);
      }
      // Setup event Queue (used for VM execution).  The queue has the same name as the service.
      queueProfile.configureQueue(name, muleContext.getQueueManager());
      queue = muleContext.getQueueManager().getQueueSession().getQueue(name);
      if (queue == null) {
        throw new InitialisationException(
            MessageFactory.createStaticMessage(
                "Queue " + name + " not created for service " + name),
            this);
      }
    } catch (InitialisationException e) {
      throw e;
    } catch (Throwable e) {
      throw new InitialisationException(
          CoreMessages.objectFailedToInitialise("Service Queue"), e, this);
    }
  }
コード例 #5
0
  /**
   * While the service isn't stopped this runs a continuous loop checking for new events in the
   * queue.
   */
  public void run() {
    DefaultMuleEvent event = null;
    QueueSession queueSession = muleContext.getQueueManager().getQueueSession();

    while (!stopped.get()) {
      try {
        // Wait if the service is paused
        if (paused.get()) {
          paused.whenFalse(null);

          // If service is resumed as part of stopping
          if (stopping.get()) {
            if (!queueProfile.isPersistent() && (queueSession != null && getQueueSize() > 0)) {
              // Any messages in a non-persistent queue went paused service is stopped are lost
              logger.warn(
                  CoreMessages.stopPausedSedaServiceNonPeristentQueueMessageLoss(
                      getQueueSize(), this));
            }
            stopping.set(false);
            break;
          }
        }

        // If we're doing a draining stop, read all events from the queue
        // before stopping
        if (stopping.get()) {
          if (queueProfile.isPersistent() || (queueSession == null || getQueueSize() <= 0)) {
            stopping.set(false);
            break;
          }
        }

        if (stats.isEnabled()) {
          synchronized (queueStatsGuard) {
            event = (DefaultMuleEvent) dequeue();
            if (event != null) {
              stats.decQueuedEvent();
            }
          }
        } else {
          // just dequeue without any hit for synchronization
          event = (DefaultMuleEvent) dequeue();
        }

        if (event != null) {
          if (logger.isDebugEnabled()) {
            logger.debug(
                MessageFormat.format(
                    "Service: {0} dequeued event on: {1}",
                    name, event.getEndpoint().getEndpointURI()));
          }
          workManager.scheduleWork(
              new ComponentStageWorker(event), WorkManager.INDEFINITE, null, this);
        }
      } catch (Exception e) {
        if (e instanceof InterruptedException) {
          stopping.set(false);
          break;
        }
        if (e instanceof MuleException) {
          handleException(e);
        } else {
          handleException(
              new ServiceException(
                  CoreMessages.eventProcessingFailedFor(name),
                  (event == null ? null : event.getMessage()),
                  this,
                  e));
        }
      }
    }
  }