properties file support for game and player limits. add this information to stats.jsp
This commit is contained in:
parent
acfae4e67c
commit
7be74010a6
|
@ -0,0 +1,2 @@
|
|||
pyx.server.max_users=800
|
||||
pyx.server.max_games=200
|
|
@ -37,7 +37,6 @@ Administration tools.
|
|||
<%@ page import="net.socialgamer.cah.Constants.LongPollEvent" %>
|
||||
<%@ page import="net.socialgamer.cah.Constants.LongPollResponse" %>
|
||||
<%@ page import="net.socialgamer.cah.Constants.ReturnableData" %>
|
||||
<%@ page import="net.socialgamer.cah.StartupUtils" %>
|
||||
<%@ page import="net.socialgamer.cah.data.ConnectedUsers" %>
|
||||
<%@ page import="net.socialgamer.cah.data.QueuedMessage" %>
|
||||
<%@ page import="net.socialgamer.cah.data.QueuedMessage.MessageType" %>
|
||||
|
@ -122,6 +121,11 @@ if ("true".equals(reloadLog4j)) {
|
|||
StartupUtils.reconfigureLogging(this.getServletContext());
|
||||
}
|
||||
|
||||
String reloadProps = request.getParameter("reloadProps");
|
||||
if ("true".equals(reloadProps)) {
|
||||
StartupUtils.reloadProperties(this.getServletContext());
|
||||
}
|
||||
|
||||
%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
@ -235,6 +239,9 @@ boolean verboseDebug = verboseDebugObj != null ? verboseDebugObj.booleanValue()
|
|||
<p>
|
||||
<a href="?reloadLog4j=true">Reload log4j.properties.</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="?reloadProps=true">Reload pyx.properties.</a>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -28,6 +28,7 @@ most useful graph if it is only updated every 15 minutes, but it is still nice t
|
|||
@author Andy Janata (ajanata@socialgamer.net)
|
||||
--%>
|
||||
<%@ page language="java" contentType="text/plain; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
<%@ page import="java.util.Properties" %>
|
||||
<%@ page import="com.google.inject.Injector" %>
|
||||
<%@ page import="net.socialgamer.cah.data.ConnectedUsers" %>
|
||||
<%@ page import="net.socialgamer.cah.data.GameManager" %>
|
||||
|
@ -38,8 +39,11 @@ Injector injector = (Injector) servletContext.getAttribute(StartupUtils.INJECTOR
|
|||
|
||||
ConnectedUsers users = injector.getInstance(ConnectedUsers.class);
|
||||
GameManager games = injector.getInstance(GameManager.class);
|
||||
Properties props = injector.getInstance(Properties.class);
|
||||
|
||||
out.clear();
|
||||
out.println("USERS " + users.getUsers().size());
|
||||
out.println("GAMES " + games.getGameList().size());
|
||||
out.println("MAX_USERS " + props.get("pyx.server.max_users"));
|
||||
out.println("MAX_GAMES " + props.get("pyx.server.max_games"));
|
||||
%>
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.socialgamer.cah.data.GameManager;
|
||||
|
@ -53,14 +54,26 @@ public class CahModule extends AbstractModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO Provide a configuration option for this instead of hard-coding it.
|
||||
*
|
||||
* @return The maximum number of games allowed on this server.
|
||||
*/
|
||||
@Provides
|
||||
@MaxGames
|
||||
Integer provideMaxGames() {
|
||||
return 250;
|
||||
return Integer.valueOf((String) properties.get("pyx.server.max_games"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The maximum number of users allowed to connect to this server.
|
||||
*/
|
||||
@Provides
|
||||
@MaxUsers
|
||||
Integer provideMaxUsers() {
|
||||
return Integer.valueOf((String) properties.get("pyx.server.max_users"));
|
||||
}
|
||||
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MaxUsers {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,4 +101,11 @@ public class CahModule extends AbstractModule {
|
|||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BanList {
|
||||
}
|
||||
|
||||
private final static Properties properties = new Properties();
|
||||
|
||||
@Provides
|
||||
Properties provideProperties() {
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
|
||||
package net.socialgamer.cah;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.Timer;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
@ -106,6 +109,20 @@ public class StartupUtils extends GuiceServletContextListener {
|
|||
context.setAttribute(DATE_NAME, serverStarted);
|
||||
|
||||
reconfigureLogging(contextEvent.getServletContext());
|
||||
reloadProperties(contextEvent.getServletContext());
|
||||
}
|
||||
|
||||
public static void reloadProperties(final ServletContext context) {
|
||||
final Injector injector = (Injector) context.getAttribute(INJECTOR);
|
||||
final Properties props = injector.getInstance(Properties.class);
|
||||
final File propsFile = new File(context.getRealPath("/WEB-INF/pyx.properties"));
|
||||
try {
|
||||
props.clear();
|
||||
props.load(new FileReader(propsFile));
|
||||
} catch (final Exception e) {
|
||||
// we should probably do something?
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void reconfigureLogging(final ServletContext context) {
|
||||
|
|
Loading…
Reference in New Issue