org.apache.mina.common
Class AbstractPollingIoProcessor<T extends AbstractIoSession>

java.lang.Object
  extended by org.apache.mina.common.AbstractPollingIoProcessor<T>
All Implemented Interfaces:
IoProcessor<T>
Direct Known Subclasses:
AprIoProcessor, NioProcessor

public abstract class AbstractPollingIoProcessor<T extends AbstractIoSession>
extends Object
implements IoProcessor<T>

An abstract implementation of IoProcessor which helps transport developers to write an IoProcessor easily.

Version:
$Rev: 627803 $, $Date: 2008-02-14 18:03:14 +0100 (Thu, 14 Feb 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Nested Class Summary
protected static class AbstractPollingIoProcessor.SessionState
           
 
Constructor Summary
protected AbstractPollingIoProcessor(Executor executor)
           
 
Method Summary
 void add(T session)
          Adds the specified session to the I/O processor so that the I/O processor starts to perform any I/O operations related with the session.
protected abstract  Iterator<T> allSessions()
           
protected abstract  void destroy(T session)
           
 void dispose()
          Releases any resources allocated by this processor.
protected abstract  void dispose0()
           
 void flush(T session)
          Flushes the internal write request queue of the specified session.
protected abstract  void init(T session)
           
 boolean isDisposed()
          Returns true if and if only all resources of this processor have been disposed.
 boolean isDisposing()
          Returns true if and if only IoProcessor.dispose() method has been called.
protected abstract  boolean isInterestedInRead(T session)
          is this session registered for reading
protected abstract  boolean isInterestedInWrite(T session)
          is this session registered for writing
protected abstract  boolean isReadable(T session)
          Is the session ready for reading
protected abstract  boolean isWritable(T session)
          Is the session ready for writing
protected abstract  int read(T session, IoBuffer buf)
           
 void remove(T session)
          Removes and closes the specified session from the I/O processor so that the I/O processor closes the connection associated with the session and releases any other related resources.
protected abstract  boolean select(int timeout)
          poll those sessions for the given timeout
protected abstract  Iterator<T> selectedSessions()
           
protected abstract  void setInterestedInRead(T session, boolean interested)
          register a session for reading
protected abstract  void setInterestedInWrite(T session, boolean interested)
          register a session for writing
protected abstract  AbstractPollingIoProcessor.SessionState state(T session)
           
protected abstract  int transferFile(T session, FileRegion region, int length)
           
 void updateTrafficMask(T session)
          Controls the traffic of the specified session as specified in IoSession.getTrafficMask().
protected abstract  void wakeup()
           
protected abstract  int write(T session, IoBuffer buf, int length)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPollingIoProcessor

protected AbstractPollingIoProcessor(Executor executor)
Method Detail

isDisposing

public final boolean isDisposing()
Description copied from interface: IoProcessor
Returns true if and if only IoProcessor.dispose() method has been called. Please note that this method will return true even after all the related resources are released.

Specified by:
isDisposing in interface IoProcessor<T extends AbstractIoSession>

isDisposed

public final boolean isDisposed()
Description copied from interface: IoProcessor
Returns true if and if only all resources of this processor have been disposed.

Specified by:
isDisposed in interface IoProcessor<T extends AbstractIoSession>

dispose

public final void dispose()
Description copied from interface: IoProcessor
Releases any resources allocated by this processor. Please note that the resources might not be released as long as there are any sessions managed by this processor. Most implementations will close all sessions immediately and release the related resources.

Specified by:
dispose in interface IoProcessor<T extends AbstractIoSession>

dispose0

protected abstract void dispose0()
                          throws Exception
Throws:
Exception

select

protected abstract boolean select(int timeout)
                           throws Exception
poll those sessions for the given timeout

Parameters:
timeout - milliseconds before the call timeout if no event appear
Returns:
true if at least a session is ready for read or for write
Throws:
Exception - if some low level IO error occurs

wakeup

protected abstract void wakeup()

allSessions

protected abstract Iterator<T> allSessions()

selectedSessions

protected abstract Iterator<T> selectedSessions()

state

protected abstract AbstractPollingIoProcessor.SessionState state(T session)

isWritable

protected abstract boolean isWritable(T session)
Is the session ready for writing

Parameters:
session - the session queried
Returns:
true is ready, false if not ready

isReadable

protected abstract boolean isReadable(T session)
Is the session ready for reading

Parameters:
session - the session queried
Returns:
true is ready, false if not ready

setInterestedInWrite

protected abstract void setInterestedInWrite(T session,
                                             boolean interested)
                                      throws Exception
register a session for writing

Parameters:
session - the session registered
interested - true for registering, false for removing
Throws:
Exception

setInterestedInRead

protected abstract void setInterestedInRead(T session,
                                            boolean interested)
                                     throws Exception
register a session for reading

Parameters:
session - the session registered
interested - true for registering, false for removing
Throws:
Exception

isInterestedInRead

protected abstract boolean isInterestedInRead(T session)
is this session registered for reading

Parameters:
session - the session queried
Returns:
true is registered for reading

isInterestedInWrite

protected abstract boolean isInterestedInWrite(T session)
is this session registered for writing

Parameters:
session - the session queried
Returns:
true is registered for writing

init

protected abstract void init(T session)
                      throws Exception
Throws:
Exception

destroy

protected abstract void destroy(T session)
                         throws Exception
Throws:
Exception

read

protected abstract int read(T session,
                            IoBuffer buf)
                     throws Exception
Throws:
Exception

write

protected abstract int write(T session,
                             IoBuffer buf,
                             int length)
                      throws Exception
Throws:
Exception

transferFile

protected abstract int transferFile(T session,
                                    FileRegion region,
                                    int length)
                             throws Exception
Throws:
Exception

add

public final void add(T session)
Description copied from interface: IoProcessor
Adds the specified session to the I/O processor so that the I/O processor starts to perform any I/O operations related with the session.

Specified by:
add in interface IoProcessor<T extends AbstractIoSession>

remove

public final void remove(T session)
Description copied from interface: IoProcessor
Removes and closes the specified session from the I/O processor so that the I/O processor closes the connection associated with the session and releases any other related resources.

Specified by:
remove in interface IoProcessor<T extends AbstractIoSession>

flush

public final void flush(T session)
Description copied from interface: IoProcessor
Flushes the internal write request queue of the specified session.

Specified by:
flush in interface IoProcessor<T extends AbstractIoSession>

updateTrafficMask

public final void updateTrafficMask(T session)
Description copied from interface: IoProcessor
Controls the traffic of the specified session as specified in IoSession.getTrafficMask().

Specified by:
updateTrafficMask in interface IoProcessor<T extends AbstractIoSession>


Copyright © 2004-2009 Apache MINA Project. All Rights Reserved.