Commit f1154c68 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Ported changes from TRUNK.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches/3_0_branch@4402 b35dd754-fafc-0310-a699-88a17e54d16e
parent a546de4f
......@@ -44,8 +44,9 @@
Presence Plugin Changelog
</h1>
<p><b>1.2.1</b> -- June ??, 2006</p>
<p><b>1.3.0</b> -- July 10, 2006</p>
<ul>
<li>Added support for probing presence of components.
<li>Fixed minor problem in readme.html -- the example Apache redirect was incorrect.
</ul>
......
......@@ -5,8 +5,8 @@
<name>Presence Service</name>
<description>Exposes presence information through HTTP.</description>
<author>Jive Software</author>
<version>1.2.0</version>
<date>4/19/2006</date>
<version>1.3.0</version>
<date>7/10/2006</date>
<minServerVersion>2.5.1</minServerVersion>
<adminconsole>
......
......@@ -58,7 +58,7 @@ Presence Plugin Readme
<p>
The presence plugin is a service that provides simple presence information over HTTP.
It can be used to display an online status icon for a user on a web page or to
It can be used to display an online status icon for a user or component on a web page or to
poll for presence information from a web service.
</p>
......
......@@ -12,7 +12,6 @@
package org.jivesoftware.wildfire.plugin;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.PresenceManager;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.container.Plugin;
......@@ -20,20 +19,20 @@ import org.jivesoftware.wildfire.container.PluginManager;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.component.Component;
import org.xmpp.component.ComponentManager;
import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.component.Component;
import org.xmpp.packet.JID;
import org.xmpp.packet.Presence;
import org.xmpp.packet.Packet;
import org.xmpp.packet.Presence;
import java.io.File;
import java.util.HashMap;
import java.lang.Thread;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Plugin that includes a servlet that provides information about the presence type of the
* users in the server. For security reasons, the XMPP spec does not allow anyone to see
* Plugin that includes a servlet that provides information about users' and components'
* presence in the server. For security reasons, the XMPP spec does not allow anyone to see
* the presence of any user. Only the users that are subscribed to the presence of other
* users may see their presences.<p/>
*
......@@ -41,19 +40,25 @@ import java.lang.Thread;
* so that anyone or only the users that are subscribed to a user presence may see the presence
* of other users.<p/>
*
* Currently, the servlet provides information about user presences in two formats. In XML format
* or using images.
* Currently, the servlet provides presence information in two formats: 1) In XML format
* and 2) using images.<p>
*
* The presence plugin is also a component so that it can probe presences of other components.
* The new component will use <tt>presence</tt> as the subdomain subdomain.
*
* @author Gaston Dombiak
*/
public class PresencePlugin implements Plugin, Component {
private static final String subdomain = "presence";
private UserManager userManager;
private PresenceManager presenceManager;
private PluginManager pluginManager;
private ComponentManager componentManager;
private String hostname;
private HashMap<String, Presence> probedPresence;
private Map<String, Presence> probedPresence;
private JID componentJID;
public void initializePlugin(PluginManager manager, File pluginDirectory) {
pluginManager = manager;
......@@ -61,11 +66,12 @@ public class PresencePlugin implements Plugin, Component {
userManager = server.getUserManager();
presenceManager = server.getPresenceManager();
hostname = server.getServerInfo().getName();
probedPresence = new HashMap<String, Presence>();
probedPresence = new ConcurrentHashMap<String, Presence>();
componentJID = new JID(subdomain + "." + hostname);
// Register new component
componentManager = ComponentManagerFactory.getComponentManager();
try {
componentManager.addComponent("presence", this);
componentManager.addComponent(subdomain, this);
}
catch (Exception e) {
componentManager.getLog().error(e);
......@@ -75,9 +81,9 @@ public class PresencePlugin implements Plugin, Component {
public void destroyPlugin() {
userManager = null;
presenceManager = null;
// Remove presence plugin component
try {
componentManager.removeComponent("presence");
componentManager.removeComponent(subdomain);
componentManager = null;
}
catch (Exception e) {
......@@ -103,9 +109,14 @@ public class PresencePlugin implements Plugin, Component {
}
public void processPacket(Packet packet) {
// Check that we are getting an answer to a presence probe
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
probedPresence.put(presence.getFrom().toString(), presence);
if (presence.isAvailable() || presence.getType() == Presence.Type.unavailable ||
presence.getType() == Presence.Type.error) {
// Store answer of presence probes
probedPresence.put(presence.getFrom().toString(), presence);
}
}
}
......@@ -152,29 +163,30 @@ public class PresencePlugin implements Plugin, Component {
if (!hostname.equals(targetJID.getDomain())) {
// Sender is requesting information about component presence, so we send a
// presence probe to the component.
presenceManager.probePresence(new JID("presence." + hostname), targetJID);
presenceManager.probePresence(componentJID, targetJID);
// Wait 30 seconds until we get the probe presence result
int count = 0;
while (!probedPresence.containsKey(jid)) {
Presence presence = probedPresence.get(jid);
while (presence == null) {
if (count > 300) {
// After 30 seconds, timeout
throw new UserNotFoundException(
"Request for component presence has timed-out.");
}
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
// don't care!
}
presence = probedPresence.get(jid);
count++;
if (count > 300) {
// After 30 seconds, timeout
throw new UserNotFoundException("Request for user presence has timed-out.");
}
}
// Clean-up
Presence presence = probedPresence.get(jid);
// Clean-up probe presence result
probedPresence.remove(jid);
// Return component presence
return presence;
}
if (targetJID.getNode() == null ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment