gr.uoa.di.madgik.grs.proxy.tcp
Class TCPReaderProxy

java.lang.Object
  extended by gr.uoa.di.madgik.grs.proxy.tcp.TCPReaderProxy
All Implemented Interfaces:
IProxy, IReaderProxy
Direct Known Subclasses:
TCPStoreReaderProxy

public class TCPReaderProxy
extends java.lang.Object
implements IReaderProxy

This proxy is an implementation of the IReaderProxy interface available to be used by readers that want to access an IBuffer made available by a writer that is not necessarily collocated in the same JVM as they are. This proxy enables access to a local or remote host through a raw TCP connection

Author:
gpapanikos

Nested Class Summary
 
Nested classes/interfaces inherited from interface gr.uoa.di.madgik.grs.proxy.IProxy
IProxy.ProxyType
 
Field Summary
 
Fields inherited from interface gr.uoa.di.madgik.grs.proxy.IProxy
ProxyScheme, ProxyStoreScheme
 
Constructor Summary
TCPReaderProxy()
           
 
Method Summary
 void fromLocator(java.net.URI locator)
          Populates an instance of the IReaderProxy implementer with the information provided through the specific locator URI
 IBuffer getBuffer()
          After the proxy has been initialized, through this method, the IBuffer that can be used by the reader to access the writer side IBuffer can be retrieved
 java.lang.String getHostname()
          Retrieves the hostname where the TCPWriterProxy is located and is serving the consumed IBuffer
 int getPort()
          Retrieves the port that the TCPWriterProxy is using to serve the consumed IBuffer
static boolean isOfType(java.net.URI locator)
          Checks if the provided URI is of a type that can be managed by an instance of this class.
 void overrideBufferCapacity(int capacity)
          After the proxy has been initialized, this method can be used to provide a hint to the IReaderProxy to use a capacity different than that of the producer's buffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPReaderProxy

public TCPReaderProxy()
Method Detail

getHostname

public java.lang.String getHostname()
Retrieves the hostname where the TCPWriterProxy is located and is serving the consumed IBuffer

Returns:
the hostname

getPort

public int getPort()
Retrieves the port that the TCPWriterProxy is using to serve the consumed IBuffer

Returns:
the port

fromLocator

public void fromLocator(java.net.URI locator)
                 throws GRS2ProxyInvalidOperationException,
                        GRS2ProxyInvalidArgumentException
Populates an instance of the IReaderProxy implementer with the information provided through the specific locator URI

This method parses the provided URI to retrieve the needed information. An example of the URI this proxy can manage is grs2-proxy://foo.bar.gr:53361?key=272b934d-e796-4c30-944c-44ec2aec7eb7#TCP

Specified by:
fromLocator in interface IReaderProxy
Throws:
GRS2ProxyInvalidOperationException - if the proxy has already been initialized
GRS2ProxyInvalidArgumentException - if the provided locator is null or empty, or the parsed information is not valid
See Also:
IReaderProxy.fromLocator(java.net.URI)

overrideBufferCapacity

public void overrideBufferCapacity(int capacity)
                            throws GRS2ProxyInvalidOperationException
After the proxy has been initialized, this method can be used to provide a hint to the IReaderProxy to use a capacity different than that of the producer's buffer. Whether or not this hint is taken into account depends on the IReaderProxy implementation. For example, it is highly unlikely that it will be honored in cases when both the producer and the consumer run into the same address space. Instructs the TCPReaderMirror that will be initialized in a subsequent operation to override its buffer capacity

Specified by:
overrideBufferCapacity in interface IReaderProxy
Throws:
GRS2ProxyInvalidOperationException - if the operation is performed after buffer initialization
See Also:
IReaderProxy.overrideBufferCapacity(int)

getBuffer

public IBuffer getBuffer()
                  throws GRS2ProxyInvalidOperationException
After the proxy has been initialized, through this method, the IBuffer that can be used by the reader to access the writer side IBuffer can be retrieved

Initializes a TCPReaderMirror to handle the reader side mirroring procedure. The mirror is set with the information available to the proxy, using the TCPReaderMirror.setKey(String), TCPReaderMirror.setPort(int) and TCPReaderMirror.setHostname(String) and then the TCPReaderMirror.handle() method is invoked. The proxy waits for the mirroring procedure to be initialized blocking using TCPReaderMirror.waitInitialization() and if there was any error during the initialization procedure, it is retrieved and thrown using TCPReaderMirror.getInitializationError(). After this procedure is completed, the mirroring procedure continues in the TCPReaderMirror thread of execution. The returned IBuffer is the one available though TCPReaderMirror.getBuffer() and is populated from TCPReaderMirror

Specified by:
getBuffer in interface IReaderProxy
Returns:
The IBuffer that is serving the reader
Throws:
GRS2ProxyInvalidOperationException - if the provided locator that populated this instance has not set the needed parameters
See Also:
IReaderProxy.getBuffer()

isOfType

public static boolean isOfType(java.net.URI locator)
Checks if the provided URI is of a type that can be managed by an instance of this class. It bases its checks on the URI scheme and the fragment type. An example of the URI this proxy can manage is grs2-proxy://foo.bar.gr:53361?key=272b934d-e796-4c30-944c-44ec2aec7eb7#TCP

Parameters:
locator - the locator URi that needs to be checked
Returns:
true is this proxy class can handle the locator, false otherwise