Coverage Report - org.mule.transport.tcp.TcpSocketKey
 
Classes in this File Line Coverage Branch Coverage Complexity
TcpSocketKey
0%
0/13
0%
0/6
0
 
 1  
 /*
 2  
  * $Id: TcpSocketKey.java 20321 2010-11-24 15:21:24Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.transport.tcp;
 12  
 
 13  
 import org.mule.api.endpoint.ImmutableEndpoint;
 14  
 
 15  
 import java.net.InetAddress;
 16  
 import java.net.InetSocketAddress;
 17  
 
 18  
 /**
 19  
  * This is used to adapt an endpoint so that it can be used as a key for sockets.  It must
 20  
  * meet two requirements: (1) implement hash and equals in a way that reflects socket identity
 21  
  * (ie using address and port); (2) allow access to the endpoint for use in the socket factory.
 22  
  * For simplicity we also expose the connector, address and port directly.
 23  
  */
 24  
 public class TcpSocketKey
 25  
 {
 26  
 
 27  
     private InetSocketAddress address;
 28  
     private ImmutableEndpoint endpoint;
 29  
 
 30  
     public TcpSocketKey(ImmutableEndpoint endpoint)
 31  0
     {
 32  0
         if (!(endpoint.getConnector() instanceof TcpConnector))
 33  
         {
 34  0
             throw new IllegalArgumentException("Sockets must be keyed via a TCP endpoint");
 35  
         }
 36  0
         this.endpoint = endpoint;
 37  0
         address = new InetSocketAddress(
 38  
                 endpoint.getEndpointURI().getHost(),
 39  
                 endpoint.getEndpointURI().getPort());
 40  0
     }
 41  
 
 42  
     @Override
 43  
     public boolean equals(Object obj)
 44  
     {
 45  0
         return obj instanceof TcpSocketKey && address.equals(((TcpSocketKey) obj).address);
 46  
     }
 47  
 
 48  
     @Override
 49  
     public int hashCode()
 50  
     {
 51  0
         return address.hashCode();
 52  
     }
 53  
 
 54  
     public ImmutableEndpoint getEndpoint()
 55  
     {
 56  0
         return endpoint;
 57  
     }
 58  
 
 59  
     public TcpConnector getConnector()
 60  
     {
 61  0
         return (TcpConnector) endpoint.getConnector();
 62  
     }
 63  
 
 64  
     public InetAddress getInetAddress()
 65  
     {
 66  0
         return address.getAddress();
 67  
     }
 68  
 
 69  
     public int getPort()
 70  
     {
 71  0
         return address.getPort();
 72  
     }
 73  
 
 74  
     @Override
 75  
     public String toString()
 76  
     {
 77  0
         return getInetAddress() + ":" + getPort();
 78  
     }
 79  
 
 80  
 }