/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java revision 1672 by torben, Fri Dec 23 09:16:12 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java revision 1685 by torben, Fri Jan 27 14:12:37 2012 UTC
# Line 13  import org.bukkit.plugin.Plugin; Line 13  import org.bukkit.plugin.Plugin;
13    
14  import org.bukkit.configuration.Configuration;  import org.bukkit.configuration.Configuration;
15    
16  import org.kokakiwi.apicraft.events.ApiEvent;  /*import org.kokakiwi.apicraft.events.ApiEvent;
17  import org.kokakiwi.apicraft.events.ApiListener;  import org.kokakiwi.apicraft.events.ApiListener;*/
18    import de.codeinfection.quickwango.ApiBukkit.ApiBukkit;
19    import de.codeinfection.quickwango.ApiBukkit.ApiRequestAction;
20    import de.codeinfection.quickwango.ApiBukkit.ApiRequestException;
21    import de.codeinfection.quickwango.ApiBukkit.Net.Parameters;
22    import de.codeinfection.quickwango.ApiBukkit.ApiRequestController;
23    
24  public class StatusListener extends ApiListener {  public class StatusListener extends ApiRequestController {
25    
26          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
27    
# Line 27  public class StatusListener extends ApiL Line 32  public class StatusListener extends ApiL
32          long cachedTime = 0;          long cachedTime = 0;
33          String cachedXml = "";          String cachedXml = "";
34    
35          public StatusListener(Server server, Configuration loginConfig, Configuration homeConfig) {          public StatusListener(Plugin plugin, Server server, Configuration loginConfig, Configuration homeConfig) {
36                    super(plugin,true);
37    
38                  this.server = server;                  this.server = server;
39                  this.loginConfig = loginConfig;                          this.loginConfig = loginConfig;        
40                  this.homeConfig = homeConfig;                  this.homeConfig = homeConfig;
# Line 42  public class StatusListener extends ApiL Line 49  public class StatusListener extends ApiL
49          }          }
50                    
51          @Override          @Override
52          public void onApiEvent(ApiEvent event) {          public Object defaultAction(String action, Parameters params, Server server) throws ApiRequestException {
53                  if(!event.path[0].equalsIgnoreCase("webstatus")) {  /*              if(!event.path[0].equalsIgnoreCase("webstatus")) {
54                          return;                          return;
55                  }                  }*/
56    
57                  String xml;                  String xml;
58                  long now = System.currentTimeMillis();  
59                  if ( (now-cachedTime) > 5000) {                  synchronized(this) { //is this necessary ?
60                          xml = buildXML();                          long now = System.currentTimeMillis();
61                          cachedXml = xml;                          if ( (now-cachedTime) > 5000) {
62                          cachedTime = now;                                  xml = buildXML();
63                  } else {                                  cachedXml = xml;
64                          xml = cachedXml;                                  cachedTime = now;
65                  }                                } else {
66                                    xml = cachedXml;
67                            }
68                    }
69                                                    
70    
71                  event.setResponse(xml);  /*              event.setResponse(xml);
72                  event.setActionTaken(true);                  event.setActionTaken(true);*/
73    
74                    return xml;
75          }          }
76                    
77          private String buildXML() {          private String buildXML() {

Legend:
Removed from v.1672  
changed lines
  Added in v.1685

  ViewVC Help
Powered by ViewVC 1.1.20