| 1 | package dolda.dolcon; |
| 2 | |
| 3 | import java.util.*; |
| 4 | |
| 5 | public class Hub { |
| 6 | int id, numpeers = 0; |
| 7 | final String fnet; |
| 8 | String name = "", gid = ""; |
| 9 | String state = "syn"; |
| 10 | Set<Listener> ls = new HashSet<Listener>(); |
| 11 | |
| 12 | public Hub(int id, String fnet) { |
| 13 | this.id = id; |
| 14 | this.fnet = fnet.intern(); |
| 15 | } |
| 16 | |
| 17 | public interface Listener { |
| 18 | public void chName(Hub hub); |
| 19 | public void chNumPeers(Hub hub); |
| 20 | public void chState(Hub hub); |
| 21 | } |
| 22 | |
| 23 | public Hub copy() { |
| 24 | Hub ret = new Hub(id, fnet); |
| 25 | ret.numpeers = numpeers; |
| 26 | ret.gid = gid; |
| 27 | ret.state = state; |
| 28 | ret.name = name; |
| 29 | return(ret); |
| 30 | } |
| 31 | |
| 32 | public int getId() { |
| 33 | return(id); |
| 34 | } |
| 35 | |
| 36 | public String getGid() { |
| 37 | return(gid); |
| 38 | } |
| 39 | |
| 40 | public String getFnet() { |
| 41 | return(fnet); |
| 42 | } |
| 43 | |
| 44 | public String getName() { |
| 45 | return(name); |
| 46 | } |
| 47 | |
| 48 | public int getNumPeers() { |
| 49 | return(numpeers); |
| 50 | } |
| 51 | |
| 52 | public String getState() { |
| 53 | return(state); |
| 54 | } |
| 55 | |
| 56 | public void addListener(Listener ls) { |
| 57 | synchronized(this.ls) { |
| 58 | this.ls.add(ls); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | public String toString() { |
| 63 | return("Hub (" + id + ", " + fnet + ", \"" + name + "\")"); |
| 64 | } |
| 65 | } |