use of org.apache.activemq.artemis.core.paging.PagingManager in project activemq-artemis by apache.
the class ActiveMQServerImpl method createQueue.
public Queue createQueue(final AddressInfo addrInfo, final SimpleString queueName, final SimpleString filterString, final SimpleString user, final boolean durable, final boolean temporary, final boolean ignoreIfExists, final boolean transientQueue, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, final boolean exclusive, final boolean lastValue, final boolean autoCreateAddress) throws Exception {
final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueName);
if (binding != null) {
if (ignoreIfExists) {
return binding.getQueue();
} else {
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName, binding.getAddress());
}
}
final Filter filter = FilterImpl.createFilter(filterString);
final long txID = storageManager.generateID();
final long queueID = storageManager.generateID();
final QueueConfig.Builder queueConfigBuilder;
final SimpleString addressToUse = addrInfo == null ? queueName : addrInfo.getName();
queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, addressToUse);
AddressInfo info = postOffice.getAddressInfo(addressToUse);
RoutingType routingType = addrInfo == null ? null : addrInfo.getRoutingType();
RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType);
if (autoCreateAddress) {
if (info == null) {
final AddressInfo addressInfo = new AddressInfo(addressToUse, rt);
addressInfo.setAutoCreated(true);
addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal());
addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(rt)) {
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.add(rt);
updateAddressInfo(info.getName(), routingTypes);
}
} else if (info == null) {
throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressToUse);
} else if (!info.getRoutingTypes().contains(rt)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(rt, info.getName().toString(), info.getRoutingTypes());
}
final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(addrInfo.getRoutingType()).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateQueue(queueConfig) : null);
final Queue queue = queueFactory.createQueueWith(queueConfig);
if (transientQueue) {
queue.setConsumersRefCount(new TransientQueueManagerImpl(this, queue.getName()));
} else {
queue.setConsumersRefCount(new QueueManagerImpl(this, queue.getName()));
}
final QueueBinding localQueueBinding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
if (queue.isDurable()) {
storageManager.addQueueBinding(txID, localQueueBinding);
}
try {
postOffice.addBinding(localQueueBinding);
if (queue.isDurable()) {
storageManager.commitBindings(txID);
}
} catch (Exception e) {
try {
if (durable) {
storageManager.rollbackBindings(txID);
}
final PageSubscription pageSubscription = queue.getPageSubscription();
try {
queue.close();
} finally {
if (pageSubscription != null) {
pageSubscription.destroy();
}
}
} catch (Throwable ignored) {
logger.debug(ignored.getMessage(), ignored);
}
throw e;
}
if (addrInfo == null || !addrInfo.isInternal()) {
managementService.registerQueue(queue, queue.getAddress(), storageManager);
}
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterCreateQueue(queue) : null);
callPostQueueCreationCallbacks(queue.getName());
return queue;
}
use of org.apache.activemq.artemis.core.paging.PagingManager in project activemq-artemis by apache.
the class ActiveMQServerImpl method createQueue.
@Override
public Queue createQueue(final SimpleString address, final RoutingType routingType, final SimpleString queueName, final SimpleString filterString, final SimpleString user, final boolean durable, final boolean temporary, final boolean ignoreIfExists, final boolean transientQueue, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, final boolean exclusive, final boolean lastValue, final boolean autoCreateAddress) throws Exception {
final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueName);
if (binding != null) {
if (ignoreIfExists) {
return binding.getQueue();
} else {
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName, binding.getAddress());
}
}
final Filter filter = FilterImpl.createFilter(filterString);
final long txID = storageManager.generateID();
final long queueID = storageManager.generateID();
final QueueConfig.Builder queueConfigBuilder;
final SimpleString addressToUse = address == null ? queueName : address;
queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, addressToUse);
AddressInfo info = postOffice.getAddressInfo(addressToUse);
if (autoCreateAddress) {
RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType);
if (info == null) {
final AddressInfo addressInfo = new AddressInfo(addressToUse, rt);
addressInfo.setAutoCreated(true);
addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(routingType)) {
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.add(routingType);
updateAddressInfo(info.getName(), routingTypes);
}
} else if (info == null) {
throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressToUse);
} else if (!info.getRoutingTypes().contains(routingType)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(routingType, info.getName().toString(), info.getRoutingTypes());
}
final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(routingType).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateQueue(queueConfig) : null);
final Queue queue = queueFactory.createQueueWith(queueConfig);
if (transientQueue) {
queue.setConsumersRefCount(new TransientQueueManagerImpl(this, queue.getName()));
} else {
queue.setConsumersRefCount(new QueueManagerImpl(this, queue.getName()));
}
final QueueBinding localQueueBinding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
if (queue.isDurable()) {
storageManager.addQueueBinding(txID, localQueueBinding);
}
try {
postOffice.addBinding(localQueueBinding);
if (queue.isDurable()) {
storageManager.commitBindings(txID);
}
} catch (Exception e) {
try {
if (durable) {
storageManager.rollbackBindings(txID);
}
final PageSubscription pageSubscription = queue.getPageSubscription();
try {
queue.close();
} finally {
if (pageSubscription != null) {
pageSubscription.destroy();
}
}
} catch (Throwable ignored) {
logger.debug(ignored.getMessage(), ignored);
}
throw e;
}
managementService.registerQueue(queue, queue.getAddress(), storageManager);
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterCreateQueue(queue) : null);
callPostQueueCreationCallbacks(queue.getName());
return queue;
}
use of org.apache.activemq.artemis.core.paging.PagingManager in project activemq-artemis by apache.
the class PagingTest method testSyncPage.
@Test
public void testSyncPage() throws Exception {
Configuration config = createDefaultInVMConfig();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
try {
server.addAddressInfo(new AddressInfo(PagingTest.ADDRESS, RoutingType.ANYCAST));
server.createQueue(PagingTest.ADDRESS, RoutingType.ANYCAST, PagingTest.ADDRESS, null, true, false);
final CountDownLatch pageUp = new CountDownLatch(0);
final CountDownLatch pageDone = new CountDownLatch(1);
OperationContext ctx = new DummyOperationContext(pageUp, pageDone);
OperationContextImpl.setContext(ctx);
PagingManager paging = server.getPagingManager();
PagingStore store = paging.getPageStore(ADDRESS);
store.sync();
assertTrue(pageUp.await(10, TimeUnit.SECONDS));
assertTrue(pageDone.await(10, TimeUnit.SECONDS));
server.stop();
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
OperationContextImpl.clearContext();
}
}
use of org.apache.activemq.artemis.core.paging.PagingManager in project activemq-artemis by apache.
the class PagingTest method testSyncPageTX.
@Test
public void testSyncPageTX() throws Exception {
Configuration config = createDefaultInVMConfig();
server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
server.start();
server.createQueue(PagingTest.ADDRESS, RoutingType.ANYCAST, PagingTest.ADDRESS, null, true, false);
final CountDownLatch pageUp = new CountDownLatch(0);
final CountDownLatch pageDone = new CountDownLatch(1);
OperationContext ctx = new DummyOperationContext(pageUp, pageDone);
OperationContextImpl.setContext(ctx);
PagingManager paging = server.getPagingManager();
PagingStore store = paging.getPageStore(ADDRESS);
store.sync();
assertTrue(pageUp.await(10, TimeUnit.SECONDS));
assertTrue(pageDone.await(10, TimeUnit.SECONDS));
}
use of org.apache.activemq.artemis.core.paging.PagingManager in project activemq-artemis by apache.
the class PrintData method printPages.
private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) {
try {
ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory());
final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory());
ExecutorFactory execfactory = new ExecutorFactory() {
@Override
public ArtemisExecutor getExecutor() {
return ArtemisExecutor.delegate(executor);
}
};
final StorageManager sm = new NullStorageManager();
PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null);
HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>();
addressSettingsRepository.setDefault(new AddressSettings());
PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
printPages(describeJournal, sm, manager, out, safe);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations