1 11 12 package org.jivesoftware.messenger.spi; 13 14 import org.jivesoftware.messenger.*; 15 import org.jivesoftware.messenger.component.InternalComponentManager; 16 import org.jivesoftware.messenger.auth.UnauthorizedException; 17 import org.jivesoftware.messenger.container.BasicModule; 18 import org.jivesoftware.messenger.net.SocketPacketWriteHandler; 19 import org.xmpp.component.Component; 20 import org.xmpp.packet.JID; 21 import org.xmpp.packet.Packet; 22 23 28 public class PacketDelivererImpl extends BasicModule implements PacketDeliverer { 29 30 33 protected SocketPacketWriteHandler deliverHandler; 34 35 private OfflineMessageStrategy messageStrategy; 36 private SessionManager sessionManager; 37 38 private InternalComponentManager componentManager; 39 40 public PacketDelivererImpl() { 41 super("Packet Delivery"); 42 componentManager = InternalComponentManager.getInstance(); 43 } 44 45 public void deliver(Packet packet) throws UnauthorizedException, PacketException { 46 if (packet == null) { 47 throw new PacketException("Packet was null"); 48 } 49 if (deliverHandler == null) { 50 throw new PacketException("Could not send packet - no route" + packet.toString()); 51 } 52 JID recipient = packet.getTo(); 55 if (recipient != null && recipient.getNode() == null && recipient.getResource() == null) { 56 Component component = componentManager.getComponent(recipient); 58 if (component != null) { 59 component.processPacket(packet); 60 return; 61 } 62 } 63 deliverHandler.process(packet); 66 } 67 68 public void initialize(XMPPServer server) { 69 super.initialize(server); 70 messageStrategy = server.getOfflineMessageStrategy(); 71 sessionManager = server.getSessionManager(); 72 } 73 74 public void start() throws IllegalStateException { 75 super.start(); 76 deliverHandler = 77 new SocketPacketWriteHandler(sessionManager, 78 XMPPServer.getInstance().getRoutingTable(), messageStrategy); 79 } 80 81 public void stop() { 82 super.stop(); 83 deliverHandler = null; 84 } 85 } 86 | Popular Tags |