Top Description Inners Fields Constructors Methods
org.eclipse.jgit.util.io

public final Class InterruptTimer

extends Object
Class Inheritance
Imports
java.text.MessageFormat, org.eclipse.jgit.internal.JGitText

Triggers an interrupt on the calling thread if it doesn't complete a block.

Classes can use this to trip an alarm interrupting the calling thread if it doesn't complete a block within the specified timeout. Typical calling pattern is:

private InterruptTimer myTimer = ...;
void foo() {
  try {
    myTimer.begin(timeout);
    // work
  } finally {
    myTimer.end();
  }
}

An InterruptTimer is not recursive. To implement recursive timers, independent InterruptTimer instances are required. A single InterruptTimer may be shared between objects which won't recursively call each other.

Each InterruptTimer spawns one background thread to sleep the specified time and interrupt the thread which called begin(int). It is up to the caller to ensure that the operations within the work block between the matched begin and end calls tests the interrupt flag (most IO operations do).

To terminate the background thread, use terminate(). If the application fails to terminate the thread, it will (eventually) terminate itself when the InterruptTimer instance is garbage collected.

See Also
TimeoutInputStream

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
pack-priv static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv final InterruptTimer.AutoKiller
private final InterruptTimer.AlarmState
private final InterruptTimer.AlarmThread

Constructor Summary

AccessConstructor and Description
public
InterruptTimer()

Create a new timer with a default thread name.

public
InterruptTimer(String
name of the timer thread.
threadName
)

Create a new timer to signal on interrupt on the caller.

Method Summary

Modifier and TypeMethod and Description
public void
begin(int
number of milliseconds before the interrupt should trigger. Must be > 0.
timeout
)

Arm the interrupt timer before entering a blocking operation.

public void
end()

Disable the interrupt timer, as the operation is complete.

public void
terminate()

Shutdown the timer thread, and wait for it to terminate.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoKillerback to summary
pack-priv final InterruptTimer.AutoKiller autoKiller
stateback to summary
private final InterruptTimer.AlarmState state
threadback to summary
private final InterruptTimer.AlarmThread thread

Constructor Detail

InterruptTimerback to summary
public InterruptTimer()

Create a new timer with a default thread name.

InterruptTimerback to summary
public InterruptTimer(String threadName)

Create a new timer to signal on interrupt on the caller.

The timer thread is created in the calling thread's ThreadGroup.

Parameters
threadName:String

name of the timer thread.

Method Detail

beginback to summary
public void begin(int timeout)

Arm the interrupt timer before entering a blocking operation.

Parameters
timeout:int

number of milliseconds before the interrupt should trigger. Must be > 0.

endback to summary
public void end()

Disable the interrupt timer, as the operation is complete.

terminateback to summary
public void terminate()

Shutdown the timer thread, and wait for it to terminate.

org.eclipse.jgit.util.io back to summary

pack-priv final Class InterruptTimer.AlarmState

extends Object
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
private Thread
private long
private boolean

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv synchronized void
begin(int timeout)

pack-priv synchronized void
end()

private static long
now()

public synchronized void
run()

Implements java.lang.Runnable.run.

Runs this operation.

pack-priv synchronized void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

callingThreadback to summary
private Thread callingThread
deadlineback to summary
private long deadline
terminatedback to summary
private boolean terminated

Constructor Detail

AlarmStateback to summary
pack-priv AlarmState()

Method Detail

beginback to summary
pack-priv synchronized void begin(int timeout)
endback to summary
pack-priv synchronized void end()
nowback to summary
private static long now()
runback to summary
public synchronized void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
terminateback to summary
pack-priv synchronized void terminate()
org.eclipse.jgit.util.io back to summary

pack-priv final Class InterruptTimer.AlarmThread

extends Thread
Class Inheritance

Field Summary

Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitrunsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopthreadIdtoStringyield

Constructor Detail

AlarmThreadback to summary
pack-priv AlarmThread(String name, InterruptTimer.AlarmState q)
org.eclipse.jgit.util.io back to summary

private final Class InterruptTimer.AutoKiller

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final InterruptTimer.AlarmState

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
finalize()

Overrides java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Inherited from java.lang.Object:
cloneequalsgetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stateback to summary
private final InterruptTimer.AlarmState state

Constructor Detail

AutoKillerback to summary
pack-priv AutoKiller(InterruptTimer.AlarmState s)

Method Detail

finalizeback to summary
protected void finalize() throws Throwable

Overrides java.lang.Object.finalize.

Doc from java.lang.Object.finalize.

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup.

When running in a Java virtual machine in which finalization has been disabled or removed, the garbage collector will never call finalize(). In a Java virtual machine in which finalization is enabled, the garbage collector might call finalize only after an indefinite delay.

The general contract of finalize is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The finalize method may take any action, including making this object available again to other threads; the usual purpose of finalize, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The finalize method of class Object performs no special action; it simply returns normally. Subclasses of Object may override this definition.

The Java programming language does not guarantee which thread will invoke the finalize method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the finalize method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The finalize method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the finalize method causes the finalization of this object to be halted, but is otherwise ignored.

Annotations
@Override
Exceptions
Throwable:
the Exception raised by this method