use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.
the class SessionDispatcher method close.
public void close() {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", close ...");
if (closeInProgress) {
if (pTracer.isEnabled())
pTracer.trace(toString(), ", close in progress, return");
return;
}
closeLock.lock();
closeInProgress = true;
closeLock.unlock();
Semaphore sem = new Semaphore();
dispatch(new POSessionClose(sem));
sem.waitHere();
if (pTracer.isEnabled())
pTracer.trace(toString(), ", close done");
}
use of com.swiftmq.tools.concurrent.Semaphore 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.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.
the class Producer method send.
/**
* Send a message to the target. For transactional sends the method returns after settlement has been finished, otherwise when the message has been sent.
*
* @param msg message
* @param persistent whether the message should send/stored durable
* @param priority message priority (default is 5)
* @param ttl time to live (expiration) in milliseconds, default no expiration
* @return delivery state of the message
* @throws AMQPException on error
*/
public DeliveryStateIF send(AMQPMessage msg, boolean persistent, int priority, long ttl) throws AMQPException {
verifyState();
Header header = msg.getHeader();
if (header == null) {
header = new Header();
msg.setHeader(header);
}
header.setDurable(new AMQPBoolean(persistent));
header.setPriority(new AMQPUnsignedByte(priority));
if (ttl >= 0)
header.setTtl(new Milliseconds(ttl));
Properties props = msg.getProperties();
if (props == null) {
props = new Properties();
msg.setProperties(props);
}
if (props.getMessageId() == null)
props.setMessageId(new MessageIdString(nextMsgId()));
props.setTo(new AddressString(target));
String userName = mySession.myConnection.getUserName();
if (userName != null)
props.setUserId(new AMQPBinary(userName.getBytes()));
Semaphore sem = new Semaphore();
try {
POSendMessage po = new POSendMessage(sem, this, msg, msg.getTxnIdIF(), msg.getDeliveryTag());
mySession.dispatch(po);
sem.waitHere();
if (!po.isSuccess())
throw new AMQPException(po.getException());
return po.getDeliveryState();
} catch (Exception e) {
e.printStackTrace();
throw new AMQPException(e.toString());
}
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.
the class Session method createConsumer.
/**
* Creates a message consumer on a source.
*
* @param source the source, e.g. queue name
* @param linkCredit link credit
* @param qoS quality of service
* @param noLocal if true means it won't receive messages sent on the same topic and connection
* @param selector message selector (for SwiftMQ this would be a JMS message selector string)
* @param deliveryMemory delivery memory for recovery
* @return message consumer
* @throws AMQPException on error
*/
public Consumer createConsumer(String source, int linkCredit, int qoS, boolean noLocal, String selector, DeliveryMemory deliveryMemory) throws AMQPException {
verifyState();
QoS.verify(qoS);
Semaphore sem = new Semaphore();
POAttachConsumer po = new POAttachConsumer(sem, source, linkCredit, qoS, noLocal, selector, deliveryMemory == null ? new DefaultDeliveryMemory() : deliveryMemory);
sessionDispatcher.dispatch(po);
sem.waitHere();
if (!po.isSuccess())
throw new AMQPException(po.getException());
Consumer c = (Consumer) po.getLink();
links.add(c);
return c;
}
use of com.swiftmq.tools.concurrent.Semaphore in project swiftmq-client by iitsoftware.
the class Session method finishHandshake.
protected void finishHandshake() throws SessionHandshakeException {
Semaphore sem = new Semaphore();
POObject po = new POBegin(sem);
sessionDispatcher.dispatch(po);
sem.waitHere();
sem.reset();
if (!po.isSuccess()) {
cancel();
throw new SessionHandshakeException(po.getException());
}
}
Aggregations