bamboo.lss
Class ASyncCore
java.lang.Object
bamboo.lss.ASyncCore
- Direct Known Subclasses:
- SimulatedASyncCore
public class ASyncCore
- extends Object
A main-loop largely inspired by David Mazieres' libasync, but using
java.nio.
A note about threading: This system is designed to have one
principal thread. This thread will execute the main function, and the
various callbacks (SelectableCBs and TimerCBs) will be called from it. If
you want to run another thread, you can pass events to it through any
synchronized queue. To pass events back to the main thread, call
register_timer with a time of 0. Both register_timer and cancel_timer are
properly synchronized for this purpose.
- Version:
- $Id: ASyncCore.java,v 1.27 2005/03/02 23:34:44 srhea Exp $
- Author:
- Sean C. Rhea
|
Method Summary |
void |
async_main()
|
void |
cancel_timer(Object token)
Cancel a timer initially registered with register timer. |
SelectionKey |
register_selectable(SelectableChannel channel,
int interest_ops,
ASyncCore.SelectableCB cb,
Object user_data)
|
void |
register_selectable(SelectableChannel channel,
int interest_ops,
Runnable cb)
|
Object |
register_timer(long time_ms,
ASyncCore.TimerCB cb,
Object user_data)
Register a function to be called sometime later than
time_ms milliseconds from now. |
Object |
register_timer(long time_ms,
Runnable cb)
|
void |
registerSelectable(SelectableChannel channel,
int interestOps,
Runnable callback)
|
Object |
registerTimer(long time_ms,
Runnable cb)
|
void |
unregister_selectable(SelectableChannel channel)
|
void |
unregister_selectable(SelectableChannel channel,
int interest_ops)
|
void |
unregister_selectable(SelectionKey skey)
|
void |
unregisterSelectable(SelectableChannel channel,
int interestOps)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
logger
protected org.apache.log4j.Logger logger
selector
protected Selector selector
selectable_info
protected HashMap<SelectableChannel,ASyncCore.SelectableInfo> selectable_info
timers
protected PriorityQueue<ASyncCore.TimerInfo,Long> timers
cancelled_timers
protected HashSet<ASyncCore.TimerInfo> cancelled_timers
ASyncCore
protected ASyncCore(int dummy)
ASyncCore
public ASyncCore()
throws IOException
- Throws:
IOException
register_selectable
public SelectionKey register_selectable(SelectableChannel channel,
int interest_ops,
ASyncCore.SelectableCB cb,
Object user_data)
throws ClosedChannelException
- Throws:
ClosedChannelException
unregister_selectable
public void unregister_selectable(SelectionKey skey)
registerSelectable
public void registerSelectable(SelectableChannel channel,
int interestOps,
Runnable callback)
throws ClosedChannelException
- Throws:
ClosedChannelException
register_selectable
public void register_selectable(SelectableChannel channel,
int interest_ops,
Runnable cb)
throws ClosedChannelException
- Throws:
ClosedChannelException
unregisterSelectable
public void unregisterSelectable(SelectableChannel channel,
int interestOps)
throws ClosedChannelException
- Throws:
ClosedChannelException
unregister_selectable
public void unregister_selectable(SelectableChannel channel,
int interest_ops)
throws ClosedChannelException
- Throws:
ClosedChannelException
unregister_selectable
public void unregister_selectable(SelectableChannel channel)
register_timer
public Object register_timer(long time_ms,
ASyncCore.TimerCB cb,
Object user_data)
- Register a function to be called sometime later than
time_ms milliseconds from now. This function is safe to
call from any thread. The return value may be used as an argument to
cancel_timer, but is otherwise opaque to the user.
register_timer
public Object register_timer(long time_ms,
Runnable cb)
registerTimer
public Object registerTimer(long time_ms,
Runnable cb)
cancel_timer
public void cancel_timer(Object token)
- Cancel a timer initially registered with register timer. This function
is safe to call from any thread.
async_main
public void async_main()