/hazelcast-client/src/main/java/com/hazelcast/client/ClientConfig.java

https://bitbucket.org/gabral6_gmailcom/hazelcast · Java · 163 lines · 111 code · 30 blank · 22 comment · 3 complexity · f4a7c5744e39b8acfda68a3404339474 MD5 · raw file

  1. /*
  2. * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.hazelcast.client;
  17. import com.hazelcast.config.GroupConfig;
  18. import com.hazelcast.nio.SocketInterceptor;
  19. import com.hazelcast.security.Credentials;
  20. import java.net.InetSocketAddress;
  21. import java.util.*;
  22. public class ClientConfig {
  23. private GroupConfig groupConfig = new GroupConfig();
  24. private final List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(10);
  25. private Credentials credentials;
  26. private int connectionTimeout = 30000;
  27. private int initialConnectionAttemptLimit = 1;
  28. private int reconnectionAttemptLimit = 1;
  29. private int reConnectionTimeOut = 5000;
  30. private boolean shuffle = false;
  31. private boolean updateAutomatic = true;
  32. private SocketInterceptor socketInterceptor = null;
  33. private final Collection<EventListener> listeners = new HashSet<EventListener>();
  34. public SocketInterceptor getSocketInterceptor() {
  35. return socketInterceptor;
  36. }
  37. public void setSocketInterceptor(SocketInterceptor socketInterceptor) {
  38. this.socketInterceptor = socketInterceptor;
  39. }
  40. public int getReConnectionTimeOut() {
  41. return reConnectionTimeOut;
  42. }
  43. public ClientConfig setReConnectionTimeOut(int reConnectionTimeOut) {
  44. this.reConnectionTimeOut = reConnectionTimeOut;
  45. return this;
  46. }
  47. public int getReconnectionAttemptLimit() {
  48. return reconnectionAttemptLimit;
  49. }
  50. public ClientConfig setReconnectionAttemptLimit(int reconnectionAttemptLimit) {
  51. this.reconnectionAttemptLimit = reconnectionAttemptLimit;
  52. return this;
  53. }
  54. public int getInitialConnectionAttemptLimit() {
  55. return initialConnectionAttemptLimit;
  56. }
  57. public ClientConfig setInitialConnectionAttemptLimit(int initialConnectionAttemptLimit) {
  58. this.initialConnectionAttemptLimit = initialConnectionAttemptLimit;
  59. return this;
  60. }
  61. public int getConnectionTimeout() {
  62. return connectionTimeout;
  63. }
  64. public ClientConfig setConnectionTimeout(int connectionTimeout) {
  65. this.connectionTimeout = connectionTimeout;
  66. return this;
  67. }
  68. public Credentials getCredentials() {
  69. return credentials;
  70. }
  71. public ClientConfig setCredentials(Credentials credentials) {
  72. this.credentials = credentials;
  73. return this;
  74. }
  75. public ClientConfig addInetSocketAddress(List<InetSocketAddress> inetSocketAddresses) {
  76. this.addressList.addAll(inetSocketAddresses);
  77. return this;
  78. }
  79. public ClientConfig addInetSocketAddress(InetSocketAddress... inetSocketAddresses) {
  80. for (InetSocketAddress inetSocketAddress : inetSocketAddresses) {
  81. this.addressList.add(inetSocketAddress);
  82. }
  83. return this;
  84. }
  85. public ClientConfig addAddress(String... addresses) {
  86. for (String address : addresses) {
  87. this.addressList.addAll(AddressHelper.getSocketAddresses(address));
  88. }
  89. return this;
  90. }
  91. // required for spring module
  92. public void setAddresses(List<String> addresses) {
  93. addressList.clear();
  94. for (String address : addresses) {
  95. addressList.addAll(AddressHelper.getSocketAddresses(address));
  96. }
  97. }
  98. public Collection<InetSocketAddress> getAddressList() {
  99. return addressList;
  100. }
  101. public GroupConfig getGroupConfig() {
  102. return groupConfig;
  103. }
  104. public ClientConfig setGroupConfig(GroupConfig groupConfig) {
  105. this.groupConfig = groupConfig;
  106. return this;
  107. }
  108. public void setShuffle(boolean shuffle) {
  109. this.shuffle = shuffle;
  110. }
  111. public boolean isShuffle() {
  112. return shuffle;
  113. }
  114. public boolean isUpdateAutomatic() {
  115. return updateAutomatic;
  116. }
  117. public void setUpdateAutomatic(boolean updateAutomatic) {
  118. this.updateAutomatic = updateAutomatic;
  119. }
  120. public Collection<EventListener> getListeners() {
  121. return listeners;
  122. }
  123. /**
  124. * Adds a listener object to configuration to be registered when {@code HazelcastClient} starts.
  125. * @param listener one of {@link com.hazelcast.core.LifecycleListener}, {@link com.hazelcast.core.InstanceListener}
  126. * or {@link com.hazelcast.core.MembershipListener}
  127. * @return
  128. */
  129. public ClientConfig addListener(EventListener listener) {
  130. listeners.add(listener);
  131. return this;
  132. }
  133. }