Datasets:

Modalities:
Text
Formats:
text
Size:
< 1K
Libraries:
Datasets
License:
khulnasoft commited on
Commit
b3acecc
Β·
verified Β·
1 Parent(s): cddba7c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -54
README.md CHANGED
@@ -1,15 +1,22 @@
1
- # 🧠 Actory β€” Typed Actor Model for Dart
 
 
 
 
2
 
3
- `actory` is a lightweight actor framework for Dart that enables concurrent, message-driven systems with:
4
- - βœ… Async & sync actors
5
- - βœ… Isolate-based concurrency
6
- - βœ… Typed message passing (no `dynamic`)
7
- - βœ… Ask/reply (`Future`-based)
8
- - βœ… Supervision strategies
9
- - βœ… Remote actors with WebSocket clustering
10
- - βœ… Thread-safe data structures (SafeMap)
11
 
12
- ### πŸš€ Basic Usage
 
 
 
 
 
 
 
 
 
 
13
 
14
  ```dart
15
  final system = ActorSystem();
@@ -22,14 +29,15 @@ final greeter = await system.spawn<Greet>(
22
  greeter.send(Greet('Alice'));
23
  ```
24
 
25
- ### 🌐 Remote Actors
 
 
26
 
27
- Actory supports distributed actor systems with remote actors across multiple nodes:
28
 
29
- #### Using RemoteActorFactory (Recommended)
30
 
31
  ```dart
32
- // Create a factory for your node
33
  final factory = RemoteActorFactory(
34
  host: 'localhost',
35
  port: 8080,
@@ -38,87 +46,73 @@ final factory = RemoteActorFactory(
38
 
39
  await factory.start();
40
 
41
- // Create local actors
42
  await factory.createLocalActor<ChatMessage>(
43
  'chat-actor',
44
  ChatActor(),
45
  (msg) => msg as ChatMessage,
46
  );
47
 
48
- // Register remote actors
49
  factory.registerRemoteActor('remote-chat', 'ws://localhost:8081');
50
 
51
- // Send messages (works for both local and remote)
52
  factory.sendMessage('chat-actor', ChatMessage('User', 'Hello!'));
53
  factory.sendMessage('remote-chat', ChatMessage('User', 'Hello remote!'));
54
  ```
55
 
56
- #### Manual Remote Actor Creation
57
 
58
  ```dart
59
- // Create cluster node and registry
60
  final clusterNode = ClusterNode('localhost', 8080);
61
  final registry = ActorRegistry();
62
 
63
  await clusterNode.start();
64
 
65
- // Register local actor
66
  final localActor = await system.spawn<Message>(actor, decoder);
67
  registry.registerLocal('my-actor', localActor);
68
 
69
- // Register remote actor
70
  registry.registerRemote('remote-actor', 'ws://localhost:8081');
71
 
72
- // Get actor references
73
  final localRef = registry.get('my-actor');
74
  final remoteRef = registry.get('remote-actor'); // Returns RemoteActorRef
75
 
76
- // Send messages
77
  localRef?.send(message);
78
  remoteRef?.send(message);
79
  ```
80
 
81
- ### πŸ”’ SafeMap - Thread-Safe Data Structure
82
 
83
- SafeMap provides atomic operations for shared state management in concurrent actor systems:
84
 
85
- **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.
 
 
86
 
87
  ```dart
88
- // Create a thread-safe map
89
  final sharedData = SafeMap<String, String>();
90
 
91
- // Atomic operations
92
  sharedData.set('key', 'value');
93
  final value = sharedData.get('key');
94
 
95
- // Conditional operations
96
  final wasAdded = sharedData.putIfAbsent('key', () => 'default');
97
  final computed = sharedData.getOrCompute('key', () => 'computed');
98
 
99
- // Update operations
100
  final wasUpdated = sharedData.updateIfPresent('key', (v) => 'updated_$v');
101
 
102
- // Collection operations
103
  final keys = sharedData.keys;
104
  final values = sharedData.values;
105
  final entries = sharedData.entries;
106
 
107
- // Functional operations
108
  final filtered = sharedData.where((key, value) => key.startsWith('user_'));
109
  final transformed = sharedData.map((key, value) => MapEntry('new_$key', value.toUpperCase()));
110
 
111
- // Merge operations
112
  sharedData.merge({'key2': 'value2'});
113
  sharedData.mergeSafeMap(otherSafeMap);
114
 
115
- // Utility operations
116
  final copy = sharedData.copy();
117
  final regularMap = sharedData.toMap();
118
  sharedData.clear();
119
  ```
120
 
121
- #### SafeMap with Actors
122
 
123
  ```dart
124
  class SharedStateActor extends Actor<dynamic> {
@@ -135,22 +129,26 @@ class SharedStateActor extends Actor<dynamic> {
135
  }
136
  ```
137
 
138
- ### πŸ“ Examples
139
-
140
- - `/example/main.dart` - Basic actor usage
141
- - `/example/cluster_main.dart` - Cluster node example
142
- - `/example/simple_remote_actor.dart` - Simple remote actor example
143
- - `/example/remote_actor_example.dart` - Full remote actor demo
144
- - `/example/factory_remote_actor.dart` - RemoteActorFactory usage
145
- - `/example/safe_map_example.dart` - SafeMap usage with actors
146
- - `/example/safe_map_actor_example.dart` - Focused SafeMap actor demo
147
-
148
- ### πŸ”§ Architecture
149
-
150
- - **Actor**: Message processing unit
151
- - **ActorSystem**: Manages actor lifecycle
152
- - **ClusterNode**: WebSocket-based node for distributed communication
153
- - **ActorRegistry**: Maps actor IDs to local/remote references
154
- - **RemoteActorRef**: Proxy for remote actors
155
- - **RemoteActorFactory**: High-level API for remote actor management
156
- - **SafeMap**: Thread-safe map for shared state management
 
 
 
 
 
1
+ ---
2
+ license: gpl-3.0
3
+ pretty_name: Typed Actor Model for Rust
4
+ ---
5
+ # 🧠 Actory β€” Typed Actor Model for Rust
6
 
7
+ `actory` is a lightweight, strongly typed actor framework for Dart that enables building concurrent, message-driven systems with:
 
 
 
 
 
 
 
8
 
9
+ * βœ… Async & sync actors
10
+ * βœ… Isolate-based concurrency
11
+ * βœ… Typed message passing (no use of `dynamic`)
12
+ * βœ… Ask/reply patterns with `Future`-based messaging
13
+ * βœ… Supervision strategies for fault tolerance
14
+ * βœ… Remote actors with WebSocket clustering support
15
+ * βœ… Thread-safe data structures (SafeMap) for shared state
16
+
17
+ ---
18
+
19
+ ## πŸš€ Basic Usage
20
 
21
  ```dart
22
  final system = ActorSystem();
 
29
  greeter.send(Greet('Alice'));
30
  ```
31
 
32
+ ---
33
+
34
+ ## 🌐 Remote Actors
35
 
36
+ Actory supports distributed actor systems spanning multiple nodes.
37
 
38
+ ### Using `RemoteActorFactory` (Recommended)
39
 
40
  ```dart
 
41
  final factory = RemoteActorFactory(
42
  host: 'localhost',
43
  port: 8080,
 
46
 
47
  await factory.start();
48
 
 
49
  await factory.createLocalActor<ChatMessage>(
50
  'chat-actor',
51
  ChatActor(),
52
  (msg) => msg as ChatMessage,
53
  );
54
 
 
55
  factory.registerRemoteActor('remote-chat', 'ws://localhost:8081');
56
 
 
57
  factory.sendMessage('chat-actor', ChatMessage('User', 'Hello!'));
58
  factory.sendMessage('remote-chat', ChatMessage('User', 'Hello remote!'));
59
  ```
60
 
61
+ ### Manual Remote Actor Setup
62
 
63
  ```dart
 
64
  final clusterNode = ClusterNode('localhost', 8080);
65
  final registry = ActorRegistry();
66
 
67
  await clusterNode.start();
68
 
 
69
  final localActor = await system.spawn<Message>(actor, decoder);
70
  registry.registerLocal('my-actor', localActor);
71
 
 
72
  registry.registerRemote('remote-actor', 'ws://localhost:8081');
73
 
 
74
  final localRef = registry.get('my-actor');
75
  final remoteRef = registry.get('remote-actor'); // Returns RemoteActorRef
76
 
 
77
  localRef?.send(message);
78
  remoteRef?.send(message);
79
  ```
80
 
81
+ ---
82
 
83
+ ## πŸ”’ SafeMap β€” Thread-Safe Data Structure
84
 
85
+ `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.
86
+
87
+ ### Usage Example
88
 
89
  ```dart
 
90
  final sharedData = SafeMap<String, String>();
91
 
 
92
  sharedData.set('key', 'value');
93
  final value = sharedData.get('key');
94
 
 
95
  final wasAdded = sharedData.putIfAbsent('key', () => 'default');
96
  final computed = sharedData.getOrCompute('key', () => 'computed');
97
 
 
98
  final wasUpdated = sharedData.updateIfPresent('key', (v) => 'updated_$v');
99
 
 
100
  final keys = sharedData.keys;
101
  final values = sharedData.values;
102
  final entries = sharedData.entries;
103
 
 
104
  final filtered = sharedData.where((key, value) => key.startsWith('user_'));
105
  final transformed = sharedData.map((key, value) => MapEntry('new_$key', value.toUpperCase()));
106
 
 
107
  sharedData.merge({'key2': 'value2'});
108
  sharedData.mergeSafeMap(otherSafeMap);
109
 
 
110
  final copy = sharedData.copy();
111
  final regularMap = sharedData.toMap();
112
  sharedData.clear();
113
  ```
114
 
115
+ ### SafeMap in an Actor
116
 
117
  ```dart
118
  class SharedStateActor extends Actor<dynamic> {
 
129
  }
130
  ```
131
 
132
+ ---
133
+
134
+ ## πŸ“ Examples
135
+
136
+ * `/example/main.dart` β€” Basic actor usage
137
+ * `/example/cluster_main.dart` β€” Cluster node example
138
+ * `/example/simple_remote_actor.dart` β€” Simple remote actor
139
+ * `/example/remote_actor_example.dart` β€” Full remote actor demo
140
+ * `/example/factory_remote_actor.dart` β€” `RemoteActorFactory` usage
141
+ * `/example/safe_map_example.dart` β€” SafeMap usage with actors
142
+ * `/example/safe_map_actor_example.dart` β€” Focused SafeMap actor demo
143
+
144
+ ---
145
+
146
+ ## πŸ”§ Architecture Overview
147
+
148
+ * **Actor** β€” Basic message processing unit
149
+ * **ActorSystem** β€” Manages actor lifecycle and supervision
150
+ * **ClusterNode** β€” WebSocket-based cluster node for distributed communication
151
+ * **ActorRegistry** β€” Maps actor IDs to local or remote references
152
+ * **RemoteActorRef** β€” Proxy to communicate with remote actors
153
+ * **RemoteActorFactory** β€” High-level API to manage local and remote actors
154
+ * **SafeMap** β€” Thread-safe map implementation for shared state within isolates