org.apache.uima.collection.impl.cpm.container.deployer.vns
Class LocalVNS

java.lang.Object
  extended by org.apache.vinci.transport.VinciServableAdapter
      extended by org.apache.uima.collection.impl.cpm.container.deployer.vns.LocalVNS
All Implemented Interfaces:
java.lang.Runnable, TransportableFactory, VinciServable

public class LocalVNS
extends VinciServableAdapter
implements java.lang.Runnable

LOCAL Vinci Naming Service. Used by locally deployed TAEs. Locally, meaning TAEs running on the same machine but in different JVM. This VNS is primarily used by TAEs to advertise their availability after succesfull startup.


Constructor Summary
LocalVNS()
           
LocalVNS(int aStartPort, int aEndPort, int aVNSPort)
          Initialize local VNS instance with a range of ports, and the port for the VNS itself.
LocalVNS(java.lang.String aStartPort, java.lang.String aEndPort, java.lang.String aVNSPort)
          Instantiates Local Vinci Naming Service
 
Method Summary
 Transportable eval(Transportable in)
          Main method called by services advertising their availability.
protected  void finalize()
           
 int getPort()
          Returns the next available port.
 int getVNSPort()
          Returns the port number on which local VNS is listening for requests.
 boolean isAvailable(int port)
          Determines if a given port is free.
 void run()
          Starts VNS thread.
 void setConnectionPool(BoundedWorkQueue pQueue)
          Associates a port pool with instance of VNS.
 void shutdown()
          Stop the VNS service
 
Methods inherited from class org.apache.vinci.transport.VinciServableAdapter
cleanExit, makeTransportable
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalVNS

public LocalVNS()

LocalVNS

public LocalVNS(java.lang.String aStartPort,
                java.lang.String aEndPort,
                java.lang.String aVNSPort)
         throws java.net.PortUnreachableException
Instantiates Local Vinci Naming Service

Parameters:
aProcessor - - CASProcessor instantiating this VNS (the owner)
aStartPort - - a starting port # for clients (services)
aEndPort - - an ending port # for clients( services)
aVNSPort - - port on which this VNS will listen on
Throws:
java.net.PortUnreachableException

LocalVNS

public LocalVNS(int aStartPort,
                int aEndPort,
                int aVNSPort)
         throws java.net.PortUnreachableException
Initialize local VNS instance with a range of ports, and the port for the VNS itself. A given port is tested first for availability. If it is not available the next port is tested, until one is found to be available.

Parameters:
aStartPort - - starting port number used
aEndPort - - end port number. Together with StartPort defines the range of ports (port pool)
aVNSPort - - port on which this VNS will listen for requests
Throws:
java.net.PortUnreachableException
Method Detail

setConnectionPool

public void setConnectionPool(BoundedWorkQueue pQueue)
Associates a port pool with instance of VNS.

Parameters:
pQueue - - queue where allocated ports will be added

isAvailable

public boolean isAvailable(int port)
Determines if a given port is free. It establishes a short lived connection to the port and if successful returns false.

Parameters:
- - port number to check

getVNSPort

public int getVNSPort()
Returns the port number on which local VNS is listening for requests.

Returns:
- VNS port number

getPort

public int getPort()
            throws java.net.PortUnreachableException
Returns the next available port. The port is allocated from a cache of ports given to the VNS service on startup.

Returns:
- free port
Throws:
java.net.PortUnreachableException

eval

public Transportable eval(Transportable in)
                   throws ServiceException
Main method called by services advertising their availability. Each service, on startup sends "serveon" request to VNS and waits for assigned port. The VNS looks up its cahce of ports and returns to the service one that has not yest allocated.

Specified by:
eval in interface VinciServable
Specified by:
eval in class VinciServableAdapter
Parameters:
in - The input document
Returns:
The output document
Throws:
ServiceException - thrown when there is an application level error that should result in the client receiving the same ServiceException on the other end.

shutdown

public void shutdown()
Stop the VNS service


finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

run

public void run()
Starts VNS thread. This thread runs continuously waiting for service registrations and returning port number back.

Specified by:
run in interface java.lang.Runnable


Copyright © 2012. All Rights Reserved.