void issueCredits(int credits, boolean drain) throws org.eris.messaging.TransportException { if (drain) { _protonReceiver.setDrain(true); } _protonReceiver.flow(credits); _ssn.write(); }
public AbstractProtonReceiverContext( AMQPSessionCallback sessionSPI, AbstractConnectionContext connection, AbstractProtonSessionContext protonSession, Receiver receiver) { this.connection = connection; this.protonSession = protonSession; this.receiver = receiver; if (receiver.getRemoteTarget() != null) { this.address = receiver.getRemoteTarget().getAddress(); } else { this.address = null; } this.sessionSPI = sessionSPI; }
@Override public void onDelivery(Event event) { Receiver recv = (Receiver) event.getLink(); Delivery delivery = recv.current(); if (delivery.isReadable() && !delivery.isPartial()) { int size = delivery.pending(); byte[] buffer = new byte[size]; int read = recv.recv(buffer, 0, buffer.length); recv.advance(); Message msg = Proton.message(); msg.decode(buffer, 0, read); ++count; String msgBody = ((AmqpValue) msg.getBody()).getValue().toString(); String expected = "message-" + count; if (!expected.equals(msgBody)) { throw new RuntimeException( "Received message body '" + msgBody + "', expected: '" + expected + "'"); } if (count == numMsgs) { recv.close(); recv.getSession().close(); recv.getSession().getConnection().close(); acceptor.close(); } } }
void cancelPrevCredits() throws org.eris.messaging.TransportException { _protonReceiver.flow(0); _ssn.write(); }
void checkClosed() throws org.eris.messaging.ReceiverException { if (_protonReceiver.getLocalState() != EndpointState.ACTIVE) { throw new org.eris.messaging.ReceiverException("ErisReceiver is closed"); } }
@Override public org.eris.messaging.Receiver createReceiver( String address, ReceiverMode mode, CreditMode creditMode) throws org.eris.messaging.TransportException, org.eris.messaging.SessionException { checkPreConditions(); Receiver receiver; Source source = new Source(); Target target = new Target(); if (address == null || address.isEmpty() || address.equals("#")) { String temp = UUID.randomUUID().toString(); receiver = _session.receiver(temp); source.setDynamic(true); } else { receiver = _session.receiver(address); source.setAddress(address); } receiver.setSource(source); receiver.setTarget(target); switch (mode) { case AT_MOST_ONCE: receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); receiver.setSenderSettleMode(SenderSettleMode.SETTLED); break; case AT_LEAST_ONCE: receiver.setReceiverSettleMode(ReceiverSettleMode.FIRST); receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); break; case EXACTLY_ONCE: receiver.setReceiverSettleMode(ReceiverSettleMode.SECOND); receiver.setSenderSettleMode(SenderSettleMode.UNSETTLED); break; } receiver.open(); ReceiverImpl receiverImpl = new ReceiverImpl(address, this, receiver, creditMode); receiverImpl.setDynamicAddress(source.getDynamic()); _receivers.put(receiver, receiverImpl); receiver.setContext(receiverImpl); _conn.write(); return receiverImpl; }
public void flow(int credits) { synchronized (connection.getLock()) { receiver.flow(credits); } connection.flush(); }