Skip to content

Commit bbaec06

Browse files
stefanhahmannclaude
andcommitted
Register IJ-opened dataset as active pyramidal synchronously
Removes the race where OpenResolutionLevelCommand saw no active pyramidal until the async AWT focus event arrived (flaky under load). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ff5c4e3 commit bbaec06

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

ome-zarr-fiji/src/main/java/ome/zarr/fiji/open/ZarrOpener.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public Object openIJWithImage()
156156
final PyramidContents< ? > contents = getContents();
157157
final PyramidalDataset dataset = new PyramidalDataset( context, contents, preferredResolutionLevel );
158158
context.getService( UIService.class ).show( dataset );
159+
context.getService( PyramidalService.class ).registerImageJDataset( dataset );
159160
logger.info( "Opened dataset in ImageJ: {}", inputUri );
160161
return null;
161162
},
@@ -191,6 +192,7 @@ public Object openIJWithImage( final int resolutionLevel )
191192
throw new NonExistingResolutionLevelException( resolutionLevel, contents.numResolutionLevels() );
192193
final PyramidalDataset dataset = new PyramidalDataset( context, contents, resolutionLevel );
193194
context.getService( UIService.class ).show( dataset );
195+
context.getService( PyramidalService.class ).registerImageJDataset( dataset );
194196
logger.info( "Opened dataset at resolution level {} in ImageJ: {}", resolutionLevel, inputUri );
195197
return null;
196198
},

ome-zarr-fiji/src/main/java/ome/zarr/fiji/plugins/PyramidalService.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,25 @@ public void unregisterBdvWindow( final Window window )
168168
}
169169

170170
/** Records {@code dataset} as the active pyramidal, replacing any previously active one. */
171-
void notifyBdvWindowFocused( final Pyramidal dataset )
171+
void notifyBdvWindowFocused( final Pyramidal pyramidal )
172172
{
173-
logger.trace( "BDV window focused: {}", dataset );
174-
activePyramidal.set( dataset );
173+
logger.trace( "BDV window focused: {}", pyramidal );
174+
activePyramidal.set( pyramidal );
175+
logger.trace( "Active pyramidal set to: {}", activePyramidal.get() );
176+
}
177+
178+
/**
179+
* Records the given {@code pyramidal} as the active pyramidal immediately when it is opened in an
180+
* ImageJ window, without waiting for the asynchronous AWT {@code "activeWindow"} focus
181+
* event to arrive at the new {@link ImageWindow}. This mirrors the synchronous registration
182+
* that {@link #registerBdvWindow} performs for BDV windows. So a freshly opened pyramidal is
183+
* the active pyramidal as soon as the open call returns rather than only once the native
184+
* windowing system delivers focus (which may be delayed or never happen under load).
185+
*/
186+
public void registerImageJDataset( final Pyramidal pyramidal )
187+
{
188+
logger.trace( "ImageJ dataset opened: {}", pyramidal );
189+
activePyramidal.set( pyramidal );
175190
logger.trace( "Active pyramidal set to: {}", activePyramidal.get() );
176191
}
177192

0 commit comments

Comments
 (0)