Package org.servicemix.client

Source Code of org.servicemix.client.SpringEndPointRouter

/**
*
* Copyright 2005 Unity Systems, LLC. http://www.unity-systems.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
**/
package org.servicemix.client;

import javax.jbi.messaging.DeliveryChannel;
import javax.jbi.messaging.MessageExchange;

/**
*
* Allows us to generalize the routing of messages from the <i>DeliveryChannel</i>
* back to the ServiceEndPoints that have been defined, this works with the
* SpringServiceRegistry to all the implementations of EndPoint to be looked up in the
* ClientEndPointRegistry
*
* @author <a href="mailto:pdodds@unity-systems.com">Philip Dodds </a>
*
*/
public class SpringEndPointRouter implements Runnable {

  private DeliveryChannel channel;

  private boolean deliveryActive = true;

  private SpringServiceRegistry registry;

  /**
   * Default constructor takes the JBI delivery channel and an
   * ClientEndPointRegistry for the component
   *
   * @param channel
   *            The JBI delivery channel
   * @param registry
   *            The EndPoint registry to use for handling the forwarding
   */
  public SpringEndPointRouter(DeliveryChannel channel, SpringServiceRegistry registry) {
    this.channel = channel;
    this.registry = registry;
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Runnable#run()
   */
  public void run() {
    deliveryActive = true;
    while (deliveryActive) {
      try {
        MessageExchange exchange = channel.accept(5000);
        if (exchange != null) {
          registry.routeExchange(exchange);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  /**
   * Stops the SpringEndPointRouter listening for messages from the JBI delivery
   * channel
   *
   */
  public void stop() {
    deliveryActive = false;
  }
}
TOP

Related Classes of org.servicemix.client.SpringEndPointRouter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.