class MultiplexerPacketDeliverer implements PacketDeliverer {

    private static final Logger Log = LoggerFactory.getLogger(MultiplexerPacketDeliverer.class);

    private OfflineMessageStrategy messageStrategy;
    private String connectionManagerDomain;
    private ConnectionMultiplexerManager multiplexerManager;

    public MultiplexerPacketDeliverer() {
        this.messageStrategy = XMPPServer.getInstance().getOfflineMessageStrategy();
        multiplexerManager = ConnectionMultiplexerManager.getInstance();
    }

    public void setConnectionManagerDomain(String connectionManagerDomain) {
        this.connectionManagerDomain = connectionManagerDomain;
    }

    @Override
    public void deliver(Packet packet) throws UnauthorizedException, PacketException {<FILL_FUNCTION_BODY>}

    private void handleUnprocessedPacket(Packet packet) {
        if (!NettyClientConnectionHandler.BACKUP_PACKET_DELIVERY_ENABLED.getValue()) {
            Log.trace("Discarding packet that was due to be delivered on closed connection {}, for which no other multiplex connections are available, and no client backup deliverer was configured.", this);
            return;
        }
        if (packet instanceof Message) {
            messageStrategy.storeOffline((Message) packet);
        }
        else if (packet instanceof Presence) {
            // presence packets are dropped silently
            //dropPacket(packet);
        }
        else if (packet instanceof IQ) {
            IQ iq = (IQ) packet;
            // Check if we need to unwrap the packet
            Element child = iq.getChildElement();
            if (child != null && "session".equals(child.getName()) &&
                    "http://jabber.org/protocol/connectionmanager"
                            .equals(child.getNamespacePrefix())) {
                Element send = child.element("send");
                if (send != null) {
                    // Unwrap packet
                    Element wrappedElement = (Element) send.elements().get(0);
                    if ("message".equals(wrappedElement.getName())) {
                        handleUnprocessedPacket(new Message(wrappedElement));
                    }
                }
            }
            else {
                // IQ packets are logged but dropped
                Log.warn(LocaleUtils.getLocalizedString("admin.error.routing") + "\n" +
                        packet.toString());
            }
        }
    }
}

        // Check if we can send the packet using another session
        if (connectionManagerDomain == null) {
            // Packet deliverer has not yet been configured so handle unprocessed packet
            handleUnprocessedPacket(packet);
        }
        else {
            // Try getting another session to the same connection manager 
            ConnectionMultiplexerSession session =
                    multiplexerManager.getMultiplexerSession(connectionManagerDomain);
            if (session == null || session.isClosed()) {
                // No other session was found so handle unprocessed packet
                handleUnprocessedPacket(packet);
            }
            else {
                // Send the packet using this other session to the same connection manager
                session.process(packet);
            }
        }
    
<no_super_class>