Coverage Report - org.apache.camel.component.mina.MinaConsumer
 
Classes in this File Line Coverage Branch Coverage Complexity
MinaConsumer
94% 
100% 
0
 
 1  
 /**
 2  
  *
 3  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 4  
  * contributor license agreements.  See the NOTICE file distributed with
 5  
  * this work for additional information regarding copyright ownership.
 6  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 7  
  * (the "License"); you may not use this file except in compliance with
 8  
  * the License.  You may obtain a copy of the License at
 9  
  *
 10  
  * http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 package org.apache.camel.component.mina;
 19  
 
 20  
 import org.apache.camel.Processor;
 21  
 import org.apache.camel.impl.DefaultConsumer;
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 import org.apache.mina.common.IoAcceptor;
 25  
 import org.apache.mina.common.IoHandler;
 26  
 import org.apache.mina.common.IoHandlerAdapter;
 27  
 import org.apache.mina.common.IoSession;
 28  
 
 29  
 import java.net.SocketAddress;
 30  
 
 31  
 /**
 32  
  * A @{link Consumer} for MINA
 33  
  *
 34  
  * @version $Revision: 534145 $
 35  
  */
 36  2
 public class MinaConsumer extends DefaultConsumer<MinaExchange> {
 37  1
     private static final transient Log log = LogFactory.getLog(MinaConsumer.class);
 38  
 
 39  
     private final MinaEndpoint endpoint;
 40  
     private final SocketAddress address;
 41  
     private final IoAcceptor acceptor;
 42  
 
 43  
     public MinaConsumer(final MinaEndpoint endpoint, Processor processor) {
 44  2
         super(endpoint, processor);
 45  2
         this.endpoint = endpoint;
 46  2
          address = endpoint.getAddress();
 47  2
          acceptor = endpoint.getAcceptor();
 48  2
     }
 49  
 
 50  
     @Override
 51  
     protected void doStart() throws Exception {
 52  
 
 53  2
         if (log.isDebugEnabled()) {
 54  0
             log.debug("Binding to server address: " + address + " using acceptor: " + acceptor);
 55  
         }
 56  
 
 57  2
         IoHandler handler = new IoHandlerAdapter() {
 58  
             @Override
 59  2
             public void messageReceived(IoSession session, Object object) throws Exception {
 60  2
                 getProcessor().process(endpoint.createExchange(session, object));
 61  2
             }
 62  
         };
 63  
 
 64  2
         acceptor.bind(address, handler, endpoint.getConfig());
 65  2
     }
 66  
 
 67  
     @Override
 68  
     protected void doStop() throws Exception {
 69  2
         acceptor.unbind(address);
 70  2
         super.doStop();
 71  2
     }
 72  
 }