Exemple #1
0
 public void run() {
   try {
     in = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
     while (!Thread.interrupted()) {
       String value = in.readUTF();
       if (ConfigSettings.instance().isActivateStats()) {
         StatsCommunication.instance().sent(value.getBytes().length);
       }
       if (ConfigSettings.instance().isDumpMessages()) {
         System.out.println("Received: " + value);
       }
       Message message = (Message) MessageSerializer.readMessage(value);
       consumer.receive(message);
     }
   } catch (Throwable t) {
     t.printStackTrace();
   } finally {
     consumer = null;
     try {
       out.close();
     } catch (IOException ex) {
       ex.printStackTrace();
     }
   }
 }
Exemple #2
0
 public void send(Message message) {
   try {
     String messageValue = MessageSerializer.writeMessage(message);
     if (ConfigSettings.instance().isDumpMessages()) {
       System.out.println("Send: " + messageValue);
     }
     out.writeUTF(messageValue);
     out.flush();
     out.reset();
   } catch (IOException ex) {
     ex.printStackTrace();
     receiver.interrupt();
   }
 }