This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/server/net/ObjectWriteProxy.java

35 lines
948 B
Java
Raw Normal View History

package envoy.server.net;
import java.io.IOException;
import com.jenkov.nioserver.Message;
import com.jenkov.nioserver.WriteProxy;
import envoy.util.SerializationUtils;
/**
* Project: <strong>envoy-server-standalone</strong><br>
* File: <strong>ObjectWriteProxy.java</strong><br>
* Created: <strong>04.01.2020</strong><br>
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
public class ObjectWriteProxy {
private final WriteProxy writeProxy;
public ObjectWriteProxy(WriteProxy writeProxy) { this.writeProxy = writeProxy; }
public void write(long recipientSocketId, Object obj) throws IOException {
// Create message targeted at the client
Message response = writeProxy.getMessage();
response.socketId = recipientSocketId;
// Serialize object to byte array
byte[] objBytes = SerializationUtils.writeToByteArray(obj);
response.writeToMessage(objBytes);
writeProxy.enqueue(response);
}
}