예제 #1
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, int workerIndex = 0)
        {
            _workerIndex = workerIndex;
            _workerId = workerIdProvider.GetWorkerId(_workerIndex);
            _tickProvider = tickProvider;

            _c = _workerId[0] << 24 | _workerId[1] << 16 | _workerId[2] << 8 | _workerId[3];
            _d = _workerId[4] << 24 | _workerId[5] << 16;
        }
예제 #2
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, int workerIndex = 0)
        {
            _tickProvider = tickProvider;

            byte[] workerId = workerIdProvider.GetWorkerId(workerIndex);

            _c = workerId[0] << 24 | workerId[1] << 16 | workerId[2] << 8 | workerId[3];
            _d = workerId[4] << 24 | workerId[5] << 16;
        }
예제 #3
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, int workerIndex = 0)
        {
            _workerIndex  = workerIndex;
            _networkId    = workerIdProvider.GetWorkerId(_workerIndex);
            _tickProvider = tickProvider;

            _c = _networkId[0] << 24 | _networkId[1] << 16 | _networkId[2] << 8 | _networkId[3];
            _d = _networkId[4] << 24 | _networkId[5] << 16;
        }
예제 #4
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, int workerIndex = 0)
        {
            _tickProvider = tickProvider;

            byte[] workerId = workerIdProvider.GetWorkerId(workerIndex);

            _c = workerId[0] << 24 | workerId[1] << 16 | workerId[2] << 8 | workerId[3];
            _d = workerId[4] << 24 | workerId[5] << 16;
        }
예제 #5
0
        public void Init()
        {
            _start = DateTime.UtcNow;
            _stopwatch = Stopwatch.StartNew();

            _tickProvider = new MockTickProvider(GetTicks());
            _workerIdProvider = new MockNetworkProvider(BitConverter.GetBytes(1234567890L));
            _processIdProvider = new MockProcessIdProvider(BitConverter.GetBytes(10));
        }
예제 #6
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, IProcessIdProvider processIdProvider = null, int workerIndex = 0)
        {
            _tickProvider = tickProvider;

            byte[] workerId = workerIdProvider.GetWorkerId(workerIndex);

            _c = workerId[0] << 24 | workerId[1] << 16 | workerId[2] << 8 | workerId[3];

            if (processIdProvider != null)
            {
                var processId = processIdProvider.GetProcessId();
                _d = processId[0] << 24 | processId[1] << 16;
            }
            else
            {
                _d = workerId[4] << 24 | workerId[5] << 16;
            }
        }
예제 #7
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, IProcessIdProvider processIdProvider = null, int workerIndex = 0)
        {
            _tickProvider = tickProvider;

            byte[] workerId = workerIdProvider.GetWorkerId(workerIndex);

            _c = workerId[0] << 24 | workerId[1] << 16 | workerId[2] << 8 | workerId[3];

            if(processIdProvider != null)
            {
                var processId = processIdProvider.GetProcessId();
                _d = processId[0] << 24 | processId[1] << 16;
            }
            else
            {
                _d = workerId[4] << 24 | workerId[5] << 16;
            }
        }
예제 #8
0
        public NewIdGenerator(ITickProvider tickProvider, IWorkerIdProvider workerIdProvider, IProcessIdProvider processIdProvider = null, int workerIndex = 0)
        {
            _tickProvider = tickProvider;

            _spinLock = new SpinLock(false);

            var workerId = workerIdProvider.GetWorkerId(workerIndex);

            _c = (workerId[0] << 24) | (workerId[1] << 16) | (workerId[2] << 8) | workerId[3];

            if (processIdProvider != null)
            {
                var processId = processIdProvider.GetProcessId();
                _d = (processId[0] << 24) | (processId[1] << 16);
            }
            else
            {
                _d = (workerId[4] << 24) | (workerId[5] << 16);
            }

            _gb = (short)_c;
            _gc = (short)(_c >> 16);
        }
예제 #9
0
 public static void SetWorkerIdProvider(IWorkerIdProvider provider)
 {
     _workerIdProvider = provider;
 }