com.googlecode.mobilityrpc.network.impl.tcp
Class IncomingByteStreamReader

java.lang.Object
  extended by java.lang.Thread
      extended by com.googlecode.mobilityrpc.network.impl.tcp.IncomingByteStreamReader
All Implemented Interfaces:
Runnable

public class IncomingByteStreamReader
extends Thread

Continuously extracts individual byte[] messages from an input stream, where each message is preceded by 4 bytes which indicate the length of the message to follow.

This reader with read continuously until shutdown() is called, or an error occurs.

The reader will submit each message extracted to the supplied IncomingMessageHandler.

If an error occurs, the reader will notify the supplied ConnectionErrorHandler and then will close the input stream and terminate its thread.

Author:
Niall Gallagher

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
IncomingByteStreamReader(ConnectionId connectionId, InputStream inputStream, IncomingMessageHandler incomingMessageHandler, ConnectionErrorHandler connectionErrorHandler)
           
 
Method Summary
 boolean isShutdown()
           
 void run()
           
 void shutdown()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IncomingByteStreamReader

public IncomingByteStreamReader(ConnectionId connectionId,
                                InputStream inputStream,
                                IncomingMessageHandler incomingMessageHandler,
                                ConnectionErrorHandler connectionErrorHandler)
Parameters:
connectionId - Identifies the connection to which the stream belongs
inputStream - An input stream from which the reader will read messages
incomingMessageHandler - An object to which the reader will supply messages extracted from the stream
connectionErrorHandler - An object which the reader will notify when any exceptions occur
Method Detail

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread

shutdown

public void shutdown()

isShutdown

public boolean isShutdown()


Copyright © 2012. All Rights Reserved.