35 lines
948 B
Java
35 lines
948 B
Java
|
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);
|
||
|
}
|
||
|
}
|