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 java.io.ByteArrayOutputStream;
12 import java.io.IOException;
13 import java.io.ObjectOutputStream;
14 import java.io.Serializable;
15 import java.util.List;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
18 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.PersistentPayload;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 * Payload data for server configuration log entries.
25 * @author Thomas Pantelis
27 public class ServerConfigurationPayload extends Payload implements PersistentPayload, Serializable {
28 private static final long serialVersionUID = 1L;
30 private static final Logger LOG = LoggerFactory.getLogger(ServerConfigurationPayload.class);
32 private final List<ServerInfo> serverConfig;
33 private transient int serializedSize = -1;
35 public ServerConfigurationPayload(@Nonnull List<ServerInfo> serverConfig) {
36 this.serverConfig = Preconditions.checkNotNull(serverConfig);
40 public List<ServerInfo> getServerConfig() {
46 if(serializedSize < 0) {
48 ByteArrayOutputStream bos = new ByteArrayOutputStream();
49 ObjectOutputStream out = new ObjectOutputStream(bos);
50 out.writeObject(serverConfig);
53 serializedSize = bos.toByteArray().length;
54 } catch (IOException e) {
56 LOG.error("Error serializing", e);
60 return serializedSize;
64 public String toString() {
65 return "ServerConfigurationPayload [serverConfig=" + serverConfig + "]";
68 public static class ServerInfo implements Serializable {
69 private static final long serialVersionUID = 1L;
71 private final String id;
72 private final boolean isVoting;
74 public ServerInfo(@Nonnull String id, boolean isVoting) {
75 this.id = Preconditions.checkNotNull(id);
76 this.isVoting = isVoting;
80 public String getId() {
84 public boolean isVoting() {
89 public int hashCode() {
92 result = prime * result + (isVoting ? 1231 : 1237);
93 result = prime * result + id.hashCode();
98 public boolean equals(Object obj) {
99 if (obj == null || getClass() != obj.getClass()) {
103 ServerInfo other = (ServerInfo) obj;
104 return isVoting == other.isVoting && id.equals(other.id);
108 public String toString() {
109 return "ServerInfo [id=" + id + ", isVoting=" + isVoting + "]";