org.apache.cassandra.gms.GossipDigestAck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cassandra-all Show documentation
Show all versions of cassandra-all Show documentation
The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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 org.apache.cassandra.gms;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.cassandra.db.TypeSizes;
import org.apache.cassandra.io.IVersionedSerializer;
import org.apache.cassandra.io.util.DataInputPlus;
import org.apache.cassandra.io.util.DataOutputPlus;
import org.apache.cassandra.locator.InetAddressAndPort;
import static org.apache.cassandra.locator.InetAddressAndPort.Serializer.inetAddressAndPortSerializer;
/**
* This ack gets sent out as a result of the receipt of a GossipDigestSynMessage by an
* endpoint. This is the 2 stage of the 3 way messaging in the Gossip protocol.
*/
public class GossipDigestAck
{
public static final IVersionedSerializer serializer = new GossipDigestAckSerializer();
final List gDigestList;
final Map epStateMap;
GossipDigestAck(List gDigestList, Map epStateMap)
{
this.gDigestList = gDigestList;
this.epStateMap = epStateMap;
}
List getGossipDigestList()
{
return gDigestList;
}
Map getEndpointStateMap()
{
return epStateMap;
}
}
class GossipDigestAckSerializer implements IVersionedSerializer
{
public void serialize(GossipDigestAck gDigestAckMessage, DataOutputPlus out, int version) throws IOException
{
GossipDigestSerializationHelper.serialize(gDigestAckMessage.gDigestList, out, version);
out.writeInt(gDigestAckMessage.epStateMap.size());
for (Map.Entry entry : gDigestAckMessage.epStateMap.entrySet())
{
InetAddressAndPort ep = entry.getKey();
inetAddressAndPortSerializer.serialize(ep, out, version);
EndpointState.serializer.serialize(entry.getValue(), out, version);
}
}
public GossipDigestAck deserialize(DataInputPlus in, int version) throws IOException
{
List gDigestList = GossipDigestSerializationHelper.deserialize(in, version);
int size = in.readInt();
Map epStateMap = new HashMap(size);
for (int i = 0; i < size; ++i)
{
InetAddressAndPort ep = inetAddressAndPortSerializer.deserialize(in, version);
EndpointState epState = EndpointState.serializer.deserialize(in, version);
epStateMap.put(ep, epState);
}
return new GossipDigestAck(gDigestList, epStateMap);
}
public long serializedSize(GossipDigestAck ack, int version)
{
int size = GossipDigestSerializationHelper.serializedSize(ack.gDigestList, version);
size += TypeSizes.sizeof(ack.epStateMap.size());
for (Map.Entry entry : ack.epStateMap.entrySet())
size += inetAddressAndPortSerializer.serializedSize(entry.getKey(), version)
+ EndpointState.serializer.serializedSize(entry.getValue(), version);
return size;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy