コード例 #1
0
 private void handleApplicationShutdown(ChannelHandlerContext ctx, MessageEvent me) {
   synchronized (monitor) {
     this.shutdown = true;
     emptyAcknowledgementSchedule.clear();
     ongoingMessageExchanges.clear();
   }
   ctx.sendDownstream(me);
 }
コード例 #2
0
  /**
   * If the message to be written is a {@link CoapResponse} this method decides whether the message
   * type is {@link MessageType.Name#ACK} (if there wasn't an empty acknowledgement sent yet) or
   * {@link MessageType.Name#CON} (if there was already an empty acknowledgement sent). In the
   * latter case it additionally cancels the sending of an empty acknowledgement (which was
   * scheduled by the <code>messageReceived</code> method when the request was received).
   *
   * @param ctx The {@link ChannelHandlerContext} connecting relating this class (which implements
   *     the {@link ChannelUpstreamHandler} interface) to the datagramChannel that received the
   *     message.
   * @param me the {@link MessageEvent} containing the actual message
   * @throws Exception if an error occurred
   */
  @Override
  public void writeRequested(ChannelHandlerContext ctx, MessageEvent me) throws Exception {
    if (isShutdown()) return;

    if (me.getMessage() instanceof CoapResponse) handleOutgoingCoapResponse(ctx, me);
    else if (me.getMessage() instanceof InternalApplicationShutdownMessage)
      handleApplicationShutdown(ctx, me);
    else ctx.sendDownstream(me);
  }
コード例 #3
0
  private void handleOutgoingCoapResponse(ChannelHandlerContext ctx, MessageEvent me) {

    CoapResponse coapResponse = (CoapResponse) me.getMessage();
    InetSocketAddress remoteEndpoint = (InetSocketAddress) me.getRemoteAddress();

    IncomingMessageExchange messageExchange;
    synchronized (monitor) {
      messageExchange = ongoingMessageExchanges.remove(remoteEndpoint, coapResponse.getMessageID());
    }

    if (messageExchange instanceof IncomingReliableMessageExchange) {

      // if the ongoing message exchange is reliable and the empty ACK was not yet sent make
      // response piggy-
      // backed and suppress scheduled empty ACK
      if (!((IncomingReliableMessageExchange) messageExchange).isAcknowledgementSent()) {
        coapResponse.setMessageType(MessageType.Name.ACK.getNumber());
        ((IncomingReliableMessageExchange) messageExchange).setAcknowledgementSent();
      }
    }

    ctx.sendDownstream(me);
  }