示例#1
0
 @Override
 public void onLinkFlow(Event event) {
   Sender snd = (Sender) event.getLink();
   if (snd.getCredit() > 0 && snd.getLocalState() != EndpointState.CLOSED) {
     Message message = Proton.message();
     ++count;
     message.setBody(new AmqpValue("message-" + count));
     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(count).getBytes();
     Delivery dlv = snd.delivery(tag);
     snd.send(msgData, 0, length);
     dlv.settle();
     snd.advance();
     if (count == numMsgs) {
       snd.close();
       snd.getSession().close();
       snd.getSession().getConnection().close();
       result = true;
     }
   }
 }
示例#2
0
    @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();
        }
      }
    }
示例#3
0
 @Override
 public void onReactorInit(Event event) {
   try {
     acceptor = event.getReactor().acceptor("localhost", port);
   } catch (IOException ioException) {
     throw new RuntimeException(ioException);
   }
 }
示例#4
0
 @Override
 public void onConnectionInit(Event event) {
   Connection conn = event.getConnection();
   Session ssn = conn.session();
   Sender snd = ssn.sender("sender");
   conn.open();
   ssn.open();
   snd.open();
 }
示例#5
0
 @Override
 public void onTransportError(Event event) {
   result = false;
   ErrorCondition condition = event.getTransport().getCondition();
   if (condition != null) {
     System.err.println("Error: " + condition.getDescription());
   } else {
     System.err.println("Error (no description returned).");
   }
 }
 @Override
 public void onUnhandled(Event event) {
   if (TRACE_LOGGER.isLoggable(Level.FINE)) {
     TRACE_LOGGER.log(
         Level.FINE,
         "Connection.onUnhandled: name["
             + event.getConnection().getHostname()
             + "] : event["
             + event
             + "]");
   }
   super.onUnhandled(event);
 }
  @Override
  public void onConnectionBound(Event event) {
    Transport transport = event.getTransport();
    SslDomain domain = Proton.sslDomain();
    domain.init(Mode.SERVER);

    domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
    transport.ssl(domain);

    Sasl sasl = transport.sasl();
    sasl.allowSkip(true);
    sasl.setMechanisms("PLAIN");
    // sasl.done(SaslOutcome.PN_SASL_OK);*/
  }
 @Override
 public void onConnectionRemoteOpen(Event event) {
   super.onConnectionRemoteOpen(event);
   event.getConnection().open();
 }
示例#9
0
 @Override
 public void onReactorInit(Event event) {
   Reactor r = event.getReactor();
   r.connectionToHost(host, port, sendHandler);
 }
 /**
  * Event handler for reactor init event.
  *
  * @param event Proton Event object
  */
 @Override
 public void onReactorInit(Event event) {
   // Codes_SRS_AMQPSIOTHUBCONNECTION_14_030: [The event handler shall set the member
   // AmqpsIotHubConnectionBaseHandler object to handle the connection events.]
   event.getReactor().connection(this.amqpsHandler);
 }