Skip to content

Commit

Permalink
Merge pull request #128 from henrypinkard/main
Browse files Browse the repository at this point in the history
Propagate exceptions on writing thread to caller
  • Loading branch information
henrypinkard committed Aug 1, 2023
2 parents 68c1a3f + 20376b4 commit aa0ced2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.micro-manager.ndtiffstorage</groupId>
<artifactId>NDTiffStorage</artifactId>
<version>2.13.1</version>
<version>2.13.2</version>
<packaging>jar</packaging>
<name>NDTiff Storage file format</name>
<description>Java-based writer and reader used for NDTiffStorage format</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.micromanager.ndtiffstorage;

import java.awt.Point;
import java.awt.geom.Rectangle2D;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -39,7 +38,6 @@
import mmcorej.org.json.JSONObject;

import javax.swing.*;
import javax.swing.text.html.HTML;

/**
* This class manages multiple multipage Tiff datasets, averaging multiple 2x2
Expand Down Expand Up @@ -92,6 +90,7 @@ public class NDTiffStorage implements NDTiffAPI, MultiresNDTiffAPI {
private volatile boolean discardData_ = false;

private int detectedMajorVersion_;
private volatile Exception writingException_ = null;

/**
* Constructor to load existing storage from disk dir --top level saving
Expand Down Expand Up @@ -793,14 +792,23 @@ public void discardDataForDebugging() {
discardData_ = true;
}


/**
* Check if an exception has occured on the writing thread, and if so propagate it
* to other API calls
*/
private void checkWritingException() {
if (writingException_ != null) {
throw new RuntimeException(writingException_);
}
}

/**
* This version works for regular, non-multiresolution data
*
*/
public Future putImage(Object pixels, JSONObject metadata, HashMap<String, Object> axessss,
boolean rgb, int bitDepth, int imageHeight, int imageWidth) {
checkWritingException();
TaggedImage ti = new TaggedImage(pixels, metadata);

// Make sure each axis takes all integer or all string values
Expand Down Expand Up @@ -872,8 +880,8 @@ public void run() {
}
}

} catch (IOException ex) {
throw new RuntimeException(ex.toString());
} catch (Exception ex) {
writingException_ = ex;
}
}
});
Expand All @@ -896,6 +904,7 @@ static String getAxesString(HashMap<String, Object> axes) {
@Override
public Future putImageMultiRes( Object pixels, JSONObject metadata, final HashMap<String, Object> axes,
boolean rgb, int bitDepth, int imageHeight, int imageWidth) {
checkWritingException();
TaggedImage ti = new TaggedImage(pixels, metadata);
if (!firstImageAdded_) {
//technically this doesnt need to be parsed here, because it should be fixed for the whole
Expand Down Expand Up @@ -1043,6 +1052,7 @@ public void run() {
* Singal to finish writing and block until everything pending is done
*/
public void finishedWriting() {
checkWritingException();
if (loaded_) {
return;
}
Expand Down Expand Up @@ -1129,10 +1139,12 @@ public JSONObject getDisplaySettings() {
}

public void closeAndWait() throws InterruptedException {
checkWritingException();
doClose();
}

public void close() {
checkWritingException();
//run close on a new thread
new Thread(new Runnable() {
@Override
Expand Down

0 comments on commit aa0ced2

Please sign in to comment.