public PEPService getPEPService( JID jid, boolean autoCreate ) {
        jid = jid.asBareJID();
        PEPService pepService;

        final Lock lock = pepServices.getLock(jid);
        lock.lock();
        try {
            if (pepServices.containsKey(jid)) {
                // lookup in cache
                if ( pepServices.get(jid).isAbsent() && autoCreate ) {
                    // needs auto-create despite negative cache.
                    pepService = null;
                } else {
                    return pepServices.get(jid).get();
                }
            } else {
                // lookup in database.
                pepService = XMPPServer.getInstance().getPubSubModule().getPersistenceProvider().loadPEPServiceFromDB(jid);
                pepServices.put(jid, CacheableOptional.of(pepService));
                if ( pepService != null ) {
                    pepService.initialize();
                }
            }

            if ( pepService != null ) {
                Log.debug("PEP: Restored service for {} from the database.", jid);
                pubSubEngine.start(pepService);
            } else if (autoCreate) {
                Log.debug("PEP: Auto-created service for {}.", jid);
                pepService = this.create(jid);

                // Probe presences
                pubSubEngine.start(pepService);

                // Those who already have presence subscriptions to jidFrom
                // will now automatically be subscribed to this new
                // PEPService.
                XMPPServer.getInstance().getIQPEPHandler().addSubscriptionForRosterItems( pepService );
            }
        } finally {
            lock.unlock();
        }

        return pepService;
    }
Retrieves a PEP service -- attempting first from memory, then from the
database.

This method can automatically create a PEP service if one does not exist.

@param jid
           the JID of the user that owns the PEP service.
@param autoCreate
           true if a PEP service that does not yet exist needs to be created.
@return the requested PEP service if found or null if not found.
xmppserver/src/main/java/org/jivesoftware/openfire/pep/PEPServiceManager.java