Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions Hazelcast.Net/Hazelcast.Client.Protocol.Codec/PNCounterAddCodec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
//
// 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.

using System;
using System.Collections.Generic;
using Hazelcast.Client.Protocol;
using Hazelcast.Client.Protocol.Util;
using Hazelcast.IO;
using Hazelcast.Logging;
using Hazelcast.IO.Serialization;

// Client Protocol version, Since:1.6 - Update:1.6
namespace Hazelcast.Client.Protocol.Codec
{
internal static class PNCounterAddCodec
{
private static int CalculateRequestDataSize(string name, long delta, bool getBeforeUpdate, IList<KeyValuePair<string, long>> replicaTimestamps, Address targetReplica)
{
var dataSize = ClientMessage.HeaderSize;

dataSize += ParameterUtil.CalculateDataSize(name);
dataSize += Bits.LongSizeInBytes;
dataSize += Bits.BooleanSizeInBytes;
dataSize += Bits.IntSizeInBytes;

foreach (var replicaTimestampsItem in replicaTimestamps )
{
var replicaTimestampsItemKey = replicaTimestampsItem.Key;
var replicaTimestampsItemVal = replicaTimestampsItem.Value;

dataSize += ParameterUtil.CalculateDataSize(replicaTimestampsItemKey);
dataSize += ParameterUtil.CalculateDataSize(replicaTimestampsItemVal);
}

dataSize += AddressCodec.CalculateDataSize(targetReplica);
return dataSize;
}

internal static ClientMessage EncodeRequest(string name, long delta, bool getBeforeUpdate, IList<KeyValuePair<string, long>> replicaTimestamps, Address targetReplica)
{
var requiredDataSize = CalculateRequestDataSize(name, delta, getBeforeUpdate, replicaTimestamps, targetReplica);
var clientMessage = ClientMessage.CreateForEncode(requiredDataSize);

clientMessage.SetMessageType((int)PNCounterMessageType.PNCounterAdd);
clientMessage.SetRetryable(false);
clientMessage.Set(name);
clientMessage.Set(delta);
clientMessage.Set(getBeforeUpdate);
clientMessage.Set(replicaTimestamps.Count);

foreach (var replicaTimestampsItem in replicaTimestamps)
{
var replicaTimestampsItemKey = replicaTimestampsItem.Key;
var replicaTimestampsItemVal = replicaTimestampsItem.Value;

clientMessage.Set(replicaTimestampsItemKey);
clientMessage.Set(replicaTimestampsItemVal);
}

AddressCodec.Encode(targetReplica, clientMessage);
clientMessage.UpdateFrameLength();

return clientMessage;
}

internal class ResponseParameters
{
public long value;
public IList<KeyValuePair<string, long>> replicaTimestamps;
public int replicaCount;
}

internal static ResponseParameters DecodeResponse(IClientMessage clientMessage)
{
var parameters = new ResponseParameters();
var value = clientMessage.GetLong();
parameters.value = value;

var replicaTimestampsSize = clientMessage.GetInt();
var replicaTimestamps = new List<KeyValuePair<string, long>>(replicaTimestampsSize);

for (var replicaTimestampsIndex = 0; replicaTimestampsIndex<replicaTimestampsSize; replicaTimestampsIndex++)
{
var replicaTimestampsItemKey = clientMessage.GetStringUtf8();
var replicaTimestampsItemVal = clientMessage.GetLong();
var replicaTimestampsItem = new KeyValuePair<string,long>(replicaTimestampsItemKey, replicaTimestampsItemVal);

replicaTimestamps.Add(replicaTimestampsItem);
}

parameters.replicaTimestamps = replicaTimestamps;
var replicaCount = clientMessage.GetInt();
parameters.replicaCount = replicaCount;
return parameters;
}
}
}
92 changes: 92 additions & 0 deletions Hazelcast.Net/Hazelcast.Client.Protocol.Codec/PNCounterGetCodec.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
//
// 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.

using System;
using System.Collections.Generic;
using Hazelcast.Client.Protocol;
using Hazelcast.Client.Protocol.Util;
using Hazelcast.IO;
using Hazelcast.Logging;
using Hazelcast.IO.Serialization;

// Client Protocol version, Since:1.6 - Update:1.6
namespace Hazelcast.Client.Protocol.Codec
{
internal static class PNCounterGetCodec
{
private static int CalculateRequestDataSize(string name, IList<KeyValuePair<string, long>> replicaTimestamps, Address targetReplica)
{
var dataSize = ClientMessage.HeaderSize;
dataSize += ParameterUtil.CalculateDataSize(name);
dataSize += Bits.IntSizeInBytes;
foreach (var replicaTimestampsItem in replicaTimestamps )
{
var replicaTimestampsItemKey = replicaTimestampsItem.Key;
var replicaTimestampsItemVal = replicaTimestampsItem.Value;
dataSize += ParameterUtil.CalculateDataSize(replicaTimestampsItemKey);
dataSize += ParameterUtil.CalculateDataSize(replicaTimestampsItemVal);
}
dataSize += AddressCodec.CalculateDataSize(targetReplica);
return dataSize;
}

internal static ClientMessage EncodeRequest(string name, IList<KeyValuePair<string, long>> replicaTimestamps, Address targetReplica)
{
var requiredDataSize = CalculateRequestDataSize(name, replicaTimestamps, targetReplica);
var clientMessage = ClientMessage.CreateForEncode(requiredDataSize);
clientMessage.SetMessageType((int)PNCounterMessageType.PNCounterGet);
clientMessage.SetRetryable(true);
clientMessage.Set(name);
clientMessage.Set(replicaTimestamps.Count);
foreach (var replicaTimestampsItem in replicaTimestamps)
{
var replicaTimestampsItemKey = replicaTimestampsItem.Key;
var replicaTimestampsItemVal = replicaTimestampsItem.Value;
clientMessage.Set(replicaTimestampsItemKey);
clientMessage.Set(replicaTimestampsItemVal);
}
AddressCodec.Encode(targetReplica, clientMessage);
clientMessage.UpdateFrameLength();
return clientMessage;
}

internal class ResponseParameters
{
public long value;
public IList<KeyValuePair<string, long>> replicaTimestamps;
public int replicaCount;
}

internal static ResponseParameters DecodeResponse(IClientMessage clientMessage)
{
var parameters = new ResponseParameters();
var value = clientMessage.GetLong();
parameters.value = value;
var replicaTimestampsSize = clientMessage.GetInt();
var replicaTimestamps = new List<KeyValuePair<string, long>>(replicaTimestampsSize);
for (var replicaTimestampsIndex = 0; replicaTimestampsIndex<replicaTimestampsSize; replicaTimestampsIndex++)
{
var replicaTimestampsItemKey = clientMessage.GetStringUtf8();
var replicaTimestampsItemVal = clientMessage.GetLong();
var replicaTimestampsItem = new KeyValuePair<string,long>(replicaTimestampsItemKey, replicaTimestampsItemVal);
replicaTimestamps.Add(replicaTimestampsItem);
}
parameters.replicaTimestamps = replicaTimestamps;
var replicaCount = clientMessage.GetInt();
parameters.replicaCount = replicaCount;
return parameters;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
//
// 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.

using System;
using System.Collections.Generic;
using Hazelcast.Client.Protocol;
using Hazelcast.Client.Protocol.Util;
using Hazelcast.IO;
using Hazelcast.Logging;
using Hazelcast.IO.Serialization;

// Client Protocol version, Since:1.6 - Update:1.6
namespace Hazelcast.Client.Protocol.Codec
{
internal static class PNCounterGetConfiguredReplicaCountCodec
{
private static int CalculateRequestDataSize(string name)
{
var dataSize = ClientMessage.HeaderSize;
dataSize += ParameterUtil.CalculateDataSize(name);
return dataSize;
}

internal static ClientMessage EncodeRequest(string name)
{
var requiredDataSize = CalculateRequestDataSize(name);
var clientMessage = ClientMessage.CreateForEncode(requiredDataSize);
clientMessage.SetMessageType((int)PNCounterMessageType.PNCounterGetConfiguredReplicaCount);
clientMessage.SetRetryable(true);
clientMessage.Set(name);
clientMessage.UpdateFrameLength();
return clientMessage;
}

internal class ResponseParameters
{
public int response;
}

internal static ResponseParameters DecodeResponse(IClientMessage clientMessage)
{
var parameters = new ResponseParameters();
var response = clientMessage.GetInt();
parameters.response = response;
return parameters;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
//
// 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.

namespace Hazelcast.Client.Protocol.Codec
{
internal enum PNCounterMessageType
{

PNCounterGet = 0x2001,
PNCounterAdd = 0x2002,
PNCounterGetConfiguredReplicaCount = 0x2003

}

}


5 changes: 5 additions & 0 deletions Hazelcast.Net/Hazelcast.Client.Protocol.Util/ParameterUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static int CalculateDataSize(int data)
return Bits.IntSizeInBytes;
}

public static int CalculateDataSize(long data)
{
return Bits.LongSizeInBytes;
}

public static int CalculateDataSize(bool data)
{
return Bits.BooleanSizeInBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ internal enum ClientProtocolErrorCodes
Xa = 67,
AccessControl = 68,
Login = 69,
UnsupportedCallback = 70
UnsupportedCallback = 70,
NoDataMemeber = 71,
ReplicatedMapCantBeCreated = 72,
MaxMessageSizeExceeded = 73,
WANReplicationQueueFull = 74,
AssertionError = 75,
OutOfMemory = 76,
StackOverflowError = 77,
NativeOutOfMemoryError = 78,
ServiceNotFound = 79,
StaleTaskId = 80,
DuplicateTask = 81,
StaleTask = 82,
LocalMemberReset = 83,
IndeterminateOperationState = 84,
FlakeIdNodeIdOutOfRangeException = 85,
TargetNotReplicaException = 86,
MutationDisallowedException = 87,
ConsistencyLostException = 88
}
}
Loading