PageRenderTime 32ms CodeModel.GetById 2ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 17package com.hazelcast.client;
 18
 19import com.hazelcast.config.GroupConfig;
 20import com.hazelcast.nio.SocketInterceptor;
 21import com.hazelcast.security.Credentials;
 22
 23import java.net.InetSocketAddress;
 24import java.util.*;
 25
 26public class ClientConfig {
 27
 28    private GroupConfig groupConfig = new GroupConfig();
 29    private final List<InetSocketAddress> addressList = new ArrayList<InetSocketAddress>(10);
 30    private Credentials credentials;
 31    private int connectionTimeout = 30000;
 32    private int initialConnectionAttemptLimit = 1;
 33    private int reconnectionAttemptLimit = 1;
 34    private int reConnectionTimeOut = 5000;
 35    private boolean shuffle = false;
 36    private boolean updateAutomatic = true;
 37    private SocketInterceptor socketInterceptor = null;
 38    private final Collection<EventListener> listeners = new HashSet<EventListener>();
 39
 40    public SocketInterceptor getSocketInterceptor() {
 41        return socketInterceptor;
 42    }
 43
 44    public void setSocketInterceptor(SocketInterceptor socketInterceptor) {
 45        this.socketInterceptor = socketInterceptor;
 46    }
 47
 48    public int getReConnectionTimeOut() {
 49        return reConnectionTimeOut;
 50    }
 51
 52    public ClientConfig setReConnectionTimeOut(int reConnectionTimeOut) {
 53        this.reConnectionTimeOut = reConnectionTimeOut;
 54        return this;
 55    }
 56
 57    public int getReconnectionAttemptLimit() {
 58        return reconnectionAttemptLimit;
 59    }
 60
 61    public ClientConfig setReconnectionAttemptLimit(int reconnectionAttemptLimit) {
 62        this.reconnectionAttemptLimit = reconnectionAttemptLimit;
 63        return this;
 64    }
 65
 66    public int getInitialConnectionAttemptLimit() {
 67        return initialConnectionAttemptLimit;
 68    }
 69
 70    public ClientConfig setInitialConnectionAttemptLimit(int initialConnectionAttemptLimit) {
 71        this.initialConnectionAttemptLimit = initialConnectionAttemptLimit;
 72        return this;
 73    }
 74
 75    public int getConnectionTimeout() {
 76        return connectionTimeout;
 77    }
 78
 79    public ClientConfig setConnectionTimeout(int connectionTimeout) {
 80        this.connectionTimeout = connectionTimeout;
 81        return this;
 82    }
 83
 84    public Credentials getCredentials() {
 85        return credentials;
 86    }
 87
 88    public ClientConfig setCredentials(Credentials credentials) {
 89        this.credentials = credentials;
 90        return this;
 91    }
 92
 93    public ClientConfig addInetSocketAddress(List<InetSocketAddress> inetSocketAddresses) {
 94        this.addressList.addAll(inetSocketAddresses);
 95        return this;
 96    }
 97
 98    public ClientConfig addInetSocketAddress(InetSocketAddress... inetSocketAddresses) {
 99        for (InetSocketAddress inetSocketAddress : inetSocketAddresses) {
100            this.addressList.add(inetSocketAddress);
101        }
102        return this;
103    }
104
105    public ClientConfig addAddress(String... addresses) {
106        for (String address : addresses) {
107            this.addressList.addAll(AddressHelper.getSocketAddresses(address));
108        }
109        return this;
110    }
111
112    // required for spring module
113    public void setAddresses(List<String> addresses) {
114        addressList.clear();
115        for (String address : addresses) {
116            addressList.addAll(AddressHelper.getSocketAddresses(address));
117        }
118    }
119
120    public Collection<InetSocketAddress> getAddressList() {
121        return addressList;
122    }
123
124    public GroupConfig getGroupConfig() {
125        return groupConfig;
126    }
127
128    public ClientConfig setGroupConfig(GroupConfig groupConfig) {
129        this.groupConfig = groupConfig;
130        return this;
131    }
132
133    public void setShuffle(boolean shuffle) {
134        this.shuffle = shuffle;
135    }
136
137    public boolean isShuffle() {
138        return shuffle;
139    }
140
141    public boolean isUpdateAutomatic() {
142        return updateAutomatic;
143    }
144
145    public void setUpdateAutomatic(boolean updateAutomatic) {
146        this.updateAutomatic = updateAutomatic;
147    }
148
149    public Collection<EventListener> getListeners() {
150        return listeners;
151    }
152
153    /**
154     * Adds a listener object to configuration to be registered when {@code HazelcastClient} starts.
155     * @param listener one of {@link com.hazelcast.core.LifecycleListener}, {@link com.hazelcast.core.InstanceListener}
156     *                 or {@link com.hazelcast.core.MembershipListener}
157     * @return
158     */
159    public ClientConfig addListener(EventListener listener) {
160        listeners.add(listener);
161        return this;
162    }
163}