本文整理汇总了Java中org.apache.qpid.proton.framing.TransportFrame类的典型用法代码示例。如果您正苦于以下问题:Java TransportFrame类的具体用法?Java TransportFrame怎么用?Java TransportFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransportFrame类属于org.apache.qpid.proton.framing包,在下文中一共展示了TransportFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public boolean handleFrame(TransportFrame frame)
{
if (!isHandlingFrames())
{
throw new IllegalStateException("Transport cannot accept frame: " + frame);
}
log(INCOMING, frame);
ProtocolTracer tracer = _protocolTracer.get();
if( tracer != null )
{
tracer.receivedFrame(frame);
}
frame.getBody().invoke(this,frame.getPayload(), frame.getChannel());
return _closeReceived;
}
示例2: log
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
void log(String event, TransportFrame frame)
{
if (isTraceFramesEnabled()) {
StringBuilder msg = new StringBuilder();
msg.append("[").append(System.identityHashCode(this)).append(":")
.append(frame.getChannel()).append("]");
msg.append(" ").append(event).append(" ").append(frame.getBody());
Binary bin = frame.getPayload();
if (bin != null) {
msg.append(" (").append(bin.getLength()).append(") ");
msg.append(StringUtils.toQuotedString(bin, TRACE_FRAME_PAYLOAD_LENGTH, true));
}
System.out.println(msg.toString());
}
}
示例3: handleTransfer
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
private void handleTransfer(TransportImpl transport, int deliveryNumber, String deliveryTag, String messageContent)
{
byte[] tag = deliveryTag.getBytes(StandardCharsets.UTF_8);
Message m = Message.Factory.create();
m.setBody(new AmqpValue(messageContent));
byte[] encoded = new byte[BUFFER_SIZE];
int len = m.encode(encoded, 0, BUFFER_SIZE);
assertTrue("given array was too small", len < BUFFER_SIZE);
Transfer transfer = new Transfer();
transfer.setDeliveryId(UnsignedInteger.valueOf(deliveryNumber));
transfer.setHandle(UnsignedInteger.ZERO);
transfer.setDeliveryTag(new Binary(tag));
transfer.setMessageFormat(UnsignedInteger.valueOf(DeliveryImpl.DEFAULT_MESSAGE_FORMAT));
transport.handleFrame(new TransportFrame(0, transfer, new Binary(encoded, 0, len)));
}
示例4: matches
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public boolean matches(Object transportFrameObj)
{
if(transportFrameObj == null)
{
return false;
}
TransportFrame transportFrame = (TransportFrame)transportFrameObj;
FrameBody actualFrame = transportFrame.getBody();
int _expectedChannel = _expectedTransportFrame.getChannel();
FrameBody expectedFrame = _expectedTransportFrame.getBody();
return _expectedChannel == transportFrame.getChannel()
&& expectedFrame.getClass().equals(actualFrame.getClass());
}
示例5: testTickRemoteTimeout
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Test
public void testTickRemoteTimeout()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
int timeout = 4000;
Open open = new Open();
open.setIdleTimeOut(new UnsignedInteger(4000));
TransportFrame openFrame = new TransportFrame(CHANNEL_ID, open, null);
transport.handleFrame(openFrame);
pumpMockTransport(transport);
long deadline = transport.tick(0);
assertEquals("Expected to be returned a deadline of 2000", 2000, deadline); // deadline = 4000 / 2
deadline = transport.tick(1000); // Wait for less than the deadline with no data - get the same value
assertEquals("When the deadline hasn't been reached tick() should return the previous deadline", 2000, deadline);
assertEquals("When the deadline hasn't been reached tick() shouldn't write data", 0, transport.writes.size());
deadline = transport.tick(timeout/2); // Wait for the deadline - next deadline should be (4000/2)*2
assertEquals("When the deadline has been reached expected a new deadline to be returned 4000", 4000, deadline);
assertEquals("tick() should have written data", 1, transport.writes.size());
assertEquals("tick() should have written an empty frame", null, transport.writes.get(0));
transport.writeFrame(CHANNEL_ID, new Begin(), null, null);
while(transport.pending() > 0) transport.pop(transport.head().remaining());
int framesWrittenBeforeTick = transport.writes.size();
deadline = transport.tick(3000);
assertEquals("Writing data resets the deadline", 5000, deadline);
assertEquals("When the deadline is reset tick() shouldn't write an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick);
transport.writeFrame(CHANNEL_ID, new Attach(), null, null);
assertTrue(transport.pending() > 0);
framesWrittenBeforeTick = transport.writes.size();
deadline = transport.tick(4000);
assertEquals("Having pending data does not reset the deadline", 5000, deadline);
assertEquals("Having pending data prevents tick() from sending an empty frame", 0, transport.writes.size() - framesWrittenBeforeTick);
}
示例6: testSessionBeginAfterCloseSent
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
/**
* Verify that no Begin frame is emitted by the Transport should a Session open
* after the Close frame was sent.
*/
@Test
public void testSessionBeginAfterCloseSent()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
connection.open();
Session session = connection.session();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
// Send the necessary response to Open
transport.handleFrame(new TransportFrame(0, new Open(), null));
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 1, transport.writes.size());
// Cause a Close frame to be sent
connection.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Close);
// Open the session and verify the transport doesn't
// send any Begin frame, as a Close frame was sent already.
session.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
}
示例7: receivedFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public void receivedFrame(TransportFrame transportFrame) {
if (connection.isTraceFrames()) {
TRACE_FRAMES.trace("{} | RECV: {}", connection.getRemoteURI(), transportFrame.getBody());
}
AmqpFrameValidator inspector = connection.getReceivedFrameInspector();
if (inspector != null) {
transportFrame.getBody().invoke(this, transportFrame.getPayload(), inspector);
}
}
示例8: sentFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public void sentFrame(TransportFrame transportFrame) {
if (connection.isTraceFrames()) {
TRACE_FRAMES.trace("{} | SENT: {}", connection.getRemoteURI(), transportFrame.getBody());
}
AmqpFrameValidator inspector = connection.getSentFrameInspector();
if (inspector != null) {
transportFrame.getBody().invoke(this, transportFrame.getPayload(), inspector);
}
}
示例9: receivedFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public void receivedFrame(TransportFrame transportFrame)
{
RECEIVED_LOGGER.finer(_logMessagePrefix + " received frame: " + transportFrame);
}
示例10: sentFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Override
public void sentFrame(TransportFrame transportFrame)
{
SENT_LOGGER.finer(_logMessagePrefix + " writing frame: " + transportFrame);
}
示例11: writeFrame
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
void writeFrame(int channel, Object frameBody, ByteBuffer payload,
Runnable onPayloadTooLarge)
{
startFrame();
writePerformative(frameBody);
if(_maxFrameSize > 0 && payload != null && (payload.remaining() + _performativeSize) > _maxFrameSize)
{
if(onPayloadTooLarge != null)
{
onPayloadTooLarge.run();
}
writePerformative(frameBody);
}
int capacity;
if (_maxFrameSize > 0) {
capacity = _maxFrameSize - _performativeSize;
} else {
capacity = Integer.MAX_VALUE;
}
int payloadSize = Math.min(payload == null ? 0 : payload.remaining(), capacity);
ProtocolTracer tracer = _protocolTracer == null ? null : _protocolTracer.get();
if( tracer != null || _transport.isTraceFramesEnabled())
{
// XXX: this is a bit of a hack but it eliminates duplicate
// code, further refactor will fix this
if (_frameType == AMQP_FRAME_TYPE)
{
ByteBuffer originalPayload = null;
if( payload!=null )
{
originalPayload = payload.duplicate();
originalPayload.limit(payload.position() + payloadSize);
}
Binary payloadBin = Binary.create(originalPayload);
FrameBody body = null;
if (frameBody == null)
{
body = new EmptyFrame();
}
else
{
body = (FrameBody) frameBody;
}
TransportFrame frame = new TransportFrame(channel, body, payloadBin);
_transport.log(TransportImpl.OUTGOING, frame);
if(tracer != null)
{
tracer.sentFrame(frame);
}
}
}
if(payloadSize > 0)
{
while (_buffer.remaining() < payloadSize) {
grow();
}
int oldLimit = payload.limit();
payload.limit(payload.position() + payloadSize);
_buffer.put(payload);
payload.limit(oldLimit);
}
endFrame(channel);
_framesOutput += 1;
}
示例12: doLinkAttachAfterEndSentTestImpl
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
void doLinkAttachAfterEndSentTestImpl(boolean receiverLink)
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
connection.open();
Session session = connection.session();
session.open();
Link link = null;
if(receiverLink)
{
link = session.receiver("myReceiver");
}
else
{
link = session.sender("mySender");
}
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
// Send the necessary responses to open/begin
transport.handleFrame(new TransportFrame(0, new Open(), null));
Begin begin = new Begin();
begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
transport.handleFrame(new TransportFrame(0, begin, null));
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
// Cause a End frame to be sent
session.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(2) instanceof End);
// Open the link and verify the transport doesn't
// send any Attach frame, as an End frame was sent already.
link.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}
示例13: doLinkDetachAfterEndSentTestImpl
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
void doLinkDetachAfterEndSentTestImpl(boolean receiverLink)
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
connection.open();
Session session = connection.session();
session.open();
Link link = null;
if(receiverLink)
{
link = session.receiver("myReceiver");
}
else
{
link = session.sender("mySender");
}
link.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);
// Send the necessary responses to open/begin
transport.handleFrame(new TransportFrame(0, new Open(), null));
Begin begin = new Begin();
begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
transport.handleFrame(new TransportFrame(0, begin, null));
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
// Cause an End frame to be sent
session.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(3) instanceof End);
// Close the link and verify the transport doesn't
// send any Detach frame, as an End frame was sent already.
link.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
}
示例14: testSenderSendBeforeOpenConnection
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
@Test
public void testSenderSendBeforeOpenConnection()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
Collector collector = Collector.Factory.create();
connection.collect(collector);
Session session = connection.session();
session.open();
String linkName = "mySender";
Sender sender = session.sender(linkName);
sender.open();
sendMessage(sender, "tag1", "content1");
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 0, transport.writes.size());
// Now open the connection, expect the Open and Begin and Attach frames but
// nothing else as we the sender wont have credit yet.
connection.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Attach);
// Send the necessary responses to open/begin/attach then give sender credit
transport.handleFrame(new TransportFrame(0, new Open(), null));
Begin begin = new Begin();
begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
transport.handleFrame(new TransportFrame(0, begin, null));
Attach attach = new Attach();
attach.setHandle(UnsignedInteger.ZERO);
attach.setRole(Role.RECEIVER);
attach.setName(linkName);
attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
transport.handleFrame(new TransportFrame(0, attach, null));
Flow flow = new Flow();
flow.setHandle(UnsignedInteger.ZERO);
flow.setDeliveryCount(UnsignedInteger.ZERO);
flow.setNextIncomingId(UnsignedInteger.ONE);
flow.setNextOutgoingId(UnsignedInteger.ZERO);
flow.setIncomingWindow(UnsignedInteger.valueOf(1024));
flow.setOutgoingWindow(UnsignedInteger.valueOf(1024));
flow.setLinkCredit(UnsignedInteger.valueOf(10));
transport.handleFrame(new TransportFrame(0, flow, null));
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
// Now pump the transport again and expect a transfer for the message
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Transfer);
}
示例15: testSessionEndAfterCloseSent
import org.apache.qpid.proton.framing.TransportFrame; //导入依赖的package包/类
/**
* Verify that no End frame is emitted by the Transport should a Session close
* after the Close frame was sent.
*/
@Test
public void testSessionEndAfterCloseSent()
{
MockTransportImpl transport = new MockTransportImpl();
Connection connection = Proton.connection();
transport.bind(connection);
connection.open();
Session session = connection.session();
session.open();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(0) instanceof Open);
assertTrue("Unexpected frame type", transport.writes.get(1) instanceof Begin);
// Send the necessary responses to open/begin
transport.handleFrame(new TransportFrame(0, new Open(), null));
Begin begin = new Begin();
begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
transport.handleFrame(new TransportFrame(0, begin, null));
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 2, transport.writes.size());
// Cause a Close frame to be sent
connection.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
assertTrue("Unexpected frame type", transport.writes.get(2) instanceof Close);
// Close the session and verify the transport doesn't
// send any End frame, as a Close frame was sent already.
session.close();
pumpMockTransport(transport);
assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}