Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicReference


                    throw new RuntimeException(e);
                }
            }
        });

        final AtomicReference reference = new AtomicReference();
        final ICompletableFuture completableFuture = es.asCompletableFuture(future);
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference.set(t);
                latch2.countDown();
            }
        });

        latch1.countDown();
        latch2.await(30, TimeUnit.SECONDS);
        assertEquals("success", reference.get());
    }
View Full Code Here


                    throw new RuntimeException(e);
                }
            }
        });

        final AtomicReference reference1 = new AtomicReference();
        final AtomicReference reference2 = new AtomicReference();
        final ICompletableFuture completableFuture = es.asCompletableFuture(future);
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference1.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference1.set(t);
                latch2.countDown();
            }
        });
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference2.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference2.set(t);
                latch2.countDown();
            }
        });

        latch1.countDown();
        latch2.await(30, TimeUnit.SECONDS);
        assertEquals("success", reference1.get());
        assertEquals("success", reference2.get());
    }
View Full Code Here

            }
        });

        assertOpenEventually(latch1);

        final AtomicReference reference = new AtomicReference();
        final ICompletableFuture completableFuture = es.asCompletableFuture(future);
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference.set(t);
                latch2.countDown();
            }
        });

        assertOpenEventually(latch2);
        assertEquals("success", reference.get());
    }
View Full Code Here

            }
        });

        assertOpenEventually(latch1);

        final AtomicReference reference1 = new AtomicReference();
        final AtomicReference reference2 = new AtomicReference();
        final ICompletableFuture completableFuture = es.asCompletableFuture(future);
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference1.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference1.set(t);
                latch2.countDown();
            }
        });
        completableFuture.andThen(new ExecutionCallback() {
            @Override
            public void onResponse(Object response) {
                reference2.set(response);
                latch2.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                reference2.set(t);
                latch2.countDown();
            }
        });

        assertOpenEventually(latch2);
        assertEquals("success", reference1.get());
        assertEquals("success", reference2.get());
    }
View Full Code Here

    final EventSink snk = FlumeBuilder.buildSink(new Context(),
        "collectorSink(\"hdfs://nonexistant/user/foo\", \"foo\")");

    final CountDownLatch started = new CountDownLatch(1);
    final CountDownLatch done = new CountDownLatch(1);
    final AtomicReference<Exception> are = new AtomicReference(null);
    Thread t = new Thread("append thread") {
      public void run() {
        Event e = new EventImpl("foo".getBytes());
        try {
          snk.open();
          started.countDown();
          snk.append(e);
        } catch (Exception e1) {
          // could be an exception but we don't care.
          LOG.info("don't care about this exception: ", e1);
          are.set(e1);
        }
        done.countDown();
      }
    };
    t.start();
View Full Code Here

        "collectorSink(\"hdfs://nonexistant/user/foo\", \"foo\")");

    final CountDownLatch started = new CountDownLatch(1);
    final CountDownLatch done = new CountDownLatch(1);

    final AtomicReference<Exception> are = new AtomicReference(null);
    Thread t = new Thread("append thread") {
      public void run() {
        Event e = new EventImpl("foo".getBytes());
        try {
          snk.open();
          started.countDown();
          snk.append(e);
        } catch (Exception e1) {
          e1.printStackTrace();
          are.set(e1);
        }
        done.countDown();
      }
    };
    t.start();
    boolean begun = started.await(60, TimeUnit.SECONDS);
    assertTrue("took too long to start", begun);

    // there is a race between this close call and the append call inside the
    // thread. This sleep call should give enough to cause the append to get
    // stuck.
    Clock.sleep(1000);

    snk.close();
    LOG.info("Interrupting appending thread");
    t.interrupt();
    boolean completed = done.await(60, TimeUnit.SECONDS);
    assertTrue("Timed out when attempting to shutdown", completed);
    assertTrue("Expected exit due to interrupted exception",
        are.get() instanceof InterruptedException);
  }
View Full Code Here

        Object[] arguments;
    }

    @Test
    public void testGenericImplementationWithBeanSerialization() throws Exception {
        final AtomicReference reference = new AtomicReference();
        ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
        service.setApplication(new ApplicationConfig("bean-provider"));
        service.setRegistry(new RegistryConfig("N/A"));
        service.setProtocol(new ProtocolConfig("dubbo", 29581));
        service.setInterface(DemoService.class.getName());
        service.setRef(new GenericService() {

            public Object $invoke(String method, String[] parameterTypes, Object[] args) throws GenericException {
                if ("getUsers".equals(method)) {
                    GenericParameter arg = new GenericParameter();
                    arg.method = method;
                    arg.parameterTypes = parameterTypes;
                    arg.arguments = args;
                    reference.set(arg);
                    return args[0];
                }
                if ("sayName".equals(method)) {
                    return null;
                }
                return args;
            }
        });
        service.export();
        ReferenceConfig<DemoService> ref = null;
        try {
            ref = new ReferenceConfig<DemoService>();
            ref.setApplication(new ApplicationConfig("bean-consumer"));
            ref.setInterface(DemoService.class);
            ref.setUrl("dubbo://127.0.0.1:29581?scope=remote&generic=bean");
            DemoService demoService = ref.get();
            User user = new User();
            user.setName("zhangsan");
            List<User> users = new ArrayList<User>();
            users.add(user);
            List<User> result = demoService.getUsers(users);
            Assert.assertEquals(users.size(), result.size());
            Assert.assertEquals(user.getName(), result.get(0).getName());

            GenericParameter gp = (GenericParameter)reference.get();
            Assert.assertEquals("getUsers", gp.method);
            Assert.assertEquals(1, gp.parameterTypes.length);
            Assert.assertEquals(ReflectUtils.getName(List.class), gp.parameterTypes[0]);
            Assert.assertEquals(1, gp.arguments.length);
            Assert.assertTrue(gp.arguments[0] instanceof JavaBeanDescriptor);
View Full Code Here

        Object itemObject = parser.parseObject(itemType);

        Type rawType = paramType.getRawType();
        if (rawType == AtomicReference.class) {
            return (T) new AtomicReference(itemObject);
        }

        if (rawType == WeakReference.class) {
            return (T) new WeakReference(itemObject);
        }
View Full Code Here

    public final static AtomicReferenceSerializer instance = new AtomicReferenceSerializer();

    @SuppressWarnings("rawtypes")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
        AtomicReference val = (AtomicReference) object;
        serializer.write(val.get());
    }
View Full Code Here

    @SuppressWarnings("rawtypes")
    public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
        Object item;
        if (object instanceof AtomicReference) {
            AtomicReference val = (AtomicReference) object;
            item = val.get();
        } else {
            item = ((Reference) object).get();
        }
        serializer.write(item);
    }
View Full Code Here

TOP

Related Classes of java.util.concurrent.atomic.AtomicReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.