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

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 1.2 KB
Line 
1package geniusweb.party;
2
3import geniusweb.actions.Action;
4import geniusweb.connection.ConnectionEnd;
5import geniusweb.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 connection.close();
37 this.connection = null;
38 }
39 }
40
41 @Override
42 public void terminate() {
43 disconnect();
44 }
45
46 /**
47 * @return currently available connection, or null if not currently
48 * connected.
49 */
50 public ConnectionEnd<Inform, Action> getConnection() {
51 return connection;
52 }
53
54 public Reporter getReporter() {
55 return reporter;
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.