source: party/src/main/java/geniusweb/party/DefaultParty.java@ 9

Last change on this file since 9 was 9, checked in by bart, 5 years ago

Release 1.1.0

File size: 1.2 KB
Line 
1package geniusweb.party;
2
3import geniusweb.actions.Action;
4import geniusweb.connection.ConnectionEnd;
5import geniusweb.party.inform.Inform;
6import tudelft.utilities.listener.Listener;
7import tudelft.utilities.logging.ReportToLogger;
8import tudelft.utilities.logging.Reporter;
9
10/**
11 * Party with default implementation to handle the connection.
12 *
13 */
14public abstract class DefaultParty implements Party, Listener<Inform> {
15 private ConnectionEnd<Inform, Action> connection = null;
16 protected Reporter reporter;
17
18 public DefaultParty() {
19 this(new ReportToLogger("party"));
20 }
21
22 public DefaultParty(Reporter rep) {
23 this.reporter = rep;
24 }
25
26 @Override
27 public void connect(ConnectionEnd<Inform, Action> connection) {
28 this.connection = connection;
29 connection.addListener(this);
30 }
31
32 @Override
33 public synchronized void disconnect() {
34 if (connection != null) {
35 connection.removeListener(this);
36 this.connection = null;
37 }
38 }
39
40 @Override
41 public void terminate() {
42 disconnect();
43 }
44
45 /**
46 * @return currently available connection, or null if not currently
47 * connected.
48 */
49 public ConnectionEnd<Inform, Action> getConnection() {
50 return connection;
51 }
52
53 public Reporter getReporter() {
54 return reporter;
55 }
56
57}
Note: See TracBrowser for help on using the repository browser.