Commit 9127aa74 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

PEP services are now loaded dynamically.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@9163 b35dd754-fafc-0310-a699-88a17e54d16e
parent c22a23e0
...@@ -107,8 +107,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -107,8 +107,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
*/ */
private Map<String, Set<JID>> knownRemotePresences = new ConcurrentHashMap<String, Set<JID>>(); private Map<String, Set<JID>> knownRemotePresences = new ConcurrentHashMap<String, Set<JID>>();
private static final String GET_PEP_SERVICES = "SELECT DISTINCT serviceID FROM pubsubNode";
public IQPEPHandler() { public IQPEPHandler() {
super("Personal Eventing Handler"); super("Personal Eventing Handler");
pepServices = new ConcurrentHashMap<String, PEPService>(); pepServices = new ConcurrentHashMap<String, PEPService>();
...@@ -133,27 +131,46 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -133,27 +131,46 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
pubSubEngine = new PubSubEngine(server.getPacketRouter()); pubSubEngine = new PubSubEngine(server.getPacketRouter());
// Restore previous PEP services for which nodes exist in the database. // TODO: This will need to be refactored once XEP-0115 (Entity Capabilities) is implemented.
/*
// Add this PEP handler as a packet interceptor so we may deal with
// client packets that send disco#info's explaining capabilities
// including PEP contact notification filters.
InterceptorManager.getInstance().addInterceptor(this);
*/
}
/**
* Loads a PEP service from the database, if it exists.
*
* @param jid the JID of the owner of the PEP service.
* @return the loaded PEP service, or null if not found.
*/
private PEPService loadPEPServiceFromDB(String jid) {
String GET_PEP_SERVICE = "SELECT DISTINCT serviceID FROM pubsubNode " +
"WHERE serviceID='" + jid + "'";
PEPService pepService = null;
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
try { try {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
// Get all PEP services // Get all PEP services
pstmt = con.prepareStatement(GET_PEP_SERVICES); pstmt = con.prepareStatement(GET_PEP_SERVICE);
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
// Restore old PEPServices // Restore old PEPServices
while (rs.next()) { while (rs.next()) {
String serviceID = rs.getString(1); String serviceID = rs.getString(1);
// Create a new PEPService if serviceID looks like a bare JID. // Create a new PEPService
if (serviceID.indexOf("@") >= 0) { pepService = new PEPService(XMPPServer.getInstance(), serviceID);
PEPService pepService = new PEPService(server, serviceID);
pepServices.put(serviceID, pepService); pepServices.put(serviceID, pepService);
pubSubEngine.start(pepService);
if (Log.isDebugEnabled()) { if (Log.isDebugEnabled()) {
Log.debug("PEP: Restored service for " + serviceID + " from the database."); Log.debug("PEP: Restored service for " + serviceID + " from the database.");
} }
} }
}
rs.close(); rs.close();
pstmt.close(); pstmt.close();
} }
...@@ -177,20 +194,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -177,20 +194,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
} }
// TODO: This will need to be refactored once XEP-0115 (Entity Capabilities) is implemented. return pepService;
/*
// Add this PEP handler as a packet interceptor so we may deal with
// client packets that send disco#info's explaining capabilities
// including PEP contact notification filters.
InterceptorManager.getInstance().addInterceptor(this);
*/
}
public void start() {
super.start();
for (PEPService service : pepServices.values()) {
pubSubEngine.start(service);
}
} }
public void stop() { public void stop() {
...@@ -238,7 +242,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -238,7 +242,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
if (packet.getTo() == null && packet.getType() == IQ.Type.set) { if (packet.getTo() == null && packet.getType() == IQ.Type.set) {
String jidFrom = senderJID.toBareJID(); String jidFrom = senderJID.toBareJID();
PEPService pepService = pepServices.get(jidFrom); PEPService pepService = getPEPService(jidFrom);
// If no service exists yet for jidFrom, create one. // If no service exists yet for jidFrom, create one.
if (pepService == null) { if (pepService == null) {
...@@ -274,7 +278,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -274,7 +278,6 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
// Do nothing // Do nothing
} }
} }
// If publishing a node, and the node doesn't exist, create it. // If publishing a node, and the node doesn't exist, create it.
...@@ -311,7 +314,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -311,7 +314,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
else if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) { else if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
String jidTo = packet.getTo().toBareJID(); String jidTo = packet.getTo().toBareJID();
PEPService pepService = pepServices.get(jidTo); PEPService pepService = getPEPService(jidTo);
if (pepService != null) { if (pepService != null) {
pubSubEngine.process(pepService, packet); pubSubEngine.process(pepService, packet);
...@@ -332,6 +335,21 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -332,6 +335,21 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
return null; return null;
} }
/**
* Retrieves a PEP service -- attempting first from memory, then from the database.
*
* @return the requested PEP service if found or null if not found.
*/
private PEPService getPEPService(String jid) {
PEPService pepService = pepServices.get(jid);
if (pepService == null) {
pepService = loadPEPServiceFromDB(jid);
}
return pepService;
}
/** /**
* Generates and processes an IQ stanza that subscribes to a PEP service. * Generates and processes an IQ stanza that subscribes to a PEP service.
* *
...@@ -403,7 +421,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -403,7 +421,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
*/ */
private void cancelSubscriptionToPEPService(JID unsubscriber, JID serviceOwner) { private void cancelSubscriptionToPEPService(JID unsubscriber, JID serviceOwner) {
// Retrieve recipientJID's PEP service, if it exists. // Retrieve recipientJID's PEP service, if it exists.
PEPService pepService = pepServices.get(serviceOwner.toBareJID()); PEPService pepService = getPEPService(serviceOwner.toBareJID());
if (pepService == null) { if (pepService == null) {
return; return;
} }
...@@ -452,7 +470,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -452,7 +470,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
ArrayList<Element> items = new ArrayList<Element>(); ArrayList<Element> items = new ArrayList<Element>();
String recipientJID = XMPPServer.getInstance().createJID(name, null).toBareJID(); String recipientJID = XMPPServer.getInstance().createJID(name, null).toBareJID();
PEPService pepService = pepServices.get(recipientJID); PEPService pepService = getPEPService(recipientJID);
if (pepService != null) { if (pepService != null) {
CollectionNode rootNode = pepService.getRootCollectionNode(); CollectionNode rootNode = pepService.getRootCollectionNode();
...@@ -479,7 +497,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -479,7 +497,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void subscribedToPresence(JID subscriberJID, JID authorizerJID) { public void subscribedToPresence(JID subscriberJID, JID authorizerJID) {
PEPService pepService = pepServices.get(authorizerJID.toBareJID()); PEPService pepService = getPEPService(authorizerJID.toBareJID());
if (pepService != null) { if (pepService != null) {
createSubscriptionToPEPService(pepService, subscriberJID, authorizerJID); createSubscriptionToPEPService(pepService, subscriberJID, authorizerJID);
...@@ -509,14 +527,23 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -509,14 +527,23 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
public void availableSession(ClientSession session, Presence presence) { public void availableSession(ClientSession session, Presence presence) {
// On newly-available presences, send the last published item if the resource is a subscriber.
JID newlyAvailableJID = presence.getFrom(); JID newlyAvailableJID = presence.getFrom();
for (PEPService pepService : pepServices.values()) { // Send the last published items for the contacts on newlyAvailableJID's roster.
try {
Roster roster = XMPPServer.getInstance().getRosterManager().getRoster(newlyAvailableJID.getNode());
for (RosterItem item : roster.getRosterItems()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH) {
PEPService pepService = getPEPService(item.getJid().toBareJID());
if (pepService != null) {
pepService.sendLastPublishedItems(newlyAvailableJID); pepService.sendLastPublishedItems(newlyAvailableJID);
} }
}
}
}
catch (UserNotFoundException e) {
// Do nothing
}
} }
public void remoteUserAvailable(Presence presence) { public void remoteUserAvailable(Presence presence) {
...@@ -545,7 +572,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider, ...@@ -545,7 +572,7 @@ public class IQPEPHandler extends IQHandler implements ServerIdentitiesProvider,
} }
// Send the presence packet recipient's last published items to the remote user. // Send the presence packet recipient's last published items to the remote user.
PEPService pepService = pepServices.get(jidTo.toBareJID()); PEPService pepService = getPEPService(jidTo.toBareJID());
if (pepService != null) { if (pepService != null) {
pepService.sendLastPublishedItems(jidFrom); pepService.sendLastPublishedItems(jidFrom);
} }
......
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