use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class AgentSession method updatePresence.
/**
* Updates the presence of the AgentSession with the new received presence. The max number of
* chats and number of current chats will be updated if that information was included in the presence.
* If no information was provided then default values of queues, workgroups or general settings will
* be used instead.
*
* @param packet the new presence sent by the agent.
*/
public void updatePresence(Presence packet) {
// Create a copy of the received Presence to use as the presence of the AgentSession
Presence sessionPresence = packet.createCopy();
// Remove the "agent-status" element from the new AgentSession's presence
Element child = sessionPresence.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
sessionPresence.getElement().remove(child);
// Set the new presence to the AgentSession
presence = sessionPresence;
// Set the new maximum number of chats and the number of current chats to the
// AgentSession based on the values sent within the presence (if any)
Element elem = packet.getChildElement("agent-status", "http://jabber.org/protocol/workgroup");
if (elem != null) {
Iterator<Element> metaIter = elem.elementIterator();
while (metaIter.hasNext()) {
Element agentStatusElement = metaIter.next();
if ("max-chats".equals(agentStatusElement.getName())) {
String maxChats = agentStatusElement.getText();
if (maxChats == null || maxChats.trim().length() == 0) {
setMaxChats(-1);
} else {
setMaxChats(Integer.parseInt(maxChats));
}
}
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class WorkgroupManager method processPacket.
public void processPacket(Packet packet) {
try {
// Check if the packet is a disco request
if (packet instanceof IQ) {
if (process((IQ) packet)) {
return;
}
}
// was found then let the workgroup process the packet
try {
Workgroup workgroup = getWorkgroup(packet.getTo());
workgroup.process(packet);
} catch (UserNotFoundException e) {
// above situations
if (packet instanceof Presence) {
if (((Presence) packet).getType() == Presence.Type.error) {
// Skip Presence packets of type error
return;
}
Presence reply = new Presence();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_authorized);
send(reply);
} else if (packet instanceof IQ) {
if (((IQ) packet).getType() == IQ.Type.error) {
// Skip IQ packets of type error
return;
}
IQ reply = IQ.createResultIQ((IQ) packet);
reply.setChildElement(((IQ) packet).getChildElement().createCopy());
reply.setError(PacketError.Condition.not_authorized);
send(reply);
} else {
if (((Message) packet).getType() == Message.Type.error) {
// Skip Message packets of type error
return;
}
Message reply = new Message();
reply.setID(packet.getID());
reply.setTo(packet.getFrom());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_authorized);
send(reply);
}
}
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class WorkgroupManager method handleOutdatePresence.
/**
* Checks for outdated presences caused by network failures, etc.
*/
private void handleOutdatePresence() {
for (Workgroup workgroup : getWorkgroups()) {
for (AgentSession agentSession : workgroup.getAgentSessions()) {
final JID agentJID = agentSession.getJID();
final PresenceManager presenceManager = XMPPServer.getInstance().getPresenceManager();
boolean isOnline = false;
for (Presence presence : presenceManager.getPresences(agentJID.getNode())) {
if (presence.getFrom().equals(agentJID)) {
isOnline = true;
}
}
if (!isOnline) {
// Send offline presence to workgroup.
for (Workgroup wgroup : agentSession.getWorkgroups()) {
Presence presence = new Presence();
presence.setFrom(agentJID);
presence.setTo(wgroup.getJID());
presence.setType(Presence.Type.unavailable);
wgroup.getWorkgroupPresenceHandler().process(presence);
}
}
}
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class RequestQueue method sendStatus.
public void sendStatus(JID recipient) {
try {
Presence queueStatus = getStatusPresence();
queueStatus.setTo(recipient);
workgroup.send(queueStatus);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.xmpp.packet.Presence in project Openfire by igniterealtime.
the class PacketCounter method start.
/**
* Resets all counters, and starts counting.
*/
public void start() {
// Register a packet listener so that we can track packet traffic.
interceptor = new PacketInterceptor() {
public void interceptPacket(final Packet packet, final Session session, final boolean incoming, final boolean processed) {
if (!processed) {
// don't count packets twice!
return;
}
stanza.incrementAndGet();
if (packet instanceof Message) {
message.incrementAndGet();
}
if (packet instanceof Presence) {
presence.incrementAndGet();
}
if (packet instanceof IQ) {
iq.incrementAndGet();
switch(((IQ) packet).getType()) {
case get:
iqGet.incrementAndGet();
break;
case set:
iqSet.incrementAndGet();
break;
case result:
iqResult.incrementAndGet();
break;
case error:
iqError.incrementAndGet();
break;
}
}
}
};
// reset counters
stanza.set(0);
message.set(0);
presence.set(0);
iq.set(0);
iqGet.set(0);
iqSet.set(0);
iqResult.set(0);
iqError.set(0);
// register listener
InterceptorManager.getInstance().addInterceptor(interceptor);
}
Aggregations