Skip to content

Commit 970f260

Browse files
Rename create and delete to register and unregister
Signed-off-by: Xavier Geerinck <[email protected]>
1 parent 261fc3b commit 970f260

File tree

10 files changed

+34
-101
lines changed

10 files changed

+34
-101
lines changed

src/actors/client/ActorClient/ActorClient.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { DaprClient } from '../../..';
22
import CommunicationProtocolEnum from '../../../enum/CommunicationProtocol.enum';
33
import GRPCClient from '../../../implementation/Client/GRPCClient/GRPCClient';
44
import HTTPClient from '../../../implementation/Client/HTTPClient/HTTPClient';
5-
import IClient from '../../../interfaces/Client/IClient';
65
import IClientActor from '../../../interfaces/Client/IClientActor';
76
import ActorClientGRPC from './ActorClientGRPC';
87
import ActorClientHTTP from './ActorClientHTTP';

src/actors/client/ActorClient/ActorClientGRPC.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default class ActorClientGRPC implements IClientActor {
105105
});
106106
}
107107

108-
async reminderCreate(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
108+
async registerActorReminder(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
109109
const msgService = new RegisterActorReminderRequest();
110110
msgService.setActorType(actorType);
111111
msgService.setActorId(actorId);
@@ -136,39 +136,7 @@ export default class ActorClientGRPC implements IClientActor {
136136
});
137137
}
138138

139-
// @todo: not implemented, cannot find the gRPC bindings
140-
// async reminderGet(actorType: string, actorId: string, name: string): Promise<void> {
141-
// const msgService = new RegisterActorReminderRequest();
142-
// msgService.setActorType(actorType);
143-
// msgService.setActorId(actorId);
144-
// msgService.setName(name);
145-
146-
// if (reminder.data) {
147-
// msgService.setData(Buffer.from(reminder.data, "utf-8"))
148-
// }
149-
150-
// if (reminder.period) {
151-
// msgService.setPeriod(reminder.period);
152-
// }
153-
154-
// if (reminder.dueTime) {
155-
// msgService.setDueTime(reminder.dueTime);
156-
// }
157-
158-
// return new Promise(async (resolve, reject) => {
159-
// const client = await GRPCClientSingleton.getClient();
160-
// client.registerActorReminder(msgService, (err, res) => {
161-
// if (err) {
162-
// return reject(err);
163-
// }
164-
165-
// // https://docs.dapr.io/reference/api/actors_api/#http-response-codes-3
166-
// return resolve();
167-
// });
168-
// });
169-
// }
170-
171-
async reminderDelete(actorType: string, actorId: string, name: string): Promise<void> {
139+
async unregisterActorReminder(actorType: string, actorId: string, name: string): Promise<void> {
172140
const msgService = new UnregisterActorReminderRequest();
173141
msgService.setActorType(actorType);
174142
msgService.setActorId(actorId);
@@ -187,7 +155,7 @@ export default class ActorClientGRPC implements IClientActor {
187155
});
188156
}
189157

190-
async timerCreate(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
158+
async registerActorTimer(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
191159
const msgService = new RegisterActorTimerRequest();
192160
msgService.setActorType(actorType);
193161
msgService.setActorId(actorId);
@@ -222,7 +190,7 @@ export default class ActorClientGRPC implements IClientActor {
222190
});
223191
}
224192

225-
async timerDelete(actorType: string, actorId: string, name: string): Promise<void> {
193+
async unregisterActorTimer(actorType: string, actorId: string, name: string): Promise<void> {
226194
const msgService = new UnregisterActorTimerRequest();
227195
msgService.setActorType(actorType);
228196
msgService.setActorId(actorId);

src/actors/client/ActorClient/ActorClientHTTP.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class ActorClientHTTP implements IClientActor {
3737
return result as any;
3838
}
3939

40-
async reminderCreate(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
40+
async registerActorReminder(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
4141
await this.client.execute(`/actors/${actorType}/${actorId}/reminders/${name}`, {
4242
method: 'POST',
4343
headers: {
@@ -56,13 +56,13 @@ export default class ActorClientHTTP implements IClientActor {
5656
return result as object;
5757
}
5858

59-
async reminderDelete(actorType: string, actorId: string, name: string): Promise<void> {
59+
async unregisterActorReminder(actorType: string, actorId: string, name: string): Promise<void> {
6060
await this.client.execute(`/actors/${actorType}/${actorId}/reminders/${name}`, {
6161
method: 'DELETE',
6262
});
6363
}
6464

65-
async timerCreate(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
65+
async registerActorTimer(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
6666
await this.client.execute(`/actors/${actorType}/${actorId}/timers/${name}`, {
6767
method: 'POST',
6868
headers: {
@@ -77,7 +77,7 @@ export default class ActorClientHTTP implements IClientActor {
7777
});
7878
}
7979

80-
async timerDelete(actorType: string, actorId: string, name: string): Promise<void> {
80+
async unregisterActorTimer(actorType: string, actorId: string, name: string): Promise<void> {
8181
await this.client.execute(`/actors/${actorType}/${actorId}/timers/${name}`, {
8282
method: 'DELETE',
8383
});

src/actors/runtime/AbstractActor.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { Temporal } from "@js-temporal/polyfill";
22
import DaprClient from "../../implementation/Client/DaprClient";
3-
import HTTPClientActor from "../../implementation/Client/HTTPClient/actor";
4-
import HTTPClient from "../../implementation/Client/HTTPClient/HTTPClient";
53
import ActorId from "../ActorId";
64
import ActorClient from "../client/ActorClient/ActorClient";
75
import ActorStateManager from "./ActorStateManager";
@@ -73,31 +71,31 @@ export default abstract class AbstractActor {
7371
* @param <Type> Type of the state object
7472
* @return Async void response
7573
*/
76-
async registerReminder<Type>(reminderName: string, dueTime: Temporal.Duration, period: Temporal.Duration, state?: any) {
77-
await this.actorClient.actor.reminderCreate(this.actorType, this.id.getId(), reminderName, {
74+
async registerActorReminder<Type>(reminderName: string, dueTime: Temporal.Duration, period: Temporal.Duration, state?: any) {
75+
await this.actorClient.actor.registerActorReminder(this.actorType, this.id.getId(), reminderName, {
7876
period,
7977
dueTime,
8078
data: state
8179
});
8280
}
8381

84-
async unregisterReminder(reminderName: string) {
85-
await this.actorClient.actor.reminderDelete(this.actorType, this.id.getId(), reminderName);
82+
async unregisterActorReminder(reminderName: string) {
83+
await this.actorClient.actor.unregisterActorReminder(this.actorType, this.id.getId(), reminderName);
8684
}
8785

88-
async registerTimer(timerName: string, callback: string, dueTime: Temporal.Duration, period: Temporal.Duration, state?: any) {
86+
async registerActorTimer(timerName: string, callback: string, dueTime: Temporal.Duration, period: Temporal.Duration, state?: any) {
8987
// Register the timer in the sidecar
9088
// console.log(`actorType: ${this.actorType}, actorId: ${this.id.getId()}, timerName: ${timerName}, callback: ${callback}, dueTime: ${dueTime.toString()}, period: ${period.toString()}`);
91-
return await this.actorClient.actor.timerCreate(this.actorType, this.id.getId(), timerName, {
89+
return await this.actorClient.actor.registerActorTimer(this.actorType, this.id.getId(), timerName, {
9290
period,
9391
dueTime,
9492
data: state,
9593
callback
9694
});
9795
}
9896

99-
async unregisterTimer(timerName: string) {
100-
await this.actorClient.actor.timerDelete(this.actorType, this.id.getId(), timerName);
97+
async unregisterActorTimer(timerName: string) {
98+
await this.actorClient.actor.unregisterActorTimer(this.actorType, this.id.getId(), timerName);
10199
}
102100

103101
/**

src/implementation/Client/GRPCClient/actor.ts

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default class GRPCClientActor implements IClientActor {
105105
});
106106
}
107107

108-
async reminderCreate(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
108+
async registerActorReminder(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
109109
const msgService = new RegisterActorReminderRequest();
110110
msgService.setActorType(actorType);
111111
msgService.setActorId(actorId);
@@ -136,39 +136,7 @@ export default class GRPCClientActor implements IClientActor {
136136
});
137137
}
138138

139-
// @todo: not implemented, cannot find the gRPC bindings
140-
// async reminderGet(actorType: string, actorId: string, name: string): Promise<void> {
141-
// const msgService = new RegisterActorReminderRequest();
142-
// msgService.setActorType(actorType);
143-
// msgService.setActorId(actorId);
144-
// msgService.setName(name);
145-
146-
// if (reminder.data) {
147-
// msgService.setData(Buffer.from(reminder.data, "utf-8"))
148-
// }
149-
150-
// if (reminder.period) {
151-
// msgService.setPeriod(reminder.period);
152-
// }
153-
154-
// if (reminder.dueTime) {
155-
// msgService.setDueTime(reminder.dueTime);
156-
// }
157-
158-
// return new Promise(async (resolve, reject) => {
159-
// const client = await GRPCClientSingleton.getClient();
160-
// client.registerActorReminder(msgService, (err, res) => {
161-
// if (err) {
162-
// return reject(err);
163-
// }
164-
165-
// // https://docs.dapr.io/reference/api/actors_api/#http-response-codes-3
166-
// return resolve();
167-
// });
168-
// });
169-
// }
170-
171-
async reminderDelete(actorType: string, actorId: string, name: string): Promise<void> {
139+
async unregisterActorReminder(actorType: string, actorId: string, name: string): Promise<void> {
172140
const msgService = new UnregisterActorReminderRequest();
173141
msgService.setActorType(actorType);
174142
msgService.setActorId(actorId);
@@ -187,7 +155,7 @@ export default class GRPCClientActor implements IClientActor {
187155
});
188156
}
189157

190-
async timerCreate(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
158+
async registerActorTimer(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
191159
const msgService = new RegisterActorTimerRequest();
192160
msgService.setActorType(actorType);
193161
msgService.setActorId(actorId);
@@ -222,7 +190,7 @@ export default class GRPCClientActor implements IClientActor {
222190
});
223191
}
224192

225-
async timerDelete(actorType: string, actorId: string, name: string): Promise<void> {
193+
async unregisterActorTimer(actorType: string, actorId: string, name: string): Promise<void> {
226194
const msgService = new UnregisterActorTimerRequest();
227195
msgService.setActorType(actorType);
228196
msgService.setActorId(actorId);

src/implementation/Client/HTTPClient/actor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class HTTPClientActor implements IClientActor {
3737
return result as any;
3838
}
3939

40-
async reminderCreate(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
40+
async registerActorReminder(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void> {
4141
await this.client.execute(`/actors/${actorType}/${actorId}/reminders/${name}`, {
4242
method: 'POST',
4343
headers: {
@@ -56,13 +56,13 @@ export default class HTTPClientActor implements IClientActor {
5656
return result as object;
5757
}
5858

59-
async reminderDelete(actorType: string, actorId: string, name: string): Promise<void> {
59+
async unregisterActorReminder(actorType: string, actorId: string, name: string): Promise<void> {
6060
await this.client.execute(`/actors/${actorType}/${actorId}/reminders/${name}`, {
6161
method: 'DELETE',
6262
});
6363
}
6464

65-
async timerCreate(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
65+
async registerActorTimer(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void> {
6666
await this.client.execute(`/actors/${actorType}/${actorId}/timers/${name}`, {
6767
method: 'POST',
6868
headers: {
@@ -77,7 +77,7 @@ export default class HTTPClientActor implements IClientActor {
7777
});
7878
}
7979

80-
async timerDelete(actorType: string, actorId: string, name: string): Promise<void> {
80+
async unregisterActorTimer(actorType: string, actorId: string, name: string): Promise<void> {
8181
await this.client.execute(`/actors/${actorType}/${actorId}/timers/${name}`, {
8282
method: 'DELETE',
8383
});

src/interfaces/Client/IClientActor.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export default interface IClientActor {
77
invoke(method: "GET" | "POST" | "PUT" | "DELETE", actorType: string, actorId: string, methodName: string, body?: any): Promise<object>;
88
stateTransaction(actorType: string, actorId: string, operations: OperationType[]): Promise<void>;
99
stateGet(actorType: string, actorId: string, key: string): Promise<KeyValueType | string>;
10-
reminderCreate(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void>;
11-
reminderDelete(actorType: string, actorId: string, name: string): Promise<void>;
12-
timerCreate(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void>;
13-
timerDelete(actorType: string, actorId: string, name: string): Promise<void>;
10+
registerActorReminder(actorType: string, actorId: string, name: string, reminder: ActorReminderType): Promise<void>;
11+
unregisterActorReminder(actorType: string, actorId: string, name: string): Promise<void>;
12+
registerActorTimer(actorType: string, actorId: string, name: string, timer: ActorTimerType): Promise<void>;
13+
unregisterActorTimer(actorType: string, actorId: string, name: string): Promise<void>;
1414
getActors(): Promise<object>;
1515
}

test/actor/DemoActorReminder2Impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class DemoActorReminder2Impl extends AbstractActor implements Dem
55
counter = 0;
66

77
async init(): Promise<string> {
8-
await super.registerReminder("my-reminder-name", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 123);
8+
await super.registerActorReminder("my-reminder-name", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 123);
99
return "Actor Initialized";
1010
}
1111

@@ -18,6 +18,6 @@ export default class DemoActorReminder2Impl extends AbstractActor implements Dem
1818
}
1919

2020
async removeReminder(): Promise<void> {
21-
return this.unregisterReminder("my-reminder-name");
21+
return this.unregisterActorReminder("my-reminder-name");
2222
}
2323
}

test/actor/DemoActorReminderImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class DemoActorReminderImpl extends AbstractActor implements Demo
55
counter = 0;
66

77
async init(): Promise<string> {
8-
await super.registerReminder("my-reminder-name", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 123);
8+
await super.registerActorReminder("my-reminder-name", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 123);
99
return "Actor Initialized";
1010
}
1111

@@ -18,7 +18,7 @@ export default class DemoActorReminderImpl extends AbstractActor implements Demo
1818
}
1919

2020
async removeReminder(): Promise<void> {
21-
return this.unregisterReminder("my-reminder-name");
21+
return this.unregisterActorReminder("my-reminder-name");
2222
}
2323

2424
/**

test/actor/DemoActorTimerImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default class DemoActorTimerImpl extends AbstractActor implements DemoAct
55
counter = 0;
66

77
async init(): Promise<string> {
8-
await super.registerTimer("my-timer-name", "countBy", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 100);
8+
await super.registerActorTimer("my-timer-name", "countBy", Temporal.Duration.from({ seconds: 2 }), Temporal.Duration.from({ seconds: 1 }), 100);
99
return "Actor Initialized";
1010
}
1111

@@ -22,6 +22,6 @@ export default class DemoActorTimerImpl extends AbstractActor implements DemoAct
2222
}
2323

2424
async removeTimer(): Promise<void> {
25-
return await this.unregisterTimer("my-timer-name");
25+
return await this.unregisterActorTimer("my-timer-name");
2626
}
2727
}

0 commit comments

Comments
 (0)