@@ -117,7 +117,7 @@ use crate::{
117
117
BaoFileStorage , BaoFileStorageSubscriber , CompleteStorage , DataReader ,
118
118
OutboardReader ,
119
119
} ,
120
- util:: entity_manager:: { self , ActiveEntityState } ,
120
+ util:: entity_manager,
121
121
} ,
122
122
util:: { BaoTreeSender , FixedSize , MemOrFile , ValueOrPoisioned } ,
123
123
Hash , IROH_BLOCK_SIZE ,
@@ -211,21 +211,39 @@ impl TaskContext {
211
211
}
212
212
}
213
213
214
- #[ derive( Debug ) ]
215
- struct EmParams ;
216
-
217
- impl entity_manager:: Params for EmParams {
214
+ impl entity_manager:: Params for HashContext {
218
215
type EntityId = Hash ;
219
216
220
217
type GlobalState = Arc < TaskContext > ;
221
218
222
- type EntityState = BaoFileHandle ;
219
+ fn id ( & self ) -> & Self :: EntityId {
220
+ & self . id
221
+ }
222
+
223
+ fn global ( & self ) -> & Self :: GlobalState {
224
+ & self . global
225
+ }
223
226
224
- async fn on_shutdown (
225
- state : entity_manager:: ActiveEntityState < Self > ,
226
- _cause : entity_manager:: ShutdownCause ,
227
- ) {
228
- state. persist ( ) . await ;
227
+ fn ref_count ( & self ) -> usize {
228
+ self . state . receiver_count ( ) + self . state . receiver_count ( )
229
+ }
230
+
231
+ fn new ( id : & Self :: EntityId , global : & Self :: GlobalState ) -> Self {
232
+ Self {
233
+ id : * id,
234
+ global : global. clone ( ) ,
235
+ state : BaoFileHandle :: default ( ) ,
236
+ }
237
+ }
238
+
239
+ fn reset ( & mut self , id : & Self :: EntityId , global : & Self :: GlobalState ) {
240
+ self . id = * id;
241
+ self . global = global. clone ( ) ;
242
+ self . state . send_replace ( BaoFileStorage :: Initial ) ;
243
+ }
244
+
245
+ async fn on_shutdown ( & self , _cause : entity_manager:: ShutdownCause ) {
246
+ self . persist ( ) . await ;
229
247
}
230
248
}
231
249
@@ -240,7 +258,7 @@ struct Actor {
240
258
// Tasks for import and export operations.
241
259
tasks : JoinSet < ( ) > ,
242
260
// Entity manager that handles concurrency for entities.
243
- handles : EntityManagerState < EmParams > ,
261
+ handles : EntityManagerState < HashContext > ,
244
262
// temp tags
245
263
temp_tags : TempTags ,
246
264
// waiters for idle state.
@@ -249,7 +267,12 @@ struct Actor {
249
267
_rt : RtWrapper ,
250
268
}
251
269
252
- type HashContext = ActiveEntityState < EmParams > ;
270
+ #[ derive( Debug , Clone ) ]
271
+ struct HashContext {
272
+ id : Hash ,
273
+ global : Arc < TaskContext > ,
274
+ state : BaoFileHandle ,
275
+ }
253
276
254
277
impl SyncEntityApi for HashContext {
255
278
/// Load the state from the database.
@@ -677,11 +700,11 @@ trait HashSpecificCommand: HashSpecific + Send + 'static {
677
700
678
701
/// Opportunity to send an error if spawning fails due to the task being busy (inbox full)
679
702
/// or dead (e.g. panic in one of the running tasks).
680
- fn on_error ( self , arg : SpawnArg < EmParams > ) -> impl Future < Output = ( ) > + Send + ' static ;
703
+ fn on_error ( self , arg : SpawnArg < HashContext > ) -> impl Future < Output = ( ) > + Send + ' static ;
681
704
682
705
async fn spawn (
683
706
self ,
684
- manager : & mut entity_manager:: EntityManagerState < EmParams > ,
707
+ manager : & mut entity_manager:: EntityManagerState < HashContext > ,
685
708
tasks : & mut JoinSet < ( ) > ,
686
709
) where
687
710
Self : Sized ,
@@ -715,13 +738,13 @@ impl HashSpecificCommand for ObserveMsg {
715
738
async fn handle ( self , ctx : HashContext ) {
716
739
ctx. observe ( self ) . await
717
740
}
718
- async fn on_error ( self , _arg : SpawnArg < EmParams > ) { }
741
+ async fn on_error ( self , _arg : SpawnArg < HashContext > ) { }
719
742
}
720
743
impl HashSpecificCommand for ExportPathMsg {
721
744
async fn handle ( self , ctx : HashContext ) {
722
745
ctx. export_path ( self ) . await
723
746
}
724
- async fn on_error ( self , arg : SpawnArg < EmParams > ) {
747
+ async fn on_error ( self , arg : SpawnArg < HashContext > ) {
725
748
let err = match arg {
726
749
SpawnArg :: Busy => io:: ErrorKind :: ResourceBusy . into ( ) ,
727
750
SpawnArg :: Dead => io:: Error :: other ( "entity is dead" ) ,
@@ -737,7 +760,7 @@ impl HashSpecificCommand for ExportBaoMsg {
737
760
async fn handle ( self , ctx : HashContext ) {
738
761
ctx. export_bao ( self ) . await
739
762
}
740
- async fn on_error ( self , arg : SpawnArg < EmParams > ) {
763
+ async fn on_error ( self , arg : SpawnArg < HashContext > ) {
741
764
let err = match arg {
742
765
SpawnArg :: Busy => io:: ErrorKind :: ResourceBusy . into ( ) ,
743
766
SpawnArg :: Dead => io:: Error :: other ( "entity is dead" ) ,
@@ -753,7 +776,7 @@ impl HashSpecificCommand for ExportRangesMsg {
753
776
async fn handle ( self , ctx : HashContext ) {
754
777
ctx. export_ranges ( self ) . await
755
778
}
756
- async fn on_error ( self , arg : SpawnArg < EmParams > ) {
779
+ async fn on_error ( self , arg : SpawnArg < HashContext > ) {
757
780
let err = match arg {
758
781
SpawnArg :: Busy => io:: ErrorKind :: ResourceBusy . into ( ) ,
759
782
SpawnArg :: Dead => io:: Error :: other ( "entity is dead" ) ,
@@ -769,7 +792,7 @@ impl HashSpecificCommand for ImportBaoMsg {
769
792
async fn handle ( self , ctx : HashContext ) {
770
793
ctx. import_bao ( self ) . await
771
794
}
772
- async fn on_error ( self , arg : SpawnArg < EmParams > ) {
795
+ async fn on_error ( self , arg : SpawnArg < HashContext > ) {
773
796
let err = match arg {
774
797
SpawnArg :: Busy => io:: ErrorKind :: ResourceBusy . into ( ) ,
775
798
SpawnArg :: Dead => io:: Error :: other ( "entity is dead" ) ,
@@ -788,7 +811,7 @@ impl HashSpecificCommand for (TempTag, ImportEntryMsg) {
788
811
let ( tt, cmd) = self ;
789
812
ctx. finish_import ( cmd, tt) . await
790
813
}
791
- async fn on_error ( self , arg : SpawnArg < EmParams > ) {
814
+ async fn on_error ( self , arg : SpawnArg < HashContext > ) {
792
815
let err = match arg {
793
816
SpawnArg :: Busy => io:: ErrorKind :: ResourceBusy . into ( ) ,
794
817
SpawnArg :: Dead => io:: Error :: other ( "entity is dead" ) ,
0 commit comments