001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.jbi.nmr.flow.st;
018
019 import javax.jbi.messaging.MessageExchange;
020 import javax.jbi.messaging.MessagingException;
021
022 import org.apache.servicemix.jbi.messaging.MessageExchangeImpl;
023 import org.apache.servicemix.jbi.nmr.flow.AbstractFlow;
024 import org.apache.servicemix.jbi.servicedesc.AbstractServiceEndpoint;
025
026 /**
027 * A simple Straight through flow.
028 *
029 * A MessageExchange is routed straight to it's destination with
030 * no staging or buffering. A straight through flow is best suited
031 * for the cases where the ServiceMix JBIContainer is deployed with simple
032 * flows (no state) or embedding, or where latency needs to be as low as possible.
033 *
034 * @version $Revision: 564607 $
035 * @org.apache.xbean.XBean element="stFlow"
036 */
037 public class STFlow extends AbstractFlow {
038
039 /**
040 * Distribute an ExchangePacket
041 *
042 * @param packet
043 * @throws MessagingException
044 */
045 protected void doSend(MessageExchangeImpl me) throws MessagingException {
046 if (me.getDestinationId() == null) {
047 me.setDestinationId(((AbstractServiceEndpoint) me.getEndpoint()).getComponentNameSpace());
048 }
049 doRouting(me);
050 }
051
052 /**
053 * The type of Flow
054 * @return the type
055 */
056 public String getDescription() {
057 return "st";
058 }
059
060 /**
061 * Check if the flow can support the requested QoS for this exchange
062 * @param me the exchange to check
063 * @return true if this flow can handle the given exchange
064 */
065 public boolean canHandle(MessageExchange me) {
066 if (isPersistent(me)) {
067 return false;
068 }
069 if (isClustered(me)) {
070 return false;
071 }
072 // We can not handle transactional exchanges:
073 // * asynchronous is a bit weird when the transaction is conveyed
074 // * synchronous could lead to deadlock if the provider uses Push delivery
075 if (isTransacted(me)) {
076 return false;
077 }
078 return true;
079 }
080
081 }