protected void process(final KahaRemoveDestinationCommand command, final Location location) throws IOException { this.indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { updateIndex(tx, command, location); } }); } finally { this.indexLock.writeLock().unlock(); } }
protected void process(final KahaSubscriptionCommand command, final Location location) throws IOException { this.indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { updateIndex(tx, command, location); } }); } finally { this.indexLock.writeLock().unlock(); } }
protected void process(final KahaUpdateMessageCommand command, final Location location) throws IOException { this.indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { updateIndex(tx, command, location); } }); } finally { this.indexLock.writeLock().unlock(); } }
private Location findMessageLocation(final String key, final KahaDestination destination) throws IOException { return pageFile.tx().execute(new Transaction.CallableClosure<Location, IOException>() { @Override public Location execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(destination, tx); Long sequence = sd.messageIdIndex.get(tx, key); if (sequence == null) { return null; } return sd.orderIndex.get(tx, sequence).location; } }); }
@Override public boolean isEmpty() throws IOException { indexLock.writeLock().lock(); try { return pageFile.tx().execute(new Transaction.CallableClosure<Boolean, IOException>() { @Override public Boolean execute(Transaction tx) throws IOException { // Iterate through all index entries to get a count of // messages in the destination. StoredDestination sd = getStoredDestination(dest, tx); return sd.locationIndex.isEmpty(tx); } }); } finally { indexLock.writeLock().unlock(); } }
@Override public void recover(final MessageRecoveryListener listener) throws Exception { synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<Exception>(){ @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<Long, MessageRecord>> iterator = sd.orderIndex.iterator(tx); iterator.hasNext();) { Entry<Long, MessageRecord> entry = iterator.next(); listener.recoverMessage( (Message) wireFormat.unmarshal(entry.getValue().data) ); } } }); } }
@Override public void setBatch(final MessageId identity) throws IOException { indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); Long location = (Long) identity.getFutureOrSequenceLong(); Long pending = sd.orderIndex.minPendingAdd(); if (pending != null) { location = Math.min(location, pending-1); } sd.orderIndex.setBatch(tx, location); } }); } finally { indexLock.writeLock().unlock(); } }
@Override public void recoverNextMessages(final int maxReturned, final MessageRecoveryListener listener) throws Exception { synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<Exception>(){ @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); Entry<Long, MessageRecord> entry=null; int counter = 0; for (Iterator<Entry<Long, MessageRecord>> iterator = sd.orderIndex.iterator(tx, cursorPos); iterator.hasNext();) { entry = iterator.next(); listener.recoverMessage( (Message) wireFormat.unmarshal(entry.getValue().data ) ); counter++; if( counter >= maxReturned ) { break; } } if( entry!=null ) { cursorPos = entry.getKey()+1; } } }); } }
@Override public void recover(final MessageRecoveryListener listener) throws Exception { // recovery may involve expiry which will modify indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); recoverRolledBackAcks(sd, tx, Integer.MAX_VALUE, listener); sd.orderIndex.resetCursorPosition(); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); listener.hasSpace() && iterator .hasNext(); ) { Entry<Long, MessageKeys> entry = iterator.next(); if (ackedAndPrepared.contains(entry.getValue().messageId)) { continue; } Message msg = loadMessage(entry.getValue().location); listener.recoverMessage(msg); } } }); } finally { indexLock.writeLock().unlock(); } }
public void processCommit(TransactionId key) throws IOException { synchronized (indexMutex) { ArrayList<Operation> inflightTx = inflightTransactions.remove(key); if (inflightTx == null) { inflightTx = preparedTransactions.remove(key); } if (inflightTx == null) { return; } final ArrayList<Operation> messagingTx = inflightTx; pageFile.tx().execute(new Transaction.Closure<IOException>() { public void execute(Transaction tx) throws IOException { for (Operation op : messagingTx) { op.execute(tx); } } }); } }
@Override public Set<ActiveMQDestination> getDestinations() { try { final HashSet<ActiveMQDestination> rc = new HashSet<ActiveMQDestination>(); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { for (Iterator<Entry<String, StoredDestination>> iterator = metadata.destinations.iterator(tx); iterator .hasNext();) { Entry<String, StoredDestination> entry = iterator.next(); //Removing isEmpty topic check - see AMQ-5875 rc.add(convert(entry.getKey())); } } }); }finally { indexLock.writeLock().unlock(); } return rc; } catch (IOException e) { throw new RuntimeException(e); } }
public boolean remove(final String id) throws IOException { final AtomicBoolean result = new AtomicBoolean(); synchronized (indexLock) { this.store.getPageFile().tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { result.set(remove(tx, id) != null); } }); } return result.get(); }
@Override public SubscriptionInfo[] getAllSubscriptions() throws IOException { final ArrayList<SubscriptionInfo> subscriptions = new ArrayList<SubscriptionInfo>(); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<String, KahaSubscriptionCommand>> iterator = sd.subscriptions.iterator(tx); iterator .hasNext();) { Entry<String, KahaSubscriptionCommand> entry = iterator.next(); SubscriptionInfo info = (SubscriptionInfo) wireFormat.unmarshal(new DataInputStream(entry .getValue().getSubscriptionInfo().newInput())); subscriptions.add(info); } } }); } finally { indexLock.writeLock().unlock(); } SubscriptionInfo[] rc = new SubscriptionInfo[subscriptions.size()]; subscriptions.toArray(rc); return rc; }
@Override public void recoverNextMessages(final int maxReturned, final MessageRecoveryListener listener) throws Exception { indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<Exception>() { @Override public void execute(Transaction tx) throws Exception { StoredDestination sd = getStoredDestination(dest, tx); Entry<Long, MessageKeys> entry = null; int counter = recoverRolledBackAcks(sd, tx, maxReturned, listener); for (Iterator<Entry<Long, MessageKeys>> iterator = sd.orderIndex.iterator(tx); iterator.hasNext(); ) { entry = iterator.next(); if (ackedAndPrepared.contains(entry.getValue().messageId)) { continue; } Message msg = loadMessage(entry.getValue().location); msg.getMessageId().setFutureOrSequenceLong(entry.getKey()); listener.recoverMessage(msg); counter++; if (counter >= maxReturned || !listener.canRecoveryNextMessage()) { break; } } sd.orderIndex.stoppedIterating(); } }); } finally { indexLock.writeLock().unlock(); } }
@Override public Set<ActiveMQDestination> getDestinations() { try { final HashSet<ActiveMQDestination> rc = new HashSet<ActiveMQDestination>(); synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<IOException>(){ @Override public void execute(Transaction tx) throws IOException { for (Iterator<Entry<String, StoredDestination>> iterator = destinations.iterator(tx); iterator.hasNext();) { Entry<String, StoredDestination> entry = iterator.next(); rc.add(convert(entry.getKey())); } } }); } return rc; } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void resetBatching(String clientId, String subscriptionName) { try { final String subscriptionKey = subscriptionKey(clientId, subscriptionName); indexLock.writeLock().lock(); try { pageFile.tx().execute(new Transaction.Closure<IOException>() { @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); sd.subscriptionCursors.remove(subscriptionKey); } }); }finally { indexLock.writeLock().unlock(); } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public SubscriptionInfo[] getAllSubscriptions() throws IOException { final ArrayList<SubscriptionInfo> subscriptions = new ArrayList<SubscriptionInfo>(); synchronized(indexMutex) { pageFile.tx().execute(new Transaction.Closure<IOException>(){ @Override public void execute(Transaction tx) throws IOException { StoredDestination sd = getStoredDestination(dest, tx); for (Iterator<Entry<String, KahaSubscriptionCommand>> iterator = sd.subscriptions.iterator(tx); iterator.hasNext();) { Entry<String, KahaSubscriptionCommand> entry = iterator.next(); SubscriptionInfo info = (SubscriptionInfo)wireFormat.unmarshal( new DataInputStream(entry.getValue().getSubscriptionInfo().newInput()) ); subscriptions.add(info); } } }); } SubscriptionInfo[]rc=new SubscriptionInfo[subscriptions.size()]; subscriptions.toArray(rc); return rc; }