use of net.socialgamer.cah.metrics.Metrics in project PretendYoureXyzzy by ajanata.
the class CahModule method configure.
@Override
protected void configure() {
bind(Integer.class).annotatedWith(GameId.class).toProvider(GameManager.class);
/*
* A mutable Set of IP addresses (in String format) which are banned. This Set is
* thread-safe.
*/
bind(new TypeLiteral<Set<String>>() {
}).annotatedWith(BanList.class).toInstance(Collections.synchronizedSet(new HashSet<String>()));
bind(Properties.class).toInstance(properties);
// this is only so injected constructors can log
StartupUtils.reconfigureLogging(context);
// FIXME huge hack.
StartupUtils.reloadProperties(context, properties);
final String metricsClassName = properties.getProperty("pyx.metrics.impl");
try {
@SuppressWarnings("unchecked") final Class<? extends Metrics> metricsClass = (Class<? extends Metrics>) Class.forName(metricsClassName);
bind(Metrics.class).to(metricsClass);
} catch (final ClassNotFoundException e) {
throw new RuntimeException(e);
}
bind(Date.class).annotatedWith(ServerStarted.class).toInstance(new Date());
bind(String.class).annotatedWith(UniqueId.class).toProvider(UniqueIds.class);
install(new FactoryModuleBuilder().build(User.Factory.class));
final ScheduledThreadPoolExecutor threadPool = new ScheduledThreadPoolExecutor(2 * Runtime.getRuntime().availableProcessors(), new ThreadFactory() {
final AtomicInteger threadCount = new AtomicInteger();
@Override
public Thread newThread(final Runnable r) {
final Thread t = new Thread(r);
t.setDaemon(true);
t.setName("timer-task-" + threadCount.incrementAndGet());
return t;
}
});
threadPool.setRemoveOnCancelPolicy(true);
bind(ScheduledThreadPoolExecutor.class).toInstance(threadPool);
}
use of net.socialgamer.cah.metrics.Metrics in project PretendYoureXyzzy by ajanata.
the class StartupUtils method contextInitialized.
@Override
public void contextInitialized(final ServletContextEvent contextEvent) {
final ServletContext context = contextEvent.getServletContext();
reconfigureLogging(context);
final Injector injector = getInjector(context);
final ScheduledThreadPoolExecutor timer = injector.getInstance(ScheduledThreadPoolExecutor.class);
final UserPingTask ping = injector.getInstance(UserPingTask.class);
timer.scheduleAtFixedRate(ping, PING_START_DELAY, PING_CHECK_DELAY, TimeUnit.MILLISECONDS);
final BroadcastGameListUpdateTask broadcastUpdate = injector.getInstance(BroadcastGameListUpdateTask.class);
timer.scheduleAtFixedRate(broadcastUpdate, BROADCAST_UPDATE_START_DELAY, BROADCAST_UPDATE_DELAY, TimeUnit.MILLISECONDS);
context.setAttribute(INJECTOR, injector);
context.setAttribute(DATE_NAME, injector.getInstance(Key.get(Date.class, ServerStarted.class)));
// this is called in the process of setting up the injector right now... ideally we wouldn't
// need to do that there and can just do it here again.
// reloadProperties(context);
CardcastService.hackSslVerifier();
// log that the server (re-)started to metrics logging (to flush all old games and users)
injector.getInstance(Metrics.class).serverStart(injector.getInstance(Key.get(String.class, UniqueId.class)));
}
Aggregations