| 44 | |
| 45 | // Remove the top element from the queue. |
| 46 | public static Object dequeue(TransactionContext tcx){ |
| 47 | // Remove from the top of the queue. |
| 48 | return tcx.run(new Function<Transaction,Void>(){ |
| 49 | public Void apply(Transaction tr){ |
| 50 | final KeyValue item = firstItem(tr); |
| 51 | if(item == null){ |
| 52 | return null; |
| 53 | } |
| 54 | |
| 55 | tr.clear(item.getKey()); |
| 56 | // Return the old value. |
| 57 | return Tuple.fromBytes(item.getValue()).get(0); |
| 58 | } |
| 59 | }); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | // Add an element to the queue. |
| 64 | public static void enqueue(TransactionContext tcx, final Object value){ |