use of org.apache.qpid.server.protocol.v1_0.type.BaseTarget 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.BaseTarget 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.BaseTarget 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.BaseTarget in project qpid-broker-j by apache.
the class Session_1_0 method receiveFlow.
public void receiveFlow(final Flow flow) {
receivedComplete();
final SequenceNumber flowNextIncomingId = new SequenceNumber(flow.getNextIncomingId() == null ? _initialOutgoingId.intValue() : flow.getNextIncomingId().intValue());
if (flowNextIncomingId.compareTo(_nextOutgoingId) > 0) {
final End end = new End();
end.setError(new Error(SessionError.WINDOW_VIOLATION, String.format("Next incoming id '%d' exceeds next outgoing id '%d'", flowNextIncomingId.longValue(), _nextOutgoingId.longValue())));
end(end);
} else {
_remoteIncomingWindow = flowNextIncomingId.longValue() + flow.getIncomingWindow().longValue() - _nextOutgoingId.longValue();
_nextIncomingId = new SequenceNumber(flow.getNextOutgoingId().intValue());
_remoteOutgoingWindow = flow.getOutgoingWindow();
UnsignedInteger handle = flow.getHandle();
if (handle != null) {
final LinkEndpoint<? extends BaseSource, ? extends BaseTarget> endpoint = _inputHandleToEndpoint.get(handle);
if (endpoint == null) {
End end = new End();
end.setError(new Error(SessionError.UNATTACHED_HANDLE, String.format("Received Flow with unknown handle %d", handle.intValue())));
end(end);
} else {
endpoint.receiveFlow(flow);
}
} else {
final Collection<LinkEndpoint<? extends BaseSource, ? extends BaseTarget>> allLinkEndpoints = _inputHandleToEndpoint.values();
for (LinkEndpoint<? extends BaseSource, ? extends BaseTarget> le : allLinkEndpoints) {
le.flowStateChanged();
}
if (Boolean.TRUE.equals(flow.getEcho())) {
sendFlow();
}
}
}
}
use of org.apache.qpid.server.protocol.v1_0.type.BaseTarget in project qpid-broker-j by apache.
the class Session_1_0 method receiveTransfer.
public void receiveTransfer(final Transfer transfer) {
_nextIncomingId.incr();
_remoteOutgoingWindow = _remoteOutgoingWindow.subtract(UnsignedInteger.ONE);
UnsignedInteger inputHandle = transfer.getHandle();
LinkEndpoint<? extends BaseSource, ? extends BaseTarget> linkEndpoint = _inputHandleToEndpoint.get(inputHandle);
if (linkEndpoint == null) {
Error error = new Error();
error.setCondition(SessionError.UNATTACHED_HANDLE);
error.setDescription("TRANSFER called on Session for link handle " + inputHandle + " which is not attached.");
_connection.close(error);
} else if (!(linkEndpoint instanceof AbstractReceivingLinkEndpoint)) {
Error error = new Error();
error.setCondition(AmqpError.PRECONDITION_FAILED);
error.setDescription("Received TRANSFER for link handle " + inputHandle + " which is a sending link not a receiving link.");
_connection.close(error);
} else {
AbstractReceivingLinkEndpoint endpoint = ((AbstractReceivingLinkEndpoint) linkEndpoint);
endpoint.receiveTransfer(transfer);
}
}
Aggregations