Update README.md
Browse files1234567891011121314156 unmodified lines22232425262728293031323334352 unmodified lines383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312410 unmodified lines135136137138139140141142143144145146147148149150151152153154155156# π§ Actory β Typed Actor Model for Dart`actory` is a lightweight actor framework for Dart that enables concurrent, message-driven systems with:- β Async & sync actors- β Isolate-based concurrency- β Typed message passing (no `dynamic`)- β Ask/reply (`Future`-based)- β Supervision strategies- β Remote actors with WebSocket clustering- β Thread-safe data structures (SafeMap)### π Basic Usage```dartfinal system = ActorSystem();6 unmodified linesgreeter.send(Greet('Alice'));```### π Remote ActorsActory supports distributed actor systems with remote actors across multiple nodes:#### Using RemoteActorFactory (Recommended)```dart// Create a factory for your nodefinal factory = RemoteActorFactory(host: 'localhost',port: 8080,2 unmodified linesawait factory.start();// Create local actorsawait factory.createLocalActor<ChatMessage>('chat-actor',ChatActor(),(msg) => msg as ChatMessage,);// Register remote actorsfactory.registerRemoteActor('remote-chat', 'ws://localhost:8081');// Send messages (works for both local and remote)factory.sendMessage('chat-actor', ChatMessage('User', 'Hello!'));factory.sendMessage('remote-chat', ChatMessage('User', 'Hello remote!'));```#### Manual Remote Actor Creation```dart// Create cluster node and registryfinal clusterNode = ClusterNode('localhost', 8080);final registry = ActorRegistry();await clusterNode.start();// Register local actorfinal localActor = await system.spawn<Message>(actor, decoder);registry.registerLocal('my-actor', localActor);// Register remote actorregistry.registerRemote('remote-actor', 'ws://localhost:8081');// Get actor referencesfinal localRef = registry.get('my-actor');final remoteRef = registry.get('remote-actor'); // Returns RemoteActorRef// Send messageslocalRef?.send(message);remoteRef?.send(message);```### π SafeMap - Thread-Safe Data StructureSafeMap provides atomic operations for shared state management in concurrent actor systems:**Thread Safety Note**: SafeMap is designed for use within a single Dart isolate. In Dart's actor model, each actor runs in its own isolate, so SafeMap provides safety when multiple actors within the same isolate need to share state. For cross-isolate communication, use message passing through the actor system.```dart// Create a thread-safe mapfinal sharedData = SafeMap<String, String>();// Atomic operationssharedData.set('key', 'value');final value = sharedData.get('key');// Conditional operationsfinal wasAdded = sharedData.putIfAbsent('key', () => 'default');final computed = sharedData.getOrCompute('key', () => 'computed');// Update operationsfinal wasUpdated = sharedData.updateIfPresent('key', (v) => 'updated_$v');// Collection operationsfinal keys = sharedData.keys;final values = sharedData.values;final entries = sharedData.entries;// Functional operationsfinal filtered = sharedData.where((key, value) => key.startsWith('user_'));final transformed = sharedData.map((key, value) => MapEntry('new_$key', value.toUpperCase()));// Merge operationssharedData.merge({'key2': 'value2'});sharedData.mergeSafeMap(otherSafeMap);// Utility operationsfinal copy = sharedData.copy();final regularMap = sharedData.toMap();sharedData.clear();```#### SafeMap with Actors```dartclass SharedStateActor extends Actor<dynamic> {10 unmodified lines}```### π Examples- `/example/main.dart` - Basic actor usage- `/example/cluster_main.dart` - Cluster node example- `/example/simple_remote_actor.dart` - Simple remote actor example- `/example/remote_actor_example.dart` - Full remote actor demo- `/example/factory_remote_actor.dart` - RemoteActorFactory usage- `/example/safe_map_example.dart` - SafeMap usage with actors- `/example/safe_map_actor_example.dart` - Focused SafeMap actor demo### π§ Architecture- **Actor**: Message processing unit- **ActorSystem**: Manages actor lifecycle- **ClusterNode**: WebSocket-based node for distributed communication- **ActorRegistry**: Maps actor IDs to local/remote references- **RemoteActorRef**: Proxy for remote actors- **RemoteActorFactory**: High-level API for remote actor management- **SafeMap**: Thread-safe map for shared state management123456789101112131415161718192021226 unmodified lines2930313233343536373839404142432 unmodified lines46474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711810 unmodified lines129130131132133134135136137138139140141142143144145146147148149150151152153154---license: gpl-3.0pretty_name: Typed Actor Model for Rust---# π§ Actory β Typed Actor Model for Rust`actory` is a lightweight, strongly typed actor framework for Dart that enables building concurrent, message-driven systems with:* β Async & sync actors* β Isolate-based concurrency* β Typed message passing (no use of `dynamic`)* β Ask/reply patterns with `Future`-based messaging* β Supervision strategies for fault tolerance* β Remote actors with WebSocket clustering support* β Thread-safe data structures (SafeMap) for shared state---## π Basic Usage```dartfinal system = ActorSystem();6 unmodified linesgreeter.send(Greet('Alice'));```---## π Remote ActorsActory supports distributed actor systems spanning multiple nodes.### Using `RemoteActorFactory` (Recommended)```dartfinal factory = RemoteActorFactory(host: 'localhost',port: 8080,2 unmodified linesawait factory.start();await factory.createLocalActor<ChatMessage>('chat-actor',ChatActor(),(msg) => msg as ChatMessage,);factory.registerRemoteActor('remote-chat', 'ws://localhost:8081');factory.sendMessage('chat-actor', ChatMessage('User', 'Hello!'));factory.sendMessage('remote-chat', ChatMessage('User', 'Hello remote!'));```### Manual Remote Actor Setup```dartfinal clusterNode = ClusterNode('localhost', 8080);final registry = ActorRegistry();await clusterNode.start();final localActor = await system.spawn<Message>(actor, decoder);registry.registerLocal('my-actor', localActor);registry.registerRemote('remote-actor', 'ws://localhost:8081');final localRef = registry.get('my-actor');final remoteRef = registry.get('remote-actor'); // Returns RemoteActorReflocalRef?.send(message);remoteRef?.send(message);```---## π SafeMap β Thread-Safe Data Structure`SafeMap` provides atomic and thread-safe operations on shared state **within a single Dart isolate**. Since each actor runs in its own isolate, `SafeMap` is useful for shared data inside an isolate, while cross-isolate communication should use message passing.### Usage Example```dartfinal sharedData = SafeMap<String, String>();sharedData.set('key', 'value');final value = sharedData.get('key');final wasAdded = sharedData.putIfAbsent('key', () => 'default');final computed = sharedData.getOrCompute('key', () => 'computed');final wasUpdated = sharedData.updateIfPresent('key', (v) => 'updated_$v');final keys = sharedData.keys;final values = sharedData.values;final entries = sharedData.entries;final filtered = sharedData.where((key, value) => key.startsWith('user_'));final transformed = sharedData.map((key, value) => MapEntry('new_$key', value.toUpperCase()));sharedData.merge({'key2': 'value2'});sharedData.mergeSafeMap(otherSafeMap);final copy = sharedData.copy();final regularMap = sharedData.toMap();sharedData.clear();```### SafeMap in an Actor```dartclass SharedStateActor extends Actor<dynamic> {10 unmodified lines}```---## π Examples* `/example/main.dart` β Basic actor usage* `/example/cluster_main.dart` β Cluster node example* `/example/simple_remote_actor.dart` β Simple remote actor* `/example/remote_actor_example.dart` β Full remote actor demo* `/example/factory_remote_actor.dart` β `RemoteActorFactory` usage* `/example/safe_map_example.dart` β SafeMap usage with actors* `/example/safe_map_actor_example.dart` β Focused SafeMap actor demo---## π§ Architecture Overview* **Actor** β Basic message processing unit* **ActorSystem** β Manages actor lifecycle and supervision* **ClusterNode** β WebSocket-based cluster node for distributed communication* **ActorRegistry** β Maps actor IDs to local or remote references* **RemoteActorRef** β Proxy to communicate with remote actors* **RemoteActorFactory** β High-level API to manage local and remote actors* **SafeMap** β Thread-safe map implementation for shared state within isolates
README.md+52-54