/[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 1671 by torben, Thu Dec 22 20:30:28 2011 UTC miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/StatusListener.java revision 1684 by torben, Fri Jan 27 12:21:27 2012 UTC
# Line 24  public class StatusListener extends ApiL Line 24  public class StatusListener extends ApiL
24          Configuration loginConfig;          Configuration loginConfig;
25          Configuration homeConfig;          Configuration homeConfig;
26    
27            long cachedTime = 0;
28            String cachedXml = "";
29    
30          public StatusListener(Server server, Configuration loginConfig, Configuration homeConfig) {          public StatusListener(Server server, Configuration loginConfig, Configuration homeConfig) {
31                  this.server = server;                  this.server = server;
32                  this.loginConfig = loginConfig;                          this.loginConfig = loginConfig;        
# Line 43  public class StatusListener extends ApiL Line 46  public class StatusListener extends ApiL
46                  if(!event.path[0].equalsIgnoreCase("webstatus")) {                  if(!event.path[0].equalsIgnoreCase("webstatus")) {
47                          return;                          return;
48                  }                  }
49    
50                    String xml;
51    
52                    synchronized(this) { //is this necessary ?
53                            long now = System.currentTimeMillis();
54                            if ( (now-cachedTime) > 5000) {
55                                    xml = buildXML();
56                                    cachedXml = xml;
57                                    cachedTime = now;
58                            } else {
59                                    xml = cachedXml;
60                            }
61                    }
62                            
63    
64                    event.setResponse(xml);
65                    event.setActionTaken(true);
66            }
67            
68            private String buildXML() {
69    
70                  StringBuilder sb = new StringBuilder();                  StringBuilder sb = new StringBuilder();
71    
72                  sb.append("<?xml version=\"1.0\"?> \n");                  sb.append("<?xml version=\"1.0\"?> \n");
# Line 121  public class StatusListener extends ApiL Line 145  public class StatusListener extends ApiL
145                  sb.append("</plugins>\n");                  sb.append("</plugins>\n");
146                                                                                                                    
147                  sb.append("</serverinfo>");                                      sb.append("</serverinfo>");                    
148                  event.setResponse(sb.toString());  
149                  event.setActionTaken(true);                  return sb.toString();
150                                    
151          }          }
152    

Legend:
Removed from v.1671  
changed lines
  Added in v.1684

  ViewVC Help
Powered by ViewVC 1.1.20