All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.remote.strprotocol.SerializedMessageSender Maven / Gradle / Ivy

There is a newer version: 7.10.2
Show newest version
package org.testng.remote.strprotocol;

import org.testng.remote.RemoteTestNG;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;


public class SerializedMessageSender extends BaseMessageSender {

  public SerializedMessageSender(String host, int port) {
    super(host, port);
  }

  @Override
  public void sendMessage(IMessage message) throws IOException {
    synchronized(m_outStream) {
      p("Sending message " + message);
      ObjectOutputStream oos = new ObjectOutputStream(m_outStream);
      oos.writeObject(message);
      oos.flush();

      waitForAck();
    }
  }

  @Override
  public IMessage receiveMessage() throws IOException, ClassNotFoundException {

    IMessage result = null;
    try {
      ObjectInputStream ios = new ObjectInputStream(m_inStream);
//      synchronized(m_input) {
        result = (IMessage) ios.readObject();
        p("Received message " + result);
//        sendAck();
//      }
    }
    catch(Exception ex) {
      if (RemoteTestNG.isVerbose()) {
        ex.printStackTrace();
      }
    }
    return result;
  }

  static void p(String s) {
    if (RemoteTestNG.isVerbose()) {
      System.out.println("[SerializedMessageSender] " + s);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy