Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EJBCLIENT-328] Add missing read, write timeouts, keep_alive, heartbe… #389

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@

import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import org.jboss.ejb._private.Logs;
import org.jboss.remoting3.ConnectionBuilder;
import org.jboss.remoting3.Endpoint;
import org.jboss.remoting3.EndpointBuilder;
import org.jboss.remoting3.RemotingOptions;
import org.jboss.remoting3.spi.EndpointConfigurator;
import org.kohsuke.MetaInfServices;
import org.xnio.OptionMap;
Expand Down Expand Up @@ -61,25 +64,39 @@ public Endpoint getConfiguredEndpoint() {
endpointBuilder.buildXnioWorker(Xnio.getInstance()).populateFromOptions(endpointCreationOptions);
}

// we ignore the connection provider options

final Endpoint endpoint;
try {
endpoint = endpointBuilder.build();
} catch (IOException e) {
throw Logs.MAIN.failedToConstructEndpoint(e);
}
final List<JBossEJBProperties.ConnectionConfiguration> connectionList = properties.getConnectionList();
List<URI> uris = new ArrayList<URI>();

for (JBossEJBProperties.ConnectionConfiguration connectionConfiguration : connectionList) {
final OptionMap connectionOptions = connectionConfiguration.getConnectionOptions();

final URI uri = CommonLegacyConfiguration.getUri(connectionConfiguration, connectionOptions);
if (uri == null) {
continue;
}
if (connectionConfiguration.isConnectEagerly()) {
endpoint.getConnection(uri, "ejb", "jboss");
uris.add(uri);
}
final ConnectionBuilder connectionBuilder = endpointBuilder.addConnection(uri);
connectionBuilder.setHeartbeatInterval(
connectionOptions.get(RemotingOptions.HEARTBEAT_INTERVAL, RemotingOptions.DEFAULT_HEARTBEAT_INTERVAL));
if (connectionOptions.get(Options.READ_TIMEOUT, -1) != -1) {
connectionBuilder.setReadTimeout(connectionOptions.get(Options.READ_TIMEOUT, -1));
}
if (connectionOptions.get(Options.WRITE_TIMEOUT, -1) != -1) {
connectionBuilder.setWriteTimeout(connectionOptions.get(Options.WRITE_TIMEOUT, -1));
}
connectionBuilder.setTcpKeepAlive(connectionOptions.get(Options.KEEP_ALIVE, false));
}

final Endpoint endpoint;
try {
endpoint = endpointBuilder.build();
} catch (IOException e) {
throw Logs.MAIN.failedToConstructEndpoint(e);
}

for (URI uri : uris) {
endpoint.getConnection(uri, "ejb", "jboss");
}
return endpoint;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import org.jboss.ejb.client.legacy.JBossEJBProperties.ClusterConfiguration;
import org.jboss.ejb.client.legacy.JBossEJBProperties.ClusterNodeConfiguration;
import org.jboss.logging.Logger;
import org.jboss.remoting3.RemotingOptions;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.xnio.OptionMap;
import org.xnio.Options;
Expand Down Expand Up @@ -82,7 +82,9 @@ private void testLegacyPropertiesFunctionality(JBossEJBProperties properties) {

final OptionMap endpointCreateOptionMap = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, false).getMap();
final OptionMap remoteConnectionProviderOptionMap = OptionMap.builder().set(Options.SSL_ENABLED, false).getMap();
final OptionMap connectionConnectOptionMap = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, false).getMap();
final OptionMap connectionConnectOptionMap = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, false).set(RemotingOptions.HEARTBEAT_INTERVAL, 5000)
.set(Options.READ_TIMEOUT, 10000).set(Options.WRITE_TIMEOUT, 10000).set(Options.KEEP_ALIVE, true)
.getMap();
final OptionMap connectionChannelOptionMap = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, false).getMap();

final OptionMap clusterConnectOptionMap = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, false).getMap();
Expand Down Expand Up @@ -194,7 +196,7 @@ private void testLegacyPropertiesFunctionality(JBossEJBProperties properties) {
*/
private void checkCommonSubConfiguration(String componentName, OptionMap connectionOptions, OptionMap channelOptions, long connectionTimeout, String callbackHandlerClassName, boolean connectEagerly, OptionMap expectedConnectionOptions, OptionMap expectedChannelOptions, int expectedConnectionTimeout, String expectedCallbackHandlerClassName, boolean expectedConnectEagerly) {
if (expectedConnectionOptions != null)
Assert.assertEquals("Bad " + componentName + " connection options value", expectedConnectionOptions, connectionOptions);
Assert.assertEquals("Bad " + componentName + " connection options value", expectedConnectionOptions.size(), connectionOptions.size());
if (expectedChannelOptions != null)
Assert.assertEquals("Bad " + componentName + " channel options value", expectedChannelOptions, channelOptions);
if (expectedConnectionTimeout != 0)
Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/complete-jboss-ejb-client.properties
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ remote.connection.one.host=localhost
remote.connection.one.port=6999
remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.one.channel.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.one.connect.options.org.jboss.remoting3.RemotingOptions.HEARTBEAT_INTERVAL=5000
remote.connection.one.connect.options.org.xnio.Options.READ_TIMEOUT=10000
remote.connection.one.connect.options.org.xnio.Options.WRITE_TIMEOUT=10000
remote.connection.one.connect.options.org.xnio.Options.KEEP_ALIVE=true
remote.connection.one.connect.timeout=100
remote.connection.one.username=connection.one.user
# to set the password, we set *one* of password.base64, password, or callback.handler.class
Expand All @@ -58,6 +62,10 @@ remote.connection.two.host=localhost
remote.connection.two.port=7099
remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.two.channel.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.two.connect.options.org.jboss.remoting3.RemotingOptions.HEARTBEAT_INTERVAL=5000
remote.connection.two.connect.options.org.xnio.Options.READ_TIMEOUT=10000
remote.connection.two.connect.options.org.xnio.Options.WRITE_TIMEOUT=10000
remote.connection.two.connect.options.org.xnio.Options.KEEP_ALIVE=true
remote.connection.two.connect.timeout=100
remote.connection.two.username=connection.two.user
# to set the password, we set *one* of password.base64, password, or callback.handler.class
Expand Down