use of com.swiftmq.amqp.v100.client.Consumer 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.client.Consumer 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.client.Consumer 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.client.Consumer in project swiftmq-client by iitsoftware.
the class DurableConsumer method unsubscribe.
/**
* Unsubscribes the durable consumer and destroys the durable link.
*
* @throws AMQPException
*/
public void unsubscribe() throws AMQPException {
if (!closed)
close();
Semaphore sem = new Semaphore();
POAttachDurableConsumer po = new POAttachDurableConsumer(sem, name, source, linkCredit, qoS, false, null, TerminusExpiryPolicy.LINK_DETACH, deliveryMemory);
mySession.getSessionDispatcher().dispatch(po);
sem.waitHere();
if (!po.isSuccess())
throw new AMQPException(po.getException());
DurableConsumer c = (DurableConsumer) po.getLink();
c.close();
}
use of com.swiftmq.amqp.v100.client.Consumer in project camel by apache.
the class OAuthToken method getOrRefreshAccessToken.
private synchronized void getOrRefreshAccessToken() {
if (token == null) {
LOGGER.debug("Generate OAuth token");
token = OAuthClientUtils.getAccessToken(WebClient.create(configuration.getOauthTokenUrl()), new Consumer(configuration.getOauthClientId(), configuration.getOauthClientSecret()), new ResourceOwnerGrant(configuration.getUserName(), configuration.getPassword()), true);
LOGGER.debug("OAuth token expires in {}s", token.getExpiresIn());
// Set expiration time related info in milliseconds
token.setIssuedAt(System.currentTimeMillis());
token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
authString = token.toString();
if (token.getExpiresIn() > 0) {
expireAt = token.getIssuedAt() + token.getExpiresIn();
}
} else if (expireAt > 0 && System.currentTimeMillis() >= expireAt) {
LOGGER.debug("OAuth token is expired, refresh it");
token = OAuthClientUtils.refreshAccessToken(WebClient.create(configuration.getOauthTokenUrl()), new Consumer(configuration.getOauthClientId(), configuration.getOauthClientSecret()), token, null, false);
LOGGER.debug("Refreshed OAuth token expires in {}s", token.getExpiresIn());
// Set expiration time related info in milliseconds
token.setIssuedAt(System.currentTimeMillis());
token.setExpiresIn(TimeUnit.MILLISECONDS.convert(token.getExpiresIn(), TimeUnit.SECONDS));
authString = token.toString();
if (token.getExpiresIn() > 0) {
expireAt = token.getIssuedAt() + token.getExpiresIn();
}
}
}
Aggregations