Top Description Inners Fields Constructors Methods
org.mortbay.thread

public Class Timeout

extends Object
Class Inheritance
Imports
org.mortbay.log.Log

Timeout queue. This class implements a timeout queue for timers that are at least as likely to be cancelled as they are to expire. Unlike the util timeout class, the duration of the timeouts is shared by all scheduled tasks and if the duration is changed, this affects all scheduled tasks.

The nested class Task should be extended by users of this class to obtain call back notification of expiries.

Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private long
private Timeout.Task
private Object
private long

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
public Timeout.Task

Returns:

the next expired task or null.
expired
()

Get an expired tasks.

public long

Returns:

Returns the duration.
getDuration
()

public long
public long
public boolean
public void
public void
schedule(Timeout.Task task, long
A delay in addition to the default duration of the timeout
delay
)

public void
setDuration(long
The duration to set.
duration
)

public long
public void
setNow(long now)

public void
tick(long now)

public void
tick()

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

_durationback to summary
private long _duration
_headback to summary
private Timeout.Task _head
_lockback to summary
private Object _lock
_nowback to summary
private long _now

Constructor Detail

Timeoutback to summary
public Timeout()
Timeoutback to summary
public Timeout(Object lock)

Method Detail

cancelAllback to summary
public void cancelAll()
expiredback to summary
public Timeout.Task expired()

Get an expired tasks. This is called instead of tick() to obtain the next expired Task, but without calling it's Task#expire() or Task#expired() methods.

Returns:Timeout.Task

the next expired task or null.

getDurationback to summary
public long getDuration()
Returns:long

Returns the duration.

getNowback to summary
public long getNow()
getTimeToNextback to summary
public long getTimeToNext()
isEmptyback to summary
public boolean isEmpty()
scheduleback to summary
public void schedule(Timeout.Task task)
scheduleback to summary
public void schedule(Timeout.Task task, long delay)
Parameters
delay:long

A delay in addition to the default duration of the timeout

setDurationback to summary
public void setDuration(long duration)
Parameters
duration:long

The duration to set.

setNowback to summary
public long setNow()
setNowback to summary
public void setNow(long now)
tickback to summary
public void tick(long now)
tickback to summary
public void tick()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

org.mortbay.thread back to summary

public Class Timeout.Task

extends Object
Class Inheritance

Task. The base class for scheduled timeouts. This class should be extended to implement the expire() method, which is called if the timeout expires.
Author
gregw

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv boolean
pack-priv Timeout.Task
pack-priv Timeout.Task
pack-priv Timeout
pack-priv long

Constructor Summary

AccessConstructor and Description
public
Task()

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Cancel the task.

public void
expire()

Expire task.

public void
expired()

Expire task.

public long
public long
public boolean
public boolean
public void
reschedule()

Reschedule the task on the current timeout.

public void
schedule(Timeout timer)

Schedule the task on the given timeout.

public void
schedule(Timeout timer, long delay)

Schedule the task on the given timeout.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_delayback to summary
pack-priv long _delay
_expiredback to summary
pack-priv boolean _expired
_nextback to summary
pack-priv Timeout.Task _next
_prevback to summary
pack-priv Timeout.Task _prev
_timeoutback to summary
pack-priv Timeout _timeout
_timestampback to summary
pack-priv long _timestamp

Constructor Detail

Taskback to summary
public Task()

Method Detail

cancelback to summary
public void cancel()

Cancel the task. Remove the task from the timeout.

expireback to summary
public void expire()

Expire task. This method is called when the timeout expires. It is called in the scope of the synchronize block (on this) that sets the isExpired() state to true.

See Also
For an unsynchronized callback.
expiredback to summary
public void expired()

Expire task. This method is called when the timeout expires. It is called outside of any synchronization scope and may be delayed.

getAgeback to summary
public long getAge()
getTimestampback to summary
public long getTimestamp()
isExpiredback to summary
public boolean isExpired()
isScheduledback to summary
public boolean isScheduled()
rescheduleback to summary
public void reschedule()

Reschedule the task on the current timeout. The task timeout is rescheduled as if it had been cancelled and scheduled on the current timeout.

scheduleback to summary
public void schedule(Timeout timer)

Schedule the task on the given timeout. The task exiry will be called after the timeout duration.

scheduleback to summary
public void schedule(Timeout timer, long delay)

Schedule the task on the given timeout. The task exiry will be called after the timeout duration.