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.protobuf.GeneratedMessage.GeneratedExtension;
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;
17 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
18 import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages;
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 Serializable {
28 private static final long serialVersionUID = 1L;
30 private static final Logger LOG = LoggerFactory.getLogger(ServerConfigurationPayload.class);
32 private final List<String> newServerConfig;
33 private final List<String> oldServerConfig;
34 private transient int serializedSize = -1;
36 public ServerConfigurationPayload(List<String> newServerConfig, List<String> oldServerConfig) {
37 this.newServerConfig = newServerConfig;
38 this.oldServerConfig = oldServerConfig;
41 public List<String> getNewServerConfig() {
42 return newServerConfig;
46 public List<String> getOldServerConfig() {
47 return oldServerConfig;
52 if(serializedSize < 0) {
54 ByteArrayOutputStream bos = new ByteArrayOutputStream();
55 ObjectOutputStream out = new ObjectOutputStream(bos);
56 out.writeObject(newServerConfig);
57 out.writeObject(oldServerConfig);
60 serializedSize = bos.toByteArray().length;
61 } catch (IOException e) {
63 LOG.error("Error serializing", e);
67 return serializedSize;
72 @SuppressWarnings("rawtypes")
73 public <T> Map<GeneratedExtension, T> encode() {
79 public Payload decode(AppendEntriesMessages.AppendEntries.ReplicatedLogEntry.Payload payload) {
84 public String toString() {
85 return "ServerConfigurationPayload [newServerConfig=" + newServerConfig + ", oldServerConfig="
86 + oldServerConfig + "]";