001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.camel.component.jbi; 019 020 import org.apache.camel.Consumer; 021 import org.apache.camel.Endpoint; 022 import org.apache.camel.Exchange; 023 import org.apache.camel.Processor; 024 import org.apache.camel.Producer; 025 import org.apache.camel.impl.DefaultConsumer; 026 import org.apache.camel.impl.DefaultEndpoint; 027 import org.apache.camel.impl.DefaultProducer; 028 029 /** 030 * Represents an {@link Endpoint} for interacting with JBI 031 * 032 * @version $Revision: 537816 $ 033 */ 034 public class JbiEndpoint extends DefaultEndpoint<Exchange> { 035 private Processor toJbiProcessor; 036 private final CamelJbiComponent jbiComponent; 037 038 public JbiEndpoint(CamelJbiComponent jbiComponent, String uri) { 039 super(uri, jbiComponent); 040 this.jbiComponent = jbiComponent; 041 toJbiProcessor = new ToJbiProcessor(jbiComponent.getBinding(), jbiComponent.getComponentContext(), uri); 042 } 043 044 public Producer<Exchange> createProducer() throws Exception { 045 return new DefaultProducer<Exchange>(this) { 046 public void process(Exchange exchange) throws Exception { 047 toJbiProcessor.process(exchange); 048 } 049 }; 050 } 051 052 public Consumer<Exchange> createConsumer(final Processor processor) throws Exception { 053 return new DefaultConsumer<Exchange>(this, processor) { 054 CamelJbiEndpoint jbiEndpoint; 055 056 @Override 057 protected void doStart() throws Exception { 058 super.doStart(); 059 jbiEndpoint = jbiComponent.activateJbiEndpoint(JbiEndpoint.this, processor); 060 } 061 062 @Override 063 protected void doStop() throws Exception { 064 /* 065 if (jbiEndpoint != null) { 066 jbiEndpoint.deactivate(); 067 } 068 */ 069 super.doStop(); 070 } 071 }; 072 } 073 074 075 public JbiExchange createExchange() { 076 return new JbiExchange(getContext(), getBinding()); 077 } 078 079 public JbiBinding getBinding() { 080 return jbiComponent.getBinding(); 081 } 082 083 public boolean isSingleton() { 084 return true; 085 } 086 087 }