com.bigdata.ha.pipeline
Class HAReceiveService<M extends HAWriteMessageBase>

java.lang.Object
  extended by java.lang.Thread
      extended by com.bigdata.ha.pipeline.HAReceiveService<M>
All Implemented Interfaces:
Runnable

public class HAReceiveService<M extends HAWriteMessageBase>
extends Thread

Receives data from an HASendService.

The non-blocking processing of the data cannot proceed until the message parameters and an output buffer have been set. So an accept results in a task to be run. The Future from this task is returned to the method called from the RMI control invocation, thus allowing that method to wait for the completion of the data transfer.

Author:
Martyn Cutcher, Bryan Thompson

Nested Class Summary
static interface HAReceiveService.IHAReceiveCallback<M extends HAWriteMessageBase>
          Hook to notice receive events.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected static org.apache.log4j.Logger log
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
HAReceiveService(InetSocketAddress addrSelf, InetSocketAddress addrNext)
          Create a new service instance - you MUST Thread.start() the service.
HAReceiveService(InetSocketAddress addrSelf, InetSocketAddress addrNext, HAReceiveService.IHAReceiveCallback<M> callback)
          Create a new service instance - you MUST Thread.start() the service.
 
Method Summary
 void awaitShutdown()
          Block until the service is shutdown.
 void changeDownStream(InetSocketAddress addrNext)
          Change the address to which the payloads are being relayed.
protected  void finalize()
          Extended to terminate() processing in order to ensure that the service is eventually shutdown.
 Future<Void> receiveData(M msg, ByteBuffer buffer)
          Receive data into the caller's buffer as described by the caller's message.
 void run()
           
 void start()
           
 void terminate()
          Immediate shutdown.
 String toString()
           
 
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, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log
Constructor Detail

HAReceiveService

public HAReceiveService(InetSocketAddress addrSelf,
                        InetSocketAddress addrNext)
Create a new service instance - you MUST Thread.start() the service.

Parameters:
addrSelf - The Internet socket address at which this service will listen.
addrNext - The Internet socket address of a downstream service to which each data transfer will be relayed as it is received (optional).

HAReceiveService

public HAReceiveService(InetSocketAddress addrSelf,
                        InetSocketAddress addrNext,
                        HAReceiveService.IHAReceiveCallback<M> callback)
Create a new service instance - you MUST Thread.start() the service.

Parameters:
addrSelf - The Internet socket address at which this service will listen.
addrNext - The Internet socket address of a downstream service to which each data transfer will be relayed as it is received (optional).
callback - An object which will be notified as each payload arrives.
Method Detail

toString

public String toString()
Overrides:
toString in class Thread

finalize

protected void finalize()
                 throws Throwable
Extended to terminate() processing in order to ensure that the service is eventually shutdown.

Overrides:
finalize in class Object
Throws:
Throwable

terminate

public void terminate()
Immediate shutdown.


awaitShutdown

public void awaitShutdown()
                   throws InterruptedException
Block until the service is shutdown.

Throws:
InterruptedException

start

public void start()
Overrides:
start in class Thread

run

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

receiveData

public Future<Void> receiveData(M msg,
                                ByteBuffer buffer)
                         throws InterruptedException
Receive data into the caller's buffer as described by the caller's message.

Parameters:
msg - The metadata about the data to be transferred.
buffer - The buffer in which this service will receive the data. The buffer MUST be large enough for the data to be received. The buffer SHOULD be a direct ByteBuffer in order to benefit from NIO efficiencies. This method will own the buffer until the returned Future is done.
Returns:
A future which you can await. The future will become available when the data has been transferred into the buffer, at which point the position will be ZERO (0) and the limit will be the #of bytes received into the buffer. If the data transfer fails or is interrupted, the future will report the exception.
Throws:
InterruptedException

changeDownStream

public void changeDownStream(InetSocketAddress addrNext)
Change the address to which the payloads are being relayed. This terminates the embedded HASendService and then HASendService.start(InetSocketAddress)s it with the new address (if any).

The ReadTask will throw out an exception when if there was a downstream target when the HASendService.IncSendTask is interrupted. Since the ReadTask lacks the context to issue the appropriate RMI to the downstream task, the exception must be caught hand handled by the WriteCacheService. It can simply rediscover the new downstream service and then re-submit both the RMI and the WriteCache block.

Parameters:
addrNext - The new address -or- null if payloads should not be relayed at this time.


Copyright © 2006-2012 SYSTAP, LLC. All Rights Reserved.