2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.raft;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.Lists;
12 import java.io.ByteArrayOutputStream;
13 import java.io.IOException;
14 import java.io.ObjectOutputStream;
15 import java.io.Serializable;
16 import java.util.List;
17 import javax.annotation.Nonnull;
18 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
19 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.PersistentPayload;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * Payload data for server configuration log entries.
26 * @author Thomas Pantelis
28 * @deprecated Use {@link org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload} instead.
31 public class ServerConfigurationPayload extends Payload implements PersistentPayload, Serializable {
32 private static final long serialVersionUID = 1L;
34 private static final Logger LOG = LoggerFactory.getLogger(ServerConfigurationPayload.class);
36 private final List<ServerInfo> serverConfig;
37 private transient int serializedSize = -1;
39 public ServerConfigurationPayload(@Nonnull List<ServerInfo> serverConfig) {
40 this.serverConfig = Preconditions.checkNotNull(serverConfig);
44 public List<ServerInfo> getServerConfig() {
50 if (serializedSize < 0) {
52 ByteArrayOutputStream bos = new ByteArrayOutputStream();
53 ObjectOutputStream out = new ObjectOutputStream(bos);
54 out.writeObject(serverConfig);
57 serializedSize = bos.toByteArray().length;
58 } catch (IOException e) {
60 LOG.error("Error serializing", e);
64 return serializedSize;
68 public String toString() {
69 return "ServerConfigurationPayload [serverConfig=" + serverConfig + "]";
72 private Object readResolve() {
73 return org.opendaylight.controller.cluster.raft.persisted.ServerConfigurationPayload.createMigrated(
74 Lists.transform(serverConfig, t -> new org.opendaylight.controller.cluster.raft.persisted.ServerInfo(
75 t.getId(), t.isVoting)));
78 public static class ServerInfo implements Serializable {
79 private static final long serialVersionUID = 1L;
81 private final String id;
82 private final boolean isVoting;
84 public ServerInfo(@Nonnull String id, boolean isVoting) {
85 this.id = Preconditions.checkNotNull(id);
86 this.isVoting = isVoting;
90 public String getId() {
94 public boolean isVoting() {
99 public int hashCode() {
100 final int prime = 31;
102 result = prime * result + Boolean.hashCode(isVoting);
103 result = prime * result + id.hashCode();
108 public boolean equals(Object obj) {
109 if (obj == null || getClass() != obj.getClass()) {
113 ServerInfo other = (ServerInfo) obj;
114 return isVoting == other.isVoting && id.equals(other.id);
118 public String toString() {
119 return "ServerInfo [id=" + id + ", isVoting=" + isVoting + "]";