当前位置: 首页>>代码示例>>Java>>正文


Java Connection.close方法代码示例

本文整理汇总了Java中org.apache.qpid.proton.engine.Connection.close方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.close方法的具体用法?Java Connection.close怎么用?Java Connection.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.qpid.proton.engine.Connection的用法示例。


在下文中一共展示了Connection.close方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testOutputTooBigToBeWrittenInOneGo

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
@Test
public void testOutputTooBigToBeWrittenInOneGo()
{
    int smallMaxFrameSize = 512;
    _transport = new TransportImpl(smallMaxFrameSize);

    Connection conn = new ConnectionImpl();
    _transport.bind(conn);

    // Open frame sized in order to produce a frame that will almost fill output buffer
    conn.setHostname(stringOfLength("x", 500));
    conn.open();

    // Close the connection to generate a Close frame which will cause an overflow
    // internally - we'll get the remaining bytes on the next interaction.
    conn.close();

    ByteBuffer buf = _transport.getOutputBuffer();
    assertEquals("Expecting buffer to be full", smallMaxFrameSize, buf.remaining());
    buf.position(buf.limit());
    _transport.outputConsumed();

    buf  = _transport.getOutputBuffer();
    assertTrue("Expecting second buffer to have bytes", buf.remaining() > 0);
    assertTrue("Expecting second buffer to not be full", buf.remaining() < Transport.MIN_MAX_FRAME_SIZE);
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:27,代码来源:TransportImplTest.java

示例2: processEventSessionRemoteState

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
private void processEventSessionRemoteState(Event event) {
    final String methodName = "processEventSessionRemoteState";
    logger.entry(this, methodName, event);

    if (event.getSession().getRemoteState() == EndpointState.ACTIVE) {
        if (event.getSession().getLocalState() == EndpointState.ACTIVE) {
            final EngineConnection engineConnection =
                    (EngineConnection) event.getConnection().getContext();
            if (!engineConnection.closed) {
                // First session has opened on the connection
                OpenRequest req = engineConnection.openRequest;
                engineConnection.openRequest = null;
                engineConnection.requestor.tell(new OpenResponse(req, engineConnection), this);
            }
        } else {
            // The remote end is trying to establish a new session with us, which is not allowed. I don't think this is a usual case,
            // but could occur with a badly written remote end (i.e. sends an initial AMQP open immediately followed by a begin)
            final Connection protonConnection = event.getConnection();
            protonConnection.setCondition(new ErrorCondition(Symbol.getSymbol("mqlight:session-remote-open-rejected"),
                                                             "MQ Light client is unable to accept an open session request"));
            protonConnection.close();
        }
    }

    logger.exit(this, methodName);
}
 
开发者ID:mqlight,项目名称:java-mqlight,代码行数:27,代码来源:Engine.java

示例3: onRemoteClose

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
@Override
public void onRemoteClose(Connection connection) {
   lock();
   try {
      connection.close();
      connection.free();
   } finally {
      unlock();
   }

   for (AMQPSessionContext protonSession : sessions.values()) {
      protonSession.close();
   }
   sessions.clear();

   // We must force write the channel before we actually destroy the connection
   handler.flushBytes();
   destroy();
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:20,代码来源:AMQPConnectionContext.java

示例4: onConnectionRemoteClose

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
@Override
public void onConnectionRemoteClose(Event evt) {
    Connection conn = evt.getConnection();
    if (conn.getLocalState() != EndpointState.CLOSED) {
        conn.close();
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:8,代码来源:Handshaker.java

示例5: testSessionBeginAfterCloseSent

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:41,代码来源:TransportImplTest.java

示例6: login

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
@Override
public boolean login() throws LoginException {

    boolean success = false;
    try {
        List<X509Certificate> certs = new ArrayList<>();

        if(isAuthenticatedUsingCerts(certs)) {
            success = populateUserAndRolesFromCert(certs.get(0));
        } else {

            Transport transport = Proton.transport();
            Connection connection = Proton.connection();
            transport.bind(connection);
            Sasl sasl = transport.sasl();
            sasl.client();

            Socket socket = createSocket();

            InputStream in = socket.getInputStream();
            OutputStream out = socket.getOutputStream();

            transport.open();

            // write Headers
            writeToNetwork(connection, out);

            SaslMechanism mechanism = chooseSaslMechanismAndSendInit(connection, in, out);

            performSaslSteps(connection, in, out, mechanism);

            if (isSaslAuthenticated(connection, mechanism)) {
                performConnectionOpen(connection, in, out);
                getUserAndRolesFromConnection(connection);
                success = true;
            } else {
                LOG.debug("Login failed");
            }

            connection.close();
            transport.close();
            socket.close();
        }

    } catch (IOException | UnsupportedCallbackException | InvalidNameException e) {
        LoginException loginException = new LoginException("Exception attempting to authenticate using SASL delegation");
        loginException.initCause(e);
        LOG.warn(e);
        throw loginException;
    }
    loginSucceeded = success;
    return success;
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:54,代码来源:SaslDelegatingLogin.java

示例7: testSessionEndAfterCloseSent

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的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());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:47,代码来源:TransportImplTest.java

示例8: doLinkAttachAfterCloseSentTestImpl

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
void doLinkAttachAfterCloseSentTestImpl(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 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);

    // Open the link and verify the transport doesn't
    // send any Attach frame, as a Close frame was sent already.
    link.open();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:52,代码来源:TransportImplTest.java

示例9: testReceiverFlowAfterCloseSent

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
/**
 * Verify that no Flow frame is emitted by the Transport should a Receiver
 * have credit added after the Close frame was sent.
 */
@Test
public void testReceiverFlowAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.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
    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));

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 3, transport.writes.size());

    // Cause the Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Close);

    // Grant new credit for the Receiver and verify the transport doesn't
    // send any Flow frame, as a Close frame was sent already.
    receiver.flow(1);
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:59,代码来源:TransportImplTest.java

示例10: testDispositionAfterCloseSent

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
/**
 * Verify that no Disposition frame is emitted by the Transport should a Delivery
 * have disposition applied after the Close frame was sent.
 */
@Test
public void testDispositionAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();
    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Session session = connection.session();
    session.open();

    String linkName = "myReceiver";
    Receiver receiver = session.receiver(linkName);
    receiver.flow(5);
    receiver.open();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, 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);
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Flow);

    Delivery delivery = receiver.current();
    assertNull("Should not yet have a delivery", delivery);

    // Send the necessary responses to open/begin/attach as well as a transfer
    transport.handleFrame(new TransportFrame(0, new Open(), null));

    Begin begin = new Begin();
    begin.setRemoteChannel(UnsignedShort.valueOf((short) 0));
    begin.setNextOutgoingId(UnsignedInteger.ONE);
    begin.setIncomingWindow(UnsignedInteger.valueOf(1024));
    begin.setOutgoingWindow(UnsignedInteger.valueOf(1024));
    transport.handleFrame(new TransportFrame(0, begin, null));

    Attach attach = new Attach();
    attach.setHandle(UnsignedInteger.ZERO);
    attach.setRole(Role.SENDER);
    attach.setName(linkName);
    attach.setInitialDeliveryCount(UnsignedInteger.ZERO);
    transport.handleFrame(new TransportFrame(0, attach, null));

    String deliveryTag = "tag1";
    String messageContent = "content1";
    handleTransfer(transport, 1, deliveryTag, messageContent);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());

    delivery = verifyDelivery(receiver, deliveryTag, messageContent);
    assertNotNull("Should now have a delivery", delivery);

    // Cause the Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(4) instanceof Close);

    delivery.disposition(Released.getInstance());
    delivery.settle();

    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 5, transport.writes.size());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:74,代码来源:TransportImplTest.java

示例11: testTransferAfterCloseSent

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
/**
 * Verify that no Transfer frame is emitted by the Transport should a Delivery
 * be sendable after the Close frame was sent.
 */
@Test
public void testTransferAfterCloseSent()
{
    MockTransportImpl transport = new MockTransportImpl();

    Connection connection = Proton.connection();
    transport.bind(connection);

    connection.open();

    Collector collector = Collector.Factory.create();
    connection.collect(collector);

    Session session = connection.session();
    session.open();

    String linkName = "mySender";
    Sender sender = session.sender(linkName);
    sender.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());

    // Cause the Close frame to be sent
    connection.close();
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
    assertTrue("Unexpected frame type", transport.writes.get(3) instanceof Close);

    // Send a new message and verify the transport doesn't
    // send any Transfer frame, as a Close frame was sent already.
    sendMessage(sender, "tag1", "content1");
    pumpMockTransport(transport);

    assertEquals("Unexpected frames written: " + getFrameTypesWritten(transport), 4, transport.writes.size());
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:74,代码来源:TransportImplTest.java

示例12: onRemoteOpen

import org.apache.qpid.proton.engine.Connection; //导入方法依赖的package包/类
@Override
public void onRemoteOpen(Connection connection) throws Exception {
   lock();
   try {
      try {
         initInternal();
      } catch (Exception e) {
         log.error("Error init connection", e);
      }
      if (!validateConnection(connection)) {
         connection.close();
      } else {
         connection.setContext(AMQPConnectionContext.this);
         connection.setContainer(containerId);
         connection.setProperties(connectionProperties);
         connection.setOfferedCapabilities(getConnectionCapabilitiesOffered());
         connection.open();
      }
   } finally {
      unlock();
   }
   initialise();

      /*
      * This can be null which is in effect an empty map, also we really don't need to check this for in bound connections
      * but its here in case we add support for outbound connections.
      * */
   if (connection.getRemoteProperties() == null || !connection.getRemoteProperties().containsKey(CONNECTION_OPEN_FAILED)) {
      long nextKeepAliveTime = handler.tick(true);
      if (nextKeepAliveTime != 0 && scheduledPool != null) {
         scheduledPool.schedule(new Runnable() {
            @Override
            public void run() {
               long rescheduleAt = handler.tick(false);
               if (rescheduleAt != 0) {
                  scheduledPool.schedule(this, rescheduleAt - TimeUnit.NANOSECONDS.toMillis(System.nanoTime()), TimeUnit.MILLISECONDS);
               }
            }
         }, (nextKeepAliveTime - TimeUnit.NANOSECONDS.toMillis(System.nanoTime())), TimeUnit.MILLISECONDS);
      }
   }
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:43,代码来源:AMQPConnectionContext.java


注:本文中的org.apache.qpid.proton.engine.Connection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。