use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.
the class OutcomeFactory method create.
/**
* Creates a OutcomeIF object.
*
* @param bare the bare AMQP type
* @return OutcomeIF
*/
public static OutcomeIF create(AMQPType bare) throws Exception {
if (bare.getCode() == AMQPTypeDecoder.NULL)
return null;
AMQPDescribedConstructor constructor = bare.getConstructor();
if (constructor == null)
throw new IOException("Missing constructor: " + bare);
AMQPType descriptor = constructor.getDescriptor();
int code = descriptor.getCode();
if (AMQPTypeDecoder.isULong(code)) {
long type = ((AMQPUnsignedLong) descriptor).getValue();
if (type == Accepted.DESCRIPTOR_CODE)
return new Accepted(((AMQPList) bare).getValue());
if (type == Rejected.DESCRIPTOR_CODE)
return new Rejected(((AMQPList) bare).getValue());
if (type == Released.DESCRIPTOR_CODE)
return new Released(((AMQPList) bare).getValue());
if (type == Modified.DESCRIPTOR_CODE)
return new Modified(((AMQPList) bare).getValue());
if (type == Declared.DESCRIPTOR_CODE)
return new Declared(((AMQPList) bare).getValue());
throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
} else if (AMQPTypeDecoder.isSymbol(code)) {
String type = ((AMQPSymbol) descriptor).getValue();
if (type.equals(Accepted.DESCRIPTOR_NAME))
return new Accepted(((AMQPList) bare).getValue());
if (type.equals(Rejected.DESCRIPTOR_NAME))
return new Rejected(((AMQPList) bare).getValue());
if (type.equals(Released.DESCRIPTOR_NAME))
return new Released(((AMQPList) bare).getValue());
if (type.equals(Modified.DESCRIPTOR_NAME))
return new Modified(((AMQPList) bare).getValue());
if (type.equals(Declared.DESCRIPTOR_NAME))
return new Declared(((AMQPList) bare).getValue());
throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
} else
throw new Exception("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare);
}
use of com.swiftmq.amqp.v100.types.AMQPSymbol 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.types.AMQPSymbol 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");
}
use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.
the class SessionDispatcher method visit.
public void visit(POAttachConsumer 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.getSource() + "/" + (nextLinkId++);
deliveryMemory.setLinkName(name);
}
Consumer consumer = null;
if (po.getLinkCredit() == -1)
consumer = new Consumer(mySession, po.getSource(), name, po.getQoS(), deliveryMemory);
else
consumer = new Consumer(mySession, po.getSource(), name, po.getLinkCredit(), po.getQoS(), deliveryMemory);
int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
consumer.setHandle(handle);
po.setLink(consumer);
waitingPO.put(name, po);
try {
AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
attachFrame.setName(new AMQPString(name));
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);
source.setDurable(TerminusDurability.NONE);
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
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(name));
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.types.AMQPSymbol in project swiftmq-client by iitsoftware.
the class Connection method close.
protected void close(String condition, String description) {
if (closed)
return;
if (condition == null) {
Semaphore sem = new Semaphore();
POSendClose po = new POSendClose(sem, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
connectionDispatcher.dispatch(po);
sem.waitHere();
} else {
POSendClose po = new POSendClose(null, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
connectionDispatcher.dispatch(po);
}
cancel();
if (exceptionListener != null && condition != null && description != null)
exceptionListener.onException(new ConnectionClosedException(condition + " / " + description));
}
Aggregations