use of org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl in project activemq-artemis by apache.
the class ActiveMQServerImpl method initialisePart1.
/**
* Starts everything apart from RemotingService and loading the data.
* <p>
* After optional intermediary steps, Part 1 is meant to be followed by part 2
* {@link #initialisePart2(boolean)}.
*
* @param scalingDown
*/
synchronized boolean initialisePart1(boolean scalingDown) throws Exception {
if (state == SERVER_STATE.STOPPED)
return false;
if (configuration.getJournalType() == JournalType.ASYNCIO) {
if (!AIOSequentialFileFactory.isSupported()) {
ActiveMQServerLogger.LOGGER.switchingNIO();
configuration.setJournalType(JournalType.NIO);
} else if (!AIOSequentialFileFactory.isSupported(configuration.getJournalLocation())) {
ActiveMQServerLogger.LOGGER.switchingNIOonPath(configuration.getJournalLocation().getAbsolutePath());
configuration.setJournalType(JournalType.NIO);
}
}
managementService = new ManagementServiceImpl(mbeanServer, configuration);
if (configuration.getMemoryMeasureInterval() != -1) {
memoryManager = new MemoryManager(configuration.getMemoryWarningThreshold(), configuration.getMemoryMeasureInterval());
memoryManager.start();
}
// Create the hard-wired components
callPreActiveCallbacks();
// startReplication();
storageManager = createStorageManager();
if (configuration.getClusterConfigurations().size() > 0 && ActiveMQDefaultConfiguration.getDefaultClusterUser().equals(configuration.getClusterUser()) && ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(configuration.getClusterPassword())) {
ActiveMQServerLogger.LOGGER.clusterSecurityRisk();
}
securityStore = new SecurityStoreImpl(securityRepository, securityManager, configuration.getSecurityInvalidationInterval(), configuration.isSecurityEnabled(), configuration.getClusterUser(), configuration.getClusterPassword(), managementService);
queueFactory = new QueueFactoryImpl(executorFactory, scheduledPool, addressSettingsRepository, storageManager, this);
pagingManager = createPagingManager();
resourceManager = new ResourceManagerImpl((int) (configuration.getTransactionTimeout() / 1000), configuration.getTransactionTimeoutScanPeriod(), scheduledPool);
postOffice = new PostOfficeImpl(this, storageManager, pagingManager, queueFactory, managementService, configuration.getMessageExpiryScanPeriod(), configuration.getMessageExpiryThreadPriority(), configuration.getWildcardConfiguration(), configuration.getIDCacheSize(), configuration.isPersistIDCache(), addressSettingsRepository);
// This can't be created until node id is set
clusterManager = new ClusterManager(executorFactory, this, postOffice, scheduledPool, managementService, configuration, nodeManager, haPolicy.isBackup());
backupManager = new BackupManager(this, executorFactory, scheduledPool, nodeManager, configuration, clusterManager);
clusterManager.deploy();
remotingService = new RemotingServiceImpl(clusterManager, configuration, this, managementService, scheduledPool, protocolManagerFactories, executorFactory.getExecutor(), serviceRegistry);
messagingServerControl = managementService.registerServer(postOffice, securityStore, storageManager, configuration, addressSettingsRepository, securityRepository, resourceManager, remotingService, this, queueFactory, scheduledPool, pagingManager, haPolicy.isBackup());
if (!scalingDown) {
deployAddressSettingsFromConfiguration();
}
storageManager.start();
postOffice.start();
pagingManager.start();
managementService.start();
resourceManager.start();
deploySecurityFromConfiguration();
deployGroupingHandlerConfiguration(configuration.getGroupingHandlerConfiguration());
this.reloadManager = new ReloadManagerImpl(getScheduledPool(), executorFactory.getExecutor(), configuration.getConfigurationFileRefreshPeriod());
if (configuration.getConfigurationUrl() != null && getScheduledPool() != null) {
reloadManager.addCallback(configuration.getConfigurationUrl(), new ConfigurationFileReloader());
}
return true;
}
use of org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl in project activemq-artemis by apache.
the class PostOfficeJournalLoader method initQueues.
@Override
public void initQueues(Map<Long, QueueBindingInfo> queueBindingInfosMap, List<QueueBindingInfo> queueBindingInfos) throws Exception {
int duplicateID = 0;
for (final QueueBindingInfo queueBindingInfo : queueBindingInfos) {
queueBindingInfosMap.put(queueBindingInfo.getId(), queueBindingInfo);
final Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());
final boolean isTopicIdentification = FilterUtils.isTopicIdentification(filter);
if (postOffice.getBinding(queueBindingInfo.getQueueName()) != null) {
if (isTopicIdentification) {
final long tx = storageManager.generateID();
storageManager.deleteQueueBinding(tx, queueBindingInfo.getId());
storageManager.commitBindings(tx);
continue;
} else {
final SimpleString newName = queueBindingInfo.getQueueName().concat("-" + (duplicateID++));
ActiveMQServerLogger.LOGGER.queueDuplicatedRenaming(queueBindingInfo.getQueueName().toString(), newName.toString());
queueBindingInfo.replaceQueueName(newName);
}
}
final QueueConfig.Builder queueConfigBuilder;
if (queueBindingInfo.getAddress() == null) {
queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName());
} else {
queueConfigBuilder = QueueConfig.builderWith(queueBindingInfo.getId(), queueBindingInfo.getQueueName(), queueBindingInfo.getAddress());
}
queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(queueBindingInfo.getUser()).durable(true).temporary(false).autoCreated(queueBindingInfo.isAutoCreated()).purgeOnNoConsumers(queueBindingInfo.isPurgeOnNoConsumers()).maxConsumers(queueBindingInfo.getMaxConsumers()).exclusive(queueBindingInfo.isExclusive()).lastValue(queueBindingInfo.isLastValue()).routingType(RoutingType.getType(queueBindingInfo.getRoutingType()));
final Queue queue = queueFactory.createQueueWith(queueConfigBuilder.build());
queue.setConsumersRefCount(new QueueManagerImpl(((PostOfficeImpl) postOffice).getServer(), queueBindingInfo.getQueueName()));
if (queueBindingInfo.getQueueStatusEncodings() != null) {
for (QueueStatusEncoding encoding : queueBindingInfo.getQueueStatusEncodings()) {
if (encoding.getStatus() == QueueStatus.PAUSED)
queue.reloadPause(encoding.getId());
}
}
final Binding binding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
queues.put(queue.getID(), queue);
postOffice.addBinding(binding);
managementService.registerQueue(queue, queue.getAddress(), storageManager);
}
}
use of org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl in project activemq-artemis by apache.
the class ScaleDownHandler method scaleDownMessages.
public long scaleDownMessages(ClientSessionFactory sessionFactory, SimpleString nodeId, String user, String password) throws Exception {
long messageCount = 0;
targetNodeId = nodeId != null ? nodeId.toString() : getTargetNodeId(sessionFactory);
try (ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, 0)) {
ClientProducer producer = session.createProducer();
// perform a loop per address
for (SimpleString address : postOffice.getAddresses()) {
logger.debug("Scaling down address " + address);
Bindings bindings = postOffice.getBindingsForAddress(address);
// It will get a list of queues on this address, ordered by the number of messages
Set<Queue> queues = new TreeSet<>(new OrderQueueByNumberOfReferencesComparator());
for (Binding binding : bindings.getBindings()) {
if (binding instanceof LocalQueueBinding) {
Queue queue = ((LocalQueueBinding) binding).getQueue();
// as part of scale down we will cancel any scheduled message and pass it to theWhile we scan for the queues we will also cancel any scheduled messages and deliver them right away
queue.deliverScheduledMessages();
queues.add(queue);
}
}
String sfPrefix = ((PostOfficeImpl) postOffice).getServer().getInternalNamingPrefix() + "sf.";
if (address.toString().startsWith(sfPrefix)) {
messageCount += scaleDownSNF(address, queues, producer);
} else {
messageCount += scaleDownRegularMessages(address, queues, session, producer);
}
}
}
return messageCount;
}
use of org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl in project activemq-artemis by apache.
the class DuplicateDetectionTest method testDuplicateIDCacheMemoryRetention.
public void testDuplicateIDCacheMemoryRetention(boolean temporary) throws Exception {
final int TEST_SIZE = 100;
locator = createInVMNonHALocator().setBlockOnNonDurableSend(true);
sf = createSessionFactory(locator);
ClientSession session = sf.createSession(false, true, true);
session.start();
Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
final SimpleString addressName = new SimpleString("DuplicateDetectionTestAddress");
for (int i = 0; i < TEST_SIZE; i++) {
final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue_" + i);
if (temporary) {
session.createTemporaryQueue(addressName, queueName, null);
} else {
session.createQueue(addressName, queueName, null, true);
}
ClientProducer producer = session.createProducer(addressName);
ClientConsumer consumer = session.createConsumer(queueName);
ClientMessage message = createMessage(session, 1);
SimpleString dupID = new SimpleString("abcdefg");
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
ClientMessage message2 = consumer.receive(1000);
Assert.assertEquals(1, message2.getObjectProperty(propKey));
message = createMessage(session, 2);
message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData());
producer.send(message);
message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
message = createMessage(session, 3);
message.putBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, dupID.getData());
producer.send(message);
message2 = consumer.receive(1000);
Assert.assertEquals(3, message2.getObjectProperty(propKey));
message = createMessage(session, 4);
message.putBytesProperty(Message.HDR_BRIDGE_DUPLICATE_ID, dupID.getData());
producer.send(message);
message2 = consumer.receiveImmediate();
Assert.assertNull(message2);
producer.close();
consumer.close();
// there will be 2 ID caches, one for messages using "_AMQ_DUPL_ID" and one for "_AMQ_BRIDGE_DUP"
Assert.assertEquals(2, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
session.deleteQueue(queueName);
Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
}
Assert.assertEquals(0, ((PostOfficeImpl) server.getPostOffice()).getDuplicateIDCaches().size());
}
use of org.apache.activemq.artemis.core.postoffice.impl.PostOfficeImpl in project activemq-artemis by apache.
the class LiveOnlyActivation method scaleDown.
public long scaleDown() throws Exception {
ScaleDownHandler scaleDownHandler = new ScaleDownHandler(activeMQServer.getPagingManager(), activeMQServer.getPostOffice(), activeMQServer.getNodeManager(), activeMQServer.getClusterManager().getClusterController(), activeMQServer.getStorageManager());
ConcurrentMap<SimpleString, DuplicateIDCache> duplicateIDCaches = ((PostOfficeImpl) activeMQServer.getPostOffice()).getDuplicateIDCaches();
Map<SimpleString, List<Pair<byte[], Long>>> duplicateIDMap = new HashMap<>();
for (SimpleString address : duplicateIDCaches.keySet()) {
DuplicateIDCache duplicateIDCache = activeMQServer.getPostOffice().getDuplicateIDCache(address);
duplicateIDMap.put(address, duplicateIDCache.getMap());
}
return scaleDownHandler.scaleDown(scaleDownClientSessionFactory, activeMQServer.getResourceManager(), duplicateIDMap, activeMQServer.getManagementService().getManagementAddress(), null);
}
Aggregations