Top Description Fields Constructors Methods
org.python.modules._io

pack-priv Class Closer<C extends PyIOBase>

extends Object
implements Callable<Void>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Imports
java.lang.ref.WeakReference, java.util.concurrent.Callable, java.util.concurrent.atomic.AtomicBoolean, org.python.core.PyObject, .PySystemState

A class to take responsibility for closing a stream on JVM shutdown. On creation a Closer adds itself to a list that will be run by PySystemState on shutdown and it maintains a reference to its client PyIOBase. The client (assuming it kept a reference to the Closer) may dismiss the closer at any time: normally this will be when the client stream is closed directly, or implicitly through PyIOBase#__exit__(PyObject, PyObject, PyObject). A possibility is that the JVM exits before an close() is called. In that case, Closer#call() will be called, and the Closer will call the client's close operation.

In case the close operation is overridden so that it does not dismiss the closer, it is useful to have the client's finalize dismiss the closer. If not, the Closer will remain registered and this will keep the PyIOBase object alive in the JVM, which is mostly harmless.

Field Summary

Modifier and TypeField and Description
private final WeakReference<C>
client

The client in need of closing.

private AtomicBoolean
protected PySystemState
sys

Interpreter state that will call call() on shutdown.

Constructor Summary

AccessConstructor and Description
public
Closer(C toClose, PySystemState sys)

Method Summary

Modifier and TypeMethod and Description
public Void
call()

Implements java.util.concurrent.Callable.call.

Called as part of a shutdown process.

public void
dismiss()

Tell the Closer that its services are no longer required.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

clientback to summary
private final WeakReference<C> client

The client in need of closing.

dismissedback to summary
private AtomicBoolean dismissed
sysback to summary
protected PySystemState sys

Interpreter state that will call call() on shutdown.

Constructor Detail

Closerback to summary
public Closer(C toClose, PySystemState sys)

Method Detail

callback to summary
public Void call()

Implements java.util.concurrent.Callable.call.

Called as part of a shutdown process. If the client is still (weakly) reachable, invoke its "close" method.

Returns:Void

Doc from java.util.concurrent.Callable.call.

computed result

Annotations
@Override
dismissback to summary
public void dismiss()

Tell the Closer that its services are no longer required. This unhooks it from the shutdown list. Repeated calls are allowed but only the first has any effect.