@Override @SuppressWarnings("unchecked") public Map.Entry<?, ?> read( Class<Map.Entry<?, ?>> type, BufferInput buffer, Serializer serializer) { Object key = serializer.readObject(buffer); Object value = serializer.readObject(buffer); return new MapEntry<>(key, value); }
/** Tests serializing and deserializing a member. */ public void testSerializeDeserialize() { ServerMember member = new ServerMember(Member.Type.ACTIVE, new Address("localhost", 5000), null); Serializer serializer = new Serializer().resolve(new SessionTypeResolver(), new StateTypeResolver()); ServerMember result = serializer.readObject(serializer.writeObject(member).flip()); assertEquals(result.type(), member.type()); }
private Builder(Address clientAddress, Address serverAddress, Collection<Address> members) { this.members = Assert.notNull(members, "members"); Serializer serializer = new Serializer(); this.clientAddress = Assert.notNull(clientAddress, "clientAddress"); this.clientBuilder = CopycatClient.builder(members).withSerializer(serializer.clone()); this.serverBuilder = CopycatServer.builder(clientAddress, serverAddress, members) .withSerializer(serializer.clone()); }
protected int entrySize() { Serializer serializer = new Serializer(); serializer.register(TestEntry.class); Buffer buffer = DirectBuffer.allocate(1000); TestEntry entry = new TestEntry(); entry.setPadding(entryPadding); serializer.writeObject(entry, buffer); return (int) buffer.position() + Short.BYTES + Long.BYTES; }
@Override public void writeObject(BufferOutput<?> buffer, Serializer serializer) { buffer.writeByte(status.id()); if (status == Status.OK) { buffer.writeLong(session); buffer.writeLong(timeout); serializer.writeObject(members, buffer); } else { buffer.writeByte(error.id()); } }
@Override public void readObject(BufferInput<?> buffer, Serializer serializer) { status = Status.forId(buffer.readByte()); if (status == Status.OK) { error = null; session = buffer.readLong(); timeout = buffer.readLong(); members = serializer.readObject(buffer); } else { error = RaftError.forId(buffer.readByte()); session = 0; members = null; } }
/** Sets up a server state. */ @BeforeMethod void beforeMethod() throws Throwable { serializer = new Serializer(); serializer.resolve(new ServiceLoaderTypeResolver()); storage = new Storage(StorageLevel.MEMORY); storage.serializer().resolve(new ServiceLoaderTypeResolver()); log = storage.open("test"); stateMachine = new TestStateMachine(); members = createMembers(3); transport = new LocalTransport(new LocalServerRegistry()); serverCtx = new SingleThreadContext("test-server", serializer); serverState = new ServerState( members.get(0), members, log, stateMachine, new ConnectionManager(transport.client()), serverCtx); }
@Override public void readObject(BufferInput<?> buffer, Serializer serializer) { member = serializer.readObject(buffer); }
@Override public void writeObject(BufferOutput<?> buffer, Serializer serializer) { serializer.writeObject(member, buffer); }
@Override public void readObject(BufferInput<?> buffer, Serializer serializer) { operation = serializer.readObject(buffer); }
@Override public void writeObject(BufferOutput<?> buffer, Serializer serializer) { serializer.writeObject(operation, buffer); }
/** * Writes an object to the snapshot. * * @param object The object to write. * @return The snapshot writer. */ public SnapshotWriter writeObject(Object object) { serializer.writeObject(object, buffer); return this; }
@Override public void readObject(BufferInput<?> buffer, Serializer serializer) { super.readObject(buffer, serializer); value = serializer.readObject(buffer); }
@Override public void writeObject(BufferOutput<?> buffer, Serializer serializer) { super.writeObject(buffer, serializer); serializer.writeObject(value, buffer); }
@Override @SuppressWarnings("unchecked") public void write(Map.Entry<?, ?> object, BufferOutput buffer, Serializer serializer) { serializer.writeObject(object.getKey(), buffer); serializer.writeObject(object.getValue(), buffer); }