@Override @Before public void setUp() throws Exception { super.setUp(); server = internalCreateServer(); server.createAddressInfo(new AddressInfo(ADDRESS, RoutingType.ANYCAST)); Queue queue = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false); queue.getPageSubscription().getPagingStore().startPaging(); for (int i = 0; i < 10; i++) { queue.getPageSubscription().getPagingStore().forceAnotherPage(); } final ClientSessionFactory sf = createSessionFactory(locator); ClientSession session = sf.createSession(null, null, false, true, true, false, 0); ClientProducer prod = session.createProducer(ADDRESS); for (int i = 0; i < 500; i++) { ClientMessage msg = session.createMessage(true); msg.putIntProperty("key", i); prod.send(msg); if (i > 0 && i % 10 == 0) { session.commit(); } } session.close(); locator.close(); server.stop(); internalCreateServer(); }
/** * This is done to prevent non tx to get out of sync in case of failures * * @param tx * @param page * @param ctx * @throws Exception */ private void applyPageCounters(Transaction tx, Page page, RouteContextList ctx) throws Exception { List<org.apache.activemq.artemis.core.server.Queue> durableQueues = ctx.getDurableQueues(); List<org.apache.activemq.artemis.core.server.Queue> nonDurableQueues = ctx.getNonDurableQueues(); for (org.apache.activemq.artemis.core.server.Queue q : durableQueues) { if (tx == null) { // non transactional writes need an intermediate place // to avoid the counter getting out of sync q.getPageSubscription().getCounter().pendingCounter(page, 1); } else { // null tx is treated through pending counters q.getPageSubscription().getCounter().increment(tx, 1); } } for (org.apache.activemq.artemis.core.server.Queue q : nonDurableQueues) { q.getPageSubscription().getCounter().increment(tx, 1); } }
private long[] routeQueues(Transaction tx, RouteContextList ctx) throws Exception { List<org.apache.activemq.artemis.core.server.Queue> durableQueues = ctx.getDurableQueues(); List<org.apache.activemq.artemis.core.server.Queue> nonDurableQueues = ctx.getNonDurableQueues(); long[] ids = new long[durableQueues.size() + nonDurableQueues.size()]; int i = 0; for (org.apache.activemq.artemis.core.server.Queue q : durableQueues) { q.getPageSubscription().notEmpty(); ids[i++] = q.getID(); } for (org.apache.activemq.artemis.core.server.Queue q : nonDurableQueues) { q.getPageSubscription().getCounter().increment(tx, 1); q.getPageSubscription().notEmpty(); ids[i++] = q.getID(); } return ids; }