• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AtomicReference类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AtomicReference的典型用法代码示例。如果您正苦于以下问题:C# AtomicReference类的具体用法?C# AtomicReference怎么用?C# AtomicReference使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AtomicReference类属于命名空间,在下文中一共展示了AtomicReference类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CuratorFrameworkImpl

        public CuratorFrameworkImpl(CuratorFrameworkFactory.Builder builder)
        {
            IZookeeperFactory localZookeeperFactory = makeZookeeperFactory(builder.GetZookeeperFactory());
            this.client = new CuratorZookeeperClient(localZookeeperFactory,
                                                        builder.GetEnsembleProvider(),
                                                        builder.GetSessionTimeoutMs(),
                                                        builder.GetConnectionTimeoutMs(),
                                                        new WatchedWatcher(this),
                                                        builder.GetRetryPolicy(),
                                                        builder.CanBeReadOnly());

            listeners = new ListenerContainer<ICuratorListener>();
            unhandledErrorListeners = new ListenerContainer<IUnhandledErrorListener>();
            backgroundOperations = new DelayQueue<OperationAndData<object>>();
            @namespace = new NamespaceImpl(this, builder.GetNamespace());
            maxCloseWaitMs = builder.GetMaxCloseWaitMs();
            connectionStateManager = new ConnectionStateManager(this, builder.GetEventQueueSize());
            compressionProvider = builder.GetCompressionProvider();
            aclProvider = builder.GetAclProvider();
            state = new AtomicReference<CuratorFrameworkState>(CuratorFrameworkState.LATENT);
            useContainerParentsIfAvailable = builder.UseContainerParentsIfAvailable();

            byte[] builderDefaultData = builder.GetDefaultData();
            byte[] destDefaults = new byte[builderDefaultData.Length];
            Array.Copy(builderDefaultData, destDefaults, builderDefaultData.Length);
            defaultData = (builderDefaultData != null)
                            ?  destDefaults
                            : new byte[0];
            authInfos = buildAuths(builder);

            failedDeleteManager = new FailedDeleteManager(this);
            namespaceWatcherMap = new NamespaceWatcherMap(this);
            namespaceFacadeCache = new NamespaceFacadeCache(this);
        }
开发者ID:Lagrang,项目名称:CuratorNet,代码行数:34,代码来源:CuratorFrameworkImpl.cs


示例2: CompareAndSet_when_equal_returns_true

        public void CompareAndSet_when_equal_returns_true()
        {
            var expected = new object();
            var obj = new AtomicReference<object>(expected);

            Assert.IsTrue(obj.CompareAndSet(expected, new object()));
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:7,代码来源:AtomicReferenceTests.cs


示例3: ToString_returns_a_string_representation_of_the_object

        public void ToString_returns_a_string_representation_of_the_object()
        {
            var shared = new AtomicReference<object>();

            const string expected = "AtomicReference<System.Object>";

            Assert.AreEqual(expected, shared.ToString());
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:8,代码来源:AtomicReferenceTests.cs


示例4: AtomicReference_IEquatable_Of_Ref_Should_Compare

        public void AtomicReference_IEquatable_Of_Ref_Should_Compare()
        {
            IEquatable<object> firstAtomic = new AtomicReference<object>(new object());
            IEquatable<object> secondAtomic = new AtomicReference<object>(null);

            Assert.False(firstAtomic.Equals(false));
            Assert.False(secondAtomic.Equals(true));
        }
开发者ID:szKarlen,项目名称:atomics.net,代码行数:8,代码来源:AtomicReferenceEqualityTests.cs


示例5: GetAndSet_sets_new_value

        public void GetAndSet_sets_new_value()
        {
            var obj = new AtomicReference<object>();
            var value = new object();

            obj.GetAndSet(value);

            Assert.AreEqual(value, obj.Value);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:9,代码来源:AtomicReferenceTests.cs


示例6: GetAndSet_returns_old_value

        public void GetAndSet_returns_old_value()
        {
            var value = new object();
            var obj = new AtomicReference<object>(value);

            var actual = obj.GetAndSet(new object());

            Assert.AreEqual(value, actual);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:9,代码来源:AtomicReferenceTests.cs


示例7: Constructor_when_given_a_value_instantiates_with_it

        public void Constructor_when_given_a_value_instantiates_with_it()
        {
            var value = new object();
            var obj = new AtomicReference<object>(value);

            var actual = obj.Value;

            Assert.AreEqual(value, actual);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:9,代码来源:AtomicReferenceTests.cs


示例8: ObjectDirectory

 /// <summary>
 /// Initialize a reference to an on-disk object directory.
 /// </summary>
 /// <param name="dir">the location of the <code>objects</code> directory.</param>
 /// <param name="alternateObjectDir">a list of alternate object directories</param>
 public ObjectDirectory(DirectoryInfo dir, DirectoryInfo[] alternateObjectDir)
 {
     _objects = dir;
     _alternateObjectDir = alternateObjectDir;
     _infoDirectory = new DirectoryInfo(_objects.FullName + "/info");
     _packDirectory = new DirectoryInfo(_objects.FullName + "/pack");
     _alternatesFile = new FileInfo(_infoDirectory + "/alternates");
     _packList = new AtomicReference<PackList>(NoPacks);
 }
开发者ID:dev218,项目名称:GitSharp,代码行数:14,代码来源:ObjectDirectory.cs


示例9: CompareAndSet_when_not_equal_does_not_set_value

        public void CompareAndSet_when_not_equal_does_not_set_value()
        {
            var initial = new object();
            var obj = new AtomicReference<object>(initial);

            obj.CompareAndSet(new object(), new object());

            Assert.AreEqual(initial, obj.Value);
        }
开发者ID:ondfisk,项目名称:C5.Concurrent,代码行数:9,代码来源:AtomicReferenceTests.cs


示例10: EnsurePath

 protected EnsurePath(String path, 
                         AtomicReference<Helper> helper, 
                         bool makeLastNode, 
                         IInternalACLProvider aclProvider)
 {
     this.path = path;
     this.makeLastNode = makeLastNode;
     this.aclProvider = aclProvider;
     this.helper = helper ?? new AtomicReference<Helper>(new InitialHelper(this));
 }
开发者ID:Lagrang,项目名称:CuratorNet,代码行数:10,代码来源:EnsurePath.cs


示例11: AtomicReference_Implicit_Reassignment_Should_Change_Reference

        public void AtomicReference_Implicit_Reassignment_Should_Change_Reference()
        {
            var firstAtomic = new AtomicReference<object>(new object());
            var secondAtomic = firstAtomic;

            firstAtomic = false;

            Assert.NotEqual(secondAtomic, firstAtomic);
            Assert.False(object.ReferenceEquals(secondAtomic, firstAtomic));
        }
开发者ID:szKarlen,项目名称:atomics.net,代码行数:10,代码来源:AtomicReferenceEqualityTests.cs


示例12: AtomicReference_Implicit_Ref_AcqRel_Should_Success

        public void AtomicReference_Implicit_Ref_AcqRel_Should_Success()
        {
            var source = new object();
            var atomicReference = new AtomicReference<object>(source);

            var func = new Func<object, object>(i => i);

            Assert.NotEqual(source, func(atomicReference));
            Assert.Equal(source, func(atomicReference.Value));
        }
开发者ID:szKarlen,项目名称:atomics.net,代码行数:10,代码来源:AtomicReferenceEqualityTests.cs


示例13: ShouldExchangeAndReturnOldValue

    public void ShouldExchangeAndReturnOldValue() {
      ReferenceMock reference = Reference;

      AtomicReference<ReferenceMock> ar =
        new AtomicReference<ReferenceMock>(reference);

      ReferenceMock new_mock = new ReferenceMock("new_mock");
      ReferenceMock old_mock = ar.Exchange(new_mock);
      Assert.AreEqual(new_mock, ar.Value);
      Assert.AreEqual(reference, old_mock);
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:11,代码来源:AtomicReferenceTests.cs


示例14: ShouldNotUpdateWhenComparisonIsFalseAndReturnOldValue

    public void ShouldNotUpdateWhenComparisonIsFalseAndReturnOldValue() {
      ReferenceMock reference = Reference;

      AtomicReference<ReferenceMock> ar =
        new AtomicReference<ReferenceMock>(reference);

      ReferenceMock new_mock = new ReferenceMock("new-mock");
      ReferenceMock old_mock = ar.CompareExchange(new_mock, new_mock);
      Assert.AreEqual(reference, ar.Value);
      Assert.AreEqual(reference, old_mock);
    }
开发者ID:joethinh,项目名称:nohros-must,代码行数:11,代码来源:AtomicReferenceTests.cs


示例15: AtomicReference_Should_Implement_Reference_Equality

        public void AtomicReference_Should_Implement_Reference_Equality()
        {
            var firstAtomic = new AtomicReference<object>(new object());
            var secondAtomic = new AtomicReference<object>(null);

            Assert.False(firstAtomic.Equals(secondAtomic));
            Assert.False(secondAtomic.Equals(firstAtomic));

            // self equality
            Assert.True(firstAtomic.Equals(firstAtomic));
            Assert.True(secondAtomic.Equals(secondAtomic));
        }
开发者ID:szKarlen,项目名称:atomics.net,代码行数:12,代码来源:AtomicReferenceEqualityTests.cs


示例16: Cache_should_be_updated_with_the_latest_resolved

 public void Cache_should_be_updated_with_the_latest_resolved()
 {
     var localClock = new AtomicReference<long>(0);
     var cache = new SimpleDnsCacheTestDouble(localClock);
     var cacheEntryOne = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
     var cacheEntryTwo = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
     long ttl = 500;
     cache.Put(cacheEntryOne, ttl);
     cache.Cached("test.local").ShouldBe(cacheEntryOne);
     cache.Put(cacheEntryTwo, ttl);
     cache.Cached("test.local").ShouldBe(cacheEntryTwo);
 }
开发者ID:skotzko,项目名称:akka.net,代码行数:12,代码来源:SimpleDnsCacheSpec.cs


示例17: TcpSocketChannel_should_not_throw_on_shutdown

        public async Task TcpSocketChannel_should_not_throw_on_shutdown()
        {
            AtomicReference<Exception> clientError = new AtomicReference<Exception>(null);
            AtomicReference<Exception> serverError = new AtomicReference<Exception>(null);

            IChannel s = null;
            IChannel c = null;
            try
            {
                var sb = new ServerBootstrap()
                    .Channel<TcpServerSocketChannel>()
                    .ChildHandler(
                        new ActionChannelInitializer<TcpSocketChannel>(
                            channel => { channel.Pipeline.AddLast(new FailAssertionHandler(serverError)); }))
                    .Group(_serverGroup);

                s = sb.BindAsync(new IPEndPoint(IPAddress.IPv6Loopback, 0)).Result;


                var cb = new ClientBootstrap()
                    .Channel<TcpSocketChannel>()
                    .Option(ChannelOption.TcpNodelay, true)
                    .Option(ChannelOption.ConnectTimeout, TimeSpan.FromMilliseconds(100))
                    .Handler(
                        new ActionChannelInitializer<TcpSocketChannel>(
                            channel => { channel.Pipeline.AddLast(new FailAssertionHandler(clientError)); }))
                    .Group(_clientGroup);

                var clientEp = s.LocalAddress;
                c = cb.ConnectAsync(clientEp).Result;
                c.WriteAndFlushAsync(Unpooled.Buffer(4).WriteInt(2)).Wait(20);
                Assert.True(c.IsOpen);
                await c.CloseAsync();

                // assert that the counters were never decremented
                Assert.True(clientError.Value == null,
                    $"Expected null but error on client was {clientError.Value?.Message} {clientError.Value?.StackTrace}");
                Assert.True(serverError.Value == null,
                    $"Expected null but error on server was {serverError.Value?.Message} {serverError.Value?.StackTrace}");
            }
            finally
            {
                try
                {
                    c?.CloseAsync().Wait(TimeSpan.FromMilliseconds(200));
                    s?.CloseAsync().Wait(TimeSpan.FromMilliseconds(200));
                }
                catch
                {
                }
            }
        }
开发者ID:helios-io,项目名称:helios,代码行数:52,代码来源:TcpSocketChannelShutdownSpecs.cs


示例18: TestHandlerAddedExecutedInEventLoop

 public void TestHandlerAddedExecutedInEventLoop(int timeout)
 {
     var latch = new CountdownEvent(1);
     var ex = new AtomicReference<Exception>();
     IChannelHandler handler = new ChannelHandler3(latch, ex);
     var channel = new EmbeddedChannel(handler);
     Assert.False(channel.Finish());
     Assert.True(latch.Wait(timeout));
     var cause = ex.Value;
     if (cause != null)
     {
         throw cause;
     }
 }
开发者ID:helios-io,项目名称:helios,代码行数:14,代码来源:EmbeddedChannelTest.cs


示例19: Cache_should_not_reply_with_expired_but_not_yet_swept_out_entries

        public void Cache_should_not_reply_with_expired_but_not_yet_swept_out_entries()
        {
            var localClock = new AtomicReference<long>(0);
            var cache = new SimpleDnsCacheTestDouble(localClock);
            var cacheEntry = Dns.Resolved.Create("test.local", System.Net.Dns.GetHostEntry("127.0.0.1").AddressList);
            cache.Put(cacheEntry, 5000);

            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(0, 4999);
            cache.Cached("test.local").ShouldBe(cacheEntry);
            localClock.CompareAndSet(4999, 5000);
            cache.Cached("test.local").ShouldBe(null);

        }
开发者ID:skotzko,项目名称:akka.net,代码行数:14,代码来源:SimpleDnsCacheSpec.cs


示例20: ConnectionState

        internal ConnectionState(ZookeeperFactory zookeeperFactory, EnsembleProvider ensembleProvider,
            int sessionTimeoutMs, int connectionTimeoutMs, Watcher parentWatcher, AtomicReference<TracerDriver> tracer,
            bool canBeReadOnly)
        {
            this.ensembleProvider = ensembleProvider;
            this.sessionTimeoutMs = sessionTimeoutMs;
            this.connectionTimeoutMs = connectionTimeoutMs;
            this.tracer = tracer;
            if (parentWatcher != null)
            {
                parentWatchers.AddLast(parentWatcher);
            }

            zooKeeper = new HandleHolder(zookeeperFactory, this, ensembleProvider, sessionTimeoutMs, canBeReadOnly);
        }
开发者ID:shayhatsor,项目名称:curator,代码行数:15,代码来源:ConnectionState.cs



注:本文中的AtomicReference类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AtomicUndoOperation类代码示例发布时间:2022-05-24
下一篇:
C# AtomicComposition类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap