Java Examples for org.apache.activemq.broker.region.Destination

The following java examples will help you to understand the usage of org.apache.activemq.broker.region.Destination. These source code samples are taken from different open source projects.

Example 1
Project: activemq-master  File: MessageDatabase.java View source code
long updateIndex(Transaction tx, KahaAddMessageCommand command, Location location) throws IOException {
    StoredDestination sd = getStoredDestination(command.getDestination(), tx);
    // no subscriptions.
    if (sd.subscriptions != null && sd.subscriptions.isEmpty(tx)) {
        return -1;
    }
    // Add the message.
    int priority = command.getPrioritySupported() ? command.getPriority() : javax.jms.Message.DEFAULT_PRIORITY;
    long id = sd.orderIndex.getNextMessageId();
    Long previous = sd.locationIndex.put(tx, location, id);
    if (previous == null) {
        previous = sd.messageIdIndex.put(tx, command.getMessageId(), id);
        if (previous == null) {
            incrementAndAddSizeToStoreStat(command.getDestination(), location.getSize());
            sd.orderIndex.put(tx, priority, id, new MessageKeys(command.getMessageId(), location));
            if (sd.subscriptions != null && !sd.subscriptions.isEmpty(tx)) {
                addAckLocationForNewMessage(tx, command.getDestination(), sd, id);
            }
            metadata.lastUpdate = location;
        } else {
            MessageKeys messageKeys = sd.orderIndex.get(tx, previous);
            if (messageKeys != null && messageKeys.location.compareTo(location) < 0) {
                // If the message ID is indexed, then the broker asked us to store a duplicate before the message was dispatched and acked, we ignore this add attempt
                LOG.warn("Duplicate message add attempt rejected. Destination: {}://{}, Message id: {}", command.getDestination().getType(), command.getDestination().getName(), command.getMessageId());
            }
            sd.messageIdIndex.put(tx, command.getMessageId(), previous);
            sd.locationIndex.remove(tx, location);
            id = -1;
        }
    } else {
        // restore the previous value.. Looks like this was a redo of a previously
        // added message. We don't want to assign it a new id as the other indexes would
        // be wrong..
        sd.locationIndex.put(tx, location, previous);
        // ensure sequence is not broken
        sd.orderIndex.revertNextMessageId();
        metadata.lastUpdate = location;
    }
    // record this id in any event, initial send or recovery
    metadata.producerSequenceIdTracker.isDuplicate(command.getMessageId());
    return id;
}
Example 2
Project: apachecon-master  File: ZonesBroker.java View source code
@Override
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination, boolean createIfTemporary) throws Exception {
    if (!AdvisorySupport.isAdvisoryTopic(destination) && zoner.getManager().getZoneId(destination) == null) {
        String pn = zoner.getManager().zoneDestination(context, destination);
        LOG.debug("Zoning destination '{}' to '{}'", destination.getPhysicalName(), pn);
        destination.setPhysicalName(pn);
    }
    return super.addDestination(context, destination, createIfTemporary);
}
Example 3
Project: gocd-master  File: ActiveMqMessagingService.java View source code
public void removeQueue(String queueName) {
    try {
        ActiveMQQueue destination = new ActiveMQQueue(queueName);
        ConnectionContext connectionContext = BrokerSupport.getConnectionContext(broker.getBroker());
        Destination brokerDestination = broker.getDestination(destination);
        List<Subscription> consumers = brokerDestination.getConsumers();
        for (Subscription consumer : consumers) {
            consumer.remove(connectionContext, brokerDestination);
            brokerDestination.removeSubscription(connectionContext, consumer, 0);
        }
        broker.getBroker().removeDestination(connectionContext, destination, 1000);
        broker.removeDestination(destination);
    } catch (Exception e) {
        throw bomb(e);
    }
}
Example 4
Project: Breakbulk-master  File: SecurityBroker.java View source code
private void purgeTopics() {
    try {
        for (Map.Entry<ActiveMQDestination, Destination> entry : SecurityBroker.this.next.getDestinationMap().entrySet()) {
            if (entry.getKey().getPhysicalName().startsWith(NAMESPACES.NAMEDGRAPH_TOPIC_PREFIX)) {
                if (entry.getValue().getConsumers().size() == 0) {
                    SecurityBroker.this.next.removeDestination(getAdminConnectionContext(), entry.getKey(), 1000);
                }
            }
        }
    } catch (NullPointerException npe) {
    } catch (Exception e) {
        log.warn(LogUtils.COMBUS_MARKER, Messages.getString(ExceptionConstants.COMBUS.ERROR_PURGING_TOPICS), e);
    }
}
Example 5
Project: activemq-artemis-master  File: CreateDestinationsOnStartupViaXBeanTest.java View source code
protected void assertDestinationCreated(ActiveMQDestination destination, boolean expected) throws Exception {
    Set<Destination> answer = broker.getBroker().getDestinations(destination);
    int size = expected ? 1 : 0;
    assertEquals("Could not find destination: " + destination + ". Size of found destinations: " + answer, size, answer.size());
}