Atomically updated variable which may contain any type of record.
| 710 | * Atomically updated variable which may contain any type of record. |
| 711 | */ |
| 712 | public static final class Var<E> { |
| 713 | |
| 714 | protected final Store store; |
| 715 | protected final long recid; |
| 716 | protected final Serializer<E> serializer; |
| 717 | |
| 718 | public Var(Store store, long recid, Serializer<E> serializer) { |
| 719 | this.store = store; |
| 720 | this.recid = recid; |
| 721 | this.serializer = serializer; |
| 722 | } |
| 723 | // |
| 724 | // /* used for deserialization */ |
| 725 | // protected Var(Store store, SerializerBase serializerBase, DataInput is, SerializerBase.FastArrayList<Object> objectStack) throws IOException { |
| 726 | // objectStack.add(this); |
| 727 | // this.store = store; |
| 728 | // this.recid = DataIO.unpackLong(is); |
| 729 | // this.serializer = (Serializer<E>) serializerBase.deserialize(is,objectStack); |
| 730 | // } |
| 731 | |
| 732 | /** |
| 733 | * @return recid under which value is saved |
| 734 | */ |
| 735 | public long getRecid(){ |
| 736 | return recid; |
| 737 | } |
| 738 | |
| 739 | |
| 740 | public java.lang.String toString() { |
| 741 | E v = get(); |
| 742 | return v==null? null : v.toString(); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Returns the current value. |
| 747 | * |
| 748 | * @return the current value |
| 749 | */ |
| 750 | public final E get() { |
| 751 | return store.get(recid, serializer); |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * Atomically sets the value to the given updated value |
| 756 | * if the current value equals the expected value. |
| 757 | * |
| 758 | * @param expect the expected value |
| 759 | * @param update the new value |
| 760 | * @return true if successful. False return indicates that |
| 761 | * the actual value was not equal to the expected value. |
| 762 | */ |
| 763 | public final boolean compareAndSet(E expect, E update) { |
| 764 | return store.compareAndSwap(recid, expect, update, serializer); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | /** |
| 769 | * Unconditionally sets to the given value. |
nothing calls this directly
no outgoing calls
no test coverage detected