Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve shutdown behavior when writing exception happens #129

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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