public void handleMessage(Message msg) {
        if (discard.get()) {
            msg.discard();
            return;
        }

        Reply reply = ((DocumentMessage)msg).createReply();
        try {
            switch (msg.getType()) {

                case DocumentProtocol.MESSAGE_GETDOCUMENT:
                    reply = new GetDocumentReply(local.get(((GetDocumentMessage)msg).getDocumentId()));
                    break;

                case DocumentProtocol.MESSAGE_PUTDOCUMENT:
                    local.put(((PutDocumentMessage)msg).getDocumentPut());
                    break;

                case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
                    local.remove(new DocumentRemove(((RemoveDocumentMessage)msg).getDocumentId()));
                    break;

                case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
                    local.update(((UpdateDocumentMessage)msg).getDocumentUpdate());
                    break;

                case DocumentProtocol.MESSAGE_CREATEVISITOR:
                    ((CreateVisitorReply) reply).setLastBucket(ProgressToken.FINISHED_BUCKET);
                    break;

                default:
                    throw new UnsupportedOperationException("Unsupported message type '" + msg.getType() + "'.");
            }
        } catch (Exception e) {
            reply = new EmptyReply();
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, e.toString()));
        }
        msg.swapState(reply);
        session.reply(reply);
    }
Mock-up destination used for testing.

@author Einar M R Rosenvinge
documentapi/src/test/java/com/yahoo/documentapi/messagebus/Destination.java