mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
42 lines
1.2 KiB
Java
42 lines
1.2 KiB
Java
package io.ebeaninternal.server.cluster;
|
|
|
|
import io.ebeaninternal.api.BinaryReadContext;
|
|
import io.ebeaninternal.api.SpiEbeanServer;
|
|
import io.ebeaninternal.server.transaction.RemoteTransactionEvent;
|
|
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* Mechanism to convert RemoteTransactionEvent to/from byte[] content.
|
|
*/
|
|
public class BinaryTransactionEventReader {
|
|
|
|
private final ServerLookup serverLookup;
|
|
|
|
public BinaryTransactionEventReader(ServerLookup serverLookup) {
|
|
this.serverLookup = serverLookup;
|
|
}
|
|
|
|
/**
|
|
* Read Transaction from bytes.
|
|
*/
|
|
public RemoteTransactionEvent read(byte[] byteData) throws IOException {
|
|
return read(new BinaryReadContext(byteData));
|
|
}
|
|
|
|
/**
|
|
* Read Transaction using BinaryReadContext.
|
|
*/
|
|
public RemoteTransactionEvent read(BinaryReadContext dataInput) throws IOException {
|
|
|
|
String serverName = dataInput.readUTF();
|
|
SpiEbeanServer server = (SpiEbeanServer) serverLookup.getServer(serverName);
|
|
if (server == null) {
|
|
throw new IllegalStateException("EbeanServer not found for name [" + serverName + "]");
|
|
}
|
|
RemoteTransactionEvent event = new RemoteTransactionEvent(server);
|
|
event.readBinary(dataInput);
|
|
return event;
|
|
}
|
|
}
|