Exemplo n.º 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="cfg">Configuration.</param>
        /// <param name="name">Grid name.</param>
        /// <param name="proc">Interop processor.</param>
        /// <param name="marsh">Marshaller.</param>
        /// <param name="lifecycleHandlers">Lifecycle beans.</param>
        /// <param name="cbs">Callbacks.</param>
        public Ignite(IgniteConfiguration cfg, string name, IPlatformTargetInternal proc, Marshaller marsh,
                      IList <LifecycleHandlerHolder> lifecycleHandlers, UnmanagedCallbacks cbs) : base(proc)
        {
            Debug.Assert(cfg != null);
            Debug.Assert(proc != null);
            Debug.Assert(marsh != null);
            Debug.Assert(lifecycleHandlers != null);
            Debug.Assert(cbs != null);

            _cfg               = cfg;
            _name              = name;
            _proc              = proc;
            _marsh             = marsh;
            _lifecycleHandlers = lifecycleHandlers;
            _cbs               = cbs;

            marsh.Ignite = this;

            _prj = new ClusterGroupImpl(Target.OutObjectInternal((int)Op.GetClusterGroup), null);

            _binary = new Binary.Binary(marsh);

            _binaryProc = new BinaryProcessor(DoOutOpObject((int)Op.GetBinaryProcessor));

            cbs.Initialize(this);

            // Set reconnected task to completed state for convenience.
            _clientReconnectTaskCompletionSource.SetResult(false);

            SetCompactFooter();

            _pluginProcessor = new PluginProcessor(this);

            _nearCacheManager = new NearCacheManager(this);
        }
Exemplo n.º 2
0
 internal void DoShutdown()
 {
     Clients.TryRemove(_instanceName, out _);
     DisposeAll(_onClientShutdownDisposables);
     // Statistics.Destroy();
     ExecutionService.Shutdown();
     ConnectionManager.Shutdown();
     ProxyManager.Destroy();
     InvocationService.Shutdown();
     NearCacheManager.Shutdown();
     ListenerService.Dispose();
     SerializationService.Destroy();
     CredentialsFactory.Dispose();
 }
Exemplo n.º 3
0
 internal ClientContext(ISerializationService serializationService, IClientClusterService clusterService,
                        IClientPartitionService partitionService, IClientInvocationService invocationService,
                        IClientExecutionService executionService, IClientListenerService listenerService,
                        NearCacheManager nearCacheManager, ProxyManager proxyManager, ClientConfig clientConfig)
 {
     _serializationService = serializationService;
     _clusterService       = clusterService;
     _partitionService     = partitionService;
     _invocationService    = invocationService;
     _executionService     = executionService;
     _listenerService      = listenerService;
     _proxyManager         = proxyManager;
     _clientConfig         = clientConfig;
     _nearCacheManager     = nearCacheManager;
 }
Exemplo n.º 4
0
        private HazelcastClient(ClientConfig config)
        {
            _config = config;
            var groupConfig = config.GetGroupConfig();

            _instanceName = "hz.client_" + _id + (groupConfig != null ? "_" + groupConfig.GetName() : string.Empty);

            _lifecycleService = new LifecycleService(this);
            try
            {
                //TODO make partition strategy parametric
                var partitioningStrategy = new DefaultPartitioningStrategy();
                _serializationService =
                    new SerializationServiceBuilder().SetManagedContext(new HazelcastClientManagedContext(this,
                                                                                                          config.GetManagedContext()))
                    .SetConfig(config.GetSerializationConfig())
                    .SetPartitioningStrategy(partitioningStrategy)
                    .SetVersion(SerializationService.SerializerVersion)
                    .Build();
            }
            catch (Exception e)
            {
                throw ExceptionUtil.Rethrow(e);
            }
            _proxyManager = new ProxyManager(this);

            //TODO EXECUTION SERVICE
            _executionService = new ClientExecutionService(_instanceName, config.GetExecutorPoolSize());
            _clusterService   = new ClientClusterService(this);
            _loadBalancer     = config.GetLoadBalancer() ?? new RoundRobinLB();

            _addressProvider          = new AddressProvider(_config);
            _connectionManager        = new ClientConnectionManager(this);
            _invocationService        = CreateInvocationService();
            _listenerService          = new ClientListenerService(this);
            _userContext              = new ConcurrentDictionary <string, object>();
            _partitionService         = new ClientPartitionService(this);
            _lockReferenceIdGenerator = new ClientLockReferenceIdGenerator();
            _statistics         = new Statistics(this);
            _nearCacheManager   = new NearCacheManager(this);
            _credentialsFactory = InitCredentialsFactory(config);
        }
 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());
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HazelcastClient"/> class.
        /// </summary>
        /// <param name="options">The client configuration.</param>
        /// <param name="cluster">A cluster.</param>
        /// <param name="serializationService">A serialization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public HazelcastClient(HazelcastOptions options, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
        {
            _options             = options ?? throw new ArgumentNullException(nameof(options));
            Cluster              = cluster ?? throw new ArgumentNullException(nameof(cluster));
            SerializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService));
            _loggerFactory       = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger              = loggerFactory.CreateLogger <IHazelcastClient>();

            _distributedOjects = new DistributedObjectFactory(Cluster, serializationService, loggerFactory);
            _nearCacheManager  = new NearCacheManager(cluster, serializationService, loggerFactory, options.NearCache);

            if (options.Metrics.Enabled)
            {
                _metricsPublisher = new MetricsPublisher(cluster, options.Metrics, loggerFactory);
                _metricsPublisher.AddSource(new ClientMetricSource(cluster, loggerFactory));
                _metricsPublisher.AddSource(_nearCacheManager);
            }

            // wire components
            WireComponents();
        }
Exemplo n.º 7
0
 private HazelcastClient(ClientConfig config)
 {
     ClientConfig = config;
     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.GetSerializationConfig())
                                .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, config.GetExecutorPoolSize());
     LoadBalancer             = config.GetLoadBalancer() ?? new RoundRobinLB();
     PartitionService         = new PartitionService(this);
     AddressProvider          = new AddressProvider(ClientConfig);
     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 = InitCredentialsFactory(config);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HazelcastClient"/> class.
        /// </summary>
        /// <param name="options">The client configuration.</param>
        /// <param name="cluster">A cluster.</param>
        /// <param name="serializationService">A serialization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public HazelcastClient(HazelcastOptions options, Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory)
        {
            _options             = options ?? throw new ArgumentNullException(nameof(options));
            Cluster              = cluster ?? throw new ArgumentNullException(nameof(cluster));
            SerializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService));
            _loggerFactory       = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger              = loggerFactory.CreateLogger <IHazelcastClient>();

            _distributedObjectFactory = new DistributedObjectFactory(Cluster, serializationService, loggerFactory);
            Cluster.Connections.OnConnectingToNewCluster = cancellationToken => _distributedObjectFactory.CreateAllAsync(cancellationToken);

            _nearCacheManager = new NearCacheManager(cluster, serializationService, loggerFactory, options.NearCache);

            // wire events
            // this way, the cluster does not need to know about the hazelcast client,
            // and we don't have circular dependencies everywhere - cleaner
            cluster.ClusterEvents.OnObjectLifecycleEvent = OnObjectLifecycleEvent;
            cluster.ClusterEvents.OnPartitionLost        = OnPartitionLost;
            cluster.ClusterEvents.OnMemberLifecycleEvent = OnMemberLifecycleEvent;
            cluster.ClusterEvents.OnClientLifecycleEvent = OnClientLifecycleEvent;
            cluster.ClusterEvents.OnPartitionsUpdated    = OnPartitionsUpdated;
            cluster.ClusterEvents.OnConnectionAdded      = OnConnectionAdded;
            cluster.ClusterEvents.OnConnectionRemoved    = OnConnectionRemoved;
            cluster.ClusterEvents.OnConnectionRemoved    = OnConnectionRemoved;

            cluster.Connections.OnFirstConnection = async cancellationToken =>
            {
                foreach (var subscriber in options.Subscribers)
                {
                    await subscriber.SubscribeAsync(this, cancellationToken).CAF();
                }
            };

            // every async operations using this client will need a proper async context
            AsyncContext.Ensure();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="HazelcastClient"/> class.
        /// </summary>
        /// <param name="options">The client configuration.</param>
        /// <param name="cluster">A cluster.</param>
        /// <param name="serializationService">A serialization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public HazelcastClient(HazelcastOptions options, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
        {
            _options             = options ?? throw new ArgumentNullException(nameof(options));
            Cluster              = cluster ?? throw new ArgumentNullException(nameof(cluster));
            SerializationService = serializationService ?? throw new ArgumentNullException(nameof(serializationService));
            _loggerFactory       = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
            _logger              = loggerFactory.CreateLogger <IHazelcastClient>();

            _distributedOjects = new DistributedObjectFactory(Cluster, serializationService, loggerFactory);
            _nearCacheManager  = new NearCacheManager(cluster, serializationService, loggerFactory, options.NearCache);

            // wire events - clean

            // NOTE: each event that is a Func<..., ValueTask> *must* be invoked
            // through the special FuncExtensions.AwaitEach() method, see notes in
            // FuncExtensions.cs

            // when an object is created/destroyed, OnObject... triggers the user-level events
            cluster.ClusterEvents.ObjectCreated   = OnObjectCreated;
            cluster.ClusterEvents.ObjectDestroyed = OnObjectDestroyed;

            // when client/cluster state changes, OnStateChanged triggers user-level events
            cluster.State.StateChanged += OnStateChanged;

            // when partitions are updated, OnPartitionUpdated triggers the user-level event
            cluster.Events.PartitionsUpdated += OnPartitionsUpdated;

            // when a partition is lost, OnPartitionLost triggers the user-level event
            cluster.ClusterEvents.PartitionLost = OnPartitionLost;

            // when members are updated, Connections.OnMembersUpdated queues the added
            // members so that a connection is opened to each of them.
            cluster.Events.MembersUpdated += cluster.Connections.OnMembersUpdated;

            // when members are updated, OnMembersUpdated triggers the user-level event
            cluster.Events.MembersUpdated += OnMembersUpdated;

            // when a connection is created, Events.OnConnectionCreated wires the connection
            // ReceivedEvent event to Events.OnReceivedEvent, in order to handle events
            cluster.Connections.ConnectionCreated += cluster.Events.OnConnectionCreated;

            // when connecting to a new cluster, DistributedObjects.OnConnectingToNewCluster
            // re-creates all the known distributed object so far on the new cluster
            cluster.Connections.ConnectionOpened += _distributedOjects.OnConnectionOpened;

            // when a connection is added, OnConnectionOpened triggers the user-level event
            // and, if it is the first connection, subscribes to events according to the
            // subscribers defined in options.
            cluster.Connections.ConnectionOpened += OnConnectionOpened;

            // when a connection is opened, Events.OnConnectionOpened ensures that the
            // cluster connection (handling member/partition views) is set, and installs
            // subscriptions on this new connection.
            cluster.Connections.ConnectionOpened += cluster.Events.OnConnectionOpened;

            // when a connection is closed, client.OnConnectionClosed triggers the user-level event
            cluster.Connections.ConnectionClosed += OnConnectionClosed;

            // when a connection is closed, Events.OnConnectionClosed clears subscriptions
            // (cannot unsubscribe since the connection is closed) and ensures that the
            // cluster connection (handling member/partition views) is set.
            cluster.Connections.ConnectionClosed += cluster.Events.OnConnectionClosed;
        }