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.mina;
019
020 import org.apache.camel.CamelContext;
021 import org.apache.camel.Producer;
022 import org.apache.camel.Consumer;
023 import org.apache.camel.Processor;
024 import org.apache.camel.Service;
025 import org.apache.camel.impl.DefaultEndpoint;
026 import org.apache.mina.common.IoAcceptor;
027 import org.apache.mina.common.IoSession;
028 import org.apache.mina.common.IoConnector;
029 import org.apache.mina.common.IoServiceConfig;
030 import org.apache.commons.logging.Log;
031 import org.apache.commons.logging.LogFactory;
032
033 import java.net.SocketAddress;
034
035 /**
036 * @version $Revision: 537816 $
037 */
038 public class MinaEndpoint extends DefaultEndpoint<MinaExchange> {
039 private final IoAcceptor acceptor;
040 private final SocketAddress address;
041 private final IoConnector connector;
042 private final IoServiceConfig config;
043
044 public MinaEndpoint(String endpointUri, MinaComponent component, SocketAddress address, IoAcceptor acceptor, IoConnector connector, IoServiceConfig config) {
045 super(endpointUri, component);
046 this.config = config;
047 this.address = address;
048 this.acceptor = acceptor;
049 this.connector = connector;
050 }
051
052 public Producer<MinaExchange> createProducer() throws Exception {
053 return new MinaProducer(this);
054 }
055
056 public Consumer<MinaExchange> createConsumer(Processor processor) throws Exception {
057 return new MinaConsumer(this, processor);
058 }
059
060 public MinaExchange createExchange() {
061 return new MinaExchange(getContext());
062 }
063
064 public MinaExchange createExchange(IoSession session, Object object) {
065 MinaExchange exchange = new MinaExchange(getContext());
066 exchange.getIn().setBody(object);
067 // TODO store session in exchange?
068 return exchange;
069 }
070
071 // Properties
072 //-------------------------------------------------------------------------
073 public IoAcceptor getAcceptor() {
074 return acceptor;
075 }
076
077 public SocketAddress getAddress() {
078 return address;
079 }
080
081 public IoConnector getConnector() {
082 return connector;
083 }
084
085 public IoServiceConfig getConfig() {
086 return config;
087 }
088
089 public boolean isSingleton() {
090 return true;
091 }
092
093 }