private void handleFrame(Frame frame) throws IOException {

        QueueManager queueManager = QueueManager.getInstance();
        Command command = frame.getCommand();
        FrameHeader headers = frame.getHeader();

        try {
            if (command == Command.COMMIT || command == Command.ABORT || command == Command.BEGIN) {

                transmit(Command.ERROR, null, "Transactions are not supported yet.");
            } else if (command == Command.SEND) {

                String destination = (String) headers.get(FrameHeader.DESTINATION_ENTRY_NAME);
                Message message = makeMessageFromFrame(frame);
                queueManager.addMessage(destination, message);
            } else if (command == Command.SUBSCRIBE) {

                String queueName = (String) headers.get(FrameHeader.DESTINATION_ENTRY_NAME);
                String subscriptionId = (String) headers.get(FrameHeader.ID_ENTRY_NAME);
                queueManager.addSubscription(makeSubscriptionUniqueId(subscriptionId), queueName, this);
            } else if (command == Command.UNSUBSCRIBE) {

                String subscriptionId = (String) headers.get(FrameHeader.ID_ENTRY_NAME);
                queueManager.removeSubscription(makeSubscriptionUniqueId(subscriptionId));
            } else if (command == Command.ACK) {

                String subscriptionId = (String) headers.get(FrameHeader.SUBSCRIPTIONS_ENTRY_NAME);
                queueManager.ackMessage(makeSubscriptionUniqueId(subscriptionId));
            } else if (command == Command.NACK) {

                String subscriptionId = (String) headers.get(FrameHeader.SUBSCRIPTIONS_ENTRY_NAME);
                queueManager.nakcMessage(makeSubscriptionUniqueId(subscriptionId));
            } else {
                transmit(Command.ERROR, null, "Cannot understand the command.");
            }
        } catch (QueueOperationException ex) {
            transmit(Command.ERROR, null, ex.getMessage());
        }
    }