use of org.apache.qpid.server.store.MessageStore in project qpid-broker-j by apache.
the class ServerSessionDelegate method messageTransfer.
@Override
public void messageTransfer(ServerSession ssn, final MessageTransfer xfr) {
try {
if (ssn.blockingTimeoutExceeded()) {
getEventLogger(ssn).message(ChannelMessages.FLOW_CONTROL_IGNORED());
ssn.close(ErrorCodes.MESSAGE_TOO_LARGE, "Session flow control was requested, but not enforced by sender");
} else if (xfr.getBodySize() > ssn.getConnection().getMaxMessageSize()) {
exception(ssn, xfr, ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED, "Message size of " + xfr.getBodySize() + " greater than allowed maximum of " + ssn.getConnection().getMaxMessageSize());
} else {
final MessageDestination destination = getDestinationForMessage(ssn, xfr);
final DeliveryProperties delvProps = xfr.getHeader() == null ? null : xfr.getHeader().getDeliveryProperties();
if (delvProps != null && delvProps.hasTtl() && !delvProps.hasExpiration()) {
delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
}
final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
final NamedAddressSpace virtualHost = getAddressSpace(ssn);
try {
ssn.getAMQPConnection().checkAuthorizedMessagePrincipal(getMessageUserId(xfr));
ssn.authorisePublish(destination, messageMetaData.getRoutingKey(), messageMetaData.isImmediate(), ssn.getAMQPConnection().getLastReadTime());
} catch (AccessControlException e) {
ExecutionErrorCode errorCode = ExecutionErrorCode.UNAUTHORIZED_ACCESS;
exception(ssn, xfr, errorCode, e.getMessage());
return;
}
final MessageStore store = virtualHost.getMessageStore();
final StoredMessage<MessageMetaData_0_10> storeMessage = createStoreMessage(xfr, messageMetaData, store);
final MessageTransferMessage message = new MessageTransferMessage(storeMessage, ssn.getReference());
MessageReference<MessageTransferMessage> reference = message.newReference();
try {
final InstanceProperties instanceProperties = new InstanceProperties() {
@Override
public Object getProperty(final Property prop) {
switch(prop) {
case EXPIRATION:
return message.getExpiration();
case IMMEDIATE:
return message.isImmediate();
case MANDATORY:
return (delvProps == null || !delvProps.getDiscardUnroutable()) && xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT;
case PERSISTENT:
return message.isPersistent();
case REDELIVERED:
return delvProps.getRedelivered();
}
return null;
}
};
RoutingResult<MessageTransferMessage> routingResult = ssn.enqueue(message, instanceProperties, destination);
boolean explictlyRejected = routingResult.containsReject(RejectType.LIMIT_EXCEEDED);
if (!routingResult.hasRoutes() || explictlyRejected) {
boolean closeWhenNoRoute = ssn.getAMQPConnection().getPort().getCloseWhenNoRoute();
boolean discardUnroutable = delvProps != null && delvProps.getDiscardUnroutable();
if (!discardUnroutable && xfr.getAcceptMode() == MessageAcceptMode.EXPLICIT) {
RangeSet rejects = RangeSetFactory.createRangeSet();
rejects.add(xfr.getId());
MessageReject reject = new MessageReject(rejects, MessageRejectCode.UNROUTABLE, "Unroutable");
ssn.invoke(reject);
} else if (!discardUnroutable && closeWhenNoRoute && explictlyRejected) {
ExecutionErrorCode code = ExecutionErrorCode.RESOURCE_LIMIT_EXCEEDED;
String errorMessage = String.format("No route for message with destination '%s' and routing key '%s' : %s", xfr.getDestination(), message.getInitialRoutingAddress(), routingResult.getRejectReason());
ExecutionException ex = new ExecutionException();
ex.setErrorCode(code);
ex.setDescription(errorMessage);
ssn.invoke(ex);
ssn.close(ErrorCodes.RESOURCE_ERROR, errorMessage);
return;
} else {
getEventLogger(ssn).message(ExchangeMessages.DISCARDMSG(destination.getName(), messageMetaData.getRoutingKey()));
}
}
// TODO: we currently do not send MessageAccept when AcceptMode is EXPLICIT
if (ssn.isTransactional()) {
ssn.processed(xfr);
} else {
ssn.recordFuture(Futures.immediateFuture(null), new CommandProcessedAction(ssn, xfr));
}
} catch (VirtualHostUnavailableException e) {
getServerConnection(ssn).sendConnectionCloseAsync(ConnectionCloseCode.CONNECTION_FORCED, e.getMessage());
} finally {
reference.release();
}
}
} finally {
xfr.dispose();
}
}
use of org.apache.qpid.server.store.MessageStore in project qpid-broker-j by apache.
the class AbstractVirtualHost method executeTransaction.
@Override
public void executeTransaction(TransactionalOperation op) {
final MessageStore store = getMessageStore();
final LocalTransaction txn = new LocalTransaction(store);
op.withinTransaction(new Transaction() {
@Override
public void dequeue(final QueueEntry messageInstance) {
final ServerTransaction.Action deleteAction = new ServerTransaction.Action() {
@Override
public void postCommit() {
messageInstance.delete();
}
@Override
public void onRollback() {
}
};
boolean acquired = messageInstance.acquireOrSteal(new Runnable() {
@Override
public void run() {
ServerTransaction txn = new AutoCommitTransaction(store);
txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
}
});
if (acquired) {
txn.dequeue(messageInstance.getEnqueueRecord(), deleteAction);
}
}
@Override
public void copy(QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
}
});
}
@Override
public void move(final QueueEntry entry, final Queue<?> queue) {
final ServerMessage message = entry.getMessage();
if (entry.acquire()) {
txn.enqueue(queue, message, new ServerTransaction.EnqueueAction() {
@Override
public void postCommit(MessageEnqueueRecord... records) {
queue.enqueue(message, null, records[0]);
}
@Override
public void onRollback() {
entry.release();
}
});
txn.dequeue(entry.getEnqueueRecord(), new ServerTransaction.Action() {
@Override
public void postCommit() {
entry.delete();
}
@Override
public void onRollback() {
}
});
}
}
});
txn.commit();
}
use of org.apache.qpid.server.store.MessageStore in project qpid-broker-j by apache.
the class AbstractVirtualHost method onActivate.
@StateTransition(currentState = { State.UNINITIALIZED, State.ERRORED }, desiredState = State.ACTIVE)
private ListenableFuture<Void> onActivate() {
long threadPoolKeepAliveTimeout = getContextValue(Long.class, CONNECTION_THREAD_POOL_KEEP_ALIVE_TIMEOUT);
final SuppressingInheritedAccessControlContextThreadFactory connectionThreadFactory = new SuppressingInheritedAccessControlContextThreadFactory("virtualhost-" + getName() + "-iopool", getSystemTaskSubject("IO Pool", getPrincipal()));
_networkConnectionScheduler = new NetworkConnectionScheduler("virtualhost-" + getName() + "-iopool", getNumberOfSelectors(), getConnectionThreadPoolSize(), threadPoolKeepAliveTimeout, connectionThreadFactory);
_networkConnectionScheduler.start();
updateAccessControl();
initialiseStatisticsReporting();
MessageStore messageStore = getMessageStore();
messageStore.openMessageStore(this);
startFileSystemSpaceChecking();
if (!(_virtualHostNode.getConfigurationStore() instanceof MessageStoreProvider)) {
getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.CREATED());
getEventLogger().message(getMessageStoreLogSubject(), MessageStoreMessages.STORE_LOCATION(messageStore.getStoreLocation()));
}
messageStore.upgradeStoreStructure();
if (_linkRegistry != null) {
_linkRegistry.open();
}
getBroker().assignTargetSizes();
final PreferenceStoreUpdater updater = new PreferenceStoreUpdaterImpl();
Collection<PreferenceRecord> records = _preferenceStore.openAndLoad(updater);
_preferenceTaskExecutor = new TaskExecutorImpl("virtualhost-" + getName() + "-preferences", null);
_preferenceTaskExecutor.start();
PreferencesRecoverer preferencesRecoverer = new PreferencesRecoverer(_preferenceTaskExecutor);
preferencesRecoverer.recoverPreferences(this, records, _preferenceStore);
if (_createDefaultExchanges) {
return doAfter(createDefaultExchanges(), new Runnable() {
@Override
public void run() {
_createDefaultExchanges = false;
postCreateDefaultExchangeTasks();
}
});
} else {
postCreateDefaultExchangeTasks();
return Futures.immediateFuture(null);
}
}
use of org.apache.qpid.server.store.MessageStore in project qpid-broker-j by apache.
the class AbstractStandardVirtualHostNode method onDelete.
@Override
protected ListenableFuture<Void> onDelete() {
final VirtualHost<?> virtualHost = getVirtualHost();
final MessageStore messageStore = virtualHost == null ? null : virtualHost.getMessageStore();
return doAfterAlways(closeVirtualHostIfExists(), () -> {
if (messageStore != null) {
messageStore.closeMessageStore();
messageStore.onDelete(virtualHost);
}
if (AbstractStandardVirtualHostNode.this instanceof PreferenceStoreProvider) {
PreferenceStore preferenceStore = ((PreferenceStoreProvider) AbstractStandardVirtualHostNode.this).getPreferenceStore();
if (preferenceStore != null) {
preferenceStore.onDelete();
}
}
DurableConfigurationStore configurationStore = getConfigurationStore();
if (configurationStore != null) {
configurationStore.closeConfigurationStore();
configurationStore.onDelete(AbstractStandardVirtualHostNode.this);
}
});
}
use of org.apache.qpid.server.store.MessageStore in project qpid-broker-j by apache.
the class AbstractVirtualHostTest method testFileSystemCheckWarnsWhenFileSystemDoesNotExist.
// This indirectly tests QPID-6283
public void testFileSystemCheckWarnsWhenFileSystemDoesNotExist() throws Exception {
Map<String, Object> attributes = Collections.<String, Object>singletonMap(AbstractVirtualHost.NAME, getTestName());
final MessageStore store = mock(MessageStore.class);
when(store.newMessageStoreReader()).thenReturn(mock(MessageStore.MessageStoreReader.class));
File nonExistingFile = TestFileUtils.createTempFile(this);
FileUtils.delete(nonExistingFile, false);
when(store.getStoreLocationAsFile()).thenReturn(nonExistingFile);
setTestSystemProperty("virtualhost.housekeepingCheckPeriod", "100");
final AbstractVirtualHost host = new AbstractVirtualHost(attributes, _node) {
@Override
protected MessageStore createMessageStore() {
return store;
}
};
String loggerName = AbstractVirtualHost.class.getName();
assertActionProducesLogMessage(new Runnable() {
@Override
public void run() {
host.open();
}
}, loggerName, Level.WARN, "Cannot check file system for disk space");
host.close();
}
Aggregations