1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
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 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
public class TcpSocketKey |
25 | |
{ |
26 | |
|
27 | |
private InetSocketAddress address; |
28 | |
private ImmutableEndpoint endpoint; |
29 | |
|
30 | |
public TcpSocketKey(ImmutableEndpoint endpoint) |
31 | 4766 | { |
32 | 4766 | if (!(endpoint.getConnector() instanceof TcpConnector)) |
33 | |
{ |
34 | 0 | throw new IllegalArgumentException("Sockets must be keyed via a TCP endpoint"); |
35 | |
} |
36 | 4766 | this.endpoint = endpoint; |
37 | 4766 | address = new InetSocketAddress( |
38 | |
endpoint.getEndpointURI().getHost(), |
39 | |
endpoint.getEndpointURI().getPort()); |
40 | 4766 | } |
41 | |
|
42 | |
public boolean equals(Object obj) |
43 | |
{ |
44 | 6581 | return obj instanceof TcpSocketKey && address.equals(((TcpSocketKey) obj).address); |
45 | |
} |
46 | |
|
47 | |
public int hashCode() |
48 | |
{ |
49 | 6749 | return address.hashCode(); |
50 | |
} |
51 | |
|
52 | |
public ImmutableEndpoint getEndpoint() |
53 | |
{ |
54 | 1823 | return endpoint; |
55 | |
} |
56 | |
|
57 | |
public TcpConnector getConnector() |
58 | |
{ |
59 | 3314 | return (TcpConnector) endpoint.getConnector(); |
60 | |
} |
61 | |
|
62 | |
public InetAddress getInetAddress() |
63 | |
{ |
64 | 2577 | return address.getAddress(); |
65 | |
} |
66 | |
|
67 | |
public int getPort() |
68 | |
{ |
69 | 2577 | return address.getPort(); |
70 | |
} |
71 | |
|
72 | |
public String toString() |
73 | |
{ |
74 | 0 | return getInetAddress() + ":" + getPort(); |
75 | |
} |
76 | |
|
77 | |
} |