Skip to content

Commit

Permalink
Merge pull request #129 from henrypinkard/main
Browse files Browse the repository at this point in the history
improve shutdown behavior when writing exception happens
  • Loading branch information
henrypinkard authored Aug 2, 2023
2 parents f1a7ab8 + f084b15 commit bf48030
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 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.2</version>
<version>2.14.0</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 @@ -42,6 +42,12 @@ public Future putImage(Object pixels, JSONObject metadata, HashMap<String, Objec
*/
public boolean isFinished();

/**
* Throw an exception if there was an error writing to disk.
* This is needed because writing occurs on a seperate thread for performance reasons
*/
public void checkForWritingException() throws Exception;

/**
* Set display settings for storage. No particular structure required as the
* storage class will only save and load them but not do anything with them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,11 @@ public void discardDataForDebugging() {
}

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

Expand All @@ -808,7 +807,11 @@ private void checkWritingException() {
*/
public Future putImage(Object pixels, JSONObject metadata, HashMap<String, Object> axessss,
boolean rgb, int bitDepth, int imageHeight, int imageWidth) {
checkWritingException();
try {
checkForWritingException();
} catch (Exception e) {
throw new RuntimeException(e);
}
TaggedImage ti = new TaggedImage(pixels, metadata);

// Make sure each axis takes all integer or all string values
Expand Down Expand Up @@ -904,7 +907,11 @@ 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();
try {
checkForWritingException();
} catch (Exception e) {
throw new RuntimeException(e);
}
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 @@ -1049,10 +1056,9 @@ public void run() {
}

/**
* Singal to finish writing and block until everything pending is done
* Signal to finish writing and block until everything pending is done
*/
public void finishedWriting() {
checkWritingException();
if (loaded_) {
return;
}
Expand Down Expand Up @@ -1139,12 +1145,10 @@ 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 bf48030

Please sign in to comment.