@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, 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);
} else {
final EJBClientConfiguration.ClusterNodeConfiguration clusterNodeConfiguration = clusterConfiguration.getNodeConfiguration(this.getNodeName());
// use the specified configurations
channelCreationOptions = clusterNodeConfiguration == null ? clusterConfiguration.getChannelCreationOptions() : clusterNodeConfiguration.getChannelCreationOptions();
final OptionMap connectionCreationOptions = clusterNodeConfiguration == null ? clusterConfiguration.getConnectionCreationOptions() : clusterNodeConfiguration.getConnectionCreationOptions();
final CallbackHandler callbackHandler = clusterNodeConfiguration == null ? clusterConfiguration.getCallbackHandler() : clusterNodeConfiguration.getCallbackHandler();
final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, destinationHost, destinationPort, null, connectionCreationOptions, callbackHandler, null);
final long timeout = clusterNodeConfiguration == null ? clusterConfiguration.getConnectionTimeout() : clusterNodeConfiguration.getConnectionTimeout();
// wait for the connection to be established
connection = IoFutureHelper.get(futureConnection, timeout, TimeUnit.MILLISECONDS);
// create a re-connect handler (which will be used on connection breaking down)
reconnectHandler = new ClusterNodeReconnectHandler(destinationHost, destinationPort, connectionCreationOptions, callbackHandler, channelCreationOptions, timeout);
}
} else {
// create the connection using defaults
final OptionMap connectionCreationOptions = OptionMap.EMPTY;
final CallbackHandler callbackHandler = new AnonymousCallbackHandler();
final IoFuture<Connection> futureConnection = NetworkUtil.connect(endpoint, 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)