- java.lang.Object
-
- com.machinezoo.sourceafis.FingerprintTransparency
-
- All Implemented Interfaces:
-
CloseableScope
,AutoCloseable
public abstract class FingerprintTransparency extends Object implements CloseableScope
Algorithm transparency API that can capture all intermediate data structures produced by SourceAFIS algorithm. See algorithm transparency pages on SourceAFIS website for more information and a tutorial on how to use this class.Applications can subclass
FingerprintTransparency
and overridetake(String, String, byte[])
method to define new transparency data logger. One default implementation ofFingerprintTransparency
is returned byzip(OutputStream)
method. Applications can control what transparency data gets produced by overridingaccepts(String)
.FingerprintTransparency
instance should be created in a try-with-resources construct. It will be capturing transparency data from all operations on current thread between invocation of the constructor and invocation ofclose()
method, which is called automatically in the try-with-resources construct.- See Also:
- Algorithm transparency in SourceAFIS
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FingerprintTransparency()
Creates an instance ofFingerprintTransparency
and activates it.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
accepts(String key)
Filters transparency data keys that can be passed totake(String, String, byte[])
.protected void
capture(String key, Map<String,Supplier<byte[]>> data)
Deprecated.void
close()
Deactivates transparency logging and releases system resources held by this instance if any.protected void
log(String key, Map<String,Supplier<ByteBuffer>> data)
Deprecated.void
take(String key, String mime, byte[] data)
Records transparency data.static FingerprintTransparency
zip(OutputStream stream)
Writes all transparency data to a ZIP file.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.machinezoo.closeablescope.CloseableScope
andFinally, andThen
-
-
-
-
Constructor Detail
-
FingerprintTransparency
protected FingerprintTransparency()
Creates an instance ofFingerprintTransparency
and activates it.Activation places the new
FingerprintTransparency
instance in thread-local storage, which causes all operations executed by current thread to log data to thisFingerprintTransparency
instance. If activations are nested, data is only logged to the currently innermostFingerprintTransparency
.Deactivation happens in
close()
method. Instances ofFingerprintTransparency
should be created in try-with-resources construct to ensure thatclose()
is always called.FingerprintTransparency
is an abstract class. This constructor is only called by subclasses.- See Also:
-
close()
-
-
Method Detail
-
accepts
public boolean accepts(String key)
Filters transparency data keys that can be passed totake(String, String, byte[])
. Default implementation always returnstrue
, i.e. all transparency data is passed totake(String, String, byte[])
. Implementation can override this method to filter some keys out, which improves performance.This method should always return the same result for the same key. Result may be cached and this method might not be called every time something is about to be logged.
- Parameters:
-
key
- transparency data key as used intake(String, String, byte[])
- Returns:
- whether transparency data under given key should be logged
- See Also:
-
take(String, String, byte[])
-
take
public void take(String key, String mime, byte[] data)
Records transparency data. Subclasses must override this method, because the default implementation does nothing. While thisFingerprintTransparency
object is active (between call to the constructor and call toclose()
), this method is called with transparency data in its parameters.Parameter
key
specifies the kind of transparency data being logged, usually corresponding to some stage in the algorithm. Parameterdata
then contains the actual transparency data. This method may be called multiple times with the samekey
if the algorithm produces that kind of transparency data repeatedly. See algorithm transparency on SourceAFIS website for documentation of the structure of the transparency data.Transparency data is offered only if
accepts(String)
returnstrue
for the samekey
. This allows applications to efficiently collect only transparency data that is actually needed.MIME type of the transparency data is provided, which may be useful for generic implementations, for example transparency data browser app that changes type of visualization based on the MIME type. Most transparency data is serialized in CBOR format (MIME application/cbor).
Implementations of this method should be synchronized. Although the current SourceAFIS algorithm is single-threaded, future versions of SourceAFIS might run some parts of the algorithm in parallel, which would result in concurrent calls to this method.
If this method throws, exception is propagated through SourceAFIS code.
- Parameters:
-
key
- specifies the kind of transparency data being logged -
mime
- MIME type of the transparency data indata
parameter -
data
- transparency data being logged - See Also:
-
Algorithm transparency in SourceAFIS,
accepts(String)
,zip(OutputStream)
-
capture
@Deprecated protected void capture(String key, Map<String,Supplier<byte[]>> data)
Deprecated.Records transparency data (deprecated). This is a deprecated variant oftake(String, String, byte[])
. This method is only called iftake(String, String, byte[])
is not overridden.- Parameters:
-
key
- specifies the kind of transparency data being reported -
data
- a map of suffixes (like.cbor
or.dat
) toSupplier
of the available transparency data - See Also:
-
take(String, String, byte[])
-
log
@Deprecated protected void log(String key, Map<String,Supplier<ByteBuffer>> data)
Deprecated.Records transparency data (deprecated). This is a deprecated variant oftake(String, String, byte[])
. This method is only called iftake(String, String, byte[])
andcapture(String, Map)
are not overridden.- Parameters:
-
key
- specifies the kind of transparency data being reported -
data
- a map of suffixes (like.cbor
or.dat
) toSupplier
of the available transparency data - See Also:
-
take(String, String, byte[])
-
close
public void close()
Deactivates transparency logging and releases system resources held by this instance if any. This method is normally called automatically whenFingerprintTransparency
is used in try-with-resources construct.Deactivation stops transparency data logging to this instance of
FingerprintTransparency
. Logging thus takes place between invocation of constructor (FingerprintTransparency()
) and invocation of this method. If activations were nested, this method reactivates the outerFingerprintTransparency
.Subclasses can override this method to perform cleanup. Default implementation of this method performs deactivation. It must be called by overriding methods for deactivation to work correctly.
- Specified by:
-
close
in interfaceAutoCloseable
- Specified by:
-
close
in interfaceCloseableScope
- See Also:
-
FingerprintTransparency()
-
zip
public static FingerprintTransparency zip(OutputStream stream)
Writes all transparency data to a ZIP file. This is a convenience method to enable easy exploration of the available data. Programmatic processing of transparency data should be done by subclassingFingerprintTransparency
and overridingtake(String, String, byte[])
method.ZIP file entries have filenames like
NNN-key.ext
whereNNN
is a sequentially assigned ID,key
comes fromtake(String, String, byte[])
parameter, andext
is derived from MIME type.The returned
FingerprintTransparency
object holds system resources and callers are responsible for callingclose()
method, perhaps using try-with-resources construct. Failure to close the returnedFingerprintTransparency
instance may result in damaged ZIP file.If the provided
stream
throwsIOException
, the exception will be wrapped in an unchecked exception and propagated.- Parameters:
-
stream
- output stream where ZIP file will be written (will be closed when the returnedFingerprintTransparency
is closed) - Returns:
- algorithm transparency logger that writes data to a ZIP file
- See Also:
-
Algorithm transparency in SourceAFIS,
close()
,take(String, String, byte[])
-
-