Example #1
0
        public AddressProvider(NetworkConfig networkConfig, HazelcastProperties properties)
        {
            var configAddressList = networkConfig.Addresses;
            var cloudConfig       = networkConfig.HazelcastCloudConfig;

            //Fail fast validate multiple setup
            if (configAddressList.Count > 0 && cloudConfig != null && cloudConfig.Enabled)
            {
                throw new InvalidConfigurationException("Only one address configuration method can be enabled at a time.");
            }

            if (cloudConfig != null && cloudConfig.Enabled)
            {
                var token = cloudConfig.DiscoveryToken;
                var connectionTimeoutInMillis = networkConfig.ConnectionTimeout;
                connectionTimeoutInMillis = connectionTimeoutInMillis == 0 ? int.MaxValue : connectionTimeoutInMillis;

                var urlBase = properties.StringValue(HazelcastProperties.CloudUrlBase);
                _hzCloudDiscovery  = new HazelcastCloudDiscovery(token, connectionTimeoutInMillis, urlBase);
                _addressProviderFn = GetHzCloudConfigAddresses;
                _canTranslate      = true;
            }
            else
            {
                _configAddresses = configAddressList.Count > 0 ? configAddressList : new List <string> {
                    "localhost"
                };
                _addressProviderFn = GetHzConfigAddresses;
            }
        }
 private HazelcastClient(Configuration config)
 {
     Configuration       = config;
     HazelcastProperties = new HazelcastProperties(config.Properties);
     if (config.InstanceName != null)
     {
         _instanceName = config.InstanceName;
     }
     else
     {
         _instanceName = "hz.client_" + _id;
     }
     LifecycleService = new LifecycleService(this);
     try
     {
         //TODO make partition strategy parametric
         var partitioningStrategy = new DefaultPartitioningStrategy();
         SerializationService = new SerializationServiceBuilder().SetConfig(config.SerializationConfig)
                                .SetPartitioningStrategy(partitioningStrategy)
                                .SetVersion(IO.Serialization.SerializationService.SerializerVersion).Build();
     }
     catch (Exception e)
     {
         throw ExceptionUtil.Rethrow(e);
     }
     ProxyManager = new ProxyManager(this);
     //TODO EXECUTION SERVICE
     ExecutionService         = new ExecutionService(_instanceName);
     LoadBalancer             = config.LoadBalancer ?? new RoundRobinLB();
     PartitionService         = new PartitionService(this);
     AddressProvider          = new AddressProvider(Configuration.NetworkConfig, HazelcastProperties);
     ConnectionManager        = new ConnectionManager(this);
     InvocationService        = new InvocationService(this);
     ListenerService          = new ListenerService(this);
     ClusterService           = new ClusterService(this);
     LockReferenceIdGenerator = new ClientLockReferenceIdGenerator();
     // Statistics = new Statistics(this);
     NearCacheManager   = new NearCacheManager(this);
     CredentialsFactory = config.SecurityConfig.AsCredentialsFactory() ??
                          new StaticCredentialsFactory(new UsernamePasswordCredentials());
 }