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 */ 017package org.apache.camel.processor; 018 019import org.apache.camel.AsyncCallback; 020import org.apache.camel.AsyncProcessor; 021import org.apache.camel.Exchange; 022import org.apache.camel.ExchangePattern; 023import org.apache.camel.spi.IdAware; 024import org.apache.camel.support.ServiceSupport; 025import org.apache.camel.util.AsyncProcessorHelper; 026 027/** 028 * Processor to set {@link org.apache.camel.ExchangePattern} on the {@link org.apache.camel.Exchange}. 029 */ 030public class ExchangePatternProcessor extends ServiceSupport implements AsyncProcessor, IdAware { 031 private String id; 032 private ExchangePattern exchangePattern = ExchangePattern.InOnly; 033 034 public ExchangePatternProcessor() { 035 } 036 037 public ExchangePatternProcessor(ExchangePattern ep) { 038 setExchangePattern(ep); 039 } 040 041 public void setExchangePattern(ExchangePattern ep) { 042 exchangePattern = ep; 043 } 044 045 public String getId() { 046 return id; 047 } 048 049 public void setId(String id) { 050 this.id = id; 051 } 052 053 public ExchangePattern getExchangePattern() { 054 return exchangePattern; 055 } 056 057 public void process(Exchange exchange) throws Exception { 058 AsyncProcessorHelper.process(this, exchange); 059 } 060 061 public boolean process(Exchange exchange, AsyncCallback callback) { 062 exchange.setPattern(exchangePattern); 063 callback.done(true); 064 return true; 065 } 066 067 @Override 068 public String toString() { 069 return "SetExchangePattern[" + exchangePattern + "]"; 070 } 071 072 @Override 073 protected void doStart() throws Exception { 074 // noop 075 } 076 077 @Override 078 protected void doStop() throws Exception { 079 // noop 080 } 081}