Class AprIoProcessor
- java.lang.Object
-
- org.apache.mina.core.polling.AbstractPollingIoProcessor<AprSession>
-
- org.apache.mina.transport.socket.apr.AprIoProcessor
-
- All Implemented Interfaces:
IoProcessor<AprSession>
public final class AprIoProcessor extends AbstractPollingIoProcessor<AprSession>
The class in charge of processing socket level IO events for theAprSocketConnector- Author:
- Apache MINA Project
-
-
Field Summary
-
Fields inherited from class org.apache.mina.core.polling.AbstractPollingIoProcessor
wakeupCalled
-
-
Constructor Summary
Constructors Constructor Description AprIoProcessor(java.util.concurrent.Executor executor)Create a new instance ofAprIoProcessorwith a given Exector for handling I/Os events.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Iterator<AprSession>allSessions()protected intallSessionsCount()Get the number ofIoSessionpolled by thisIoProcessorprotected voiddestroy(AprSession session)Destroy the underlying client socket handleprotected voiddoDispose()Dispose the resources used by thisIoProcessorfor polling the client connections.protected SessionStategetState(AprSession session)Get the state of a session (One of OPENING, OPEN, CLOSING)protected voidinit(AprSession session)Initialize the polling of a session.protected booleanisBrokenConnection()Check that the select() has not exited immediately just because of a broken connection.protected booleanisInterestedInRead(AprSession session)Tells if this session is registered for readingprotected booleanisInterestedInWrite(AprSession session)Tells if this session is registered for writingprotected booleanisReadable(AprSession session)Tells if the session ready for readingprotected booleanisSelectorEmpty()Say if the list ofIoSessionpolled by thisIoProcessoris emptyprotected booleanisWritable(AprSession session)Tells if the session ready for writingprotected intread(AprSession session, IoBuffer buffer)protected voidregisterNewSelector()In the case we are using the java select() method, this method is used to trash the buggy selector and create a new one, registring all the sockets on it.protected intselect()poll those sessions foreverprotected intselect(long timeout)poll those sessions for the given timeoutprotected java.util.Iterator<AprSession>selectedSessions()Get anIteratorfor the list ofIoSessionfound selected by the last call ofAbstractPollingIoProcessor.select(long)protected voidsetInterestedInRead(AprSession session, boolean isInterested)Set the session to be informed when a read event should be processedprotected voidsetInterestedInWrite(AprSession session, boolean isInterested)Set the session to be informed when a write event should be processedprotected inttransferFile(AprSession session, FileRegion region, int length)Write a part of a file to aIoSession, if the underlying API isn't supporting system calls like sendfile(), you can throw aUnsupportedOperationExceptionso the file will be send using usualAbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int)call.protected voidwakeup()Interrupt theAbstractPollingIoProcessor.select(long)call.protected intwrite(AprSession session, IoBuffer buf, int length)Write a sequence of bytes to aIoSession, means to be called when a session was found ready for writing.-
Methods inherited from class org.apache.mina.core.polling.AbstractPollingIoProcessor
add, dispose, flush, isDisposed, isDisposing, remove, updateTrafficControl, updateTrafficMask, write
-
-
-
-
Constructor Detail
-
AprIoProcessor
public AprIoProcessor(java.util.concurrent.Executor executor)
Create a new instance ofAprIoProcessorwith a given Exector for handling I/Os events.- Parameters:
executor- theExecutorfor handling I/O events
-
-
Method Detail
-
doDispose
protected void doDispose()
Dispose the resources used by thisIoProcessorfor polling the client connections. The implementing class doDispose method will be called.- Specified by:
doDisposein classAbstractPollingIoProcessor<AprSession>
-
select
protected int select() throws java.lang.Exceptionpoll those sessions forever- Specified by:
selectin classAbstractPollingIoProcessor<AprSession>- Returns:
- The number of session ready for read or for write
- Throws:
java.lang.Exception- if some low level IO error occurs
-
select
protected int select(long timeout) throws java.lang.Exceptionpoll those sessions for the given timeout- Specified by:
selectin classAbstractPollingIoProcessor<AprSession>- Parameters:
timeout- milliseconds before the call timeout if no event appear- Returns:
- The number of session ready for read or for write
- Throws:
java.lang.Exception- if some low level IO error occurs
-
isSelectorEmpty
protected boolean isSelectorEmpty()
Say if the list ofIoSessionpolled by thisIoProcessoris empty- Specified by:
isSelectorEmptyin classAbstractPollingIoProcessor<AprSession>- Returns:
- true if at least a session is managed by this
IoProcessor
-
wakeup
protected void wakeup()
Interrupt theAbstractPollingIoProcessor.select(long)call.- Specified by:
wakeupin classAbstractPollingIoProcessor<AprSession>
-
allSessions
protected java.util.Iterator<AprSession> allSessions()
- Specified by:
allSessionsin classAbstractPollingIoProcessor<AprSession>- Returns:
IteratorofIoSession
-
allSessionsCount
protected int allSessionsCount()
Get the number ofIoSessionpolled by thisIoProcessor- Specified by:
allSessionsCountin classAbstractPollingIoProcessor<AprSession>- Returns:
- the number of sessions attached to this
IoProcessor
-
selectedSessions
protected java.util.Iterator<AprSession> selectedSessions()
Get anIteratorfor the list ofIoSessionfound selected by the last call ofAbstractPollingIoProcessor.select(long)- Specified by:
selectedSessionsin classAbstractPollingIoProcessor<AprSession>- Returns:
IteratorofIoSessionread for I/Os operation
-
init
protected void init(AprSession session) throws java.lang.Exception
Description copied from class:AbstractPollingIoProcessorInitialize the polling of a session. Add it to the polling process.- Specified by:
initin classAbstractPollingIoProcessor<AprSession>- Parameters:
session- theIoSessionto add to the polling- Throws:
java.lang.Exception- any exception thrown by the underlying system calls
-
destroy
protected void destroy(AprSession session) throws java.lang.Exception
Destroy the underlying client socket handle- Specified by:
destroyin classAbstractPollingIoProcessor<AprSession>- Parameters:
session- theIoSession- Throws:
java.lang.Exception- any exception thrown by the underlying system calls
-
getState
protected SessionState getState(AprSession session)
Get the state of a session (One of OPENING, OPEN, CLOSING)- Specified by:
getStatein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- theIoSessionto inspect- Returns:
- the state of the session
-
isReadable
protected boolean isReadable(AprSession session)
Tells if the session ready for reading- Specified by:
isReadablein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the queried session- Returns:
- true is ready, false if not ready
-
isWritable
protected boolean isWritable(AprSession session)
Tells if the session ready for writing- Specified by:
isWritablein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the queried session- Returns:
- true is ready, false if not ready
-
isInterestedInRead
protected boolean isInterestedInRead(AprSession session)
Tells if this session is registered for reading- Specified by:
isInterestedInReadin classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the queried session- Returns:
- true is registered for reading
-
isInterestedInWrite
protected boolean isInterestedInWrite(AprSession session)
Tells if this session is registered for writing- Specified by:
isInterestedInWritein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the queried session- Returns:
- true is registered for writing
-
setInterestedInRead
protected void setInterestedInRead(AprSession session, boolean isInterested) throws java.lang.Exception
Set the session to be informed when a read event should be processed- Specified by:
setInterestedInReadin classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the session for which we want to be interested in read eventsisInterested- true for registering, false for removing- Throws:
java.lang.Exception- If there was a problem while registering the session
-
setInterestedInWrite
protected void setInterestedInWrite(AprSession session, boolean isInterested) throws java.lang.Exception
Set the session to be informed when a write event should be processed- Specified by:
setInterestedInWritein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the session for which we want to be interested in write eventsisInterested- true for registering, false for removing- Throws:
java.lang.Exception- If there was a problem while registering the session
-
read
protected int read(AprSession session, IoBuffer buffer) throws java.lang.Exception
Reads a sequence of bytes from aIoSessioninto the givenIoBuffer. Is called when the session was found ready for reading.- Specified by:
readin classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the session to readbuffer- the buffer to fill- Returns:
- the number of bytes read
- Throws:
java.lang.Exception- any exception thrown by the underlying system calls
-
write
protected int write(AprSession session, IoBuffer buf, int length) throws java.io.IOException
Write a sequence of bytes to aIoSession, means to be called when a session was found ready for writing.- Specified by:
writein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the session to writebuf- the buffer to writelength- the number of bytes to write can be superior to the number of bytes remaining in the buffer- Returns:
- the number of byte written
- Throws:
java.io.IOException- any exception thrown by the underlying system calls
-
transferFile
protected int transferFile(AprSession session, FileRegion region, int length) throws java.lang.Exception
Write a part of a file to aIoSession, if the underlying API isn't supporting system calls like sendfile(), you can throw aUnsupportedOperationExceptionso the file will be send using usualAbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int)call.- Specified by:
transferFilein classAbstractPollingIoProcessor<AprSession>- Parameters:
session- the session to writeregion- the file region to writelength- the length of the portion to send- Returns:
- the number of written bytes
- Throws:
java.lang.Exception- any exception thrown by the underlying system calls
-
registerNewSelector
protected void registerNewSelector()
In the case we are using the java select() method, this method is used to trash the buggy selector and create a new one, registring all the sockets on it.- Specified by:
registerNewSelectorin classAbstractPollingIoProcessor<AprSession>
-
isBrokenConnection
protected boolean isBrokenConnection() throws java.io.IOExceptionCheck that the select() has not exited immediately just because of a broken connection. In this case, this is a standard case, and we just have to loop.- Specified by:
isBrokenConnectionin classAbstractPollingIoProcessor<AprSession>- Returns:
- true if a connection has been brutally closed.
- Throws:
java.io.IOException- If we got an exception
-
-