/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kuujo.copycat.raft.log.entry;

import net.kuujo.copycat.cluster.MemberInfo;
import net.kuujo.copycat.io.serializer.SerializeWith;
import net.kuujo.copycat.io.util.ReferenceManager;

/**
 * Register client entry.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
@SerializeWith(id=1006)
public class RegisterEntry extends TimestampedEntry<RegisterEntry> {
  private MemberInfo member;

  public RegisterEntry() {
  }

  public RegisterEntry(ReferenceManager<Entry<?>> referenceManager) {
    super(referenceManager);
  }

  /**
   * Returns the member info.
   *
   * @return The member info.
   */
  public MemberInfo getMember() {
    return member;
  }

  /**
   * Sets the member info.
   *
   * @param info The member info.
   * @return The register entry.
   */
  public RegisterEntry setMember(MemberInfo info) {
    this.member = info;
    return this;
  }

  @Override
  public String toString() {
    return String.format("%s[index=%d, member=%s, timestamp=%d]", getClass().getSimpleName(), getIndex(), member, getTimestamp());
  }

}

/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.kuujo.copycat.raft.log.entry;

import net.kuujo.copycat.cluster.MemberInfo;
import net.kuujo.copycat.io.Buffer;
import net.kuujo.copycat.io.serializer.SerializeWith;
import net.kuujo.copycat.io.serializer.Serializer;
import net.kuujo.copycat.io.util.ReferenceManager;

/**
 * Register client entry.
 *
 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
 */
@SerializeWith(id=1006)
public class RegisterEntry extends TimestampedEntry<RegisterEntry> {
  private MemberInfo member;

  public RegisterEntry() {
  }

  public RegisterEntry(ReferenceManager<Entry<?>> referenceManager) {
    super(referenceManager);
  }

  /**
   * Returns the member info.
   *
   * @return The member info.
   */
  public MemberInfo getMember() {
    return member;
  }

  /**
   * Sets the member info.
   *
   * @param member The member info.
   * @return The register entry.
   */
  public RegisterEntry setMember(MemberInfo member) {
    this.member = member;
    return this;
  }

  @Override
  public void writeObject(Buffer buffer, Serializer serializer) {
    super.writeObject(buffer, serializer);
    serializer.writeObject(member, buffer);
  }

  @Override
  public void readObject(Buffer buffer, Serializer serializer) {
    super.readObject(buffer, serializer);
    member = serializer.readObject(buffer);
  }

  @Override
  public String toString() {
    return String.format("%s[index=%d, member=%s, timestamp=%d]", getClass().getSimpleName(), getIndex(), member, getTimestamp());
  }

}

Handle serialization of member info in register entries.