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