1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
package com.orbekk.same;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ClientServiceImpl implements ClientService, UrlReceiver {
private Logger logger = LoggerFactory.getLogger(getClass());
private ConnectionManager connections;
private State state;
private String myUrl = null;
public ClientServiceImpl(State state, ConnectionManager connections) {
this.state = state;
this.connections = connections;
}
@Override
public void notifyNetwork(String networkName, String masterUrl) {
logger.error("NotifyNetwork not yet implemented.");
}
@Override
public void setState(String component, String data, long revision) {
boolean status = state.update(component, data, revision);
if (!status) {
logger.warn("Ignoring update: {}",
new State.Component(component, revision, data));
}
}
@Override
public void setUrl(String myUrl) {
this.myUrl = myUrl + "ClientService.json";
logger.info("My URL is {}.", this.myUrl);
}
public String getUrl() {
return myUrl;
}
public void joinNetwork(String masterUrl) {
if (myUrl != null) {
MasterService master = connections.getMaster(masterUrl);
state.clear();
try {
master.joinNetworkRequest(myUrl);
} catch (Exception e) {
logger.error("Unable to connect to master.", e);
}
} else {
logger.error("Tried to join network at {}, but my url is unknown. " +
"Run discovery service.", masterUrl);
}
}
State testGetState() {
return state;
}
}
|