本文整理汇总了Java中org.apache.qpid.proton.engine.Sender类的典型用法代码示例。如果您正苦于以下问题:Java Sender类的具体用法?Java Sender怎么用?Java Sender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Sender类属于org.apache.qpid.proton.engine包,在下文中一共展示了Sender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDelivery
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public void onDelivery(Event evt) {
Delivery dlv = evt.getDelivery();
Link link = dlv.getLink();
if (link instanceof Sender) {
dlv.settle();
} else {
Receiver rcv = (Receiver) link;
if (!dlv.isPartial()) {
byte[] bytes = new byte[dlv.pending()];
rcv.recv(bytes, 0, bytes.length);
String address = router.getAddress(rcv);
Message message = new Message(bytes);
messages.put(address, message);
dlv.disposition(Accepted.getInstance());
dlv.settle();
if (!quiet) {
System.out.println(String.format("Got message(%s): %s", address, message));
}
send(address);
}
}
}
示例2: Pool
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
public Pool(Collector collector, final Router router) {
this.collector = collector;
connections = new HashMap<String,Connection>();
if (router != null) {
outgoingResolver = new LinkResolver<Sender>() {
public Sender resolve(String address) {
return router.getOutgoing(address).choose();
}
};
incomingResolver = new LinkResolver<Receiver>() {
public Receiver resolve(String address) {
return router.getIncoming(address).choose();
}
};
} else {
outgoingResolver = new LinkResolver<Sender>() {
public Sender resolve(String address) { return null; }
};
incomingResolver = new LinkResolver<Receiver>() {
public Receiver resolve(String address) { return null; }
};
}
}
示例3: onLinkFlow
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public void onLinkFlow(Event evt) {
Link link = evt.getLink();
if (link instanceof Sender) {
Sender sender = (Sender) link;
while ((sent < count) && sender.getCredit() > 0) {
Delivery dlv = sender.delivery(String.format("spout-%s", sent).getBytes());
Message msg = new Message(String.format("Hello World! [%s]", sent));
byte[] bytes = msg.getBytes();
sender.send(bytes, 0, bytes.length);
sender.advance();
if (!quiet) {
System.out.println(String.format("Sent %s to %s: %s", new String(dlv.getTag()),
sender.getTarget().getAddress(), msg));
}
sent++;
}
}
}
示例4: onConnectionInit
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public void onConnectionInit(Event event) {
Connection conn = event.getConnection();
// Every session or link could have their own handler(s) if we
// wanted simply by adding the handler to the given session
// or link
Session ssn = conn.session();
// If a link doesn't have an event handler, the events go to
// its parent session. If the session doesn't have a handler
// the events go to its parent connection. If the connection
// doesn't have a handler, the events go to the reactor.
Sender snd = ssn.sender("sender");
conn.open();
ssn.open();
snd.open();
}
示例5: onLinkFlow
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public void onLinkFlow(Event event) {
Sender snd = (Sender)event.getLink();
if (snd.getCredit() > 0) {
byte[] msgData = new byte[1024];
int length;
while(true) {
try {
length = message.encode(msgData, 0, msgData.length);
break;
} catch(BufferOverflowException e) {
msgData = new byte[msgData.length * 2];
}
}
byte[] tag = String.valueOf(nextTag++).getBytes();
Delivery dlv = snd.delivery(tag);
snd.send(msgData, 0, length);
dlv.settle();
snd.advance();
snd.close();
snd.getSession().close();
snd.getSession().getConnection().close();
}
}
示例6: sendMessageToClient
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
private Delivery sendMessageToClient(String deliveryTag, int messageBody)
{
byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);
Message m = Proton.message();
m.setBody(new AmqpValue(messageBody));
byte[] encoded = new byte[BUFFER_SIZE];
int len = m.encode(encoded, 0, BUFFER_SIZE);
assertTrue("given array was too small", len < BUFFER_SIZE);
Sender serverSender = getServer().getSender();
Delivery serverDelivery = serverSender.delivery(tag);
int sent = serverSender.send(encoded, 0, len);
assertEquals("sender unable to send all data at once as assumed for simplicity", len, sent);
boolean senderAdvanced = serverSender.advance();
assertTrue("sender has not advanced", senderAdvanced);
return serverDelivery;
}
示例7: testGetTransportWithDeliveryContext
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Test
public void testGetTransportWithDeliveryContext()
{
Transport transport = Transport.Factory.create();
Connection connection = Connection.Factory.create();
transport.bind(connection);
Session session = connection.session();
Sender sender = session.sender("mySender");
Delivery delivery = sender.delivery("tag".getBytes());
EventImpl event = createEvent(delivery, Event.Type.DELIVERY);
assertNotNull("No transport returned", event.getTransport());
assertSame("Incorrect transport returned", transport, event.getTransport());
}
示例8: onLinkRemoteOpen
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public void onLinkRemoteOpen(Event e) {
System.out.println("onLinkRemoteOpen");
e.getLink().open();
if (e.getLink() instanceof Sender) {
Sender sender = (Sender)e.getLink();
delivery = sender.delivery(new byte[]{1});
sender.send(new byte[]{1, 2, 3}, 0, 3);
sender.advance();
} else {
Receiver receiver = (Receiver)e.getLink();
receiver.flow(1024);
}
if (closeConnection) {
e.getConnection().setCondition(new ErrorCondition(Symbol.getSymbol("symbol"), "Something went wrong!"));
e.getConnection().close();
}
}
示例9: sendTxCommand
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
private void sendTxCommand(Message message) throws IOException {
int encodedSize = 0;
byte[] buffer = OUTBOUND_BUFFER;
while (true) {
try {
encodedSize = message.encode(buffer, 0, buffer.length);
break;
} catch (BufferOverflowException e) {
buffer = new byte[buffer.length * 2];
}
}
Sender sender = getEndpoint();
sender.send(buffer, 0, encodedSize);
sender.advance();
}
示例10: doOpen
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
protected void doOpen() {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(TxnCapability.LOCAL_TXN);
Source source = new Source();
String coordinatorName = "qpid-jms:coordinator:" + session.getConnection().getConnectionId();
Sender sender = session.getEndpoint().sender(coordinatorName);
sender.setSource(source);
sender.setTarget(coordinator);
sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
setEndpoint(sender);
super.doOpen();
}
示例11: remoteLinkOpened
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
protected void remoteLinkOpened(Link link) throws Exception {
AMQPSessionContext protonSession = getSessionExtension(link.getSession());
link.setSource(link.getRemoteSource());
link.setTarget(link.getRemoteTarget());
if (link instanceof Receiver) {
Receiver receiver = (Receiver) link;
if (link.getRemoteTarget() instanceof Coordinator) {
Coordinator coordinator = (Coordinator) link.getRemoteTarget();
protonSession.addTransactionHandler(coordinator, receiver);
} else {
protonSession.addReceiver(receiver);
}
} else {
Sender sender = (Sender) link;
protonSession.addSender(sender);
}
}
示例12: createOutboundLink
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
public OutgoingLink createOutboundLink(String address, ReliabilityMode mode) throws MessagingException {
checkClosed();
String name = UUID.randomUUID().toString();
Sender sender = _ssn.sender(name);
// Source source = new Source();
Target target = new Target();
if (address == null || address.isEmpty() || address.equals("#")) {
target.setDynamic(true);
} else {
target.setAddress(address);
}
sender.setTarget(target);
// sender.setSource(source);
sender.setSenderSettleMode(mode == ReliabilityMode.UNRELIABLE ? SenderSettleMode.SETTLED
: SenderSettleMode.UNSETTLED);
sender.open();
OutgoingLinkImpl outLink = new OutgoingLinkImpl(this, address, sender);
outLink.setDynamicAddress(target.getDynamic());
_links.put(sender, outLink);
sender.setContext(outLink);
return outLink;
}
示例13: send
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
TrackerImpl send(org.apache.qpid.proton.message.Message m) throws MessageFormatException, MessagingException {
checkClosed();
Sender sender = (Sender) _link;
byte[] tag = longToBytes(_ssn.getNextDeliveryTag());
Delivery delivery = sender.delivery(tag);
TrackerImpl tracker = new TrackerImpl(_ssn);
delivery.setContext(tracker);
if (m.getAddress() == null) {
m.setAddress(_address);
}
byte[] buffer = new byte[1024];
int encoded = m.encode(buffer, 0, buffer.length);
sender.send(buffer, 0, encoded);
if (sender.getSenderSettleMode() == SenderSettleMode.SETTLED) {
delivery.settle();
tracker.markSettled();
}
sender.advance();
_ssn.getConnection().write();
return tracker;
}
示例14: sendTxCommand
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
private void sendTxCommand(Message message) throws IOException {
int encodedSize = 0;
byte[] buffer = OUTBOUND_BUFFER;
while (true) {
try {
encodedSize = message.encode(buffer, 0, buffer.length);
break;
} catch (BufferOverflowException e) {
buffer = new byte[buffer.length * 2];
}
}
Sender sender = getEndpoint();
sender.send(buffer, 0, encodedSize);
sender.advance();
}
示例15: createEndpoint
import org.apache.qpid.proton.engine.Sender; //导入依赖的package包/类
@Override
protected Sender createEndpoint(JmsSessionInfo resourceInfo) {
Coordinator coordinator = new Coordinator();
coordinator.setCapabilities(TxnCapability.LOCAL_TXN);
Symbol[] outcomes = new Symbol[]{ Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL, Released.DESCRIPTOR_SYMBOL, Modified.DESCRIPTOR_SYMBOL };
Source source = new Source();
source.setOutcomes(outcomes);
String coordinatorName = "qpid-jms:coordinator:" + resourceInfo.getId().toString();
Sender sender = getParent().getSession().getEndpoint().sender(coordinatorName);
sender.setSource(source);
sender.setTarget(coordinator);
sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
return sender;
}