private void addAckLocation(Transaction tx, StoredDestination sd, Long messageSequence, String subscriptionKey) throws IOException { SequenceSet sequences = sd.ackPositions.get(tx, subscriptionKey); if (sequences == null) { sequences = new SequenceSet(); sequences.add(messageSequence); sd.ackPositions.add(tx, subscriptionKey, sequences); } else { sequences.add(messageSequence); sd.ackPositions.put(tx, subscriptionKey, sequences); } }
@Override public synchronized Location addFirst(Transaction tx, String key, Location value) throws IOException { Location location = super.addFirst(tx, key, value); messageSize.addSize(value.getSize()); return location; }
synchronized public Value addFirst(Transaction tx, Key key, Value value) throws IOException { assertLoaded(); getHead(tx).addFirst(tx, key, value); size.incrementAndGet(); flushCache(); return null; }
protected ListNode<Key,Value> getHead(Transaction tx) throws IOException { return loadNode(tx, getHeadPageId()); }
synchronized public Value add(Transaction tx, Key key, Value value) throws IOException { assertLoaded(); getTail(tx).put(tx, key, value); size.incrementAndGet(); flushCache(); return null; }
final Page<ListNode<Key,Value>> p = tx.load(getHeadPageId(), null); if( p.getType() == Page.PAGE_FREE_TYPE ) { ListNode<Key, Value> root = createNode(p); storeNode(tx, root, true); setHeadPageId(p.getPageId()); setTailPageId(getHeadPageId()); } else { ListNode<Key, Value> node = loadNode(tx, getHeadPageId()); setTailPageId(getHeadPageId()); size.addAndGet(node.size(tx)); onLoad(node, tx); while (node.getNext() != NOT_SET ) { node = loadNode(tx, node.getNext()); size.addAndGet(node.size(tx)); onLoad(node, tx); setTailPageId(node.getPageId());
rc.subscriptions = new BTreeIndex<>(pageFile, tx.allocate()); rc.subscriptionAcks = new BTreeIndex<>(pageFile, tx.allocate()); rc.ackPositions = new ListIndex<>(pageFile, tx.allocate()); rc.subLocations = new ListIndex<>(pageFile, tx.allocate()); rc.subscriptionAcks.load(tx); rc.ackPositions.setKeyMarshaller(StringMarshaller.INSTANCE); rc.ackPositions.setValueMarshaller(SequenceSet.Marshaller.INSTANCE); rc.ackPositions.load(tx); rc.subLocations.setKeyMarshaller(StringMarshaller.INSTANCE); rc.subLocations.setValueMarshaller(LocationMarshaller.INSTANCE); rc.subLocations.load(tx); Iterator<Entry<String, SequenceSet>> subscriptions = rc.ackPositions.iterator(tx); while (subscriptions.hasNext()) { Entry<String, SequenceSet> subscription = subscriptions.next();
tx.free(sd.subscriptionAcks.getPageId()); sd.ackPositions.clear(tx); sd.ackPositions.unload(tx); tx.free(sd.ackPositions.getHeadPageId()); sd.subLocations.clear(tx); sd.subLocations.unload(tx); tx.free(sd.subLocations.getHeadPageId());
lastGetEntryCache.setValue(value); lastGetNodeCache.storeUpdate(tx); flushCache(); return oldValue; oldValue = entry.setValue(value); ((ListIterator) iterator).getCurrent().storeUpdate(tx); flushCache(); return oldValue; flushCache(); Iterator<Map.Entry<Key, Value>> iterator = iterator(tx); while (iterator.hasNext() && ((ListIterator) iterator).getCurrent() != lastGetNodeCache) { Map.Entry<Key, Value> entry = iterator.next(); oldValue = entry.setValue(value); ((ListIterator) iterator).getCurrent().storeUpdate(tx); flushCache(); return oldValue; flushCache(); return add(tx, key, value);
@Override synchronized public boolean containsKey(Transaction tx, Key key) throws IOException { assertLoaded(); if (size.get() == 0) { return false; } for (Iterator<Map.Entry<Key,Value>> iterator = iterator(tx); iterator.hasNext(); ) { Map.Entry<Key,Value> candidate = iterator.next(); if (key.equals(candidate.getKey())) { return true; } } return false; }
@Override @SuppressWarnings("rawtypes") synchronized public Value remove(Transaction tx, Key key) throws IOException { assertLoaded(); if (entry.getKey().equals(key)) { iterator.remove(); flushCache(); return entry.getValue(); flushCache(); Iterator<Map.Entry<Key, Value>> iterator = iterator(tx); while (iterator.hasNext() && ((ListIterator) iterator).getCurrent() != lastGetNodeCache) { Map.Entry<Key, Value> entry = iterator.next(); if (entry.getKey().equals(key)) { iterator.remove(); flushCache(); return entry.getValue();
private void split(Transaction tx, boolean isAddFirst) throws IOException { ListNode<Key, Value> extension = getContainingList().createNode(tx); if (isAddFirst) { // head keeps the first entry, insert extension with the rest extension.setEntries(entries.getHead().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); this.setNext(extension.getPageId()); } else { extension.setEntries(entries.getTail().getPrevious().splitAfter()); extension.setNext(this.getNext()); extension.store(tx, isAddFirst); getContainingList().setTailPageId(extension.getPageId()); this.setNext(extension.getPageId()); } store(tx, true); }
Iterator<Entry<String, Location>> iter = entry.getValue().subLocations.iterator(tx); while (iter.hasNext()) { Entry<String, Location> subscription = iter.next(); final StoredDestination destination = entry.getValue(); final String subscriptionKey = subscription.getKey(); SequenceSet pendingAcks = destination.ackPositions.get(tx, subscriptionKey); destination.subLocations.put( tx, subscriptionKey, checkpointSubscriptionCommand(kahaSub));
@Override synchronized public void clear(Transaction tx) throws IOException { for (Iterator<ListNode<Key,Value>> iterator = listNodeIterator(tx); iterator.hasNext(); ) { ListNode<Key,Value>candidate = iterator.next(); candidate.clear(tx); // break up the transaction tx.commit(); } flushCache(); size.set(0); }
@Override synchronized public Iterator<Map.Entry<Key,Value>> iterator(final Transaction tx) throws IOException { return getHead(tx).iterator(tx); }
public boolean isHead() { return getPageId() == containingList.getHeadPageId(); }
protected SequenceSet getSequenceSet(Transaction tx, StoredDestination sd, String subscriptionKey) throws IOException { if (sd.ackPositions != null) { final SequenceSet messageSequences = sd.ackPositions.get(tx, subscriptionKey); return messageSequences; } return null; }
@Override public synchronized void clear(Transaction tx) throws IOException { messageSize.reset(); super.clear(tx); }
@Override public synchronized Location add(Transaction tx, String key, Location value) throws IOException { Location location = super.add(tx, key, value); messageSize.addSize(value.getSize()); return location; }