Last change
on this file since 39 was 39, checked in by bart, 3 years ago |
Geniusweb 2.0.3. MOPAC protocol translated to Python. Small fixes.
|
File size:
1.2 KB
|
Rev | Line | |
---|
[39] | 1 | package geniusweb.party;
|
---|
| 2 |
|
---|
| 3 | import geniusweb.actions.Action;
|
---|
| 4 | import geniusweb.connection.ConnectionEnd;
|
---|
| 5 | import geniusweb.inform.Inform;
|
---|
| 6 | import tudelft.utilities.listener.Listener;
|
---|
| 7 | import tudelft.utilities.logging.ReportToLogger;
|
---|
| 8 | import tudelft.utilities.logging.Reporter;
|
---|
| 9 |
|
---|
| 10 | /**
|
---|
| 11 | * Party with default implementation to handle the connection.
|
---|
| 12 | *
|
---|
| 13 | */
|
---|
| 14 | public 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.