public static boolean isConsumerAdvisoryTopic(ActiveMQDestination destination) { if (destination.isComposite()) { ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations(); for (int i = 0; i < compositeDestinations.length; i++) { if (isConsumerAdvisoryTopic(compositeDestinations[i])) { return true; } } return false; } else { return destination.isTopic() && destination.getPhysicalName().startsWith(CONSUMER_ADVISORY_TOPIC_PREFIX); } }
@Override public Object convert(Object value) { return ActiveMQDestination.createDestination((String)value, ActiveMQDestination.QUEUE_TYPE); } });
private boolean isDuplicateSuppressionOff(final ConsumerInfo consumerInfo) { return !configuration.isSuppressDuplicateQueueSubscriptions() && !configuration.isSuppressDuplicateTopicSubscriptions() || consumerInfo.getDestination().isQueue() && !configuration.isSuppressDuplicateQueueSubscriptions() || consumerInfo.getDestination().isTopic() && !configuration.isSuppressDuplicateTopicSubscriptions(); }
public static boolean isTempDestinationAdvisoryTopic(ActiveMQDestination destination) { if (destination.isComposite()) { ActiveMQDestination[] compositeDestinations = destination.getCompositeDestinations(); for (int i = 0; i < compositeDestinations.length; i++) { if (!isTempDestinationAdvisoryTopic(compositeDestinations[i])) { return false; } } return true; } else { return destination.equals(TEMP_QUEUE_ADVISORY_TOPIC) || destination.equals(TEMP_TOPIC_ADVISORY_TOPIC); } }
public static ActiveMQTopic getSlowConsumerAdvisoryTopic(ActiveMQDestination destination) { String name = SLOW_CONSUMER_TOPIC_PREFIX + destination.getDestinationTypeAsString() + "." + destination.getPhysicalName(); return new ActiveMQTopic(name); }
@Override public int doGetMessageCount(TransactionContext c, ActiveMQDestination destination) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; int result = 0; try { s = c.getConnection().prepareStatement(this.statements.getDestinationMessageCountStatement()); s.setString(1, destination.getQualifiedName()); rs = s.executeQuery(); if (rs.next()) { result = rs.getInt(1); } } finally { close(rs); close(s); } return result; }
@Override public void doRecover(TransactionContext c, ActiveMQDestination destination, JDBCMessageRecoveryListener listener) throws Exception { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindAllMessagesStatement()); s.setString(1, destination.getQualifiedName()); rs = s.executeQuery(); if (this.statements.isUseExternalMessageReferences()) { while (rs.next()) { if (!listener.recoverMessageReference(rs.getString(2))) { break; } } } else { while (rs.next()) { if (!listener.recoverMessage(rs.getLong(1), getBinaryData(rs, 2))) { break; } } } } finally { close(rs); close(s); } }
@Override public SubscriptionInfo[] doGetAllSubscriptions(TransactionContext c, ActiveMQDestination destination) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindAllDurableSubsStatement()); s.setString(1, destination.getQualifiedName()); rs = s.executeQuery(); ArrayList<SubscriptionInfo> rc = new ArrayList<SubscriptionInfo>(); while (rs.next()) { SubscriptionInfo subscription = new SubscriptionInfo(); subscription.setDestination(destination); subscription.setSelector(rs.getString(1)); subscription.setSubscriptionName(rs.getString(2)); subscription.setClientId(rs.getString(3)); subscription.setSubscribedDestination(ActiveMQDestination.createDestination(rs.getString(4), ActiveMQDestination.QUEUE_TYPE)); rc.add(subscription); } return rc.toArray(new SubscriptionInfo[rc.size()]); } finally { close(rs); close(s); } }
@Override public long[] getStoreSequenceId(TransactionContext c, ActiveMQDestination destination, MessageId messageID) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindMessageSequenceIdStatement()); s.setString(1, messageID.getProducerId().toString()); s.setLong(2, messageID.getProducerSequenceId()); s.setString(3, destination.getQualifiedName()); rs = s.executeQuery(); if (!rs.next()) { return new long[]{0,0}; } return new long[]{rs.getLong(1), rs.getLong(2)}; } finally { close(rs); close(s); } }
@Override public long doGetLastAckedDurableSubscriberMessageId(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriberName) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; long result = -1; try { s = c.getConnection().prepareStatement(this.statements.getLastAckedDurableSubscriberMessageStatement()); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId); s.setString(3, subscriberName); rs = s.executeQuery(); if (rs.next()) { result = rs.getLong(1); if (result == 0 && rs.wasNull()) { result = -1; } } } finally { close(rs); close(s); } return result; }
@Override public void doDeleteSubscription(TransactionContext c, ActiveMQDestination destination, String clientId, String subscriptionName) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getDeleteSubscriptionStatement()); s.setString(1, destination.getQualifiedName()); s.setString(2, clientId); s.setString(3, subscriptionName); s.executeUpdate(); } finally { close(s); } }
@Override public Set<ActiveMQDestination> doGetDestinations(TransactionContext c) throws SQLException, IOException { HashSet<ActiveMQDestination> rc = new HashSet<ActiveMQDestination>(); PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindAllDestinationsStatement()); rs = s.executeQuery(); while (rs.next()) { rc.add(ActiveMQDestination.createDestination(rs.getString(1), ActiveMQDestination.QUEUE_TYPE)); } } finally { close(rs); close(s); } return rc; }
@Override public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { if (!AdvisorySupport.isAdvisoryTopic(info.getDestination()) && !info.getDestination().isTemporary()) { if (singleSelectorPerDestination) { String destinationName = info.getDestination().getQualifiedName(); Set<String> selectors = subSelectorCache.get(destinationName); if (info.getSelector() == null && selectors.size() > 1) { boolean removed = selectors.remove(MATCH_EVERYTHING); LOG.debug("A non-selector consumer has dropped. Removing the catchall matching pattern 'TRUE'. Successful? " + removed); } } } super.removeConsumer(context, info); }
if (!AdvisorySupport.isAdvisoryTopic(info.getDestination())) { ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()); consumersLock.writeLock().lock(); try { consumers.put(info.getConsumerId(), info); if (getBrokerService().isUseVirtualDestSubs()) { for (VirtualDestination virtualDestination : virtualDestinations) { if (virtualDestinationMatcher.matches(virtualDestination, info.getDestination())) { if (AdvisorySupport.isConnectionAdvisoryTopic(info.getDestination())) { for (Iterator<ConnectionInfo> iter = connections.values().iterator(); iter.hasNext(); ) { ConnectionInfo value = iter.next(); ActiveMQTopic topic = AdvisorySupport.getConnectionAdvisoryTopic(); if (AdvisorySupport.isTempDestinationAdvisoryTopic(info.getDestination())) { for (DestinationInfo destination : destinations.values()) { if (destination.getDestination().isTemporary()) { ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination.getDestination()); fireAdvisory(context, topic, destination, info.getConsumerId()); } else if (AdvisorySupport.isDestinationAdvisoryTopic(info.getDestination())) { for (DestinationInfo destination : destinations.values()) { ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination.getDestination()); fireAdvisory(context, topic, destination, info.getConsumerId());
@Override public Response processAddDestination(DestinationInfo info) { if (info != null) { ConnectionState cs = connectionStates.get(info.getConnectionId()); if (cs != null && info.getDestination().isTemporary()) { cs.addTempDestination(info); } } return TRACKED_RESPONSE_MARKER; }
private void fireVirtualDestinationRemoveAdvisory(ConnectionContext context, ConsumerInfo info) throws Exception { VirtualDestination virtualDestination = virtualDestinationConsumers.remove(info); if (virtualDestination != null) { LOG.debug("Virtual consumer removed: {}, for virtual destination: {}", info, virtualDestination); ActiveMQTopic topic = AdvisorySupport.getVirtualDestinationConsumerAdvisoryTopic(virtualDestination.getVirtualDestination()); ActiveMQDestination dest = info.getDestination(); if (!dest.isTemporary() || destinations.containsKey(dest)) { fireConsumerAdvisory(context, dest, topic, info.createRemoveCommand()); } } }
@Override public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception { final SecurityContext securityContext = checkSecurityContext(producerExchange.getConnectionContext()); if (!securityContext.isBrokerContext() && !securityContext.getAuthorizedWriteDests().containsValue(messageSend.getDestination())) { Set<?> allowedACLs = null; if (!messageSend.getDestination().isTemporary()) { allowedACLs = authorizationMap.getWriteACLs(messageSend.getDestination()); } else { allowedACLs = authorizationMap.getTempDestinationWriteACLs(); } if (allowedACLs != null && !securityContext.isInOneOf(allowedACLs)) { throw new SecurityException("User " + securityContext.getUserName() + " is not authorized to write to: " + messageSend.getDestination()); } securityContext.getAuthorizedWriteDests().put(messageSend.getDestination(), messageSend.getDestination()); } super.send(producerExchange, messageSend); }
if (info.isNetworkSubscription() && info.getDestination().isQueue() && !configuration.isConduitNetworkQueueSubscriptions()) { return false; for (DemandSubscription ds : subscriptionMapByLocalId.values()) { DestinationFilter filter = DestinationFilter.parseFilter(ds.getLocalInfo().getDestination()); if (canConduit(ds) && filter.matches(info.getDestination())) { LOG.debug("{} {} with ids {} matched (add interest) {}", new Object[]{
@Override public void removeConsumer(ConnectionContext context, ConsumerInfo info) throws Exception { super.removeConsumer(context, info); // Don't advise advisory topics. ActiveMQDestination dest = info.getDestination(); if (!AdvisorySupport.isAdvisoryTopic(dest)) { ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(dest); consumersLock.writeLock().lock(); try { consumers.remove(info.getConsumerId()); //remove the demand for this consumer if it matches a virtual destination if(getBrokerService().isUseVirtualDestSubs()) { fireVirtualDestinationRemoveAdvisory(context, info); } } finally { consumersLock.writeLock().unlock(); } if (!dest.isTemporary() || destinations.containsKey(dest)) { fireConsumerAdvisory(context, dest, topic, info.createRemoveCommand()); } } }
if (getBrokerService().isUseVirtualDestSubsOnCreation()) { for (ActiveMQDestination destination : destinations.keySet()) { if(destination.isQueue()) { if (virtualDestinationMatcher.matches(virtualDestination, destination)) { fireVirtualDestinationAddAdvisory(context, null, destination, virtualDestination); if (virtualDestinationMatcher.matches(virtualDestination, info.getDestination())) { fireVirtualDestinationAddAdvisory(context, info, info.getDestination(), virtualDestination);