OK, so I am probably doing something that I am not supposed to do. But I have a reload function in my server that unloads all systems, including closing all servers, then loads them back up again.
I am running into an issue where then my server gets created again, I get this error:
java.lang.RuntimeException: Serializer registry locked trying to register class:class com.jme3.network.message.SerializerRegistrationsMessage
at com.jme3.network.serializing.Serializer.registerClassForId(Serializer.java:210)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:252)
at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:166)
at com.jme3.network.service.serializer.ServerSerializerRegistrationsService.onInitialize(ServerSerializerRegistrationsService.java:53)
at com.jme3.network.service.serializer.ServerSerializerRegistrationsService.onInitialize(ServerSerializerRegistrationsService.java:48)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:74)
at com.jme3.network.service.AbstractService.initialize(AbstractService.java:44)
at com.jme3.network.service.ServiceManager.addService(ServiceManager.java:126)
at com.jme3.network.service.HostedServiceManager.addService(HostedServiceManager.java:82)
at com.jme3.network.base.DefaultServer.addStandardServices(DefaultServer.java:112)
at com.jme3.network.base.DefaultServer.<init>(DefaultServer.java:100)
at com.jme3.network.Network.createServer(Network.java:95)
This is the server creation code:
server = Network.createServer(getWorld().getName(), getWorld().getVersionId(), getPort(), getPort());
The server has been closed prior to running this line, I have confirmed that. How to I get around this?
@Domenic thanks for the reply, unfortunately that did not work.
EDIT:
This is what my unload now looks like:
public void unload() {
if (server != null) {
server.getServices().removeService(server.getServices().getService(ServerSerializerRegistrationsService.class));
server.close();
}
server = null;
loaded = false;
LOGGER.log(Level.INFO, "Server {0} stopped on port {1,number,#}", new Object[]{getName(), getPort()});
}
EDIT 2:
This is what my load looks like:
public void load() {
if (server != null || loaded) {
unload();
}
//-- REGISTER Messages
if (!registered) {
Serializer.registerClass(JmeAuthRequestMessage.class);
Serializer.registerClass(JmeAuthResponseMessage.class);
registered = true;
}
//--DONE
try {
server = Network.createServer(getWorld().getName(), getWorld().getVersionId(), getPort(), getPort());
server.addMessageListener(this);
server.addConnectionListener(this);
server.start();
LOGGER.log(Level.INFO, "Server {0} running on port {1,number,#}", new Object[]{getName(), getPort()});
} catch (IOException ex) {
Logger.getLogger(JmeServer.class.getName()).log(Level.SEVERE, null, ex);
}
loaded = true;
}
I also had the same issue with the registration, thus the flag to check if I have already registered the message classes.