Search in sources :

Example 11 with MessageStore

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();
    }
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) MessageDestination(org.apache.qpid.server.message.MessageDestination) InstanceProperties(org.apache.qpid.server.message.InstanceProperties) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) MessageReference(org.apache.qpid.server.message.MessageReference) RoutingResult(org.apache.qpid.server.message.RoutingResult) VirtualHostUnavailableException(org.apache.qpid.server.virtualhost.VirtualHostUnavailableException) StoredMessage(org.apache.qpid.server.store.StoredMessage) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 12 with MessageStore

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();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) PrivilegedAction(java.security.PrivilegedAction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerMessage(org.apache.qpid.server.message.ServerMessage) MessageEnqueueRecord(org.apache.qpid.server.store.MessageEnqueueRecord) QueueEntry(org.apache.qpid.server.queue.QueueEntry) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) LocalTransaction(org.apache.qpid.server.txn.LocalTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction)

Example 13 with MessageStore

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);
    }
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) PreferenceStoreUpdater(org.apache.qpid.server.store.preferences.PreferenceStoreUpdater) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) SuppressingInheritedAccessControlContextThreadFactory(org.apache.qpid.server.pool.SuppressingInheritedAccessControlContextThreadFactory) MessageStoreProvider(org.apache.qpid.server.store.MessageStoreProvider) PreferenceStoreUpdaterImpl(org.apache.qpid.server.store.preferences.PreferenceStoreUpdaterImpl) PreferencesRecoverer(org.apache.qpid.server.store.preferences.PreferencesRecoverer) NetworkConnectionScheduler(org.apache.qpid.server.transport.NetworkConnectionScheduler)

Example 14 with MessageStore

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);
        }
    });
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) PreferenceStoreProvider(org.apache.qpid.server.store.preferences.PreferenceStoreProvider) DurableConfigurationStore(org.apache.qpid.server.store.DurableConfigurationStore) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore)

Example 15 with MessageStore

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();
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) File(java.io.File)

Aggregations

MessageStore (org.apache.qpid.server.store.MessageStore)20 MessageEnqueueRecord (org.apache.qpid.server.store.MessageEnqueueRecord)7 NullMessageStore (org.apache.qpid.server.store.NullMessageStore)6 Transaction (org.apache.qpid.server.store.Transaction)6 MessageHandler (org.apache.qpid.server.store.handler.MessageHandler)6 MessageInstanceHandler (org.apache.qpid.server.store.handler.MessageInstanceHandler)6 UUID (java.util.UUID)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 StorableMessageMetaData (org.apache.qpid.server.store.StorableMessageMetaData)5 ServerMessage (org.apache.qpid.server.message.ServerMessage)3 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)2 VirtualHost (org.apache.qpid.server.model.VirtualHost)2 QueueEntry (org.apache.qpid.server.queue.QueueEntry)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 TestMemoryMessageStore (org.apache.qpid.server.store.TestMemoryMessageStore)2 EnqueueRecord (org.apache.qpid.server.store.Transaction.EnqueueRecord)2 TransactionLogResource (org.apache.qpid.server.store.TransactionLogResource)2 DistributedTransactionHandler (org.apache.qpid.server.store.handler.DistributedTransactionHandler)2 File (java.io.File)1 AccessControlException (java.security.AccessControlException)1