gr.uoa.di.madgik.grs.proxy.http.mirror
Class HTTPWriterMirror

java.lang.Object
  extended by java.lang.Thread
      extended by gr.uoa.di.madgik.grs.proxy.http.mirror.HTTPWriterMirror
All Implemented Interfaces:
IMirror, java.lang.Runnable

public class HTTPWriterMirror
extends java.lang.Thread
implements IMirror

This implementation of the IMirror interface specializes the mirroring procedure that needs to be performed from the writer side of the mirroring procedure. The technology employed is communication over HTTP connections. The communication protocol is coupled with the one implemented by the HTTPReaderMirror which is the writer side counterpart of this class

Author:
Alex Antoniadis

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Nested classes/interfaces inherited from interface gr.uoa.di.madgik.grs.proxy.mirror.IMirror
IMirror.MirroringState
 
Field Summary
static int dataformat
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
HTTPWriterMirror()
           
 
Method Summary
 void dispose()
          Dispose the resources employed by the mirroring implementations
 void dispose(boolean purge)
          This method disposes the resources that are used by the instance but does so in two phases.
 IBuffer getBuffer()
          Retrieves the IBuffer that is managed by the IMirror implementation.
 void handle(java.lang.String request, java.net.Socket socket, java.io.BufferedOutputStream out)
          This invocation of this method starts a new execution thread where the mirroring procedure is executed.
 boolean pollPartial(long recordIndex, int fieldIndex)
          
 long requestPartial(long recordIndex, int fieldIndex, IBuffer.TransportOverride override, java.lang.Object notify)
          This method is used by the reader side mirror to request payload that belongs to an IBuffer item that has been transfered only partially and more data is requested by the reader client
 void run()
           
 void setKey(java.lang.String key)
          Sets the local GRSRegistry key associated with the IBuffer that needs to be mirrored
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, 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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataformat

public static final int dataformat
See Also:
Constant Field Values
Constructor Detail

HTTPWriterMirror

public HTTPWriterMirror()
Method Detail

setKey

public void setKey(java.lang.String key)
Sets the local GRSRegistry key associated with the IBuffer that needs to be mirrored

Parameters:
key - the key associated with the served IBuffer

getBuffer

public IBuffer getBuffer()
Retrieves the IBuffer that is managed by the IMirror implementation. Depending on the mirror side, this instance is either the one the writer is authoring, or the one the reader is accessing.

Specified by:
getBuffer in interface IMirror
Returns:
the IBuffer that is managed by the IMirror implementation
See Also:
IMirror.getBuffer()

handle

public void handle(java.lang.String request,
                   java.net.Socket socket,
                   java.io.BufferedOutputStream out)
            throws GRS2ProxyMirrorInvalidOperationException
This invocation of this method starts a new execution thread where the mirroring procedure is executed. The created thread of execution is executed in the background and as a daemon service. Every new invocation pushes the request into a blocking queue in order to avoid contentions. See HTTPWriterMirror.run

Throws:
GRS2ProxyMirrorInvalidOperationException - if the mirroring state does not allow the operation to be executed

dispose

public void dispose()
Dispose the resources employed by the mirroring implementations

This method actually invokes the respective dispose(boolean) with an argument of false. This is because the actual disposing needs to take place when the mirroring thread is prepared to gracefully exit its execution

Specified by:
dispose in interface IMirror
See Also:
IMirror.dispose()

dispose

public void dispose(boolean purge)
This method disposes the resources that are used by the instance but does so in two phases. One can request the disposal passing an argument of false which puts the mirroring thread in a state where the needed actions are taken to gracefully exit this part of the protocol but also notify the respective HTTPReaderMirror to stop the mirroring procedure gracefully. When the method in again invoked with a true argument from the protocol implementing thread, all resources are disposed.

Parameters:
purge - whether the resources need to be immediately disposed, or this need to wait until the protocol thread is ready to purge the involved resources

pollPartial

public boolean pollPartial(long recordIndex,
                           int fieldIndex)
                    throws GRS2ProxyMirrorInvalidOperationException

This method is not supported in the HTTPWriterMirror

Specified by:
pollPartial in interface IMirror
Parameters:
recordIndex - The record index / id, for which the requester has requested data to be delivered
fieldIndex - The field index of the specific record for which data are requested
Returns:
false if the requester needs to wait again until data is returned false otherwise. In case true is returned, the data have either been retrieved, or no more data is expected to be send, possibly because of a closed connection
Throws:
GRS2ProxyMirrorInvalidOperationException - if the method is invoked
See Also:
IMirror.pollPartial(long, int)

requestPartial

public long requestPartial(long recordIndex,
                           int fieldIndex,
                           IBuffer.TransportOverride override,
                           java.lang.Object notify)
                    throws GRS2ProxyMirrorInvalidOperationException
This method is used by the reader side mirror to request payload that belongs to an IBuffer item that has been transfered only partially and more data is requested by the reader client

This method is not supported in the HTTPWriterMirror

Specified by:
requestPartial in interface IMirror
Parameters:
recordIndex - The index of the record whose payload is requested. As described in Record, this index coincides with the record id.
fieldIndex - The index of the field belonging to the defined record for which additional data is requested
override - whether or not the field's IBuffer.TransportDirective should be overridden as explained in IBuffer
notify - A synchronization object that can be used for the requester to block on until the required data is provided
Returns:
An indicative amount of time that the requester can wait before the data is available. This value is only indicative and it does not imply that after this period the data will be available. For this. the IMirror.pollPartial(long, int) should be used
Throws:
GRS2ProxyMirrorInvalidOperationException - if the method is invoked
See Also:
IMirror.requestPartial(long, int, gr.uoa.di.madgik.grs.buffer.IBuffer.TransportOverride, java.lang.Object)

run

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