Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. public class MessageManager
  2. {
  3.     private Message lastMessage = null;
  4.     private Network net;
  5.    
  6.    
  7.     public MessageManager(Network net)
  8.     {
  9.         this.net = net;
  10.     }
  11.    
  12.     private boolean send(Message m)
  13.     {
  14.         try
  15.         {
  16.             net.sendMessage(m);
  17.             lastMessage = null;
  18.             return true;
  19.         }
  20.         catch(IOException e)
  21.         {
  22.             lastMessage = m;
  23.             return false;
  24.         }
  25.     }
  26.    
  27.     public void run()
  28.     {
  29.         if (lastMessage != null)
  30.         {
  31.             if (!send(lastMessage))
  32.                 return;
  33.         }
  34.  
  35.         while (net.hasMessageAvailable())
  36.         {
  37.             if (!send(net.readNextMessage()))
  38.                 return;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement