public void messageWriting()

in coap/src/main/java/org/apache/mina/coap/retry/CoapRetryFilter.java [120:174]


    public void messageWriting(final IoSession session, final WriteRequest message, WriteFilterChainController controller) {
        LOGGER.debug("Processing a MESSAGE_WRITING for session {}", session);

        final CoapMessage coapMsg = (CoapMessage) message.getMessage();
        final String transmissionId = CoapTransmission.uniqueId(session, coapMsg);

        switch (coapMsg.getType()) {

        case NON_CONFIRMABLE:
            controller.callWriteNextFilter(message);
            break;
        case RESET:
        case ACK:
            // let's keep track of the message to avoid processing it again in
            // case of duplicate copy.
            processed.put(transmissionId, coapMsg);

            controller.callWriteNextFilter(message);
            break;

        case CONFIRMABLE:
            // initialize a transmission if this is not a retry
            CoapTransmission t = inFlight.get(transmissionId);
            if (t == null) {
                t = new CoapTransmission(session, coapMsg);
                inFlight.put(t.getId(), t);
            }

            // schedule a retry
            ScheduledFuture<?> future = retryExecutor.schedule(new Runnable() {

                @Override
                public void run() {
                    CoapTransmission t = inFlight.get(transmissionId);

                    // send again the message if the maximum number of attempts
                    // is not reached
                    if (t != null && t.timeout()) {
                        LOGGER.debug("Retry for message with ID {}", coapMsg.requestId());
                        session.write(coapMsg);
                    } else {
                        // abort transmission
                        LOGGER.debug("No more retry for message with ID {}", coapMsg.requestId());
                    }
                }
            }, t.getNextTimeout(), TimeUnit.MILLISECONDS);

            t.setRetryFuture(future);

            // move to the next filter
            controller.callWriteNextFilter(message);
            break;
        }

    }