Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="HRingBuffer{TItem}"/> class.
        /// </summary>
        /// <param name="name">The unique name of the ring buffer.</param>
        /// <param name="factory">The factory owning this object.</param>
        /// <param name="cluster">The cluster.</param>
        /// <param name="serializationService">The serialization service.</param>
        /// <param name="loggerFactory">A logger factory.</param>
        public HRingBuffer(string name, DistributedObjectFactory factory, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
            : base(ServiceNames.RingBuffer, name, factory, cluster, serializationService, loggerFactory)
        {
            const int maxBatchSize = 1000;

            MaxBatchSize = maxBatchSize;
        }
Exemple #2
0
        private MemberConnection _connection; // the client supporting the transaction
#pragma warning restore CA2213

        // TODO transactions need some TLC
        // how is two-phases commit supposed to work? is it all server-side (and then, why
        // do we have 'prepared' state on client's side?)
        // what about TransactionXxxExceptions, are we ever throwing them, and where?

        /// <summary>
        /// Initializes a new instance of the <see cref="TransactionContext"/> class.
        /// </summary>
        /// <param name="cluster">The cluster.</param>
        /// <param name="options">Transaction options.</param>
        /// <param name="serializationService">The serialization service.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        public TransactionContext(Cluster cluster, TransactionOptions options, SerializationService serializationService, ILoggerFactory loggerFactory)
        {
            _cluster = cluster ?? throw new ArgumentNullException(nameof(cluster));
            _options = options ?? throw new ArgumentNullException(nameof(options));

            if (serializationService == null)
            {
                throw new ArgumentNullException(nameof(serializationService));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            _distributedObjectFactory = new DistributedObjectFactory(cluster, serializationService, loggerFactory);
        }
Exemple #3
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();
        }
Exemple #4
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();
        }
 protected HCollectionBase(string serviceName, string name, DistributedObjectFactory factory, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
     : base(serviceName, name, factory, cluster, serializationService, loggerFactory)
 {
 }
 public HSet(string name, DistributedObjectFactory factory, Cluster cluster, SerializationService serializationService, ILoggerFactory loggerFactory)
     : base(ServiceNames.Set, name, factory, cluster, serializationService, loggerFactory)
 {
 }
Exemple #7
0
 // uh refactor this ctor
 public Executor(string serviceName, string name, DistributedObjectFactory factory, Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory)
     : base(serviceName, name, factory, cluster, serializationService, loggerFactory)
 {
 }
 public HTxDictionary(string name, DistributedObjectFactory factory, Cluster cluster, MemberConnection transactionClientConnection, Guid transactionId, ISerializationService serializationService, ILoggerFactory loggerFactory)
     : base(HDictionary.ServiceName, name, factory, cluster, transactionClientConnection, transactionId, serializationService, loggerFactory)
 {
 }
Exemple #9
0
 public HMultiMap(string name, DistributedObjectFactory factory, Cluster cluster, SerializationService serializationService, ISequence <long> lockReferenceIdSequence, ILoggerFactory loggerFactory)
     : base(ServiceNames.MultiMap, name, factory, cluster, serializationService, loggerFactory)
 {
     _lockReferenceIdSequence = lockReferenceIdSequence;
 }
 /// <summary>
 /// Initializes a new version of the <see cref="HDictionaryWithCache{TKey,TValue}"/> class.
 /// </summary>
 /// <param name="name">The unique name of the object.</param>
 /// <param name="cluster">A cluster.</param>
 /// <param name="serializationService">A serialization service.</param>
 /// <param name="lockReferenceIdSequence">A lock reference identifiers sequence.</param>
 /// <param name="cache">A cache.</param>
 /// <param name="loggerFactory">A logger factory.</param>
 public HDictionaryWithCache(string name, DistributedObjectFactory factory, Cluster cluster, ISerializationService serializationService, ISequence <long> lockReferenceIdSequence, NearCache <TValue> cache, ILoggerFactory loggerFactory)
     : base(name, factory, cluster, serializationService, lockReferenceIdSequence, loggerFactory)
 {
     _cache = cache;
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Topic{T}"/> class.
 /// </summary>
 /// <param name="name">The unique name of the object.</param>
 /// <param name="factory">The factory that owns this object.</param>
 /// <param name="cluster">A cluster.</param>
 /// <param name="serializationService">A serialization service.</param>
 /// <param name="loggerFactory">A logger factory.</param>
 public HTopic(string name, DistributedObjectFactory factory, Cluster cluster, ISerializationService serializationService, ILoggerFactory loggerFactory)
     : base(HTopic.ServiceName, name, factory, cluster, serializationService, loggerFactory)
 {
 }
Exemple #12
0
 public HReplicatedMap(string name, DistributedObjectFactory factory, Cluster cluster, SerializationService serializationService, int partitionId, ILoggerFactory loggerFactory)
     : base(ServiceNames.ReplicatedMap, name, factory, cluster, serializationService, loggerFactory)
 {
     _partitionId = partitionId;
 }
 public HTxMultiMap(string name, DistributedObjectFactory factory, Cluster cluster, MemberConnection transactionClientConnection, Guid transactionId, SerializationService serializationService, ILoggerFactory loggerFactory)
     : base(ServiceNames.MultiMap, name, factory, cluster, transactionClientConnection, transactionId, serializationService, loggerFactory)
 {
 }
        /// <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;
        }
Exemple #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HDictionary{TKey,TValue}"/> class.
 /// </summary>
 /// <param name="name">The unique name of the object.</param>
 /// <param name="factory">The factory owning this object.</param>
 /// <param name="cluster">A cluster.</param>
 /// <param name="serializationService">A serialization service.</param>
 /// <param name="lockReferenceIdSequence">A lock reference identifiers sequence.</param>
 /// <param name="logggerFactory">A logger factory.</param>
 public HDictionary(string name, DistributedObjectFactory factory, Cluster cluster, ISerializationService serializationService, ISequence <long> lockReferenceIdSequence, ILoggerFactory logggerFactory)
     : base(HDictionary.ServiceName, name, factory, cluster, serializationService, logggerFactory)
 {
     _lockReferenceIdSequence = lockReferenceIdSequence;
 }
 public HReplicatedDictionary(string name, DistributedObjectFactory factory, Cluster cluster, ISerializationService serializationService, int partitionId, ILoggerFactory loggerFactory)
     : base(HReplicatedDictionary.ServiceName, name, factory, cluster, serializationService, loggerFactory)
 {
     _partitionId = partitionId;
 }