11import logging
2- from typing import Any , Dict , List , Optional
2+ from typing import Any
33
44from polystore .streaming .receivers .core import DebouncedBatchEngine
55
99class FijiBatchProcessor :
1010 """
1111 Batch processor for Fiji viewer with configurable batching strategies.
12-
13- Accumulates items and builds hyperstacks based on batch_size configuration:
14- - None: Wait for all items in operation, then build hyperstack once
15- - N: Rebuild hyperstack every N items incrementally
16-
12+
1713 Uses debouncing to collect items arriving in rapid succession.
1814 """
19-
15+
2016 def __init__ (
2117 self ,
2218 fiji_server ,
23- batch_size : Optional [int ] = None ,
2419 debounce_delay_ms : int = 500 ,
2520 max_debounce_wait_ms : int = 2000 ,
2621 ):
2722 """
2823 Initialize batch processor.
29-
24+
3025 Args:
3126 fiji_server: Reference to FijiViewerServer for display operations
32- batch_size: Number of items to batch before displaying
33- None = wait for all (default), N = display every N items
3427 debounce_delay_ms: Wait time after last item before processing (ms)
3528 max_debounce_wait_ms: Maximum total wait time before forcing display (ms)
3629 """
3730 self .fiji_server = fiji_server
38- self .batch_size = batch_size
3931 self .debounce_delay_ms = debounce_delay_ms
4032 self .max_debounce_wait_ms = max_debounce_wait_ms
41-
33+
4234 self ._engine = DebouncedBatchEngine (
4335 process_fn = self ._process_batch ,
4436 debounce_delay_ms = debounce_delay_ms ,
4537 max_debounce_wait_ms = max_debounce_wait_ms ,
4638 )
47-
39+
4840 logger .info (
49- f"FijiBatchProcessor: Created with batch_size={ batch_size } , "
50- f"debounce={ debounce_delay_ms } ms, max_wait={ max_debounce_wait_ms } ms"
41+ "FijiBatchProcessor: Created with debounce=%sms, max_wait=%sms" ,
42+ debounce_delay_ms ,
43+ max_debounce_wait_ms ,
5144 )
52-
45+
5346 def add_items (
5447 self ,
5548 window_key : str ,
56- items : List [ Dict [str , Any ]],
57- display_config : Dict [str , Any ],
49+ items : list [ dict [str , Any ]],
50+ display_config : dict [str , Any ],
5851 images_dir : str ,
59- component_names_metadata : Dict [str , Any ],
60- component_value_domain : Dict [str , Any ],
52+ component_names_metadata : dict [str , Any ],
53+ component_value_domain : dict [str , Any ],
6154 ):
6255 """
6356 Add items to the batch for processing.
64-
57+
6558 Args:
6659 window_key: Unique identifier for the Fiji window
6760 items: List of items to add (images)
@@ -88,7 +81,7 @@ def flush(self) -> None:
8881 """Force immediate processing of the pending batch."""
8982 self ._engine .flush ()
9083
91- def _process_batch (self , items : List [ Dict [str , Any ]], context : Dict [str , Any ]) -> None :
84+ def _process_batch (self , items : list [ dict [str , Any ]], context : dict [str , Any ]) -> None :
9285 """Process callback used by shared debounced batch engine."""
9386 display_config = context ["display_config" ]
9487 images_dir = context ["images_dir" ]
0 commit comments