1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.openr66.proxy.network;
21
22 import org.waarp.openr66.protocol.exception.OpenR66ProtocolSystemException;
23
24 import java.net.SocketAddress;
25 import java.util.HashMap;
26
27
28
29
30 public class ProxyEntry {
31 public static final HashMap<String, ProxyEntry> proxyEntries =
32 new HashMap<String, ProxyEntry>();
33
34 private final String name;
35 private final SocketAddress localSocketAddress;
36 private final boolean localIsSsl;
37 private final SocketAddress remoteSocketAddress;
38 private final boolean remoteIsSsl;
39
40 public static void add(final SocketAddress localAddress,
41 final boolean localIsSsl,
42 final SocketAddress remoteAddress,
43 final boolean remoteIsSsl)
44 throws OpenR66ProtocolSystemException {
45 final String sla = localAddress.toString();
46 if (proxyEntries.containsKey(sla)) {
47 throw new OpenR66ProtocolSystemException(
48 "Error in the configuration: Two entries with the same localAdress");
49 }
50 proxyEntries.put(sla, new ProxyEntry(sla, localAddress, localIsSsl,
51 remoteAddress, remoteIsSsl));
52 }
53
54 public static ProxyEntry get(final String name) {
55 synchronized (proxyEntries) {
56 if (proxyEntries.containsKey(name)) {
57 return proxyEntries.get(name);
58 } else {
59
60 return null;
61 }
62 }
63 }
64
65
66
67
68
69
70
71
72 private ProxyEntry(final String name, final SocketAddress localSocketAddress,
73 final boolean localIsSsl,
74 final SocketAddress remoteSocketAddress,
75 final boolean remoteIsSsl) {
76 this.name = name;
77 this.localSocketAddress = localSocketAddress;
78 this.localIsSsl = localIsSsl;
79 this.remoteSocketAddress = remoteSocketAddress;
80 this.remoteIsSsl = remoteIsSsl;
81 }
82
83
84
85
86 public final SocketAddress getLocalSocketAddress() {
87 return localSocketAddress;
88 }
89
90
91
92
93 public final boolean isLocalSsl() {
94 return localIsSsl;
95 }
96
97
98
99
100 public final SocketAddress getRemoteSocketAddress() {
101 return remoteSocketAddress;
102 }
103
104
105
106
107 public final String getName() {
108 return name;
109 }
110
111
112
113
114 public final boolean isRemoteSsl() {
115 return remoteIsSsl;
116 }
117
118 @Override
119 public String toString() {
120 return "from: " + localSocketAddress + ':' + localIsSsl + " to: " +
121 remoteSocketAddress + ':' + remoteIsSsl;
122 }
123 }