use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.
the class AbstractAMQPConnection method registerTransactionTickers.
@Override
public void registerTransactionTickers(final ServerTransaction serverTransaction, final Action<String> closeAction, final long notificationRepeatPeriod) {
NamedAddressSpace addressSpace = getAddressSpace();
if (addressSpace instanceof QueueManagingVirtualHost) {
final QueueManagingVirtualHost<?> virtualhost = (QueueManagingVirtualHost<?>) addressSpace;
EventLogger eventLogger = virtualhost.getEventLogger();
final Set<Ticker> tickers = new LinkedHashSet<>(4);
if (virtualhost.getStoreTransactionOpenTimeoutWarn() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.OPEN_TXN(age))));
}
if (virtualhost.getStoreTransactionOpenTimeoutClose() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionOpenTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionStartTime, age -> closeAction.performAction(OPEN_TRANSACTION_TIMEOUT_ERROR)));
}
if (virtualhost.getStoreTransactionIdleTimeoutWarn() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutWarn(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> eventLogger.message(getLogSubject(), ConnectionMessages.IDLE_TXN(age))));
}
if (virtualhost.getStoreTransactionIdleTimeoutClose() > 0) {
tickers.add(new TransactionTimeoutTicker(virtualhost.getStoreTransactionIdleTimeoutClose(), notificationRepeatPeriod, serverTransaction::getTransactionUpdateTime, age -> closeAction.performAction(IDLE_TRANSACTION_TIMEOUT_ERROR)));
}
if (!tickers.isEmpty()) {
for (Ticker ticker : tickers) {
getAggregateTicker().addTicker(ticker);
}
notifyWork();
}
_transactionTickers.put(serverTransaction, tickers);
}
}
use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeImpl method onMaster.
private void onMaster() {
boolean success = false;
try {
boolean firstOpening = false;
closeVirtualHostIfExist().get();
getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_START());
VirtualHostStoreUpgraderAndRecoverer upgraderAndRecoverer = new VirtualHostStoreUpgraderAndRecoverer(this);
if (getConfigurationStore().isOpen()) {
upgraderAndRecoverer.reloadAndRecover(getConfigurationStore());
} else {
getConfigurationStore().upgradeStoreStructure();
ConfiguredObjectRecord[] initialRecords = getInitialRecords();
if (upgraderAndRecoverer.upgradeAndRecover(getConfigurationStore(), initialRecords)) {
setAttributes(Collections.<String, Object>singletonMap(VIRTUALHOST_INITIAL_CONFIGURATION, "{}"));
firstOpening = initialRecords.length == 0;
}
}
getEventLogger().message(getConfigurationStoreLogSubject(), ConfigStoreMessages.RECOVERY_COMPLETE());
VirtualHost<?> host = getVirtualHost();
if (host == null) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Creating new virtualhost with name : " + getGroupName());
}
Map<String, Object> hostAttributes = new HashMap<>();
hostAttributes.put(VirtualHost.MODEL_VERSION, BrokerModel.MODEL_VERSION);
hostAttributes.put(VirtualHost.NAME, getGroupName());
hostAttributes.put(VirtualHost.TYPE, BDBHAVirtualHostImpl.VIRTUAL_HOST_TYPE);
createChild(VirtualHost.class, hostAttributes);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Recovered virtualhost with name : " + getGroupName());
}
final VirtualHost<?> recoveredHost = host;
// so the following test should always return true
if (recoveredHost instanceof QueueManagingVirtualHost) {
((QueueManagingVirtualHost<?>) recoveredHost).setFirstOpening(firstOpening);
}
Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Object>() {
@Override
public Object run() {
recoveredHost.open();
return null;
}
});
}
success = true;
} catch (Exception e) {
LOGGER.error("Failed to activate on hearing MASTER change event", e);
} finally {
setState(success ? State.ACTIVE : State.ERRORED);
}
}
use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.
the class ExchangeSendingDestination method getQueue.
private static Queue<?> getQueue(Exchange<?> exchange, Source source, String subscriptionName, BindingInfo bindingInfo) throws AmqpErrorException {
boolean isDurable = source.getExpiryPolicy() == TerminusExpiryPolicy.NEVER;
boolean isShared = hasCapability(source.getCapabilities(), SHARED_CAPABILITY);
QueueManagingVirtualHost virtualHost;
if (exchange.getAddressSpace() instanceof QueueManagingVirtualHost) {
virtualHost = (QueueManagingVirtualHost) exchange.getAddressSpace();
} else {
throw new AmqpErrorException(new Error(AmqpError.INTERNAL_ERROR, "Address space of unexpected type"));
}
Queue<?> queue;
final Map<String, Object> attributes = new HashMap<>();
ExclusivityPolicy exclusivityPolicy;
if (isShared) {
exclusivityPolicy = ExclusivityPolicy.SHARED_SUBSCRIPTION;
} else {
exclusivityPolicy = ExclusivityPolicy.LINK;
}
org.apache.qpid.server.model.LifetimePolicy lifetimePolicy = getLifetimePolicy(source.getExpiryPolicy());
attributes.put(Queue.ID, UUID.randomUUID());
attributes.put(Queue.NAME, subscriptionName);
attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
attributes.put(Queue.DURABLE, isDurable);
Map<String, Map<String, Object>> bindings = bindingInfo.getBindings();
try {
queue = virtualHost.getSubscriptionQueue(exchange.getName(), attributes, bindings);
} catch (NotFoundException e) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, e.getMessage()));
} catch (IllegalStateException e) {
throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, "Subscription is already in use"));
}
return queue;
}
use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.
the class LegacyAccessControlAdapter method createObjectPropertiesForExchangeBind.
private ObjectProperties createObjectPropertiesForExchangeBind(final Map<String, Object> arguments, final PermissionedObject configuredObject) {
ObjectProperties properties = new ObjectProperties();
Exchange<?> exchange = (Exchange<?>) configuredObject;
final QueueManagingVirtualHost virtualhost = exchange.getVirtualHost();
properties.setName(exchange.getName());
final String destination = (String) arguments.get("destination");
properties.put(ObjectProperties.Property.QUEUE_NAME, destination);
properties.put(ObjectProperties.Property.ROUTING_KEY, (String) arguments.get("bindingKey"));
properties.put(ObjectProperties.Property.VIRTUALHOST_NAME, virtualhost.getName());
MessageDestination dest = virtualhost.getAttainedMessageDestination(destination);
if (dest != null) {
// express rules about the binding of temporary queues (whose names cannot be predicted).
if (dest instanceof ConfiguredObject) {
ConfiguredObject queue = (ConfiguredObject) dest;
properties.put(ObjectProperties.Property.TEMPORARY, queue.getLifetimePolicy() != LifetimePolicy.PERMANENT);
}
properties.put(ObjectProperties.Property.DURABLE, dest.isDurable());
}
return properties;
}
use of org.apache.qpid.server.virtualhost.QueueManagingVirtualHost in project qpid-broker-j by apache.
the class LinkRegistryTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
final QueueManagingVirtualHost virtualHost = mock(QueueManagingVirtualHost.class);
_linkRegistry = new LinkRegistryImpl(virtualHost);
}
Aggregations