1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package fulmine.distribution.connection.tcp;
17
18 import static fulmine.distribution.connection.tcp.ProtocolMessageConstants.DELIMITER;
19 import fulmine.context.IFrameworkContext;
20 import fulmine.distribution.connection.AbstractConnectionDiscoverer;
21 import fulmine.distribution.connection.IConnectionBroker;
22 import fulmine.distribution.connection.IConnectionDiscoverer;
23 import fulmine.distribution.connection.IConnectionParameters;
24 import fulmine.util.log.AsyncLog;
25
26
27
28
29
30
31 public final class TcpConnectionDiscoverer extends AbstractConnectionDiscoverer
32 implements IConnectionDiscoverer
33 {
34 final static AsyncLog LOG = new AsyncLog(TcpConnectionDiscoverer.class);
35
36
37 private final String address;
38
39
40 private final int port;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public TcpConnectionDiscoverer(IFrameworkContext context,
61 String hostAddress, int tcpPort, String udpNetwork, int udpPort,
62 String udpNic)
63 {
64 super(context, udpNetwork, udpPort, udpNic);
65 this.address = hostAddress;
66 this.port = tcpPort;
67 }
68
69
70
71
72
73
74
75
76
77
78
79 TcpConnectionDiscoverer(IFrameworkContext context, String address,
80 int tcpPort)
81 {
82 super(context);
83 this.address = address;
84 this.port = tcpPort;
85 }
86
87 @Override
88 protected AsyncLog getLog()
89 {
90 return LOG;
91 }
92
93 @Override
94 protected final void doStart()
95 {
96 super.doStart();
97 }
98
99 @Override
100 protected IConnectionParameters getConnectionParameters(String data)
101 {
102 final String[] values = data.split(DELIMITER);
103 if (values.length == 5)
104 {
105 final String identity = values[1];
106 final int hashCode = Integer.parseInt(values[2]);
107 final String inetAddr = values[3];
108 final int port = Integer.parseInt(values[4]);
109 return new TcpConnectionParameters(identity, hashCode, inetAddr,
110 port);
111 }
112 if (getLog().isDebugEnabled())
113 {
114 getLog().debug("Could not decipher '" + data + "'");
115 }
116 return null;
117 }
118
119 @Override
120 protected String getProtocolConnectionParameters()
121 {
122 return this.address + DELIMITER + this.port;
123 }
124
125 }