-
Notifications
You must be signed in to change notification settings - Fork 3
/
REPLACE.cs
57 lines (53 loc) · 2.21 KB
/
REPLACE.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Text;
using BeetleX.Buffers;
namespace Infinispan.Hotrod.Core.Commands
{
public class REPLACE<K, V> : CommandWithKey<K>, ICommandWithExpiration
{
public REPLACE(Marshaller<K> km, Marshaller<V> vm, K key, V data)
{
Key = key;
Value = data;
KeyMarshaller = km;
ValueMarshaller = vm;
NetworkReceive = OnReceive;
}
public Marshaller<V> ValueMarshaller;
public int TimeOut { get; set; }
public ExpirationTime Lifespan { get; set; } = new ExpirationTime { Unit = TimeUnit.DEFAULT, Value = 0 };
public ExpirationTime MaxIdle { get; set; } = new ExpirationTime { Unit = TimeUnit.DEFAULT, Value = 0 };
public override string Name => "REPLACE";
public override Byte Code => 0x07;
public V Value { get; set; }
public V PrevValue { get; private set; }
public Boolean Replaced { get; private set; }
internal override void OnExecute(CommandContext ctx)
{
base.OnExecute(ctx);
}
internal override void Execute(CommandContext ctx, InfinispanClient client, PipeStream stream)
{
base.Execute(ctx, client, stream);
Codec.writeArray(KeyMarshaller.marshall(Key), stream);
Codec.writeExpirations(Lifespan, MaxIdle, stream);
Codec.writeArray(ValueMarshaller.marshall(Value), stream);
stream.Flush();
}
public override Result OnReceive(InfinispanRequest request, ResponseStream stream)
{
Replaced = Codec30.isSuccess(request.ResponseStatus);
if ((request.Command.Flags & 0x01) == 1 && Codec30.hasPrevious(request.ResponseStatus))
{
var retValAsArray = Codec.readArray(stream);
if (retValAsArray.Length > 0)
{
PrevValue = ValueMarshaller.unmarshall(retValAsArray);
return new Result { Status = ResultStatus.Completed, ResultType = ResultType.Object };
}
}
return new Result { Status = ResultStatus.Completed, ResultType = ResultType.Null };
}
}
}