Forum: Building VoltDB Clients

Post: No Connections-org.voltdb.client.NoConnectionsException

No Connections-org.voltdb.client.NoConnectionsException
Miyuru
Mar 17, 2014
Hi,
Does any one know why I get this exception when I start my client application:
org.voltdb.client.NoConnectionsException: No connections.
at org.voltdb.client.Distributer.queue(Distributer.java:698)
at org.voltdb.client.ClientImpl.callProcedure(ClientImpl.java:241)
at org.voltdb.client.ClientImpl.callProcedureWithTimeout(ClientImpl.java:206)
at org.voltdb.client.ClientImpl.callProcedure(ClientImpl.java:187)
at com.millenniumit.voltdb.dao.VoltJdbcTemplate.queryProc(VoltJdbcTemplate.java:50)
at com.millenniumit.voltdb.dao.PerfTestDAOImpl.perfTestTradeCaptureReportProc(PerfTestDAOImpl.java:74)
at com.millenniumit.voltdb.service.PerfTestServiceImpl.perfTestTradeCaptureReport(PerfTestServiceImpl.java:40)
at com.millenniumit.voltdb.TestVoltDBClient$Task.run(TestVoltDBClient.java:104)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
nshi
Mar 17, 2014
Hi Miyuru,

The exception is thrown when you try to call a procedure on a client that is closed or has a broken connection to the server. You have to call Client.createConnection() before using the client instance for procedure invocations. The following doc shows how to establish a client connection and call procedures.

https://voltdb.com/docs/UsingVoltDB/DesignAppLogic.php
Miyuru
Mar 18, 2014
Hi Nshi,

Thanks for the reply Nshi. I think I have call the createConnecton() before using the client instance for procedure invocations. An I have add my sample code I am using. I don't get this error every time I run my client program.

public class VoltJdbcTemplate {


private Client client;

private VoltDataSource dataSource;

public VoltTable[] query(String sql) throws IOException, ProcCallException {
return getClient().callProcedure("@AdHoc", sql).getResults();

}



public VoltTable[] queryProc(String procedeureName,List<String> params) throws NoConnectionsException, IOException, ProcCallException, InterruptedException{

VoltTable[] resultRow = getClient().callProcedure(procedeureName,params.get(0),params.get(1)).getResults();
return resultRow;
}



public Client getClient() throws IOException {
if (client == null) {
String[] hostArray = new String[]{dataSource.getUrl()};
this.initClient(hostArray);
}
return client;
}


private void initClient(String hostNames[])
throws IOException {
ClientConfig config = new ClientConfig(dataSource.getUsername(), dataSource.getPassword());

config.setProcedureCallTimeout(900*1000);
config.setConnectionResponseTimeout(900*1000);
config.setMaxTransactionsPerSecond(100);

client = ClientFactory.createClient(config);
this.initConnections(hostNames);
}

private void initConnections(String hostNames[])
throws IOException {
if (hostNames != null && hostNames.length > 0) {
for (String host : hostNames) {
client.createConnection(host.trim());
}
} else {
throw new UnknownHostException("No hosts specified");
}
}

public void closeClientConnection(){
try {
this.client.close();
} catch (InterruptedException e) {
e.printStackTrace();
}
}


public void setDataSource(VoltDataSource dataSource) {
this.dataSource = dataSource;
}
}

Thanks.
nshi
Mar 18, 2014
Hi Miyuru,

Could the server be terminated before the client? You can add a status listener to the client instance to track when the connection is closed.

http://voltdb.com/docs/UsingVoltDB/DesignAppErrHandling.php#DesignAppErrOther
bonds22
Apr 13, 2015
Thanks for the reply Nshi. I think I have call the createConnecton() before using the client instance for procedure invocations. An I have add my sample code I am using. I don't get this error every time I run my client program.