Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicReference


@Beta
public final class Atomics
{
  public static AtomicReference newReference()
  {
    return new AtomicReference();
  }
View Full Code Here


    return new AtomicReference();
  }

  public static AtomicReference newReference(Object paramObject)
  {
    return new AtomicReference(paramObject);
  }
View Full Code Here

                        //
                        // handle "unwrapping" objects -- AtomicReference
                        //
                        if (info.actualValue != null && f.getType().equals(AtomicReference.class)) {
                            //logger.debug("AtomicReference found, going to unwrap it");
                            AtomicReference ref = (AtomicReference)info.actualValue;
                            // get the actual underlying value
                            info.actualValue = ref.get();
                            // if not null, we can get its type too
                            if (info.actualValue != null) {
                                info.fieldClass = info.actualValue.getClass();
                            }
                        }
View Full Code Here

@RunWith(ScriptRunner.class)
public class AtomicReferenceTest {

    @Test
    public void accessor() throws Exception {
        AtomicReference<String> reference = new AtomicReference();
        reference.set("test");

        assert reference.get().equals("test");
    }
View Full Code Here

        assert reference.get().equals("test");
    }

    @Test
    public void compareAndSet() throws Exception {
        AtomicReference<String> reference = new AtomicReference();
        reference.compareAndSet(null, "test");
        assert reference.get().equals("test");

        assert reference.compareAndSet("test", "update");
        assert reference.get().equals("update");

        assert !reference.compareAndSet("don't", "apply");
        assert reference.get().equals("update");
    }
View Full Code Here

        assert reference.get().equals("update");
    }

    @Test
    public void getAndSet() throws Exception {
        AtomicReference<String> reference = new AtomicReference();
        assert reference.getAndSet("test") == null;
        assert reference.getAndSet("update").equals("test");
        assert reference.get().equals("update");
    }
View Full Code Here

        assert reference.get().equals("update");
    }

    @Test
    public void updateAndSet() throws Exception {
        AtomicReference<String> reference = new AtomicReference();
        assert reference.updateAndGet(v -> {
            return "update";
        }) == "update";
    }
View Full Code Here

        mapListeners(DBMaker.newMemoryDB().transactionDisable().make().getTreeMap("test"));
    }


    void mapListeners(Bind.MapWithModificationListener test) {
        final AtomicReference rkey = new AtomicReference();
        final AtomicReference roldVal = new AtomicReference();
        final AtomicReference rnewVal = new AtomicReference();

        test.modificationListenerAdd(new Bind.MapListener() {
            @Override
            public void update(Object key, Object oldVal, Object newVal) {
                rkey.set(key);
                roldVal.set(oldVal);
                rnewVal.set(newVal);
            }
        });

        int max = (int) 1e6;
        Random r = new Random();
        for(int i=0;i<max;i++){
            Integer k = r.nextInt(max/100);
            Integer v = k*1000;
            Integer vold = null;

            if(test.containsKey(k)){
                vold = v*10;
                test.put(k,vold);
            }


            test.put(k,v);
            assertEquals(k, rkey.get());
            assertEquals(v, rnewVal.get());
            assertEquals(vold, roldVal.get());

            final int m = i%20;
            if(m==1){
                test.remove(k);
                assertEquals(k, rkey.get());
                assertEquals(null, rnewVal.get());
                assertEquals(v, roldVal.get());
            }else  if(m==2){
                test.put(k,i*20);
                assertEquals(k, rkey.get());
                assertEquals(i*20, rnewVal.get());
                assertEquals(v, roldVal.get());
            }else if(m==3&& !test.containsKey(i+1)){
                ((ConcurrentMap)test).putIfAbsent(i+1,i+2);
                assertEquals(i+1, rkey.get());
                assertEquals(i+2, rnewVal.get());
                assertEquals(null, roldVal.get());
            }else if(m==4){
                ((ConcurrentMap)test).remove(k,v);
                assertEquals(k, rkey.get());
                assertEquals(null, rnewVal.get());
                assertEquals(v, roldVal.get());
            }else if(m==5){
                ((ConcurrentMap)test).replace(k,v,i*i);
                assertEquals(k, rkey.get());
                assertEquals(i*i, rnewVal.get());
                assertEquals(v, roldVal.get());
            }else if(m==5){
                ((ConcurrentMap)test).replace(k,i*i);
                assertEquals(k, rkey.get());
                assertEquals(i*i, rnewVal.get());
                assertEquals(v, roldVal.get());
            }



View Full Code Here

final public class Atom extends ARef{
final AtomicReference state;

public Atom(Object state){
  this.state = new AtomicReference(state);
}
View Full Code Here

  this.state = new AtomicReference(state);
}

public Atom(Object state, IPersistentMap meta){
  super(meta);
  this.state = new AtomicReference(state);
}
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.