Esempio n. 1
0
 @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);
 }
Esempio n. 2
0
 /** 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());
 }
Esempio n. 3
0
 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());
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
 @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());
   }
 }
Esempio n. 6
0
 @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;
   }
 }
Esempio n. 7
0
  /** 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);
  }
Esempio n. 8
0
 @Override
 public void readObject(BufferInput<?> buffer, Serializer serializer) {
   member = serializer.readObject(buffer);
 }
Esempio n. 9
0
 @Override
 public void writeObject(BufferOutput<?> buffer, Serializer serializer) {
   serializer.writeObject(member, buffer);
 }
Esempio n. 10
0
 @Override
 public void readObject(BufferInput<?> buffer, Serializer serializer) {
   operation = serializer.readObject(buffer);
 }
Esempio n. 11
0
 @Override
 public void writeObject(BufferOutput<?> buffer, Serializer serializer) {
   serializer.writeObject(operation, buffer);
 }
Esempio n. 12
0
 /**
  * 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;
 }
Esempio n. 13
0
 @Override
 public void readObject(BufferInput<?> buffer, Serializer serializer) {
   super.readObject(buffer, serializer);
   value = serializer.readObject(buffer);
 }
Esempio n. 14
0
 @Override
 public void writeObject(BufferOutput<?> buffer, Serializer serializer) {
   super.writeObject(buffer, serializer);
   serializer.writeObject(value, buffer);
 }
Esempio n. 15
0
 @Override
 @SuppressWarnings("unchecked")
 public void write(Map.Entry<?, ?> object, BufferOutput buffer, Serializer serializer) {
   serializer.writeObject(object.getKey(), buffer);
   serializer.writeObject(object.getValue(), buffer);
 }