-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adriano Santos
committed
Oct 18, 2023
1 parent
c3977ee
commit 154c5b8
Showing
8 changed files
with
63 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import 'package:spawn_dart/spawn_dart.dart'; | ||
import 'package:spawn_dart/src/protocol/eigr/functions/protocol/actors/protocol.pb.dart'; | ||
|
||
abstract class ActorHandler { | ||
ActorRef getActorRef(); | ||
String getRegisteredName(); | ||
ActorInvocationResponse handleInvoke(ActorInvocation invocation); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,64 @@ | ||
import 'dart:mirrors'; | ||
|
||
import 'package:optional/optional.dart'; | ||
import 'package:spawn_dart/spawn_dart.dart'; | ||
import 'package:spawn_dart/src/actor_handler.dart'; | ||
import 'package:spawn_dart/src/protocol/eigr/functions/protocol/actors/protocol.pb.dart'; | ||
import 'package:spawn_dart/src/protocol/eigr/functions/protocol/actors/protocol.pb.dart' | ||
as spawn_protocol; | ||
import 'package:spawn_dart/src/reflect_helper.dart'; | ||
|
||
class StatefulNamedActorHandler implements ActorHandler { | ||
Type? actorEntity; | ||
Type? actorEntityType; | ||
DeclarationMirror? _mirror; | ||
StatefulNamedActor? statefulNamedActorAnnotationInstance; | ||
StatefulNamedActor? _statefulNamedActorAnnotationInstance; | ||
List<MethodMirror> _allDeclaredMethods = []; | ||
|
||
StatefulNamedActorHandler(Type actorEntity) { | ||
actorEntity = actorEntity; | ||
_mirror = reflectClass(actorEntity); | ||
actorEntityType = actorEntity; | ||
_mirror = reflectClass(actorEntityType!); | ||
|
||
var statefulActorAnnotationMirror = reflectClass(StatefulNamedActor); | ||
final InstanceMirror? statefulActorAnnotationInstanceMirror = _mirror | ||
?.metadata | ||
.firstWhere((d) => d.type == statefulActorAnnotationMirror); | ||
|
||
statefulNamedActorAnnotationInstance = | ||
_statefulNamedActorAnnotationInstance = | ||
(statefulActorAnnotationInstanceMirror?.reflectee | ||
as StatefulNamedActor); | ||
} | ||
|
||
@override | ||
ActorRef getActorRef() { | ||
// TODO: implement getActorRef | ||
return ActorRef(); | ||
if (_allDeclaredMethods.isEmpty) { | ||
_allDeclaredMethods = | ||
ReflectHelper.getAllMethods(reflectClass(_mirror.runtimeType)); | ||
} | ||
} | ||
|
||
@override | ||
ActorInvocationResponse handleInvoke(ActorInvocation invocation) { | ||
return ActorInvocationResponse.create()..actorName = invocation.actor.name; | ||
spawn_protocol.ActorInvocationResponse handleInvoke( | ||
spawn_protocol.ActorInvocation invocation) { | ||
// TODO: implement invoke | ||
Optional<Object> actorInstance = | ||
Optional.of(ReflectHelper.createInstance(actorEntityType!)); | ||
|
||
if (actorInstance.isEmpty) { | ||
throw StateError("Actor not found Or error during instance creation"); | ||
} | ||
|
||
spawn_protocol.ActorInvocationResponse response = | ||
spawn_protocol.ActorInvocationResponse.create() | ||
..actorName = invocation.actor.name | ||
..actorSystem = invocation.actor.system | ||
..updatedContext = spawn_protocol.Context.create(); | ||
return response; | ||
} | ||
|
||
@override | ||
String getRegisteredName() { | ||
// TODO: implement getRegisteredName | ||
return ""; | ||
String? name = _statefulNamedActorAnnotationInstance?.name; | ||
|
||
if (name == null || name.isEmpty) { | ||
return MirrorSystem.getName(_mirror!.simpleName); | ||
} | ||
|
||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters