Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. private class myTimerTask extends TimerTask {
  2. private Connection con;
  3.  
  4. public myTimerTask(Connection con) {
  5. this.con = con;
  6. }
  7.  
  8. public void run()
  9. {
  10. this.con.sendHeartbeat();
  11. }
  12.  
  13. public Connection getCon() {
  14. return con;
  15. }
  16. public void setCon(Connection con) {
  17. this.con = con;
  18. }
  19. }
  20.  
  21. class Connection {
  22. private int type;
  23. private Timer connectionTimer;
  24. private Socket sock;
  25.  
  26. //... Constructor
  27.  
  28. public void activateConnection (int connectionType) {
  29. this.type = connectionType;
  30.  
  31. this.connectionTimer.schedule(new myTimerTask(this), 60);
  32. }
  33.  
  34. public void sendHeartbeat() {
  35. switch (type) {
  36. case 0: socket.sendSignOfLife(1); break;
  37. case 1: socket.sendSignOfLife(2); break;
  38. case 2: socket.sendSignOfLife(3); break;
  39. default: socket.sendSignOfLife(0);
  40. }
  41. }
  42.  
  43. //... Getters & Setters
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement