1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.transport.tcp; |
8 | |
|
9 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
10 | |
|
11 | |
import java.net.InetAddress; |
12 | |
import java.net.InetSocketAddress; |
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
public class TcpSocketKey |
21 | |
{ |
22 | |
|
23 | |
private InetSocketAddress address; |
24 | |
private ImmutableEndpoint endpoint; |
25 | |
|
26 | |
public TcpSocketKey(ImmutableEndpoint endpoint) |
27 | 0 | { |
28 | 0 | if (!(endpoint.getConnector() instanceof TcpConnector)) |
29 | |
{ |
30 | 0 | throw new IllegalArgumentException("Sockets must be keyed via a TCP endpoint"); |
31 | |
} |
32 | 0 | this.endpoint = endpoint; |
33 | 0 | address = new InetSocketAddress( |
34 | |
endpoint.getEndpointURI().getHost(), |
35 | |
endpoint.getEndpointURI().getPort()); |
36 | 0 | } |
37 | |
|
38 | |
@Override |
39 | |
public boolean equals(Object obj) |
40 | |
{ |
41 | 0 | return obj instanceof TcpSocketKey && address.equals(((TcpSocketKey) obj).address); |
42 | |
} |
43 | |
|
44 | |
@Override |
45 | |
public int hashCode() |
46 | |
{ |
47 | 0 | return address.hashCode(); |
48 | |
} |
49 | |
|
50 | |
public ImmutableEndpoint getEndpoint() |
51 | |
{ |
52 | 0 | return endpoint; |
53 | |
} |
54 | |
|
55 | |
public TcpConnector getConnector() |
56 | |
{ |
57 | 0 | return (TcpConnector) endpoint.getConnector(); |
58 | |
} |
59 | |
|
60 | |
public InetAddress getInetAddress() |
61 | |
{ |
62 | 0 | return address.getAddress(); |
63 | |
} |
64 | |
|
65 | |
public int getPort() |
66 | |
{ |
67 | 0 | return address.getPort(); |
68 | |
} |
69 | |
|
70 | |
@Override |
71 | |
public String toString() |
72 | |
{ |
73 | 0 | return getInetAddress() + ":" + getPort(); |
74 | |
} |
75 | |
|
76 | |
} |