use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class StatisticsModule method start.
public void start() {
// Retrieve instance of StatisticsManager
statisticsManager = StatisticsManager.getInstance();
// Register a packet listener so that we can track packet traffic.
packetInterceptor = new PacketInterceptor() {
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) {
// Only track processed packets so that we don't count them twice.
if (processed) {
packetCount.incrementAndGet();
}
}
};
InterceptorManager.getInstance().addInterceptor(packetInterceptor);
// Register all statistics.
addServerToServerStatistic();
addActiveSessionsStatistic();
addPacketStatistic();
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class OutgoingSessionPromise method init.
private void init() {
serversCache = CacheFactory.createCache(RoutingTableImpl.S2S_CACHE_NAME);
routingTable = XMPPServer.getInstance().getRoutingTable();
// Create a pool of threads that will process queued packets.
int maxThreads = JiveGlobals.getIntProperty(ConnectionSettings.Server.QUEUE_MAX_THREADS, 20);
int queueSize = JiveGlobals.getIntProperty(ConnectionSettings.Server.QUEUE_SIZE, 50);
if (maxThreads < 10) {
// Ensure that the max number of threads in the pool is at least 10
maxThreads = 10;
}
threadPool = new ThreadPoolExecutor(maxThreads / 4, maxThreads, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueSize), new ThreadPoolExecutor.CallerRunsPolicy());
// Start the thread that will consume the queued packets. Each pending packet will
// be actually processed by a thread of the pool (when available). If an error occurs
// while creating the remote session or sending the packet then a packet with error 502
// will be sent to the sender of the packet
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (!shutdown) {
try {
if (threadPool.getActiveCount() < threadPool.getMaximumPoolSize()) {
// Wait until a packet is available
final Packet packet = packets.take();
boolean newProcessor = false;
PacketsProcessor packetsProcessor;
String domain = packet.getTo().getDomain();
synchronized (domain.intern()) {
packetsProcessor = packetsProcessors.get(domain);
if (packetsProcessor == null) {
packetsProcessor = new PacketsProcessor(OutgoingSessionPromise.this, domain);
packetsProcessors.put(domain, packetsProcessor);
newProcessor = true;
}
packetsProcessor.addPacket(packet);
}
if (newProcessor) {
// Process the packet in another thread
threadPool.execute(packetsProcessor);
}
} else {
// No threads are available so take a nap :)
Thread.sleep(200);
}
} catch (InterruptedException e) {
// Do nothing
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
}
}, "Queued Packets Processor");
thread.setDaemon(true);
thread.start();
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class Workgroup method sendOccupantsInfo.
/**
* Sends information to the agent that requested it about the occupants in the specified
* room. If the room does no longer exist then no information will be returned. This means
* that the chat should be happening at the moment of the query.
*
* @param packet the request sent by the agent.
* @param roomID the id of the room that the agent is requesting information
*/
public void sendOccupantsInfo(IQ packet, String roomID) {
IQ statusPacket = IQ.createResultIQ(packet);
Element occupantsInfo = statusPacket.setChildElement("occupants-info", "http://jivesoftware.com/protocol/workgroup");
occupantsInfo.addAttribute("roomID", roomID);
Map<Packet, java.util.Date> packets = transcripts.get(roomID);
if (packets != null) {
Collection<String> processed = new ArrayList<String>();
for (Packet p : packets.keySet()) {
if (p instanceof Presence) {
Presence presence = (Presence) p;
// Get the JID of the presence's user
String userJID = presence.getChildElement("x", "http://jabber.org/protocol/muc#user").element("item").attributeValue("jid");
// occupant joined the room
if (!processed.contains(userJID)) {
processed.add(userJID);
Element occupantInfo = occupantsInfo.addElement("occupant");
occupantInfo.addElement("jid").setText(userJID);
occupantInfo.addElement("nickname").setText(presence.getFrom().getResource());
occupantInfo.addElement("joined").setText(UTC_FORMAT.format(packets.get(p)));
}
}
}
}
// Send the response
send(statusPacket);
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class MainInterceptor method presencePush.
/**
* Just pushes a available presence, we need this for GAJIM Client as it does not push available presence after
* registering We also wait a little so after register transport is on users roster. Really didnt wanted this here
* but doesnt really belong anywhere else
*
* @param to
* @param from
* @param delay MS until the job should be done
*/
private void presencePush(final JID to, final JID from, int delay) {
TimerTask pushPresenceTask = new TimerTask() {
@Override
public void run() {
PacketRouter router = server.getPacketRouter();
Packet presence = new Presence();
presence.setTo(to);
presence.setFrom(from);
router.route(presence);
}
};
Timer timer = new Timer();
timer.schedule(pushPresenceTask, delay);
}
use of org.xmpp.packet.Packet in project Openfire by igniterealtime.
the class BaseMUCTransport method processPacket.
/**
* Handles all incoming message stanzas.
*
* @param packet The message packet to be processed.
* @return list of packets that will be sent back to the message sender.
*/
private List<Packet> processPacket(Message packet) {
Log.debug("Received message packet: " + packet.toXML());
List<Packet> reply = new ArrayList<Packet>();
JID from = packet.getFrom();
JID to = packet.getTo();
try {
TransportSession<B> session = getTransport().getSessionManager().getSession(from);
if (!session.isLoggedIn()) {
Message m = new Message();
m.setError(Condition.service_unavailable);
m.setTo(from);
m.setFrom(getJID());
m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
reply.add(m);
} else if (to.getNode() == null) {
// Message to gateway itself. Throw away for now.
} else {
MUCTransportSession mucSession = session.getMUCSessionManager().getSession(to.getNode());
if (packet.getBody() != null) {
if (to.getResource() == null) {
// Message to room
mucSession.sendMessage(packet.getBody());
} else {
// Private message
mucSession.sendPrivateMessage(to.getResource(), packet.getBody());
}
} else {
if (packet.getSubject() != null) {
// Set topic of room
mucSession.updateTopic(packet.getSubject());
}
}
}
} catch (NotFoundException e) {
Log.debug("Unable to find session.");
Message m = new Message();
m.setError(Condition.service_unavailable);
m.setTo(from);
m.setFrom(getJID());
m.setBody(LocaleUtils.getLocalizedString("gateway.base.notloggedin", "kraken", Arrays.asList(getTransport().getType().toString().toUpperCase())));
reply.add(m);
}
return reply;
}
Aggregations