summaryrefslogtreecommitdiff
path: root/same/old/SameServiceImpl.java
blob: 27579b57847ec03eded4df0b9a524a7e0e530ebc (plain)
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
60
package com.orbekk.same;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SameServiceImpl implements SameService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    private SameState sameState;

    public SameServiceImpl(SameState sameState) {
        this.sameState = sameState;
    }

    @Override
    public void notifyNetwork(String networkName) {
        logger.info("Notification from network " + networkName);
    }

    @Override
    public void participateNetwork(String networkName, String clientId,
            String url) {
        if (!networkName.equals(sameState.getNetworkName())) {
            logger.warn("Client tried to join {}, but network name is {}.",
                    networkName, sameState.getNetworkName());
            return;
        }
        if (clientId.equals("") || url.equals("")) {
            logger.warn("Missing client info: ClientId({}), URL({}).",
                    clientId, url);
            return;
        }
        sameState.addParticipant(clientId, url);
    }

    @Override
    public void notifyParticipation(String networkName, String masterId) {
        logger.info("Joining network {}. Master is {}", networkName, masterId);
        // int i = 1;
        // for (Map.Entry<String, String> e : participants.entrySet()) {
        //     String clientId = e.getKey();
        //     String url = e.getValue();
        //     logger.info("  {} participant {}: {}, {}",
        //             new Object[]{networkName, i, clientId, url});
        //     i++;
        // }
        sameState.joinNetwork(networkName, masterId);
    }

    @Override
    public void setParticipants(Map<String, String> participants) {
        sameState.setParticipants(participants);
    }

    @Override
    public void setState(String newState) {
        sameState.setState(newState);
    }
}