use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class JournalStorageManager method recoverPendingLargeMessages.
/**
* Sets a list of large message files into the replicationManager for synchronization.
* <p>
* Collects a list of existing large messages and their current size, passing re.
* <p>
* So we know how much of a given message to sync with the backup. Further data appends to the
* messages will be replicated normally.
*
* @throws Exception
*/
private Map<Long, Pair<String, Long>> recoverPendingLargeMessages() throws Exception {
Map<Long, Pair<String, Long>> largeMessages = new HashMap<>();
// only send durable messages... // listFiles append a "." to anything...
List<String> filenames = largeMessagesFactory.listFiles("msg");
List<Long> idList = new ArrayList<>();
for (String filename : filenames) {
Long id = getLargeMessageIdFromFilename(filename);
if (!largeMessagesToDelete.contains(id)) {
idList.add(id);
SequentialFile seqFile = largeMessagesFactory.createSequentialFile(filename);
long size = seqFile.size();
largeMessages.put(id, new Pair<>(filename, size));
}
}
return largeMessages;
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class FileConfigurationParser method parseSecuritySettingPlugins.
private Pair<SecuritySettingPlugin, Map<String, String>> parseSecuritySettingPlugins(Node item) {
final String clazz = item.getAttributes().getNamedItem("class-name").getNodeValue();
final Map<String, String> settings = new HashMap<>();
NodeList children = item.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
final String nodeName = child.getNodeName();
if (SETTING_ELEMENT_NAME.equalsIgnoreCase(nodeName)) {
final String settingName = getAttributeValue(child, NAME_ATTR_NAME);
final String settingValue = getAttributeValue(child, VALUE_ATTR_NAME);
settings.put(settingName, settingValue);
}
}
SecuritySettingPlugin securitySettingPlugin = AccessController.doPrivileged(new PrivilegedAction<SecuritySettingPlugin>() {
@Override
public SecuritySettingPlugin run() {
return (SecuritySettingPlugin) ClassloadingUtil.newInstanceFromClassLoader(clazz);
}
});
return new Pair<>(securitySettingPlugin, settings);
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class FileConfigurationParser method parseSecurityRoles.
/**
* @param node
* @return
*/
protected Pair<String, Set<Role>> parseSecurityRoles(final Node node, final Map<String, Set<String>> roleMappings) {
final String match = node.getAttributes().getNamedItem("match").getNodeValue();
Set<Role> securityRoles = new HashSet<>();
Pair<String, Set<Role>> securityMatch = new Pair<>(match, securityRoles);
ArrayList<String> send = new ArrayList<>();
ArrayList<String> consume = new ArrayList<>();
ArrayList<String> createDurableQueue = new ArrayList<>();
ArrayList<String> deleteDurableQueue = new ArrayList<>();
ArrayList<String> createNonDurableQueue = new ArrayList<>();
ArrayList<String> deleteNonDurableQueue = new ArrayList<>();
ArrayList<String> manageRoles = new ArrayList<>();
ArrayList<String> browseRoles = new ArrayList<>();
ArrayList<String> createAddressRoles = new ArrayList<>();
ArrayList<String> deleteAddressRoles = new ArrayList<>();
ArrayList<String> allRoles = new ArrayList<>();
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
final String name = child.getNodeName();
if (PERMISSION_ELEMENT_NAME.equalsIgnoreCase(name)) {
final String type = getAttributeValue(child, TYPE_ATTR_NAME);
final String roleString = getAttributeValue(child, ROLES_ATTR_NAME);
String[] roles = roleString.split(",");
String[] mappedRoles = getMappedRoleNames(roles, roleMappings);
for (String role : mappedRoles) {
if (SEND_NAME.equals(type)) {
send.add(role.trim());
} else if (CONSUME_NAME.equals(type)) {
consume.add(role.trim());
} else if (CREATEDURABLEQUEUE_NAME.equals(type)) {
createDurableQueue.add(role.trim());
} else if (DELETEDURABLEQUEUE_NAME.equals(type)) {
deleteDurableQueue.add(role.trim());
} else if (CREATE_NON_DURABLE_QUEUE_NAME.equals(type)) {
createNonDurableQueue.add(role.trim());
} else if (DELETE_NON_DURABLE_QUEUE_NAME.equals(type)) {
deleteNonDurableQueue.add(role.trim());
} else if (CREATETEMPQUEUE_NAME.equals(type)) {
createNonDurableQueue.add(role.trim());
} else if (DELETETEMPQUEUE_NAME.equals(type)) {
deleteNonDurableQueue.add(role.trim());
} else if (MANAGE_NAME.equals(type)) {
manageRoles.add(role.trim());
} else if (BROWSE_NAME.equals(type)) {
browseRoles.add(role.trim());
} else if (CREATEADDRESS_NAME.equals(type)) {
createAddressRoles.add(role.trim());
} else if (DELETEADDRESS_NAME.equals(type)) {
deleteAddressRoles.add(role.trim());
} else {
ActiveMQServerLogger.LOGGER.rolePermissionConfigurationError(type);
}
if (!allRoles.contains(role.trim())) {
allRoles.add(role.trim());
}
}
}
}
for (String role : allRoles) {
securityRoles.add(new Role(role, send.contains(role), consume.contains(role), createDurableQueue.contains(role), deleteDurableQueue.contains(role), createNonDurableQueue.contains(role), deleteNonDurableQueue.contains(role), manageRoles.contains(role), browseRoles.contains(role), createAddressRoles.contains(role), deleteAddressRoles.contains(role)));
}
return securityMatch;
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class DuplicateDetectionUnitTest method testReloadDuplication.
// Public --------------------------------------------------------
@Test
public void testReloadDuplication() throws Exception {
JournalStorageManager journal = null;
try {
clearDataRecreateServerDirs();
SimpleString ADDRESS = new SimpleString("address");
Configuration configuration = createDefaultInVMConfig();
PostOffice postOffice = new FakePostOffice();
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<>();
FakePagingManager pagingManager = new FakePagingManager();
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(0, mapDups.size());
DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
for (int i = 0; i < 100; i++) {
cacheID.addToCache(RandomUtil.randomBytes());
}
journal.stop();
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(1, mapDups.size());
List<Pair<byte[], Long>> values = mapDups.get(ADDRESS);
Assert.assertEquals(10, values.size());
cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
cacheID.load(values);
for (int i = 0; i < 100; i++) {
cacheID.addToCache(RandomUtil.randomBytes(), null);
}
journal.stop();
mapDups.clear();
journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
Assert.assertEquals(1, mapDups.size());
values = mapDups.get(ADDRESS);
Assert.assertEquals(10, values.size());
scheduledThreadPool.shutdown();
} finally {
if (journal != null) {
try {
journal.stop();
} catch (Throwable ignored) {
}
}
}
}
use of org.apache.activemq.artemis.api.core.Pair in project activemq-artemis by apache.
the class MultiServerTestBase method setupLiveServer.
protected Pair<ActiveMQServer, NodeManager> setupLiveServer(final int node, final boolean realFiles, final boolean sharedStorage) throws Exception {
NodeManager nodeManager = null;
TransportConfiguration serverConfigAcceptor = createTransportConfiguration(useNetty(), true, generateParams(node, useNetty()));
TransportConfiguration thisConnector = createTransportConfiguration(useNetty(), false, generateParams(node, useNetty()));
if (sharedStorage) {
nodeManager = new InVMNodeManager(false);
}
Configuration configuration = createBasicConfig(node).setJournalMaxIO_AIO(1000).setThreadPoolMaxSize(10).clearAcceptorConfigurations().addAcceptorConfiguration(serverConfigAcceptor).addConnectorConfiguration("thisConnector", thisConnector).setHAPolicyConfiguration(sharedStorage ? new SharedStoreMasterPolicyConfiguration() : new ReplicatedPolicyConfiguration());
List<String> targetServersOnConnection = new ArrayList<>();
for (int targetNode = 0; targetNode < getNumberOfServers(); targetNode++) {
if (targetNode == node) {
continue;
}
String targetConnectorName = "target-" + targetNode;
TransportConfiguration targetServer = createTransportConfiguration(useNetty(), false, generateParams(targetNode, useNetty()));
configuration.getConnectorConfigurations().put(targetConnectorName, targetServer);
targetServersOnConnection.add(targetConnectorName);
// The connector towards a backup.. just to have a reference so bridges can connect to backups on their configs
String backupConnectorName = "backup-" + targetNode;
TransportConfiguration backupConnector = createTransportConfiguration(useNetty(), false, generateParams(targetNode + getNumberOfServers(), useNetty()));
configuration.getConnectorConfigurations().put(backupConnectorName, backupConnector);
}
ClusterConnectionConfiguration clusterConf = new ClusterConnectionConfiguration().setName("localCluster" + node).setAddress("cluster-queues").setConnectorName("thisConnector").setRetryInterval(100).setConfirmationWindowSize(1024).setMessageLoadBalancingType(MessageLoadBalancingType.ON_DEMAND).setStaticConnectors(targetServersOnConnection);
configuration.getClusterConfigurations().add(clusterConf);
ActiveMQServer server;
if (sharedStorage) {
server = createInVMFailoverServer(realFiles, configuration, nodeManager, node);
} else {
server = createServer(realFiles, configuration);
}
server.setIdentity(this.getClass().getSimpleName() + "/Live(" + node + ")");
addServer(server);
return new Pair<>(server, nodeManager);
}
Aggregations