Class LocalVNS
- java.lang.Object
-
- org.apache.vinci.transport.VinciServableAdapter
-
- 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.
-
-
Field Summary
Fields Modifier and Type Field Description private int
maxport
The maxport.private int
onport
The onport.private BoundedWorkQueue
portQueue
The port queue.private VinciServer
server
The server.private int
startport
The startport.private int
vnsPort
The vns port.
-
Constructor Summary
Constructors Constructor Description LocalVNS()
Instantiates a new local VNS.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
-
-
-
-
Field Detail
-
onport
private int onport
The onport.
-
startport
private int startport
The startport.
-
maxport
private int maxport
The maxport.
-
vnsPort
private int vnsPort
The vns port.
-
server
private VinciServer server
The server.
-
portQueue
private BoundedWorkQueue portQueue
The port queue.
-
-
Constructor Detail
-
LocalVNS
public LocalVNS()
Instantiates a new local VNS.
-
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:
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
- the port unreachable exception
-
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 usedaEndPort
- - 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
- unreachable port after retries
-
-
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- Returns:
- true, if is available
-
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
- can't get port in configured range
-
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 interfaceVinciServable
- Specified by:
eval
in classVinciServableAdapter
- Parameters:
in
- the in- Returns:
- the transportable
- Throws:
ServiceException
- the service exception
-
shutdown
public void shutdown()
Stop the VNS service.
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.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 interfacejava.lang.Runnable
-
-