From a7399c0a2d4c1be67971342b62ad84fa380790a7 Mon Sep 17 00:00:00 2001 From: Kabir Khan Date: Thu, 16 Mar 2017 17:42:16 +0000 Subject: [PATCH] [EJBCLIENT-200] Make the Builder methods return this --- .../jboss/ejb/client/EJBClientCluster.java | 15 ++-- .../jboss/ejb/client/EJBClientContext.java | 36 +++++--- .../ejb/client/legacy/JBossEJBProperties.java | 87 ++++++++++++------- 3 files changed, 92 insertions(+), 46 deletions(-) diff --git a/src/main/java/org/jboss/ejb/client/EJBClientCluster.java b/src/main/java/org/jboss/ejb/client/EJBClientCluster.java index 943778681..d026bf82d 100644 --- a/src/main/java/org/jboss/ejb/client/EJBClientCluster.java +++ b/src/main/java/org/jboss/ejb/client/EJBClientCluster.java @@ -103,27 +103,32 @@ public static final class Builder { public Builder() { } - public void setName(final String name) { + public Builder setName(final String name) { Assert.checkNotNullParam("name", name); this.name = name; + return this; } - public void setMaximumConnectedNodes(final long maximumConnectedNodes) { + public Builder setMaximumConnectedNodes(final long maximumConnectedNodes) { Assert.checkMinimumParameter("maximumConnectedNodes", 0, maximumConnectedNodes); this.maximumConnectedNodes = maximumConnectedNodes; + return this; } - public void setConnectTimeoutMilliseconds(final long connectTimeoutMilliseconds) { + public Builder setConnectTimeoutMilliseconds(final long connectTimeoutMilliseconds) { Assert.checkMinimumParameter("connectTimeoutMilliseconds", -1L, connectTimeoutMilliseconds); this.connectTimeoutMilliseconds = connectTimeoutMilliseconds; + return this; } - public void setClusterNodeSelector(final ClusterNodeSelector clusterNodeSelector) { + public Builder setClusterNodeSelector(final ClusterNodeSelector clusterNodeSelector) { this.clusterNodeSelector = clusterNodeSelector; + return this; } - public void setOverrideConfiguration(final AuthenticationConfiguration overrideConfiguration) { + public Builder setOverrideConfiguration(final AuthenticationConfiguration overrideConfiguration) { this.overrideConfiguration = overrideConfiguration; + return this; } /** diff --git a/src/main/java/org/jboss/ejb/client/EJBClientContext.java b/src/main/java/org/jboss/ejb/client/EJBClientContext.java index 7591ddf6e..dbeb3069b 100644 --- a/src/main/java/org/jboss/ejb/client/EJBClientContext.java +++ b/src/main/java/org/jboss/ejb/client/EJBClientContext.java @@ -541,41 +541,45 @@ public Builder() { invocationTimeout = clientContext.invocationTimeout; } - public void addInterceptor(EJBClientInterceptor interceptor) { + public Builder addInterceptor(EJBClientInterceptor interceptor) { Assert.checkNotNullParam("interceptor", interceptor); if (globalInterceptors == null) { globalInterceptors = new ArrayList<>(); } globalInterceptors.add(EJBClientInterceptorInformation.forInstance(interceptor)); + return this; } - public void addInterceptor(Class interceptorClass) { + public Builder addInterceptor(Class interceptorClass) { Assert.checkNotNullParam("interceptorClass", interceptorClass); if (globalInterceptors == null) { globalInterceptors = new ArrayList<>(); } globalInterceptors.add(EJBClientInterceptorInformation.forClass(interceptorClass)); + return this; } - public void addClassInterceptor(String className, EJBClientInterceptor interceptor) { + public Builder addClassInterceptor(String className, EJBClientInterceptor interceptor) { Assert.checkNotNullParam("className", className); Assert.checkNotNullParam("interceptor", interceptor); if (classInterceptors == null) { classInterceptors = new ArrayList<>(); } classInterceptors.add(new ClassInterceptor(className, EJBClientInterceptorInformation.forInstance(interceptor))); + return this; } - public void addClassInterceptor(String className, Class interceptorClass) { + public Builder addClassInterceptor(String className, Class interceptorClass) { Assert.checkNotNullParam("className", className); Assert.checkNotNullParam("interceptorClass", interceptorClass); if (classInterceptors == null) { classInterceptors = new ArrayList<>(); } classInterceptors.add(new ClassInterceptor(className, EJBClientInterceptorInformation.forClass(interceptorClass))); + return this; } - public void addMethodInterceptor(String className, EJBMethodLocator methodLocator, EJBClientInterceptor interceptor) { + public Builder addMethodInterceptor(String className, EJBMethodLocator methodLocator, EJBClientInterceptor interceptor) { Assert.checkNotNullParam("className", className); Assert.checkNotNullParam("methodLocator", methodLocator); Assert.checkNotNullParam("interceptor", interceptor); @@ -583,9 +587,10 @@ public void addMethodInterceptor(String className, EJBMethodLocator methodLocato methodInterceptors = new ArrayList<>(); } methodInterceptors.add(new MethodInterceptor(className, methodLocator, EJBClientInterceptorInformation.forInstance(interceptor))); + return this; } - public void addMethodInterceptor(String className, EJBMethodLocator methodLocator, Class interceptorClass) { + public Builder addMethodInterceptor(String className, EJBMethodLocator methodLocator, Class interceptorClass) { Assert.checkNotNullParam("className", className); Assert.checkNotNullParam("methodLocator", methodLocator); Assert.checkNotNullParam("interceptorClass", interceptorClass); @@ -593,45 +598,52 @@ public void addMethodInterceptor(String className, EJBMethodLocator methodLocato methodInterceptors = new ArrayList<>(); } methodInterceptors.add(new MethodInterceptor(className, methodLocator, EJBClientInterceptorInformation.forClass(interceptorClass))); + return this; } - public void addTransportProvider(EJBTransportProvider provider) { + public Builder addTransportProvider(EJBTransportProvider provider) { Assert.checkNotNullParam("provider", provider); if (transportProviders == null) { transportProviders = new ArrayList<>(); } transportProviders.add(provider); + return this; } - public void addClientConnection(EJBClientConnection connection) { + public Builder addClientConnection(EJBClientConnection connection) { Assert.checkNotNullParam("connection", connection); if (clientConnections == null) { clientConnections = new ArrayList<>(); } clientConnections.add(connection); + return this; } - public void addClientCluster(EJBClientCluster cluster) { + public Builder addClientCluster(EJBClientCluster cluster) { Assert.checkNotNullParam("cluster", cluster); if (clientClusters == null) { clientClusters = new ArrayList<>(); } clientClusters.add(cluster); + return this; } - public void setClusterNodeSelector(final ClusterNodeSelector clusterNodeSelector) { + public Builder setClusterNodeSelector(final ClusterNodeSelector clusterNodeSelector) { Assert.checkNotNullParam("clusterNodeSelector", clusterNodeSelector); this.clusterNodeSelector = clusterNodeSelector; + return this; } - public void setDeploymentNodeSelector(final DeploymentNodeSelector deploymentNodeSelector) { + public Builder setDeploymentNodeSelector(final DeploymentNodeSelector deploymentNodeSelector) { Assert.checkNotNullParam("deploymentNodeSelector", deploymentNodeSelector); this.deploymentNodeSelector = deploymentNodeSelector; + return this; } - public void setInvocationTimeout(final long invocationTimeout) { + public Builder setInvocationTimeout(final long invocationTimeout) { Assert.checkMinimumParameter("invocationTimeout", 0L, invocationTimeout); this.invocationTimeout = invocationTimeout; + return this; } public EJBClientContext build() { diff --git a/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java b/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java index ba0eb89e5..6102a8eb8 100644 --- a/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java +++ b/src/main/java/org/jboss/ejb/client/legacy/JBossEJBProperties.java @@ -469,40 +469,49 @@ static final class Builder extends CommonSubconfiguration.Builder { Builder() { } - void setEndpointName(final String endpointName) { + Builder setEndpointName(final String endpointName) { this.endpointName = endpointName; + return this; } - void setEndpointCreationOptions(final OptionMap endpointCreationOptions) { + Builder setEndpointCreationOptions(final OptionMap endpointCreationOptions) { this.endpointCreationOptions = endpointCreationOptions; + return this; } - void setRemoteConnectionProviderCreationOptions(final OptionMap remoteConnectionProviderCreationOptions) { + Builder setRemoteConnectionProviderCreationOptions(final OptionMap remoteConnectionProviderCreationOptions) { this.remoteConnectionProviderCreationOptions = remoteConnectionProviderCreationOptions; + return this; } - void setConnectionList(final List connectionList) { + Builder setConnectionList(final List connectionList) { this.connectionList = connectionList; + return this; } - void setClusterConfigurations(final Map clusterConfigurations) { + Builder setClusterConfigurations(final Map clusterConfigurations) { this.clusterConfigurations = clusterConfigurations; + return this; } - void setInvocationTimeout(final long invocationTimeout) { + Builder setInvocationTimeout(final long invocationTimeout) { this.invocationTimeout = invocationTimeout; + return this; } - void setReconnectTimeout(final long reconnectTimeout) { + Builder setReconnectTimeout(final long reconnectTimeout) { this.reconnectTimeout = reconnectTimeout; + return this; } - void setDeploymentNodeSelectorClassName(final String deploymentNodeSelectorClassName) { + Builder setDeploymentNodeSelectorClassName(final String deploymentNodeSelectorClassName) { this.deploymentNodeSelectorClassName = deploymentNodeSelectorClassName; + return this; } - void setDeploymentNodeSelectorSupplier(final ExceptionSupplier deploymentNodeSelectorSupplier) { + Builder setDeploymentNodeSelectorSupplier(final ExceptionSupplier deploymentNodeSelectorSupplier) { this.deploymentNodeSelectorSupplier = deploymentNodeSelectorSupplier; + return this; } } @@ -565,32 +574,39 @@ abstract static class Builder { Builder() { } - void setConnectionOptions(final OptionMap connectionOptions) { + Builder setConnectionOptions(final OptionMap connectionOptions) { this.connectionOptions = connectionOptions; + return this; } - void setCallbackHandlerClassName(final String callbackHandlerClassName) { + Builder setCallbackHandlerClassName(final String callbackHandlerClassName) { this.callbackHandlerClassName = callbackHandlerClassName; + return this; } - void setCallbackHandlerSupplier(final ExceptionSupplier callbackHandlerSupplier) { + Builder setCallbackHandlerSupplier(final ExceptionSupplier callbackHandlerSupplier) { this.callbackHandlerSupplier = callbackHandlerSupplier; + return this; } - void setConnectionTimeout(final long connectionTimeout) { + Builder setConnectionTimeout(final long connectionTimeout) { this.connectionTimeout = connectionTimeout; + return this; } - void setChannelOptions(final OptionMap channelOptions) { + Builder setChannelOptions(final OptionMap channelOptions) { this.channelOptions = channelOptions; + return this; } - void setConnectEagerly(final boolean connectEagerly) { + Builder setConnectEagerly(final boolean connectEagerly) { this.connectEagerly = connectEagerly; + return this; } - void setAuthenticationConfiguration(final AuthenticationConfiguration authenticationConfiguration) { + Builder setAuthenticationConfiguration(final AuthenticationConfiguration authenticationConfiguration) { this.authenticationConfiguration = authenticationConfiguration; + return this; } boolean populateFromProperties(final Properties properties, final String prefix, final ClassLoader classLoader, final Builder defaultsBuilder) { @@ -687,12 +703,14 @@ boolean populateFromProperties(final Properties properties, final String prefix, return true; } - void setHost(final String host) { + Builder setHost(final String host) { this.host = host; + return this; } - void setPort(final int port) { + Builder setPort(final int port) { this.port = port; + return this; } } } @@ -743,24 +761,29 @@ static final class Builder extends CommonSubconfiguration.Builder { Builder() { } - void setClusterName(final String clusterName) { + Builder setClusterName(final String clusterName) { this.clusterName = clusterName; + return this; } - void setMaximumAllowedConnectedNodes(final long maximumAllowedConnectedNodes) { + Builder setMaximumAllowedConnectedNodes(final long maximumAllowedConnectedNodes) { this.maximumAllowedConnectedNodes = maximumAllowedConnectedNodes; + return this; } - void setClusterNodeSelectorClassName(final String clusterNodeSelectorClassName) { + Builder setClusterNodeSelectorClassName(final String clusterNodeSelectorClassName) { this.clusterNodeSelectorClassName = clusterNodeSelectorClassName; + return this; } - void setClusterNodeSelectorSupplier(final ExceptionSupplier clusterNodeSelectorSupplier) { + Builder setClusterNodeSelectorSupplier(final ExceptionSupplier clusterNodeSelectorSupplier) { this.clusterNodeSelectorSupplier = clusterNodeSelectorSupplier; + return this; } - void setNodeConfigurations(final List nodeConfigurations) { + Builder setNodeConfigurations(final List nodeConfigurations) { this.nodeConfigurations = nodeConfigurations; + return this; } boolean populateFromProperties(final Properties properties, final String prefix, final ClassLoader classLoader, final CommonSubconfiguration.Builder defaultsBuilder) { @@ -825,8 +848,9 @@ static final class Builder extends CommonSubconfiguration.Builder { Builder() { } - void setNodeName(final String nodeName) { + Builder setNodeName(final String nodeName) { this.nodeName = nodeName; + return this; } } } @@ -876,24 +900,29 @@ static final class Builder { Builder() { } - void setUserName(final String userName) { + Builder setUserName(final String userName) { this.userName = userName; + return this; } - void setPassword(final String password) { + Builder setPassword(final String password) { this.password = password; + return this; } - void setMechanismRealm(final String mechanismRealm) { + Builder setMechanismRealm(final String mechanismRealm) { this.mechanismRealm = mechanismRealm; + return this; } - void setCallbackHandlerClassName(final String callbackHandlerClassName) { + Builder setCallbackHandlerClassName(final String callbackHandlerClassName) { this.callbackHandlerClassName = callbackHandlerClassName; + return this; } - void setCallbackHandlerSupplier(final ExceptionSupplier callbackHandlerSupplier) { + Builder setCallbackHandlerSupplier(final ExceptionSupplier callbackHandlerSupplier) { this.callbackHandlerSupplier = callbackHandlerSupplier; + return this; } boolean populateFromProperties(final Properties properties, final String prefix, final ClassLoader classLoader) {