use of org.apache.qpid.server.protocol.v1_0.type.BaseSource in project qpid-broker-j by apache.
the class Interaction method copyAttach.
private Attach copyAttach(final Attach attach) {
final Attach attachCopy = new Attach();
attachCopy.setName(attach.getName());
attachCopy.setHandle(attach.getHandle());
attachCopy.setRole(attach.getRole());
attachCopy.setSndSettleMode(attach.getSndSettleMode());
attachCopy.setRcvSettleMode(attach.getRcvSettleMode());
final BaseSource baseSource = attach.getSource();
if (baseSource != null && baseSource instanceof Source) {
final Source source = (Source) baseSource;
final Source sourceCopy = new Source();
sourceCopy.setAddress(source.getAddress());
sourceCopy.setDurable(source.getDurable());
sourceCopy.setExpiryPolicy(source.getExpiryPolicy());
sourceCopy.setTimeout(source.getTimeout());
sourceCopy.setDynamic(source.getDynamic());
if (source.getDynamicNodeProperties() != null) {
sourceCopy.setDynamicNodeProperties(new LinkedHashMap<>(source.getDynamicNodeProperties()));
}
sourceCopy.setFilter(source.getFilter());
sourceCopy.setDefaultOutcome(source.getDefaultOutcome());
sourceCopy.setOutcomes(source.getOutcomes());
sourceCopy.setCapabilities(source.getCapabilities());
attachCopy.setSource(sourceCopy);
} else {
attachCopy.setSource(baseSource);
}
final BaseTarget baseTarget = attach.getTarget();
if (baseTarget != null && baseTarget instanceof Target) {
final Target target = (Target) baseTarget;
final Target targetCopy = new Target();
targetCopy.setAddress(target.getAddress());
targetCopy.setDurable(target.getDurable());
targetCopy.setExpiryPolicy(target.getExpiryPolicy());
targetCopy.setTimeout(target.getTimeout());
targetCopy.setDynamic(target.getDynamic());
if (target.getDynamicNodeProperties() != null) {
targetCopy.setDynamicNodeProperties(new LinkedHashMap<>(target.getDynamicNodeProperties()));
}
targetCopy.setCapabilities(target.getCapabilities());
attachCopy.setTarget(targetCopy);
} else {
attachCopy.setTarget(baseTarget);
}
if (attach.getUnsettled() != null) {
attachCopy.setUnsettled(new LinkedHashMap<>(attach.getUnsettled()));
}
attachCopy.setIncompleteUnsettled(attach.getIncompleteUnsettled());
attachCopy.setInitialDeliveryCount(attach.getInitialDeliveryCount());
attachCopy.setMaxMessageSize(attach.getMaxMessageSize());
attachCopy.setOfferedCapabilities(attach.getOfferedCapabilities());
attachCopy.setDesiredCapabilities(attach.getDesiredCapabilities());
if (attach.getProperties() != null) {
attachCopy.setProperties(new LinkedHashMap<>(attach.getProperties()));
}
return attachCopy;
}
use of org.apache.qpid.server.protocol.v1_0.type.BaseSource 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)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.BaseSource in project qpid-broker-j by apache.
the class LinkRegistryImpl method open.
@Override
public void open() {
Collection<LinkDefinition<Source, Target>> links = _linkStore.openAndLoad(new LinkStoreUpdaterImpl());
for (LinkDefinition<? extends BaseSource, ? extends BaseTarget> link : links) {
ConcurrentMap<LinkKey, Link_1_0<? extends BaseSource, ? extends BaseTarget>> linkRegistry = getLinkRegistry(link.getRole());
linkRegistry.put(new LinkKey(link), new LinkImpl<>(link, this));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.BaseSource in project qpid-broker-j by apache.
the class JDBCLinkStore method update.
private void update(final Connection connection, final String linkKey, final LinkDefinition<? extends BaseSource, ? extends BaseTarget> linkDefinition) throws SQLException {
try (PreparedStatement statement = connection.prepareStatement(String.format("UPDATE %s SET source = ?, target = ? WHERE link_key = ?", getLinksTableName()))) {
saveObjectAsBlob(statement, 1, linkDefinition.getSource());
saveObjectAsBlob(statement, 2, linkDefinition.getTarget());
statement.setString(3, linkKey);
if (statement.executeUpdate() != 1) {
throw new StoreException(String.format("Cannot save link %s", new LinkKey(linkDefinition)));
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.BaseSource in project qpid-broker-j by apache.
the class SendingLinkEndpoint method recoverLink.
@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
Source source = getSource();
if (source == null && attach.getDesiredCapabilities() != null) {
List<Symbol> capabilities = Arrays.asList(attach.getDesiredCapabilities());
if (capabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && capabilities.contains(Session_1_0.SHARED_CAPABILITY) && getLinkName().endsWith("|global")) {
NamedAddressSpace namedAddressSpace = getSession().getConnection().getAddressSpace();
Collection<Link_1_0<? extends BaseSource, ? extends BaseTarget>> links = namedAddressSpace.findSendingLinks(ANY_CONTAINER_ID, Pattern.compile("^" + Pattern.quote(getLinkName()) + "$"));
for (Link_1_0<? extends BaseSource, ? extends BaseTarget> link : links) {
BaseSource baseSource = link.getSource();
if (baseSource instanceof Source) {
Source linkSource = (Source) baseSource;
source = new Source(linkSource);
getLink().setSource(source);
break;
}
}
}
}
if (source == null) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, ""));
}
attach.setSource(source);
receiveAttach(attach);
}
Aggregations