/** * Delivers the packet to the Connection Manager that in turn will forward it to the target user. * Connection Managers may have one or many connections to the server so just get any connection * to the Connection Manager (uses a random) and use it. * * <p>If the packet to send does not have a TO attribute then wrap the packet with a special IQ * packet. The wrapper IQ packet will be sent to the Connection Manager and the stream ID of this * Client Session will be used for identifying that the wrapped packet must be sent to the * connected user. Since some packets can be exchanged before the user has a binded JID we need to * use the stream ID as the unique identifier. * * @param packet the packet to send to the user. */ @Override public void deliver(Packet packet) { String streamID = session.getStreamID().getID(); ConnectionMultiplexerSession multiplexerSession = multiplexerManager.getMultiplexerSession(connectionManagerName, streamID); if (multiplexerSession != null) { // Wrap packet so that the connection manager can figure out the target session Route wrapper = new Route(streamID); wrapper.setFrom(serverName); wrapper.setTo(connectionManagerName); wrapper.setChildElement(packet.getElement().createCopy()); // Deliver wrapper multiplexerSession.process(wrapper); session.incrementServerPacketCount(); } }