source: src/main/java/geniusweb/runserver/RunningNegotiationsRepo.java@ 45

Last change on this file since 45 was 45, checked in by ruud, 20 months ago

Fixed small issues in domaineditor.

File size: 2.1 KB
RevLine 
[45]1package geniusweb.runserver;
2
3import java.util.Collection;
4import java.util.Collections;
5import java.util.HashMap;
6import java.util.Map;
7import java.util.logging.Level;
8
9import tudelft.utilities.listener.DefaultListenable;
10import tudelft.utilities.logging.ReportToLogger;
11import tudelft.utilities.logging.Reporter;
12import tudelft.utilities.repository.Repository;
13
14/**
15 * Central repo for all currently running sessions.
16 */
17public class RunningNegotiationsRepo extends DefaultListenable<String>
18 implements Repository<String, RunningNego> {
19
20 private final Map<String, RunningNego> negotiations;
21 private final static RunningNegotiationsRepo instance = new RunningNegotiationsRepo(
22 new HashMap<>(), new ReportToLogger("runserver"));
23 private final Reporter log;
24
25 /**
26 * Only for testing and internal use
27 *
28 * @param newnegos the currently running negotiations
29 */
30 protected RunningNegotiationsRepo(Map<String, RunningNego> newnegos,
31 Reporter reporter) {
32 this.negotiations = newnegos;
33 this.log = reporter;
34 }
35
36 public static RunningNegotiationsRepo instance() {
37 return instance;
38 }
39
40 @Override
41 public RunningNego get(String id) {
42 return negotiations.get(id);
43 }
44
45 @Override
46 public Collection<RunningNego> list() {
47 return Collections.unmodifiableCollection(negotiations.values());
48 }
49
50 @Override
51 public void put(RunningNego entity) {
52 if (negotiations.containsKey(entity.getID())) {
53 throw new IllegalArgumentException(
54 "Negotiation " + entity.getID() + " is already running");
55 }
56 negotiations.put(entity.getID(), entity);
57 notifyListeners(entity.getID());
58 log.log(Level.FINEST, "started " + entity.getID());
59 }
60
61 @Override
62 public void remove(String id) {
63 negotiations.remove(id);
64 notifyListeners(id);
65 log.log(Level.FINEST, "stopped negotiation " + id);
66 }
67
68 @Override
69 public void replace(RunningNego entity) {
70 if (!negotiations.containsKey(entity.getID())) {
71 throw new IllegalArgumentException(
72 "Negotiation " + entity.getID() + " is not running");
73 }
74 negotiations.put(entity.getID(), entity);
75 notifyListeners(entity.getID());
76 log.log(Level.FINEST, "replaced " + entity.getID());
77
78 }
79
80}
Note: See TracBrowser for help on using the repository browser.