private void despatchMessage(final LegacyOCPMessage message)
            throws LinkMessageException {
        OCPMessageHandler handler = null;

        if (message instanceof LinkMessage) {
            // Link message, handle it internally
            handleMessage(message);
        } else if (message instanceof CallControlMessage) {
            // Call control message
            int taskID = message.getDestTID();
            synchronized (tidHandlers) {
                handler = tidHandlers.get(taskID);
            }
            if (handler != null) {
                // The task ID has been registered. Send it to the handler.
                try {
                    handler.queueMessage(message, this);
                } catch (Exception e) {
                    log.warn("Exception occurred in handler " + handler, e);
                }
            } else if (taskID == OCPMessage.MANAGEMENT_TASK_ID
                    && managementTidHandler != null) {
                // The message is for the management task ID and we have a
                // registered handler.
                try {
                    managementTidHandler.queueMessage(message, this);
                } catch (Exception e) {
                    log.warn("Exception occurred in management handler "
                            + managementTidHandler, e);
                }
            } else {
                // We don't know about this task ID. Reject the message.
                log.warn("Message received for unregistered task: command "
                        + message.getCommandCode() + ", destination " + taskID);
                if (!(message instanceof Abort)) { // Do not reply to an Abort
                    Abort abort = new Abort();
                    abort.setDestTID(message.getOrigTID());
                    abort.setOrigTID(message.getDestTID());
                    abort.setInvalidLegID(Abort.TASK_NOT_RUNNING);
                    this.queueMessage(abort, null);
                }
            }
        } else {
            // Unknown message type (but one that OCPMessage knows about!)
            log.warn("Received an OCP message with an unexpected command type");
        }
    }