public class TCPWriterMirror extends Thread implements IMirror
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 raw TCP sockets. The communication
protocol is coupled with the one implemented by the TCPReaderMirror which is the writer side counterpart of this classThread.State, Thread.UncaughtExceptionHandlerIMirror.MirroringStateMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
TCPWriterMirror() |
| Modifier and Type | Method and Description |
|---|---|
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()
|
void |
handle()
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,
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 |
setInputStream(ObjectInputStream ois) |
void |
setKey(String key)
Sets the local
GRSRegistry key associated with the IBuffer that needs to be mirrored |
void |
setSocket(Socket socket)
Sets the socket used by the
TCPReaderMirror |
void |
writerAcceptRequests() |
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, yieldpublic void setInputStream(ObjectInputStream ois)
public void setSocket(Socket socket)
TCPReaderMirrorsocket - the socket to use for the communicationpublic void setKey(String key)
GRSRegistry key associated with the IBuffer that needs to be mirroredkey - the key associated with the served IBufferpublic IBuffer getBuffer()
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.getBuffer in interface IMirrorIBuffer that is managed by the IMirror implementationIMirror.getBuffer()public void handle()
throws GRS2ProxyMirrorInvalidOperationException
GRS2ProxyMirrorInvalidOperationException - if the mirroring state does not allow the operation to be executedpublic void dispose()
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
dispose in interface IMirrorIMirror.dispose()public void dispose(boolean purge)
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 TCPReaderMirror 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.purge - whether the resources need to be immediately disposed, or this need to wait until the protocol thread
is ready to purge the involved resourcespublic boolean pollPartial(long recordIndex,
int fieldIndex)
throws GRS2ProxyMirrorInvalidOperationException
This method is not supported in the TCPWriterMirror
pollPartial in interface IMirrorrecordIndex - The record index / id, for which the requester has requested data to be deliveredfieldIndex - The field index of the specific record for which data are requestedGRS2ProxyMirrorInvalidOperationException - if the method is invokedIMirror.pollPartial(long, int)public long requestPartial(long recordIndex,
int fieldIndex,
IBuffer.TransportOverride override,
Object notify)
throws GRS2ProxyMirrorInvalidOperationException
IBuffer
item that has been transfered only partially and more data is requested by the reader client
This method is not supported in the TCPWriterMirror
requestPartial in interface IMirrorrecordIndex - 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 requestedoverride - whether or not the field's IBuffer.TransportDirective should be overridden as explained in IBuffernotify - A synchronization object that can be used for the requester to block on until the required data is providedIMirror.pollPartial(long, int) should be usedGRS2ProxyMirrorInvalidOperationException - if the method is invokedIMirror.requestPartial(long, int, gr.uoa.di.madgik.grs.buffer.IBuffer.TransportOverride, java.lang.Object)public void writerAcceptRequests()
throws Exception
In the context of the mirroring procedure, the execution of this thread includes the following actions.
Initially, the local GRSRegistry is queried for the IBuffer to serve and its state is checked
to make sure that it is available for mirroring.
The main protocol loop is then initialized. On every iteration, the reader request is read and the needed Records
are returned limited based on the mirroring factor defined by the IBuffer and the available records. Additionally,
if there are requests for partial data to be transfered, they are included in the response.
Additionally, after the request is read, the incoming events are read and emitted in the local IBuffer and
after all record data is send, the available events are send.
ExceptionThread.run()Copyright © 2014. All Rights Reserved.