Commit 353ae312 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

Added isStarted() to XMPPServer, which cleans PubSubEngine.start() up some.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches/pep@8773 b35dd754-fafc-0310-a699-88a17e54d16e
parent 876c8e83
...@@ -101,6 +101,7 @@ public class XMPPServer { ...@@ -101,6 +101,7 @@ public class XMPPServer {
private Version version; private Version version;
private Date startDate; private Date startDate;
private boolean initialized = false; private boolean initialized = false;
private boolean started = false;
private NodeID nodeID; private NodeID nodeID;
private static final NodeID DEFAULT_NODE_ID = new NodeID(new byte[0]); private static final NodeID DEFAULT_NODE_ID = new NodeID(new byte[0]);
...@@ -451,6 +452,8 @@ public class XMPPServer { ...@@ -451,6 +452,8 @@ public class XMPPServer {
Log.info(startupBanner); Log.info(startupBanner);
System.out.println(startupBanner); System.out.println(startupBanner);
started = true;
// Notify server listeners that the server has been started // Notify server listeners that the server has been started
for (XMPPServerListener listener : listeners) { for (XMPPServerListener listener : listeners) {
listener.serverStarted(); listener.serverStarted();
...@@ -1383,4 +1386,13 @@ public class XMPPServer { ...@@ -1383,4 +1386,13 @@ public class XMPPServer {
public void setRemoteSessionLocator(RemoteSessionLocator remoteSessionLocator) { public void setRemoteSessionLocator(RemoteSessionLocator remoteSessionLocator) {
this.remoteSessionLocator = remoteSessionLocator; this.remoteSessionLocator = remoteSessionLocator;
} }
/**
* Returns whether or not the server has been started.
*
* @return whether or not the server has been started.
*/
public boolean isStarted() {
return started;
}
} }
...@@ -293,7 +293,8 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene ...@@ -293,7 +293,8 @@ public class IQDiscoInfoHandler extends IQHandler implements ClusterEventListene
serverIdentities.add(it.next()); serverIdentities.add(it.next());
} }
} }
//
// FIXME: Create a UserIdentityProvider interface
if (server.getIQPEPHandler() != null) { if (server.getIQPEPHandler() != null) {
Element userIdentity = DocumentHelper.createElement("identity"); Element userIdentity = DocumentHelper.createElement("identity");
userIdentity.addAttribute("category", "pubsub"); userIdentity.addAttribute("category", "pubsub");
......
...@@ -92,6 +92,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -92,6 +92,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
// TODO: Much to be done here... // TODO: Much to be done here...
if (packet.getTo() == null) { if (packet.getTo() == null) {
// TODO: Do not allow anonymous users to create a service
String jidFrom = packet.getFrom().toBareJID(); String jidFrom = packet.getFrom().toBareJID();
PEPService pepService = pepServices.get(jidFrom); PEPService pepService = pepServices.get(jidFrom);
...@@ -100,9 +101,13 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -100,9 +101,13 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
if (pepService == null) { if (pepService == null) {
pepService = new PEPService(XMPPServer.getInstance(), jidFrom); pepService = new PEPService(XMPPServer.getInstance(), jidFrom);
pepServices.put(jidFrom, pepService); pepServices.put(jidFrom, pepService);
pubSubEngine.start(pepService); // Keep DB synced
// Probe presences
pubSubEngine.start(pepService);
if (Log.isDebugEnabled()) {
Log.debug("PEP: " + jidFrom + " had a PEPService created"); Log.debug("PEP: " + jidFrom + " had a PEPService created");
} }
}
// If publishing a node, and the node doesn't exist, create it. // If publishing a node, and the node doesn't exist, create it.
if (packet.getType() == IQ.Type.set) { if (packet.getType() == IQ.Type.set) {
...@@ -117,18 +122,24 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -117,18 +122,24 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
LeafNode newNode = new LeafNode(pepService, null, nodeID, creator); LeafNode newNode = new LeafNode(pepService, null, nodeID, creator);
newNode.addOwner(creator); newNode.addOwner(creator);
newNode.saveToDB(); newNode.saveToDB();
if (Log.isDebugEnabled()) {
Log.debug("PEP: Created node ('" + nodeID + "') for " + jidFrom); Log.debug("PEP: Created node ('" + nodeID + "') for " + jidFrom);
} }
} }
} }
}
// Process with PubSub as usual. // Process with PubSub as usual.
if (pubSubEngine.process(pepService, packet)) { if (pubSubEngine.process(pepService, packet)) {
if (Log.isDebugEnabled()) {
Log.debug("PEP: The pubSubEngine processed a packet for " + jidFrom + "'s pepService."); Log.debug("PEP: The pubSubEngine processed a packet for " + jidFrom + "'s pepService.");
} }
}
else { else {
if (Log.isDebugEnabled()) {
Log.debug("PEP: The pubSubEngine did not process a packet for " + jidFrom + "'s pepService."); Log.debug("PEP: The pubSubEngine did not process a packet for " + jidFrom + "'s pepService.");
} }
}
} }
else { else {
......
...@@ -1673,28 +1673,37 @@ public class PubSubEngine { ...@@ -1673,28 +1673,37 @@ public class PubSubEngine {
return completedForm; return completedForm;
} }
public void start(PubSubService service) { public void start(final PubSubService service) {
// Probe presences of users that this service has subscribed to (once the server // Probe presences of users that this service has subscribed to (once the server
// has started) // has started)
final PubSubService tempService = service; // TODO: Needs to be tested for correctness
if (XMPPServer.getInstance().isStarted()) {
probePresences(service);
}
else {
XMPPServer.getInstance().addServerListener(new XMPPServerListener() { XMPPServer.getInstance().addServerListener(new XMPPServerListener() {
public void serverStarted() { public void serverStarted() {
probePresences(service);
}
public void serverStopping() {
}
});
}
}
private void probePresences(final PubSubService service) {
Set<JID> affiliates = new HashSet<JID>(); Set<JID> affiliates = new HashSet<JID>();
for (Node node : tempService.getNodes()) { for (Node node : service.getNodes()) {
affiliates.addAll(node.getPresenceBasedSubscribers()); affiliates.addAll(node.getPresenceBasedSubscribers());
} }
for (JID jid : affiliates) { for (JID jid : affiliates) {
// Send probe presence // Send probe presence
Presence subscription = new Presence(Presence.Type.probe); Presence subscription = new Presence(Presence.Type.probe);
subscription.setTo(jid); subscription.setTo(jid);
subscription.setFrom(tempService.getAddress()); subscription.setFrom(service.getAddress());
tempService.send(subscription); service.send(subscription);
}
}
public void serverStopping() {
} }
});
} }
public void shutdown(PubSubService service) { public void shutdown(PubSubService service) {
......
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