Save data when server restarts

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Save data when server restarts

Postby potmo » 26 Jan 2009, 15:57

Hi!

Im having some extra data on each user that i'd like to save when the server restarts. The problem is that the I can't find any place to save the data at.

First i hoped that the internal event "userLost" would be fired when the server stopped but that didnt happen.

Then I tried destoy() in my zone extension like this.

Code: Select all

   public void destroy() {
      
      System.out.println("Kicking all users in zone");
      @SuppressWarnings("unchecked")
      LinkedList<User> allUsers = this.zone.getAllUsersInZone();
      
      //try to logout all users
      for(User u:allUsers){
         System.out.println("Kicking user " + u.getName());
         this.server.logoutUser(u, false, true);
      }
      
      System.out.println("Zone destoyed");
   }


it only traces
2009-jan-26 17:59:34 it.gotoandplay.smartfoxserver.extensions.AdminExtension sendHaltSignal
INFO: Server Halt was requested by administrator.


Halting Server ...


Kicking all users in zone
Zone destoyed


Is there any other place that I can handle a logut nice and save all my data to a mysql-database.

This is a problem right now since all users online will lose their stats if we restart the database.

There are sone exceptions thrown after "Zone destoyed" but i think thats a trailproblem from users not being kicked and then our Ping-module tries to kick it again since it havn't been cleaned up correctly.
Anyway it looks like this. Might be to any help:


Thanks in advance

b.t.w we are using SFS Pro 1.6.3
17:59:44.969 - [ WARNING ] > Generic Exception in acceptNewConnections():java.nio.channels.ClosedSelectorException
2009-jan-26 17:59:44 it.gotoandplay.smartfoxserver.SmartFoxServer acceptNewConnections
VARNING: Generic Exception in acceptNewConnections():java.nio.channels.ClosedSelectorException
java.nio.channels.ClosedSelectorException
at sun.nio.ch.SelectorImpl.selectedKeys(SelectorImpl.java:57)
at it.gotoandplay.smartfoxserver.SmartFoxServer.acceptNewConnections(SmartFoxServer.java:711)
at it.gotoandplay.smartfoxserver.SmartFoxServer.run(SmartFoxServer.java:657)
2009-jan-26 17:59:45 org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.apache.cxf.bus.spring.BusApplicationContext@4c261e41: display name [org.apache.cxf.bus.spring.BusApplicationContext@4c261e41]; startup date [Mon Jan 26 17:59:06 CET 2009]; parent: org.springframework.web.context.support.XmlWebApplicationContext@5820c3da
2009-jan-26 17:59:45 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@8505bad: defining beans []; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@4f5c1769
2009-01-26 17:59:45.877:/cxfApp:INFO: Closing Spring root WebApplicationContext
2009-jan-26 17:59:45 org.springframework.context.support.AbstractApplicationContext doClose
INFO: Closing org.springframework.web.context.support.XmlWebApplicationContext@5820c3da: display name [Root WebApplicationContext]; startup date [Mon Jan 26 17:58:53 CET 2009]; root of context hierarchy
2009-jan-26 17:59:45 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@4f5c1769: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,org.apache.cxf.resource.ResourceManager,org.apache.cxf.configuration.Configurer,org.apache.cxf.binding.BindingFactoryManager,org.apache.cxf.transport.DestinationFactoryManager,org.apache.cxf.transport.ConduitInitiatorManager,org.apache.cxf.wsdl.WSDLManager,org.apache.cxf.phase.PhaseManager,org.apache.cxf.workqueue.WorkQueueManager,org.apache.cxf.buslifecycle.BusLifeCycleManager,org.apache.cxf.endpoint.ServerRegistry,org.apache.cxf.endpoint.ServerLifeCycleManager,org.apache.cxf.endpoint.ClientLifeCycleManager,org.apache.cxf.transports.http.QueryHandlerRegistry,org.apache.cxf.endpoint.EndpointResolverRegistry,org.apache.cxf.headers.HeaderManager,org.apache.cxf.catalog.OASISCatalogManager,org.apache.cxf.endpoint.ServiceContractResolverRegistry,org.apache.cxf.binding.soap.SoapBindingFactory,org.apache.cxf.binding.soap.SoapTransportFactory,org.apache.cxf.binding.soap.customEditorConfigurer,org.apache.cxf.transport.servlet.ServletTransportFactory,loginservice]; root of factory hierarchy
2009-jan-26 17:59:46 it.gotoandplay.smartfoxserver.webserver.WebServer stop
INFO: Web server stopped.
---------------------Native error-----------------------
Exception name: java.lang.NullPointerException
Error Time: 26 jan 09 - 18:00:18
Error Code: Not availible
Error Desc: Not availible
Error Mess: null
User Name: Not availible
User Ip: Not availible
Stack Trace:
null
null
it.gotoandplay.smartfoxserver.SmartFoxServer.getChannelQueue(SmartFoxServer.java:795)
it.gotoandplay.smartfoxserver.EventWriter.handleEvent(EventWriter.java:136)
it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.sendGenericMessage(ExtensionHelper.java:261)
se.raketspel.smartbox.core.ExtensionCore.sendSmartBoxMessage(ExtensionCore.java:217)
se.raketspel.smartbox.application.authManager.AuthManagerProtocolManager.PING(AuthManagerProtocolManager.java:145)
se.raketspel.smartbox.core.IdleUsersHandler.checkTimeOuts(IdleUsersHandler.java:124)
se.raketspel.smartbox.core.IdleUsersHandler.run(IdleUsersHandler.java:105)
java.util.TimerThread.mainLoop(Timer.java:512)
java.util.TimerThread.run(Timer.java:462)
--------------------------------------------------------
18:00:38.590 - [ WARNING ] > Exception during client disconnection: java.lang.NullPointerException
2009-jan-26 18:00:38 it.gotoandplay.smartfoxserver.SmartFoxServer lostConnection
VARNING: Exception during client disconnection: java.lang.NullPointerException
java.lang.NullPointerException
at it.gotoandplay.smartfoxserver.SmartFoxServer.lostConnection(SmartFoxServer.java:1451)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.kickUser(SystemHandler.java:2558)
at it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.disconnectUser(ExtensionHelper.java:940)
at se.raketspel.smartbox.core.IdleUsersHandler.checkTimeOuts(IdleUsersHandler.java:158)
at se.raketspel.smartbox.core.IdleUsersHandler.run(IdleUsersHandler.java:105)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Exception in thread "IdleUserManagerClock" java.lang.NullPointerException
at it.gotoandplay.smartfoxserver.SmartFoxServer.lostConnection(SmartFoxServer.java:1546)
at it.gotoandplay.smartfoxserver.controllers.SystemHandler.kickUser(SystemHandler.java:2558)
at it.gotoandplay.smartfoxserver.extensions.ExtensionHelper.disconnectUser(ExtensionHelper.java:940)
at se.raketspel.smartbox.core.IdleUsersHandler.checkTimeOuts(IdleUsersHandler.java:158)
at se.raketspel.smartbox.core.IdleUsersHandler.run(IdleUsersHandler.java:105)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Nisse Bergman
Raketspel
User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Postby potmo » 26 Jan 2009, 15:58

just writing to get the notify when anyone writes something
Nisse Bergman

Raketspel
cevans
Posts: 15
Joined: 02 Jul 2007, 11:00

Postby cevans » 08 Feb 2009, 09:35

This would be useful for me as well. If anyone is willing to share a solution or workaround for this it would be greatly appreciated!

Right now I have the server periodically save certain information to XML files. The data isn't important enough to constantly save to the DB, but it's important enough that I would like to recover it if the server suddenly crashes.

It would be great if right before the server kicks the bucket or if I need to manually restart it, it could save certain information to XML files.
User avatar
potmo
Posts: 154
Joined: 02 Feb 2007, 14:28
Location: Stockholm Sweden
Contact:

Postby potmo » 09 Feb 2009, 06:54

right now I have solved it with a costy workaround.

First I lock the server so that no-one can log in. Then I kick all users that are not in a game and save all their data.
Then I kick all users that leave a game under a period of 15 minutes.
Then after 15 minutes I kick all the users that haven't left the games.

Now the server is empty and i can save all other info and then restart the server manually.
Nisse Bergman

Raketspel

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 17 guests