Skip to content

Commit e265308

Browse files
committed
Updated the signature of Method SaveData(MyData data, TimeSpan ttl);
1 parent c6a8379 commit e265308

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

examples/Actor/ActorClient/Program.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ public class Program
3232
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
3333
public static async Task Main(string[] args)
3434
{
35-
var data = new MyData()
35+
var data = new MyDataWithTTL()
3636
{
37-
PropertyA = "ValueA",
38-
PropertyB = "ValueB",
37+
MyData = new MyData
38+
{
39+
PropertyA = "ValueA",
40+
PropertyB = "ValueB",
41+
},
42+
TTL = TimeSpan.FromMinutes(10),
3943
};
4044

4145
// Create an actor Id.
@@ -46,7 +50,7 @@ public static async Task Main(string[] args)
4650
var proxy = ActorProxy.Create<IDemoActor>(actorId, "DemoActor");
4751

4852
Console.WriteLine("Making call using actor proxy to save data.");
49-
await proxy.SaveData(data, TimeSpan.FromMinutes(10));
53+
await proxy.SaveData(data);
5054
Console.WriteLine("Making call using actor proxy to get data.");
5155
var receivedData = await proxy.GetData();
5256
Console.WriteLine($"Received data is {receivedData}.");
@@ -103,7 +107,7 @@ public static async Task Main(string[] args)
103107
await proxy.UnregisterTimer();
104108
Console.WriteLine("Deregistering reminder. Reminders are durable and would not stop until an explicit deregistration or the actor is deleted.");
105109
await proxy.UnregisterReminder();
106-
110+
107111
Console.WriteLine("Registering reminder with repetitions - The reminder will repeat 3 times.");
108112
await proxy.RegisterReminderWithRepetitions(3);
109113
Console.WriteLine("Waiting so the reminder can be triggered");

examples/Actor/DemoActor/DemoActor.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,50 +57,59 @@ public DemoActor(
5757
}
5858
}
5959

60-
public async Task SaveData(MyData data, TimeSpan ttl)
60+
/// <inheritdoc/>
61+
public async Task SaveData(MyDataWithTTL data)
6162
{
6263
Console.WriteLine($"This is Actor id {this.Id} with data {data}.");
6364

6465
// Set State using StateManager, state is saved after the method execution.
65-
await this.StateManager.SetStateAsync<MyData>(StateName, data, ttl);
66+
await this.StateManager.SetStateAsync<MyData>(StateName, data.MyData, data.TTL);
6667
}
6768

69+
/// <inheritdoc/>
6870
public Task<MyData> GetData()
6971
{
7072
// Get state using StateManager.
7173
return this.StateManager.GetStateAsync<MyData>(StateName);
7274
}
7375

76+
/// <inheritdoc/>
7477
public Task TestThrowException()
7578
{
7679
throw new NotImplementedException();
7780
}
7881

82+
/// <inheritdoc/>
7983
public Task TestNoArgumentNoReturnType()
8084
{
8185
return Task.CompletedTask;
8286
}
8387

88+
/// <inheritdoc/>
8489
public async Task RegisterReminder()
8590
{
8691
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
8792
}
8893

94+
/// <inheritdoc/>
8995
public async Task RegisterReminderWithTtl(TimeSpan ttl)
9096
{
9197
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), ttl);
9298
}
9399

100+
/// <inheritdoc/>
94101
public async Task RegisterReminderWithRepetitions(int repetitions)
95102
{
96103
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), repetitions);
97104
}
98105

106+
/// <inheritdoc/>
99107
public async Task RegisterReminderWithTtlAndRepetitions(TimeSpan ttl, int repetitions)
100108
{
101109
await this.RegisterReminderAsync("TestReminder", null, TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1), repetitions, ttl);
102110
}
103111

112+
/// <inheritdoc/>
104113
public async Task<ActorReminderData> GetReminder()
105114
{
106115
var reminder = await this.GetReminderAsync("TestReminder");
@@ -115,11 +124,13 @@ public async Task<ActorReminderData> GetReminder()
115124
: null;
116125
}
117126

127+
/// <inheritdoc/>
118128
public Task UnregisterReminder()
119129
{
120130
return this.UnregisterReminderAsync("TestReminder");
121131
}
122132

133+
/// <inheritdoc/>
123134
public async Task ReceiveReminderAsync(string reminderName, byte[] state, TimeSpan dueTime, TimeSpan period)
124135
{
125136
// This method is invoked when an actor reminder is fired.
@@ -147,6 +158,7 @@ public Task RegisterTimer()
147158
return this.RegisterTimerAsync("TestTimer", nameof(this.TimerCallback), serializedTimerParams, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3));
148159
}
149160

161+
/// <inheritdoc/>
150162
public Task RegisterTimerWithTtl(TimeSpan ttl)
151163
{
152164
var timerParams = new TimerParams
@@ -159,6 +171,7 @@ public Task RegisterTimerWithTtl(TimeSpan ttl)
159171
return this.RegisterTimerAsync("TestTimer", nameof(this.TimerCallback), serializedTimerParams, TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(3), ttl);
160172
}
161173

174+
/// <inheritdoc/>
162175
public Task UnregisterTimer()
163176
{
164177
return this.UnregisterTimerAsync("TestTimer");
@@ -195,6 +208,7 @@ public async Task TimerCallback(byte[] data)
195208
Console.WriteLine("Timer parameter2: " + timerParams.StringParam);
196209
}
197210

211+
/// <inheritdoc/>
198212
public async Task<AccountBalance> GetAccountBalance()
199213
{
200214
var starting = new AccountBalance()
@@ -207,6 +221,7 @@ public async Task<AccountBalance> GetAccountBalance()
207221
return balance;
208222
}
209223

224+
/// <inheritdoc/>
210225
public async Task Withdraw(WithdrawRequest withdraw)
211226
{
212227
var starting = new AccountBalance()

examples/Actor/IDemoActor/IDemoActor.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ namespace IDemoActorInterface
1616
using System;
1717
using System.Threading.Tasks;
1818
using Dapr.Actors;
19-
using Dapr.Actors.Runtime;
2019

2120
/// <summary>
2221
/// Interface for Actor method.
@@ -26,10 +25,9 @@ public interface IDemoActor : IActor
2625
/// <summary>
2726
/// Method to save data.
2827
/// </summary>
29-
/// <param name="data">DAta to save.</param>
30-
/// <param name="ttl">TTL of state key.</param>
28+
/// <param name="data">Data to save with its TTL.</param>
3129
/// <returns>A task that represents the asynchronous save operation.</returns>
32-
Task SaveData(MyData data, TimeSpan ttl);
30+
Task SaveData(MyDataWithTTL data);
3331

3432
/// <summary>
3533
/// Method to get data.
@@ -80,14 +78,14 @@ public interface IDemoActor : IActor
8078
/// <param name="ttl">Optional TimeSpan that dictates when the timer expires.</param>
8179
/// <returns>A task that represents the asynchronous save operation.</returns>
8280
Task RegisterTimerWithTtl(TimeSpan ttl);
83-
81+
8482
/// <summary>
8583
/// Registers a reminder with repetitions.
8684
/// </summary>
8785
/// <param name="repetitions">The number of repetitions for which the reminder should be invoked.</param>
8886
/// <returns>A task that represents the asynchronous save operation.</returns>
8987
Task RegisterReminderWithRepetitions(int repetitions);
90-
88+
9189
/// <summary>
9290
/// Registers a reminder with ttl and repetitions.
9391
/// </summary>
@@ -134,6 +132,25 @@ public override string ToString()
134132
}
135133
}
136134

135+
/// <summary>
136+
/// Variant of MyData with TTL.
137+
/// </summary>
138+
public class MyDataWithTTL
139+
{
140+
/// <summary>
141+
/// Gets or sets the MyData value.
142+
/// </summary>
143+
public MyData MyData { get; set; }
144+
145+
/// <summary>
146+
/// Duration for which the state is valid.
147+
/// </summary>
148+
public TimeSpan TTL { get; set; }
149+
}
150+
151+
/// <summary>
152+
/// Object to hold reminder data.
153+
/// </summary>
137154
public class ActorReminderData
138155
{
139156
public string Name { get; set; }

0 commit comments

Comments
 (0)