public abstract class ManagedResource<T>
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
ManagedResource(java.lang.String resourceId,
TaskGlobalContext taskGlobalContext,
java.util.concurrent.Callable<T> resourceConstructor) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the resource if it's an instance of java.io.Closeable.
|
T |
getResource()
Constructs the resource using the provided constructor if it doesn't yet
exist in the resource map
|
protected abstract java.util.List |
idTuple(TaskGlobalContext context) |
public ManagedResource(java.lang.String resourceId, TaskGlobalContext taskGlobalContext, java.util.concurrent.Callable<T> resourceConstructor)
resourceId
- - a unique ID for this resourcetaskGlobalContext
- - the current TaskGlobalContextresourceConstructor
- - a function returning a new instance of the resourceprotected abstract java.util.List idTuple(TaskGlobalContext context)
public T getResource()
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException