You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Connection.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) Xerox Corporation 1998-2002. All rights reserved.
  3. Use and copying of this software and preparation of derivative works based
  4. upon this software are permitted. Any distribution of this software or
  5. derivative works must comply with all applicable United States export control
  6. laws.
  7. This software is made available AS IS, and Xerox Corporation makes no warranty
  8. about the software, its performance or its conformity to any specification.
  9. |<--- this code is formatted to fit into 80 columns --->|
  10. |<--- this code is formatted to fit into 80 columns --->|
  11. |<--- this code is formatted to fit into 80 columns --->|
  12. */
  13. package telecom;
  14. /**
  15. * Connections are circuits between customers
  16. * There are two kinds: local and long distance
  17. * see subclasses at the end of this file.
  18. */
  19. public abstract class Connection {
  20. public static final int PENDING = 0;
  21. public static final int COMPLETE = 1;
  22. public static final int DROPPED = 2;
  23. Customer caller, receiver;
  24. private int state = PENDING;
  25. /**
  26. * Creatte a new Connection between a and b
  27. */
  28. Connection(Customer a, Customer b) {
  29. this.caller = a;
  30. this.receiver = b;
  31. }
  32. /**
  33. * what is the state of the connection?
  34. */
  35. public int getState(){
  36. return state;
  37. }
  38. /**
  39. * get the customer who initiated this connection
  40. */
  41. public Customer getCaller() { return caller; }
  42. /**
  43. * get the customer who received this connection
  44. */
  45. public Customer getReceiver() { return receiver; }
  46. /**
  47. * Called when a call is picked up. This means the b side has picked up
  48. * and the connection should now complete itself and start passing data.
  49. */
  50. void complete() {
  51. state = COMPLETE;
  52. System.out.println("connection completed");
  53. }
  54. /**
  55. * Called when the connection is dropped from a call. Is intended to
  56. * free up any resources the connection was consuming.
  57. */
  58. void drop() {
  59. state = DROPPED;
  60. System.out.println("connection dropped");
  61. }
  62. /**
  63. * Is customer c connected by this connection?
  64. */
  65. public boolean connects(Customer c){
  66. return (caller == c || receiver == c);
  67. }
  68. }