Search in sources :

Example 16 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class BDBLinkStore method getLinkDefinitions.

private Collection<LinkDefinition<Source, Target>> getLinkDefinitions(final LinkStoreUpdater updater) {
    Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
    Collection<LinkDefinition<Source, Target>> links = new HashSet<>();
    ModelVersion currentVersion = new ModelVersion(BrokerModel.MODEL_MAJOR_VERSION, BrokerModel.MODEL_MINOR_VERSION);
    ModelVersion storedVersion = getStoredVersion();
    if (currentVersion.lessThan(storedVersion)) {
        throw new StoreException(String.format("Cannot downgrade preference store from '%s' to '%s'", storedVersion, currentVersion));
    }
    try (Cursor cursor = linksDatabase.openCursor(null, null)) {
        final DatabaseEntry key = new DatabaseEntry();
        final DatabaseEntry value = new DatabaseEntry();
        LinkKeyEntryBinding keyEntryBinding = LinkKeyEntryBinding.getInstance();
        LinkValueEntryBinding linkValueEntryBinding = LinkValueEntryBinding.getInstance();
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            LinkKey linkKey = keyEntryBinding.entryToObject(key);
            LinkValue linkValue = linkValueEntryBinding.entryToObject(value);
            LinkDefinition<Source, Target> link = new LinkDefinitionImpl<>(linkKey.getRemoteContainerId(), linkKey.getLinkName(), linkKey.getRole(), linkValue.getSource(), linkValue.getTarget());
            links.add(link);
        }
    }
    if (storedVersion.lessThan(currentVersion)) {
        links = updater.update(storedVersion.toString(), links);
        final Transaction txn = getEnvironmentFacade().beginTransaction(null);
        try {
            linksDatabase = getEnvironmentFacade().clearDatabase(txn, LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
            for (LinkDefinition<Source, Target> link : links) {
                save(linksDatabase, txn, link);
            }
            updateVersion(txn, currentVersion.toString());
            txn.commit();
            linksDatabase.close();
        } catch (Exception e) {
            txn.abort();
            throw e;
        }
    }
    return links;
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) StoreException(org.apache.qpid.server.store.StoreException) DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) StoreException(org.apache.qpid.server.store.StoreException) LinkDefinition(org.apache.qpid.server.protocol.v1_0.LinkDefinition) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) LinkDefinitionImpl(org.apache.qpid.server.protocol.v1_0.LinkDefinitionImpl) Transaction(com.sleepycat.je.Transaction) Database(com.sleepycat.je.Database) ModelVersion(org.apache.qpid.server.model.ModelVersion) HashSet(java.util.HashSet)

Example 17 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class BDBLinkStore method doSaveLink.

@Override
protected void doSaveLink(final LinkDefinition<Source, Target> link) {
    try {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
        save(linksDatabase, null, link);
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed saving of link '%s'", new LinkKey(link)), e);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) Database(com.sleepycat.je.Database)

Example 18 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class BDBLinkStore method doDeleteLink.

@Override
protected void doDeleteLink(final LinkDefinition<Source, Target> linkDefinition) {
    LinkKey linkKey = new LinkKey(linkDefinition);
    try {
        Database linksDatabase = getEnvironmentFacade().openDatabase(LINKS_DB_NAME, DEFAULT_DATABASE_CONFIG);
        final DatabaseEntry databaseEntry = new DatabaseEntry();
        LinkKeyEntryBinding.getInstance().objectToEntry(linkKey, databaseEntry);
        OperationStatus status = linksDatabase.delete(null, databaseEntry);
        if (status != OperationStatus.SUCCESS) {
            LOGGER.debug(String.format("Unexpected status '%s' for deletion of '%s'", status, linkKey));
        }
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException(String.format("Failed deletion of link '%s'", linkKey), e);
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 19 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source in project qpid-broker-j by apache.

the class JDBCLinkStore method insert.

private void insert(final Connection connection, final String linkKey, final LinkDefinition<? extends BaseSource, ? extends BaseTarget> linkDefinition) throws SQLException {
    try (PreparedStatement statement = connection.prepareStatement(String.format("INSERT INTO %s (link_key, remote_container_id, link_name, link_role, source, target) VALUES (?,?,?,?,?,?)", getLinksTableName()))) {
        statement.setString(1, linkKey);
        saveStringAsBlob(statement, 2, linkDefinition.getRemoteContainerId());
        saveStringAsBlob(statement, 3, linkDefinition.getName());
        statement.setInt(4, linkDefinition.getRole().getValue() ? 1 : 0);
        saveObjectAsBlob(statement, 5, linkDefinition.getSource());
        saveObjectAsBlob(statement, 6, linkDefinition.getTarget());
        if (statement.executeUpdate() != 1) {
            throw new StoreException(String.format("Cannot save link %s", new LinkKey(linkDefinition)));
        }
    }
}
Also used : LinkKey(org.apache.qpid.server.protocol.v1_0.LinkKey) PreparedStatement(java.sql.PreparedStatement) StoreException(org.apache.qpid.server.store.StoreException)

Example 20 with Source

use of org.apache.qpid.server.protocol.v1_0.type.messaging.Source 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;
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) NotFoundException(org.apache.qpid.server.model.NotFoundException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)32 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)16 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)15 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)14 Test (org.junit.Test)14 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)13 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)13 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)11 Target (org.apache.qpid.server.protocol.v1_0.type.messaging.Target)10 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)10 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 MessageSource (org.apache.qpid.server.message.MessageSource)9 LinkKey (org.apache.qpid.server.protocol.v1_0.LinkKey)8 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)8 StoreException (org.apache.qpid.server.store.StoreException)8 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)7 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)7 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)6 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)6 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)6