*
* @return
* @throws Exception
*/
private Connection bind() throws Exception {
TcpLink link = null;
try {
link = new TcpLink(configuration.getHost(), configuration.getPort());
connection = new Connection(link, true);
autoAckMessages(connection);
MessageListener messageListener = new MessageListener();
connection.addObserver(messageListener);
connection.bind(getConnectionType(configuration), configuration.getSystemId(), configuration.getPassword(), configuration.getSystemType(),
getBindTON(), getBindNPI(), null);
BindResp bindResp = messageListener.getBindResponse(configuration.getBindTimeout());
if (bindResp == null || bindResp.getCommandStatus() != 0) {
// close the link if no response
if (link != null) {
try { link.close(); } catch (Exception f) {}
}
throw new Exception("Bind Response failed: " + bindResp);
}
return connection;
} catch (Exception e) {
// close the link if an exception was thrown
if (link != null) {
try { link.close(); } catch (Exception f) {}
}
throw e;
}
}