use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-ce by iitsoftware.
the class SessionHandler method sendDetach.
private void sendDetach(Handle handle, ErrorConditionIF condition, AMQPString description) {
DetachFrame detachFrame = new DetachFrame(channel);
detachFrame.setHandle(handle);
detachFrame.setClosed(AMQPBoolean.TRUE);
if (condition != null) {
Error error = new Error();
error.setCondition(condition);
if (description != null)
error.setDescription(description);
detachFrame.setError(error);
}
versionedConnection.send(detachFrame);
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.
the class SessionDispatcher method doSend.
private void doSend(POSendMessage po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", dataLength=" + po.getPackager().getSize());
try {
Producer producer = po.getProducer();
producer.verifyState();
Packager packager = po.getPackager();
if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
do {
boolean wasFirstPacket = false;
boolean isAtMostOnce = producer.getQoS() == QoS.AT_MOST_ONCE;
packager.setMaxFrameSize(mySession.myConnection.connectionDispatcher.getMaxFrameSize());
TransferFrame frame = new TransferFrame(mySession.getChannel());
frame.setHandle(new Handle(producer.getHandle()));
frame.setSettled(new AMQPBoolean(isAtMostOnce));
if (packager.getCurrentPacketNumber() == 0) {
long dId = nextDeliveryId();
wasFirstPacket = true;
producer.incDeliveryCountSnd();
DeliveryTag deliveryTag = po.getDeliveryTag() != null ? po.getDeliveryTag() : producer.createDeliveryTag();
if (!isAtMostOnce) {
if (po.getTxnId() == null && !po.isRecovery())
producer.getDeliveryMemory().addUnsettledDelivery(new UnsettledDelivery(deliveryTag, null, po.getMessage()));
unsettledOutgoingDeliveries.put(dId, new DeliveryMapping(deliveryTag, producer));
}
frame.setDeliveryTag(deliveryTag);
frame.setDeliveryId(new DeliveryNumber(dId));
frame.setMessageFormat(new MessageFormat(0));
TxnIdIF txnId = po.getTxnId();
if (txnId != null) {
TransactionalState txState = new TransactionalState();
txState.setTxnId(txnId);
frame.setState(txState);
}
}
packager.setMessageFormat(0);
packager.getNextPacket(frame);
// We may increase the outgoing window and send a flow before
if (wasFirstPacket && outgoingWindow - packager.getPredictedNumberPackets() < 0) {
outgoingWindow += packager.getPredictedNumberPackets();
sendFlow();
windowChanged = true;
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + packager.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + packager.getPredictedNumberPackets() + ", currentPacket=" + packager.getCurrentPacketNumber() + ", hasMore=" + packager.hasMore());
outboundHandler.send(frame);
nextOutgoingId++;
remoteIncomingWindow--;
if (!isAtMostOnce)
outgoingWindow--;
if (!packager.hasMore()) {
// b) everything else: after the last packet has been sent
if (producer.isTransactionController() || po.getTxnId() != null)
producer.setWaitingPO(po);
else {
po.setSuccess(true);
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
// If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
if (windowChanged) {
outgoingWindow = mySession.getOutgoingWindowSize();
sendFlow();
}
break;
}
} while (remoteIncomingWindow > 0 && outgoingWindow > 0);
if (packager.hasMore()) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
outboundDeliveries.add(po);
}
} else {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", doSend, po=" + po + ", remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", no window, storing message");
outboundDeliveries.add(po);
}
} catch (Exception e) {
po.setSuccess(false);
po.setException(e.getMessage());
if (po.getSemaphore() != null)
po.getSemaphore().notifySingleWaiter();
}
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachDurableConsumer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
deliveryMemory.setLinkName(po.getLinkName());
DurableConsumer consumer = new DurableConsumer(mySession, po.getSource(), po.getLinkName(), po.getLinkCredit(), po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
consumer.setHandle(handle);
po.setLink(consumer);
waitingPO.put(po.getLinkName(), po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(po.getLinkName()));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.RECEIVER);
if (consumer.getQoS() == QoS.AT_MOST_ONCE)
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
Source source = new Source();
String s = po.getSource();
if (s != null)
source.setAddress(new AddressString(s));
else
source.setDynamic(AMQPBoolean.TRUE);
// This identifies a durable
source.setDurable(TerminusDurability.CONFIGURATION);
source.setExpiryPolicy(po.getExpiryPolicy());
source.setTimeout(new Seconds(0));
Map m = null;
if (po.isNoLocal()) {
m = new HashMap();
m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
}
if (po.getSelector() != null) {
if (m == null)
m = new HashMap();
m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
}
if (m != null)
source.setFilter(new FilterSet(m));
attachFrame.setSource(source);
Target target = new Target();
target.setAddress(new AddressString(uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++)));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachProducer po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
String name = null;
DeliveryMemory deliveryMemory = po.getDeliveryMemory();
if (deliveryMemory.getLinkName() != null)
name = deliveryMemory.getLinkName();
else {
name = uniqueSessionId + "/" + po.getTarget() + "/" + (nextLinkId++);
deliveryMemory.setLinkName(name);
}
Producer producer = new Producer(mySession, po.getTarget(), name, po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, producer);
producer.setHandle(handle);
po.setLink(producer);
waitingPO.put(name, po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(name));
attachFrame.setHandle(new Handle(handle));
attachFrame.setRole(Role.SENDER);
switch(producer.getQoS()) {
case QoS.AT_LEAST_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.FIRST);
break;
case QoS.AT_MOST_ONCE:
attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
break;
case QoS.EXACTLY_ONCE:
attachFrame.setRcvSettleMode(ReceiverSettleMode.SECOND);
break;
}
Source source = new Source();
source.setAddress(new AddressString(name));
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
source.setTimeout(new Seconds(0));
attachFrame.setSource(source);
String t = po.getTarget();
if (t.equals(Coordinator.DESCRIPTOR_NAME)) {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPType[] { TxnCapability.LOCAL_TRANSACTIONS }));
attachFrame.setTarget(coordinator);
} else {
Target target = new Target();
target.setAddress(new AddressString(t));
target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
target.setTimeout(new Seconds(0));
attachFrame.setTarget(target);
}
attachFrame.setInitialDeliveryCount(new SequenceNo(producer.getDeliveryCountSnd()));
attachFrame.setUnsettled(getUnsettledMap(producer.getDeliveryMemory()));
outboundHandler.send(attachFrame);
} catch (Exception e) {
e.printStackTrace();
}
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POFillCache po) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " ...");
Consumer c = po.getConsumer();
FlowFrame flowFrame = new FlowFrame(mySession.getChannel());
flowFrame.setHandle(new Handle(c.getHandle()));
flowFrame.setAvailable(new AMQPUnsignedInt(0));
flowFrame.setDrain(AMQPBoolean.FALSE);
flowFrame.setNextIncomingId(new TransferNumber(nextIncomingId));
flowFrame.setNextOutgoingId(new TransferNumber(nextOutgoingId));
flowFrame.setLinkCredit(new AMQPUnsignedInt(po.getLinkCredit()));
flowFrame.setIncomingWindow(new AMQPUnsignedInt(incomingWindow));
flowFrame.setOutgoingWindow(new AMQPUnsignedInt(outgoingWindow));
if (po.getLastDeliveryId() != -1)
flowFrame.setDeliveryCount(new SequenceNo(po.getLastDeliveryId()));
TxnIdIF txnIdIF = po.getTxnIdIF();
if (txnIdIF != null) {
Map map = new HashMap();
map.put(new AMQPSymbol("txn-id"), txnIdIF);
try {
flowFrame.setProperties(new Fields(map));
} catch (IOException e) {
e.printStackTrace();
}
}
outboundHandler.send(flowFrame);
if (pTracer.isEnabled())
pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Aggregations