Exemplo n.º 1
0
        public static void Main()
        {
            var atomicCfg = new AtomicConfiguration
            {
                // Each node reserves 10 numbers to itself, so that 10 increments can be done locally,
                // without communicating to other nodes. After that, another 10 elements are reserved.
                AtomicSequenceReserveSize = 10
            };

            var cfg = new IgniteConfiguration
            {
                DiscoverySpi = new TcpDiscoverySpi
                {
                    IpFinder = new TcpDiscoveryMulticastIpFinder
                    {
                        Endpoints = new[] { "127.0.0.1:47500" }
                    }
                },
                AtomicConfiguration = atomicCfg
            };

            using (var ignite = Ignition.Start(cfg))
            {
                Console.WriteLine();
                Console.WriteLine(">>> Atomic sequence example started.");

                IAtomicSequence atomicSequence =
                    ignite.GetAtomicSequence(AtomicSequenceIncrementAction.AtomicSequenceName, 0, true);

                Console.WriteLine(">>> Atomic sequence initial value: " + atomicSequence.Read());

                // Broadcast an action that increments AtomicSequence a number of times.
                ignite.GetCompute().Broadcast(new AtomicSequenceIncrementAction());

                // Actual value will depend on number of participating nodes.
                Console.WriteLine("\n>>> Atomic sequence current value: " + atomicSequence.Read());
            }

            Console.WriteLine("\n>>> Check output on all nodes.");
            Console.WriteLine("\n>>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reads data from specified reader into current instance.
        /// </summary>
        /// <param name="r">The binary reader.</param>
        private void ReadCore(BinaryReader r)
        {
            // Simple properties
            _clientMode             = r.ReadBooleanNullable();
            IncludedEventTypes      = r.ReadIntArray();
            _metricsExpireTime      = r.ReadTimeSpanNullable();
            _metricsHistorySize     = r.ReadIntNullable();
            _metricsLogFrequency    = r.ReadTimeSpanNullable();
            _metricsUpdateFrequency = r.ReadTimeSpanNullable();
            _networkSendRetryCount  = r.ReadIntNullable();
            _networkSendRetryDelay  = r.ReadTimeSpanNullable();
            _networkTimeout         = r.ReadTimeSpanNullable();
            WorkDirectory           = r.ReadString();
            Localhost = r.ReadString();
            _isDaemon = r.ReadBooleanNullable();
            _isLateAffinityAssignment      = r.ReadBooleanNullable();
            _failureDetectionTimeout       = r.ReadTimeSpanNullable();
            _clientFailureDetectionTimeout = r.ReadTimeSpanNullable();
            _longQueryWarningTimeout       = r.ReadTimeSpanNullable();
            _isActiveOnStart = r.ReadBooleanNullable();

            // Thread pools
            _publicThreadPoolSize        = r.ReadIntNullable();
            _stripedThreadPoolSize       = r.ReadIntNullable();
            _serviceThreadPoolSize       = r.ReadIntNullable();
            _systemThreadPoolSize        = r.ReadIntNullable();
            _asyncCallbackThreadPoolSize = r.ReadIntNullable();
            _managementThreadPoolSize    = r.ReadIntNullable();
            _dataStreamerThreadPoolSize  = r.ReadIntNullable();
            _utilityCacheThreadPoolSize  = r.ReadIntNullable();
            _queryThreadPoolSize         = r.ReadIntNullable();

            // Cache config
            var cacheCfgCount = r.ReadInt();

            CacheConfiguration = new List <CacheConfiguration>(cacheCfgCount);
            for (int i = 0; i < cacheCfgCount; i++)
            {
                CacheConfiguration.Add(new CacheConfiguration(r));
            }

            // Discovery config
            DiscoverySpi = r.ReadBoolean() ? new TcpDiscoverySpi(r) : null;

            // Communication config
            CommunicationSpi = r.ReadBoolean() ? new TcpCommunicationSpi(r) : null;

            // Binary config
            if (r.ReadBoolean())
            {
                BinaryConfiguration = BinaryConfiguration ?? new BinaryConfiguration();

                if (r.ReadBoolean())
                {
                    BinaryConfiguration.CompactFooter = r.ReadBoolean();
                }

                if (r.ReadBoolean())
                {
                    BinaryConfiguration.NameMapper = BinaryBasicNameMapper.SimpleNameInstance;
                }
            }

            // User attributes
            UserAttributes = Enumerable.Range(0, r.ReadInt())
                             .ToDictionary(x => r.ReadString(), x => r.ReadObject <object>());

            // Atomic
            if (r.ReadBoolean())
            {
                AtomicConfiguration = new AtomicConfiguration
                {
                    AtomicSequenceReserveSize = r.ReadInt(),
                    Backups   = r.ReadInt(),
                    CacheMode = (CacheMode)r.ReadInt()
                };
            }

            // Tx
            if (r.ReadBoolean())
            {
                TransactionConfiguration = new TransactionConfiguration
                {
                    PessimisticTransactionLogSize = r.ReadInt(),
                    DefaultTransactionConcurrency = (TransactionConcurrency)r.ReadInt(),
                    DefaultTransactionIsolation   = (TransactionIsolation)r.ReadInt(),
                    DefaultTimeout = TimeSpan.FromMilliseconds(r.ReadLong()),
                    PessimisticTransactionLogLinger = TimeSpan.FromMilliseconds(r.ReadInt())
                };
            }

            // Event storage
            switch (r.ReadByte())
            {
            case 1: EventStorageSpi = new NoopEventStorageSpi();
                break;

            case 2:
                EventStorageSpi = MemoryEventStorageSpi.Read(r);
                break;
            }

            if (r.ReadBoolean())
            {
                MemoryConfiguration = new MemoryConfiguration(r);
            }

            // SQL
            if (r.ReadBoolean())
            {
                SqlConnectorConfiguration = new SqlConnectorConfiguration(r);
            }

            // Persistence.
            if (r.ReadBoolean())
            {
                PersistentStoreConfiguration = new PersistentStoreConfiguration(r);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Reads data from specified reader into current instance.
        /// </summary>
        /// <param name="r">The binary reader.</param>
        private void ReadCore(IBinaryRawReader r)
        {
            // Simple properties
            _clientMode             = r.ReadBooleanNullable();
            IncludedEventTypes      = r.ReadIntArray();
            _metricsExpireTime      = r.ReadTimeSpanNullable();
            _metricsHistorySize     = r.ReadIntNullable();
            _metricsLogFrequency    = r.ReadTimeSpanNullable();
            _metricsUpdateFrequency = r.ReadTimeSpanNullable();
            _networkSendRetryCount  = r.ReadIntNullable();
            _networkSendRetryDelay  = r.ReadTimeSpanNullable();
            _networkTimeout         = r.ReadTimeSpanNullable();
            WorkDirectory           = r.ReadString();
            Localhost = r.ReadString();
            _isDaemon = r.ReadBooleanNullable();
            _isLateAffinityAssignment = r.ReadBooleanNullable();
            _failureDetectionTimeout  = r.ReadTimeSpanNullable();

            // Cache config
            var cacheCfgCount = r.ReadInt();

            CacheConfiguration = new List <CacheConfiguration>(cacheCfgCount);
            for (int i = 0; i < cacheCfgCount; i++)
            {
                CacheConfiguration.Add(new CacheConfiguration(r));
            }

            // Discovery config
            DiscoverySpi = r.ReadBoolean() ? new TcpDiscoverySpi(r) : null;

            // Communication config
            CommunicationSpi = r.ReadBoolean() ? new TcpCommunicationSpi(r) : null;

            // Binary config
            if (r.ReadBoolean())
            {
                BinaryConfiguration = BinaryConfiguration ?? new BinaryConfiguration();

                if (r.ReadBoolean())
                {
                    BinaryConfiguration.CompactFooter = r.ReadBoolean();
                }

                var typeCount = r.ReadInt();

                if (typeCount > 0)
                {
                    var types = new List <BinaryTypeConfiguration>(typeCount);

                    for (var i = 0; i < typeCount; i++)
                    {
                        types.Add(new BinaryTypeConfiguration
                        {
                            TypeName         = r.ReadString(),
                            IsEnum           = r.ReadBoolean(),
                            EqualityComparer = BinaryEqualityComparerSerializer.Read(r)
                        });
                    }

                    BinaryConfiguration.TypeConfigurations = types;
                }
            }

            // User attributes
            UserAttributes = Enumerable.Range(0, r.ReadInt())
                             .ToDictionary(x => r.ReadString(), x => r.ReadObject <object>());

            // Atomic
            if (r.ReadBoolean())
            {
                AtomicConfiguration = new AtomicConfiguration
                {
                    AtomicSequenceReserveSize = r.ReadInt(),
                    Backups   = r.ReadInt(),
                    CacheMode = (CacheMode)r.ReadInt()
                };
            }

            // Tx
            if (r.ReadBoolean())
            {
                TransactionConfiguration = new TransactionConfiguration
                {
                    PessimisticTransactionLogSize = r.ReadInt(),
                    DefaultTransactionConcurrency = (TransactionConcurrency)r.ReadInt(),
                    DefaultTransactionIsolation   = (TransactionIsolation)r.ReadInt(),
                    DefaultTimeout = TimeSpan.FromMilliseconds(r.ReadLong()),
                    PessimisticTransactionLogLinger = TimeSpan.FromMilliseconds(r.ReadInt())
                };
            }

            // Swap
            SwapSpaceSpi = SwapSpaceSerializer.Read(r);
        }
        /// <summary>
        /// Reads data from specified reader into current instance.
        /// </summary>
        /// <param name="r">The binary reader.</param>
        private void ReadCore(BinaryReader r)
        {
            // Simple properties
            ClientMode         = r.ReadBoolean();
            IncludedEventTypes = r.ReadIntArray();

            MetricsExpireTime      = r.ReadLongAsTimespan();
            MetricsHistorySize     = r.ReadInt();
            MetricsLogFrequency    = r.ReadLongAsTimespan();
            MetricsUpdateFrequency = r.ReadLongAsTimespan();
            NetworkSendRetryCount  = r.ReadInt();
            NetworkSendRetryDelay  = r.ReadLongAsTimespan();
            NetworkTimeout         = r.ReadLongAsTimespan();
            WorkDirectory          = r.ReadString();
            Localhost = r.ReadString();
            IsDaemon  = r.ReadBoolean();

            // Cache config
            var cacheCfgCount = r.ReadInt();

            CacheConfiguration = new List <CacheConfiguration>(cacheCfgCount);
            for (int i = 0; i < cacheCfgCount; i++)
            {
                CacheConfiguration.Add(new CacheConfiguration(r));
            }

            // Discovery config
            DiscoverySpi = r.ReadBoolean() ? new TcpDiscoverySpi(r) : null;

            // Binary config
            if (r.ReadBoolean())
            {
                BinaryConfiguration = BinaryConfiguration ?? new BinaryConfiguration();
                BinaryConfiguration.CompactFooter = r.ReadBoolean();
            }

            // User attributes
            UserAttributes = Enumerable.Range(0, r.ReadInt())
                             .ToDictionary(x => r.ReadString(), x => r.ReadObject <object>());

            // Atomic
            if (r.ReadBoolean())
            {
                AtomicConfiguration = new AtomicConfiguration
                {
                    AtomicSequenceReserveSize = r.ReadInt(),
                    Backups   = r.ReadInt(),
                    CacheMode = (CacheMode)r.ReadInt()
                };
            }

            // Tx
            if (r.ReadBoolean())
            {
                TransactionConfiguration = new TransactionConfiguration
                {
                    PessimisticTransactionLogSize = r.ReadInt(),
                    DefaultTransactionConcurrency = (TransactionConcurrency)r.ReadInt(),
                    DefaultTransactionIsolation   = (TransactionIsolation)r.ReadInt(),
                    DefaultTimeout = TimeSpan.FromMilliseconds(r.ReadLong()),
                    PessimisticTransactionLogLinger = TimeSpan.FromMilliseconds(r.ReadInt())
                };
            }
        }