use of com.codecademy.eventhub.index.DatedEventIndexModule in project EventHub by Codecademy.
the class EventHubTest method getInjector.
private Injector getInjector() {
Properties prop = new Properties();
prop.put("eventhub.directory", getTempDirectory());
prop.put("eventhub.eventindex.initialNumEventIdsPerDay", "10");
prop.put("eventhub.usereventindex.numPointersPerIndexEntry", "2");
prop.put("eventhub.usereventindex.numIndexEntryPerFile", "2");
prop.put("eventhub.usereventindex.indexEntryFileCacheSize", "2");
prop.put("eventhub.usereventindex.numRecordsPerBlock", "2");
prop.put("eventhub.usereventindex.numBlocksPerFile", "2");
prop.put("eventhub.usereventindex.blockCacheSize", "2");
prop.put("eventhub.journaleventstorage.numMetaDataPerFile", "10");
prop.put("eventhub.journaleventstorage.metaDataFileCacheSize", "10");
prop.put("eventhub.journaleventstorage.journalFileSize", "1024");
prop.put("eventhub.journaleventstorage.journalWriteBatchSize", "1024");
prop.put("eventhub.cachedeventstorage.recordCacheSize", "10");
prop.put("eventhub.bloomfilteredeventstorage.bloomFilterSize", "64");
prop.put("eventhub.bloomfilteredeventstorage.numHashes", "1");
prop.put("eventhub.bloomfilteredeventstorage.numMetaDataPerFile", "10");
prop.put("eventhub.bloomfilteredeventstorage.metaDataFileCacheSize", "10");
prop.put("eventhub.journaluserstorage.numMetaDataPerFile", "10");
prop.put("eventhub.journaluserstorage.metaDataFileCacheSize", "10");
prop.put("eventhub.journaluserstorage.journalFileSize", "1024");
prop.put("eventhub.journaluserstorage.journalWriteBatchSize", "1024");
prop.put("eventhub.cacheduserstorage.recordCacheSize", "10");
prop.put("eventhub.bloomfiltereduserstorage.numMetaDataPerFile", "10");
prop.put("eventhub.bloomfiltereduserstorage.metaDataFileCacheSize", "10");
prop.put("eventhub.bloomfiltereduserstorage.bloomFilterSize", "64");
prop.put("eventhub.bloomfiltereduserstorage.numHashes", "1");
return createInjectorFor(new Properties(), new EventHubModule(prop), new DmaIdListModule(), new ShardedEventIndexModule(), new DatedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule());
}
use of com.codecademy.eventhub.index.DatedEventIndexModule in project EventHub by Codecademy.
the class EventHubHandler method main.
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(EventHub.class.getClassLoader().getResourceAsStream("hub.properties"));
properties.load(EventHubHandler.class.getClassLoader().getResourceAsStream("web.properties"));
properties.putAll(System.getProperties());
Injector injector = Guice.createInjector(Modules.override(new DmaIdListModule(), new DatedEventIndexModule(), new ShardedEventIndexModule(), new PropertiesIndexModule(), new UserEventIndexModule(), new EventStorageModule(), new UserStorageModule(), new EventHubModule(properties)).with(new Module()));
final EventHubHandler eventHubHandler = injector.getInstance(EventHubHandler.class);
int port = injector.getInstance(Key.get(Integer.class, Names.named("eventhubhandler.port")));
final Server server = new Server(port);
@SuppressWarnings("ConstantConditions") String webDir = EventHubHandler.class.getClassLoader().getResource("frontend").toExternalForm();
HashLoginService loginService = new HashLoginService();
loginService.putUser(properties.getProperty("eventhubhandler.username"), new Password(properties.getProperty("eventhubhandler.password")), new String[] { "user" });
server.addBean(loginService);
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
Constraint constraint = new Constraint();
constraint.setName("auth");
constraint.setAuthenticate(true);
constraint.setRoles(new String[] { "user", "admin" });
ConstraintMapping mapping = new ConstraintMapping();
mapping.setPathSpec("/*");
mapping.setConstraint(constraint);
securityHandler.setConstraintMappings(Collections.singletonList(mapping));
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.setLoginService(loginService);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
resourceHandler.setWelcomeFiles(new String[] { "main.html" });
resourceHandler.setResourceBase(webDir);
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { new JsonpCallbackHandler(eventHubHandler), securityHandler });
server.setHandler(handlers);
securityHandler.setHandler(resourceHandler);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if (server.isStarted()) {
try {
server.stop();
eventHubHandler.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}, "Stop Jetty Hook"));
server.join();
}
Aggregations