* @throws Exception -
* error while looking up the service
*/
public ArrayList getVinciServices(String aVinciServiceName) throws Exception {
ArrayList serviceList = new ArrayList();
BaseClient client = null;
// make sure we got a valid connection to VNS
if (vnsConnection != null && vnsConnection.isOpen()) {
// Set up VNS query
VinciFrame queryFrame = new VinciFrame();
queryFrame.fadd("vinci:COMMAND", "getlist");
queryFrame.fadd("PREFIX", aVinciServiceName);
// System.out.println("Query Frame:::"+queryFrame.toXML());
// Query the VNS
VinciFrame response = (VinciFrame) vnsConnection.sendAndReceive(queryFrame);
ArrayList serviceFrames = response.fget("SERVICE");
// Each service is returned in its own SERVICE frame. So cycle through those now
// one at a time
for (int i = 0; i < serviceFrames.size(); i++) {
VinciFrame serviceFrame = (VinciFrame) serviceFrames.get(i);
// Copy data from the frame ( host, port etc)
VinciServiceInfo serviceInfo = getServiceInfo(serviceFrame);
if (serviceInfo != null) {
// Test the service for availability. Use only those services that respond. The list
// may contain stale services that are not running
try {
// Establish a brief connection to test for availability. This test fails gracefully
// Its not an error if the service does not respond. The retry logic is done
// elsewhere.
client = new BaseClient(serviceInfo.getHost(), serviceInfo.getPort());
if (client.isOpen()) {
if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) {
UIMAFramework.getLogger(this.getClass()).logrb(
Level.FINEST,
this.getClass().getName(),
"initialize",
CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_service_active_on_port__FINEST",
new Object[] { Thread.currentThread().getName(),
serviceInfo.getServiceName(), serviceInfo.getHost(),
String.valueOf(serviceInfo.getPort()) });
}
// Service is ok, so add it to the list
serviceList.add(serviceInfo);
}
} catch (ConnectException ce) {
if (UIMAFramework.getLogger().isLoggable(Level.WARNING)) {
UIMAFramework.getLogger(this.getClass()).logrb(
Level.WARNING,
this.getClass().getName(),
"initialize",
CPMUtils.CPM_LOG_RESOURCE_BUNDLE,
"UIMA_CPM_service_not_active_on_port__WARNING",
new Object[] { Thread.currentThread().getName(),
serviceInfo.getServiceName(), serviceInfo.getHost(),
String.valueOf(serviceInfo.getPort()) });
}
} finally {
// Drop the connection if necessary.
if (client != null) {
try {
client.close();
} catch (Exception ex) {
}
}
}
}