Java Code Examples for org.apache.activemq.artemis.api.core.SimpleString#equals()
The following examples show how to use
org.apache.activemq.artemis.api.core.SimpleString#equals() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageUtil.java From activemq-artemis with Apache License 2.0 | 6 votes |
public static Set<String> getPropertyNames(Message message) { HashSet<String> set = new HashSet<>(); for (SimpleString propName : message.getPropertyNames()) { if (propName.equals(Message.HDR_GROUP_ID)) { set.add(MessageUtil.JMSXGROUPID); } else if (propName.equals(Message.HDR_GROUP_SEQUENCE)) { set.add(MessageUtil.JMSXGROUPSEQ); } else if (propName.equals(Message.HDR_VALIDATED_USER)) { set.add(MessageUtil.JMSXUSERID); } else if ((!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_)) && !propName.startsWith(CONNECTION_ID_PROPERTY_NAME) && !propName.equals(Message.HDR_ROUTING_TYPE) && !propName.startsWith(Message.HDR_ROUTE_TO_IDS)) { set.add(propName.toString()); } } set.add(JMSXDELIVERYCOUNT); return set; }
Example 2
Source File: PagingStoreFactoryDatabase.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Override public synchronized void removeFileFactory(SequentialFileFactory fileFactory) throws Exception { ((JDBCSequentialFileFactory)fileFactory).destroy(); String tableName = factoryToTableName.remove(fileFactory); if (tableName != null) { SimpleString removeTableName = SimpleString.toSimpleString(tableName); JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); directoryList.open(); int size = ((Long) directoryList.size()).intValue(); ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size); ActiveMQBuffer writeBuffer = ActiveMQBuffers.fixedBuffer(size); while (buffer.readableBytes() > 0) { SimpleString table = buffer.readSimpleString(); if (!removeTableName.equals(table)) { writeBuffer.writeSimpleString(table); } } directoryList.write(writeBuffer, true, null, false); directoryList.close(); } }
Example 3
Source File: SimpleTransformer.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Message transform(final Message messageParameter) { ICoreMessage message = messageParameter.toCore(); SimpleString oldProp = (SimpleString) message.getObjectProperty(new SimpleString("wibble")); if (!oldProp.equals(new SimpleString("bing"))) { throw new IllegalStateException("Wrong property value!!"); } // Change a property message.putStringProperty(new SimpleString("wibble"), new SimpleString("bong")); // Change the body ActiveMQBuffer buffer = message.getBodyBuffer(); buffer.readerIndex(0); String str = buffer.readString(); if (!str.equals("doo be doo be doo be doo")) { throw new IllegalStateException("Wrong body!!"); } buffer.clear(); buffer.writeString("dee be dee be dee be dee"); return message; }
Example 4
Source File: CoreMessage.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public CoreMessage setAddress(SimpleString address) { if (address == null && this.address == null) { // no-op so just return return this; } if (validBuffer && (address == null || !address.equals(this.address))) { messageChanged(); } this.address = address; return this; }
Example 5
Source File: MQTTSubscriptionManager.java From activemq-artemis with Apache License 2.0 | 5 votes |
private Queue findOrCreateQueue(BindingQueryResult bindingQueryResult, AddressInfo addressInfo, SimpleString queue, int qos) throws Exception { if (addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST)) { return session.getServerSession().createQueue(new QueueConfiguration(queue).setAddress(addressInfo.getName()).setFilterString(managementFilter).setDurable(MQTTUtil.DURABLE_MESSAGES && qos >= 0)); } if (addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST)) { if (!bindingQueryResult.getQueueNames().isEmpty()) { SimpleString name = null; for (SimpleString qName : bindingQueryResult.getQueueNames()) { if (name == null) { name = qName; } else if (qName.equals(addressInfo.getName())) { name = qName; } } return session.getServer().locateQueue(name); } else { try { return session.getServerSession().createQueue(new QueueConfiguration(addressInfo.getName()).setRoutingType(RoutingType.ANYCAST).setFilterString(managementFilter).setDurable(MQTTUtil.DURABLE_MESSAGES && qos >= 0)); } catch (ActiveMQQueueExistsException e) { return session.getServer().locateQueue(addressInfo.getName()); } } } Set<RoutingType> routingTypeSet = new HashSet(); routingTypeSet.add(RoutingType.MULTICAST); routingTypeSet.add(RoutingType.ANYCAST); throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(addressInfo.getRoutingType(), addressInfo.getName().toString(), routingTypeSet); }
Example 6
Source File: QueueImpl.java From activemq-artemis with Apache License 2.0 | 5 votes |
private SimpleString expiryAddressFromMessageAddress(MessageReference ref) { SimpleString messageAddress = extractAddress(ref.getMessage()); SimpleString expiryAddress = null; if (messageAddress == null || messageAddress.equals(getAddress())) { expiryAddress = getExpiryAddress(); } return expiryAddress; }
Example 7
Source File: ActiveMQServerImpl.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Divert updateDivert(DivertConfiguration config) throws Exception { final DivertBinding divertBinding = (DivertBinding) postOffice.getBinding(SimpleString.toSimpleString(config.getName())); if (divertBinding == null) { return null; } final Divert divert = divertBinding.getDivert(); Filter filter = FilterImpl.createFilter(config.getFilterString()); if (filter != null && !filter.equals(divert.getFilter())) { divert.setFilter(filter); } if (config.getTransformerConfiguration() != null) { getServiceRegistry().removeDivertTransformer(divert.getUniqueName().toString()); Transformer transformer = getServiceRegistry().getDivertTransformer( config.getName(), config.getTransformerConfiguration()); divert.setTransformer(transformer); } if (config.getForwardingAddress() != null) { SimpleString forwardAddress = SimpleString.toSimpleString(config.getForwardingAddress()); if (!forwardAddress.equals(config)) { divert.setForwardAddress(forwardAddress); } } if (config.getRoutingType() != null && divert.getRoutingType() != config.getRoutingType()) { divert.setRoutingType(config.getRoutingType()); } return divert; }
Example 8
Source File: TypedProperties.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * Performs a search among the valid key properties contained in {@code buffer}, starting from {@code from} * assuming it to be a valid encoded {@link TypedProperties} content. * * @throws IllegalStateException if any not-valid property is found while searching the {@code key} property */ public static boolean searchProperty(SimpleString key, ByteBuf buffer, int startIndex) { // It won't implement a straight linear search for key // because it would risk to find a SimpleString encoded property value // equals to the key we're searching for! int index = startIndex; byte b = buffer.getByte(index); index++; if (b == DataConstants.NULL) { return false; } final int numHeaders = buffer.getInt(index); index += Integer.BYTES; for (int i = 0; i < numHeaders; i++) { final int keyLength = buffer.getInt(index); index += Integer.BYTES; if (key.equals(buffer, index, keyLength)) { return true; } if (i == numHeaders - 1) { return false; } index += keyLength; byte type = buffer.getByte(index); index++; switch (type) { case NULL: { break; } case CHAR: case SHORT: { index += Short.BYTES; break; } case BOOLEAN: case BYTE: { index += Byte.BYTES; break; } case BYTES: case STRING: { index += (Integer.BYTES + buffer.getInt(index)); break; } case INT: { index += Integer.BYTES; break; } case LONG: { index += Long.BYTES; break; } case FLOAT: { index += Float.BYTES; break; } case DOUBLE: { index += Double.BYTES; break; } default: { throw ActiveMQUtilBundle.BUNDLE.invalidType(type); } } } return false; }
Example 9
Source File: StompUtils.java From activemq-artemis with Apache License 2.0 | 4 votes |
public static void copyStandardHeadersFromMessageToFrame(Message message, StompFrame command, int deliveryCount) throws Exception { command.addHeader(Stomp.Headers.Message.MESSAGE_ID, String.valueOf(message.getMessageID())); SimpleString prefix = message.getSimpleStringProperty(Message.HDR_PREFIX); command.addHeader(Stomp.Headers.Message.DESTINATION, (prefix == null ? "" : prefix) + message.getAddress()); if (message.getObjectProperty(MessageUtil.CORRELATIONID_HEADER_NAME) != null) { command.addHeader(Stomp.Headers.Message.CORRELATION_ID, message.getObjectProperty(MessageUtil.CORRELATIONID_HEADER_NAME).toString()); } command.addHeader(Stomp.Headers.Message.EXPIRATION_TIME, "" + message.getExpiration()); command.addHeader(Stomp.Headers.Message.REDELIVERED, String.valueOf(deliveryCount > 1)); command.addHeader(Stomp.Headers.Message.PRIORITY, "" + message.getPriority()); command.addHeader(Stomp.Headers.Message.PERSISTENT, "" + message.isDurable()); if (message.getStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME) != null) { command.addHeader(Stomp.Headers.Message.REPLY_TO, message.getStringProperty(ClientMessageImpl.REPLYTO_HEADER_NAME)); } command.addHeader(Stomp.Headers.Message.TIMESTAMP, "" + message.getTimestamp()); if (message.getObjectProperty(MessageUtil.TYPE_HEADER_NAME) != null) { command.addHeader(Stomp.Headers.Message.TYPE, message.getObjectProperty(MessageUtil.TYPE_HEADER_NAME).toString()); } if (message.getStringProperty(Message.HDR_CONTENT_TYPE.toString()) != null) { command.addHeader(Stomp.Headers.CONTENT_TYPE, message.getStringProperty(Message.HDR_CONTENT_TYPE.toString())); } if (message.getValidatedUserID() != null) { command.addHeader(Stomp.Headers.Message.VALIDATED_USER, message.getValidatedUserID()); } if (message.containsProperty(Message.HDR_ROUTING_TYPE)) { command.addHeader(Stomp.Headers.Send.DESTINATION_TYPE, RoutingType.getType(message.getByteProperty(Message.HDR_ROUTING_TYPE.toString())).toString()); } // now let's add all the rest of the message headers Set<SimpleString> names = message.getPropertyNames(); for (SimpleString name : names) { if (name.equals(ClientMessageImpl.REPLYTO_HEADER_NAME) || name.equals(Message.HDR_CONTENT_TYPE) || name.equals(Message.HDR_VALIDATED_USER) || name.equals(Message.HDR_ROUTING_TYPE) || name.equals(Message.HDR_PREFIX) || name.equals(MessageUtil.TYPE_HEADER_NAME) || name.equals(MessageUtil.CORRELATIONID_HEADER_NAME) || name.toString().equals(Stomp.Headers.Message.DESTINATION)) { continue; } command.addHeader(name.toString(), message.getObjectProperty(name).toString()); } }
Example 10
Source File: AddressImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
/** * This method should actually be called `isMatchedBy`. * * @return `true` if this equals otherAddr or this address is matched by a pattern represented by otherAddr */ @Override public boolean matches(final Address otherAddr) { if (otherAddr == null) return false; if (address.equals(otherAddr.getAddress())) return true; final char sepAnyWords = wildcardConfiguration.getAnyWords(); final char sepSingleWord = wildcardConfiguration.getSingleWord(); final int thisAddrPartsLen = addressParts.length; final int thisAddrPartsLastIdx = thisAddrPartsLen - 1; final SimpleString[] otherAddrParts = otherAddr.getAddressParts(); final int otherAddrPartsLen = otherAddrParts.length; final int otherAddrPartsLastIdx = otherAddrPartsLen - 1; int thisIdx = 0; int otherIdx = 0; // iterate through all parts of otherAddr while (otherIdx < otherAddrPartsLen) { // check if we already tested the last part of this address if (thisIdx > thisAddrPartsLastIdx) { // check if last part of otherAddr is the any-words wildcard and report a match if so if (otherIdx == otherAddrPartsLastIdx) { final SimpleString otherAddrLastPart = otherAddrParts[otherAddrPartsLastIdx]; return otherAddrLastPart.length() > 0 && otherAddrLastPart.charAt(0) == sepAnyWords; } return false; } SimpleString thisCurr = addressParts[thisIdx]; final SimpleString otherCurr = otherAddrParts[otherIdx]; final boolean otherCurrPartIsSingleChar = otherCurr.length() == 1; // handle single-word wildcard found in otherAddr if (otherCurrPartIsSingleChar && otherCurr.charAt(0) == sepSingleWord) { thisIdx++; otherIdx++; continue; } // handle any-words wildcard found in otherAddr if (otherCurrPartIsSingleChar && otherCurr.charAt(0) == sepAnyWords) { // if last part of otherAddr is any-words wildcard report a match if (otherIdx == otherAddrPartsLastIdx) return true; SimpleString thisNext; // check if this address has more parts to check if (thisIdx < thisAddrPartsLastIdx) { thisNext = addressParts[thisIdx + 1]; } else { // no more parts to check, thus check the current part against the next part of otherAddr thisNext = thisCurr; } final SimpleString otherNext = otherAddrParts[otherIdx + 1]; // iterate through the remaining parts of this address until the part after the any-words wildcard of otherAddr is matched while (thisCurr != null) { if (thisCurr.equals(otherNext)) { break; } thisIdx++; thisCurr = thisNext; thisNext = thisAddrPartsLastIdx > thisIdx ? addressParts[thisIdx + 1] : null; } // if no further part in this address matched the next part in otherAddr report a mismatch if (thisCurr == null) return false; otherIdx++; continue; } // compare current parts of bothaddresses and report mismatch if they differ if (!thisCurr.equals(otherCurr)) return false; thisIdx++; otherIdx++; } // report match if all parts of this address were checked return thisIdx == thisAddrPartsLen; }
Example 11
Source File: QueueImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
private Pair<String, Binding> locateTargetBinding(SimpleString queueSuffix, Message copyMessage, long oldQueueID) { String targetNodeID = null; Binding targetBinding = null; for (Map.Entry<SimpleString, Binding> entry : postOffice.getAllBindings().entrySet()) { Binding binding = entry.getValue(); // we only care about the remote queue bindings if (binding instanceof RemoteQueueBinding) { RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) binding; // does this remote queue binding point to the same queue as the message? if (oldQueueID == remoteQueueBinding.getRemoteQueueID()) { // get the name of this queue so we can find the corresponding remote queue binding pointing to the scale down target node SimpleString oldQueueName = remoteQueueBinding.getRoutingName(); // parse the queue name of the remote queue binding to determine the node ID String temp = remoteQueueBinding.getQueue().getName().toString(); targetNodeID = temp.substring(temp.lastIndexOf(".") + 1); logger.debug("Message formerly destined for " + oldQueueName + " with ID: " + oldQueueID + " on address " + copyMessage.getAddressSimpleString() + " on node " + targetNodeID); // now that we have the name of the queue we need to look through all the bindings again to find the new remote queue binding for (Map.Entry<SimpleString, Binding> entry2 : postOffice.getAllBindings().entrySet()) { binding = entry2.getValue(); // again, we only care about the remote queue bindings if (binding instanceof RemoteQueueBinding) { remoteQueueBinding = (RemoteQueueBinding) binding; temp = remoteQueueBinding.getQueue().getName().toString(); targetNodeID = temp.substring(temp.lastIndexOf(".") + 1); if (oldQueueName.equals(remoteQueueBinding.getRoutingName()) && targetNodeID.equals(queueSuffix.toString())) { targetBinding = remoteQueueBinding; if (logger.isDebugEnabled()) { logger.debug("Message now destined for " + remoteQueueBinding.getRoutingName() + " with ID: " + remoteQueueBinding.getRemoteQueueID() + " on address " + copyMessage.getAddress() + " on node " + targetNodeID); } break; } else { logger.debug("Failed to match: " + remoteQueueBinding); } } } } } } return new Pair<>(targetNodeID, targetBinding); }
Example 12
Source File: ActiveMQServerImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public BindingQueryResult bindingQuery(SimpleString address, boolean newFQQN) throws Exception { if (address == null) { throw ActiveMQMessageBundle.BUNDLE.addressIsNull(); } SimpleString realAddress = CompositeAddress.extractAddressName(address); AddressSettings addressSettings = getAddressSettingsRepository().getMatch(realAddress.toString()); boolean autoCreateQeueus = addressSettings.isAutoCreateQueues(); boolean autoCreateAddresses = addressSettings.isAutoCreateAddresses(); boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers(); int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers(); boolean defaultExclusive = addressSettings.isDefaultExclusiveQueue(); boolean defaultLastValue = addressSettings.isDefaultLastValueQueue(); SimpleString defaultLastValueKey = addressSettings.getDefaultLastValueKey(); boolean defaultNonDestructive = addressSettings.isDefaultNonDestructive(); int defaultConsumersBeforeDispatch = addressSettings.getDefaultConsumersBeforeDispatch(); long defaultDelayBeforeDispatch = addressSettings.getDefaultDelayBeforeDispatch(); List<SimpleString> names = new ArrayList<>(); // make an exception for the management address (see HORNETQ-29) ManagementService managementService = getManagementService(); if (managementService != null) { if (realAddress.equals(managementService.getManagementAddress())) { return new BindingQueryResult(true, null, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValue, defaultLastValueKey, defaultNonDestructive, defaultConsumersBeforeDispatch, defaultDelayBeforeDispatch); } } Bindings bindings = getPostOffice().getMatchingBindings(realAddress); for (Binding binding : bindings.getBindings()) { if (binding.getType() == BindingType.LOCAL_QUEUE || binding.getType() == BindingType.REMOTE_QUEUE) { SimpleString name; if (!newFQQN && CompositeAddress.isFullyQualified(address.toString())) { // need to use the FQQN here for backwards compatibility with core JMS client name = CompositeAddress.toFullyQualified(realAddress, binding.getUniqueName()); } else { name = binding.getUniqueName(); } names.add(name); } } AddressInfo info = getAddressInfo(realAddress); return new BindingQueryResult(info != null, info, names, autoCreateQeueus, autoCreateAddresses, defaultPurgeOnNoConsumers, defaultMaxConsumers, defaultExclusive, defaultLastValue, defaultLastValueKey, defaultNonDestructive, defaultConsumersBeforeDispatch, defaultDelayBeforeDispatch); }
Example 13
Source File: ActiveMQServerImpl.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override public QueueQueryResult queueQuery(SimpleString name) { if (name == null) { throw ActiveMQMessageBundle.BUNDLE.queueNameIsNull(); } SimpleString realName = CompositeAddress.extractQueueName(name); final QueueQueryResult response; Binding binding = getPostOffice().getBinding(realName); final SimpleString addressName = binding != null && binding.getType() == BindingType.LOCAL_QUEUE ? binding.getAddress() : CompositeAddress.extractAddressName(name); final AddressSettings addressSettings = getAddressSettingsRepository().getMatch(addressName.toString()); boolean autoCreateQueues = addressSettings.isAutoCreateQueues(); boolean defaultPurgeOnNoConsumers = addressSettings.isDefaultPurgeOnNoConsumers(); int defaultMaxConsumers = addressSettings.getDefaultMaxConsumers(); boolean defaultExclusiveQueue = addressSettings.isDefaultExclusiveQueue(); boolean defaultLastValueQueue = addressSettings.isDefaultLastValueQueue(); SimpleString defaultLastValueKey = addressSettings.getDefaultLastValueKey(); boolean defaultNonDestructive = addressSettings.isDefaultNonDestructive(); int defaultConsumersBeforeDispatch = addressSettings.getDefaultConsumersBeforeDispatch(); long defaultDelayBeforeDispatch = addressSettings.getDefaultDelayBeforeDispatch(); int defaultConsumerWindowSize = addressSettings.getDefaultConsumerWindowSize(); boolean defaultGroupRebalance = addressSettings.isDefaultGroupRebalance(); int defaultGroupBuckets = addressSettings.getDefaultGroupBuckets(); SimpleString defaultGroupFirstKey = addressSettings.getDefaultGroupFirstKey(); long autoDeleteQueuesDelay = addressSettings.getAutoDeleteQueuesDelay(); long autoDeleteQueuesMessageCount = addressSettings.getAutoDeleteQueuesMessageCount(); long defaultRingSize = addressSettings.getDefaultRingSize(); boolean defaultEnabled = ActiveMQDefaultConfiguration.getDefaultEnabled(); SimpleString managementAddress = getManagementService() != null ? getManagementService().getManagementAddress() : null; if (binding != null && binding.getType() == BindingType.LOCAL_QUEUE) { Queue queue = (Queue) binding.getBindable(); Filter filter = queue.getFilter(); SimpleString filterString = filter == null ? null : filter.getFilterString(); response = new QueueQueryResult(realName, binding.getAddress(), queue.isDurable(), queue.isTemporary(), filterString, queue.getConsumerCount(), queue.getMessageCount(), autoCreateQueues, true, queue.isAutoCreated(), queue.isPurgeOnNoConsumers(), queue.getRoutingType(), queue.getMaxConsumers(), queue.isExclusive(), queue.isGroupRebalance(), queue.getGroupBuckets(), queue.getGroupFirstKey(), queue.isLastValue(), queue.getLastValueKey(), queue.isNonDestructive(), queue.getConsumersBeforeDispatch(), queue.getDelayBeforeDispatch(), queue.isAutoDelete(), queue.getAutoDeleteDelay(), queue.getAutoDeleteMessageCount(), defaultConsumerWindowSize, queue.getRingSize(), queue.isEnabled()); } else if (realName.equals(managementAddress)) { // make an exception for the management address (see HORNETQ-29) response = new QueueQueryResult(realName, managementAddress, true, false, null, -1, -1, autoCreateQueues, true, false, false, RoutingType.MULTICAST, -1, false, false, null, null, null,null, null, null, null, null, null, null, defaultConsumerWindowSize, null, null); } else { response = new QueueQueryResult(realName, addressName, true, false, null, 0, 0, autoCreateQueues, false, false, defaultPurgeOnNoConsumers, RoutingType.MULTICAST, defaultMaxConsumers, defaultExclusiveQueue, defaultGroupRebalance, defaultGroupBuckets, defaultGroupFirstKey, defaultLastValueQueue, defaultLastValueKey, defaultNonDestructive, defaultConsumersBeforeDispatch, defaultDelayBeforeDispatch, isAutoDelete(false, addressSettings), autoDeleteQueuesDelay, autoDeleteQueuesMessageCount, defaultConsumerWindowSize, defaultRingSize, defaultEnabled); } return response; }