I've implemented a BuddyStorage that uses PostgreSQL as backend. I want to access the Zone's DBManager but it seems I cannot access it in my init() method as the Zone isn't initialized yet:
In my own BuddyStorage.java:
Code: Select all
@Override
public void init() {
var zone = SmartFoxServer.getInstance().getZoneManager().getZoneByName(ZONE_NAME);
if (zone == null) {
throw new RuntimeException(String.format("Zone '%s' is missing", ZONE_NAME));
}
dbManager = zone.getDBManager();
try {
checkDatabaseStructure();
inited = true;
} catch (SQLException sqlErr) {
Logger.getGlobal().log(Level.SEVERE, "Was not able to initialize BuddyStorage", sqlErr);
}
}
It gives me this error:
smartfoxserver-6dbd488df9-2vj54 — 14:25:11,706 ERROR [main] v2.SmartFoxServer - java.lang.RuntimeException:
smartfoxserver-6dbd488df9-2vj54 — ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
smartfoxserver-6dbd488df9-2vj54 — Exception: java.lang.RuntimeException
smartfoxserver-6dbd488df9-2vj54 — Message: Zone 'MyZone' is missing
smartfoxserver-6dbd488df9-2vj54 — Description: Unexpected error during Server boot. The server cannot start.
smartfoxserver-6dbd488df9-2vj54 — Solution: Please email us the content of this error message, including the stack trace to support[at]smartfoxserver.com
smartfoxserver-6dbd488df9-2vj54 — +--- --- ---+
smartfoxserver-6dbd488df9-2vj54 — Stack Trace:
smartfoxserver-6dbd488df9-2vj54 — +--- --- ---+
smartfoxserver-6dbd488df9-2vj54 — com.rrg.sfs2x.storage.BuddyStorage.init(BuddyStorage.java:47)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.buddylist.SFSBuddyListManager.init(SFSBuddyListManager.java:119)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.entities.managers.SFSZoneManager.configureBuddyListManager(SFSZoneManager.java:611)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:404)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:239)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:292)
smartfoxserver-6dbd488df9-2vj54 — com.smartfoxserver.v2.Main.main(Main.java:13)
smartfoxserver-6dbd488df9-2vj54 — ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
How should I access the DBManager in my Storage class? And, based on that, when should I check (and possibly init) the table structure if not in the init() method?
Thanks a lot!
Cheers,
Niklas