use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class PagingOrderTest method testPagingOverCreatedDestinationQueues.
@Test
public void testPagingOverCreatedDestinationQueues() throws Exception {
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
ActiveMQServer server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
JMSServerManagerImpl jmsServer = new JMSServerManagerImpl(server);
InVMNamingContext context = new InVMNamingContext();
jmsServer.setRegistry(new JndiBindingRegistry(context));
jmsServer.start();
server.getActiveMQServerControl().addAddressSettings("Q1", "DLQ", "DLQ", -1, false, 5, 100 * 1024, 10 * 1024, 5, 5, 1, 1000, 0, false, "PAGE", -1, 10, "KILL", true, true, true, true);
jmsServer.createQueue(true, "Q1", null, true, "/queue/Q1");
ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
conn = cf.createConnection();
conn.setClientID("tst");
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = (javax.jms.Queue) context.lookup("/queue/Q1");
MessageProducer prod = sess.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
BytesMessage bmt = sess.createBytesMessage();
bmt.writeBytes(new byte[1024]);
for (int i = 0; i < 500; i++) {
prod.send(bmt);
}
PagingStore store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
assertEquals(100 * 1024, store.getMaxSize());
assertEquals(10 * 1024, store.getPageSizeBytes());
assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
jmsServer.stop();
server = createServer(true, config, -1, -1, new HashMap<String, AddressSettings>());
server.getAddressSettingsRepository().getMatch("#").setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
jmsServer = new JMSServerManagerImpl(server);
context = new InVMNamingContext();
jmsServer.setRegistry(new JndiBindingRegistry(context));
jmsServer.start();
AddressSettings settings = server.getAddressSettingsRepository().getMatch("Q1");
assertEquals(100 * 1024, settings.getMaxSizeBytes());
assertEquals(10 * 1024, settings.getPageSizeBytes());
assertEquals(AddressFullMessagePolicy.PAGE, settings.getAddressFullMessagePolicy());
store = server.getPagingManager().getPageStore(new SimpleString("Q1"));
assertEquals(100 * 1024, store.getMaxSize());
assertEquals(10 * 1024, store.getPageSizeBytes());
assertEquals(AddressFullMessagePolicy.PAGE, store.getAddressFullMessagePolicy());
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class AMQPSessionCallback method offerProducerCredit.
public void offerProducerCredit(final SimpleString address, final int credits, final int threshold, final Receiver receiver) {
try {
if (address == null) {
connection.lock();
try {
receiver.flow(credits);
} finally {
connection.unlock();
}
connection.flush();
return;
}
final PagingStore store = manager.getServer().getPagingManager().getPageStore(address);
store.checkMemory(new Runnable() {
@Override
public void run() {
connection.lock();
try {
if (receiver.getRemoteCredit() <= threshold) {
receiver.flow(credits);
}
} finally {
connection.unlock();
}
connection.flush();
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.activemq.artemis.core.paging.PagingStore in project activemq-artemis by apache.
the class AMQPSessionCallback method serverSend.
public void serverSend(final ProtonServerReceiverContext context, final Transaction transaction, final Receiver receiver, final Delivery delivery, SimpleString address, int messageFormat, byte[] data) throws Exception {
AMQPMessage message = new AMQPMessage(messageFormat, data, coreMessageObjectPools);
if (address != null) {
message.setAddress(address);
} else {
// Anonymous relay must set a To value
address = message.getAddressSimpleString();
if (address == null) {
rejectMessage(delivery, Symbol.valueOf("failed"), "Missing 'to' field for message sent to an anonymous producer");
return;
}
}
// here check queue-autocreation
RoutingType routingType = context.getRoutingType(receiver, address);
if (!bindingQuery(address, routingType)) {
throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.addressDoesntExist();
}
OperationContext oldcontext = recoverContext();
try {
PagingStore store = manager.getServer().getPagingManager().getPageStore(message.getAddressSimpleString());
if (store.isRejectingMessages()) {
// We drop pre-settled messages (and abort any associated Tx)
if (delivery.remotelySettled()) {
if (transaction != null) {
String amqpAddress = delivery.getLink().getTarget().getAddress();
ActiveMQException e = new ActiveMQAMQPResourceLimitExceededException("Address is full: " + amqpAddress);
transaction.markAsRollbackOnly(e);
}
} else {
rejectMessage(delivery, AmqpError.RESOURCE_LIMIT_EXCEEDED, "Address is full: " + address);
}
} else {
serverSend(transaction, message, delivery, receiver);
}
} finally {
resetContext(oldcontext);
}
}
Aggregations