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