Skip to content

Commit

Permalink
Make AbstractFastaSequenceFile serializable by Kryo for Spark. (#1408)
Browse files Browse the repository at this point in the history
See explanation at EsotericSoftware/kryo#469
  • Loading branch information
tomwhite authored and lbergelson committed Aug 13, 2019
1 parent cea307e commit 9401637
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@

import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.function.Supplier;

/**
* Provide core sequence dictionary functionality required by all fasta file readers.
Expand All @@ -62,7 +64,8 @@ abstract class AbstractFastaSequenceFile implements ReferenceSequenceFile {
AbstractFastaSequenceFile(final Path path) {
this.path = path;
this.source = path == null ? "unknown" : path.toAbsolutePath().toString();
this.dictionary = new Lazy<>(() -> findAndLoadSequenceDictionary(path));
// ensure lambda is serializable (by Kryo, when used with Spark)
this.dictionary = new Lazy<>((Supplier<SAMSequenceDictionary> & Serializable) (() -> findAndLoadSequenceDictionary(path)));
}

/**
Expand All @@ -74,7 +77,8 @@ abstract class AbstractFastaSequenceFile implements ReferenceSequenceFile {
AbstractFastaSequenceFile(final Path path, final String source, final SAMSequenceDictionary sequenceDictionary) {
this.path = path;
this.source = source;
this.dictionary = new Lazy<>(() -> sequenceDictionary);
// ensure lambda is serializable (by Kryo, when used with Spark)
this.dictionary = new Lazy<>((Supplier<SAMSequenceDictionary> & Serializable) (() -> sequenceDictionary));
}

/** Attempts to find and load the sequence dictionary if present. */
Expand Down

0 comments on commit 9401637

Please sign in to comment.