Exemple #1
0
        public ISubscriber CreateSubscriber(params long[] subscribeToEventCodes)
        {
            if (_disposeCount != 0)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }
            if (subscribeToEventCodes == null)
            {
                throw new ArgumentNullException("subscribeToEventCodes");
            }

            Interlocked.Increment(ref _socketCount);
            Subscriber subscriber = null;

            try
            {
                if (subscribeToEventCodes.Length != 0)
                {
                    long[] subscribeToEventCodesExtended = new long[subscribeToEventCodes.Length + 1];
                    Array.Copy(subscribeToEventCodes, subscribeToEventCodesExtended, subscribeToEventCodes.Length);
                    subscribeToEventCodesExtended[subscribeToEventCodesExtended.Length - 1] = SyncEvent.EventTopic;
                    subscribeToEventCodes = subscribeToEventCodesExtended;
                }
                subscriber = new Subscriber(_subscriberAddress, _context, subscribeToEventCodes, TimeSpan.MaxValue, _verboseLog, _traces);
                if (!_synchronizer.TrySync(subscriber))
                {
                    throw new SyncException();
                }
                return(subscriber);
            }
            catch (Exception ex)
            {
                _traces.Error(ex);
                if (subscriber != null)
                {
                    Release(subscriber);
                }
                else
                {
                    Interlocked.Decrement(ref _socketCount);
                }
                throw;
            }
        }
Exemple #2
0
        /// <summary>
        /// <para>Blocks until the proxy is operational.</para>
        /// </summary>
        /// <returns>true en cas de succès.</returns>
        private bool TrySync(TimeSpan timeout)
        {
            string pubAddress = _xSubscriberAddress.StartsWith("tcp://*") ? _xSubscriberAddress.Replace("*", "localhost") : _xSubscriberAddress;
            string subAddress = _xPublisherAddress.StartsWith("tcp://*") ? _xPublisherAddress.Replace("*", "localhost") : _xPublisherAddress;
            var    publisher  = new Publisher(pubAddress, _context, _verboseLog, _traces);

            try
            {
                var synchronizer = new SocketSynchronizer(_context, pubAddress, subAddress, timeout, _verboseLog, _traces);
                if (synchronizer.TrySync(publisher))
                {
                    return(!_isFaultedState);
                }
            }
            finally
            {
                publisher.Terminate();
            }
            return(false);
        }