@Override
public EJBReceiver getEJBReceiver() {
Connection connection;
final ReconnectHandler reconnectHandler;
OptionMap channelCreationOptions = OptionMap.EMPTY;
final EJBClientConfiguration ejbClientConfiguration = this.clusterContext.getEJBClientContext().getEJBClientConfiguration();
try {
// if the client configuration is available create the connection using those configs
if (ejbClientConfiguration != null) {
final EJBClientConfiguration.ClusterConfiguration clusterConfiguration = ejbClientConfiguration.getClusterConfiguration(clusterContext.getClusterName());
if (clusterConfiguration == null) {
// use default configurations
final OptionMap connectionCreationOptions = OptionMap.EMPTY;
final CallbackHandler callbackHandler = ejbClientConfiguration.getCallbackHandler();
final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, destinationProtocol, destinationHost, destinationPort, null, connectionCreationOptions, callbackHandler, null);
// wait for the connection to be established
connection = IoFutureHelper.get(futureConnection, 5000, TimeUnit.MILLISECONDS);
// create a re-connect handler (which will be used on connection breaking down)
reconnectHandler = new ClusterNodeReconnectHandler(destinationHost, destinationPort, connectionCreationOptions, callbackHandler, channelCreationOptions, 5000);