Search in sources :

Example 6 with ServletModule

use of com.google.inject.servlet.ServletModule in project meteo by pierre.

the class RealtimeSystem method main.

public static void main(final String[] args) throws Exception {
    final Injector injector = Guice.createInjector(new RealtimeSystemModule(), new ServletModule() {

        @Override
        protected void configureServlets() {
            // Static files
            bind(DefaultServlet.class).asEagerSingleton();
            serve("/media/*").with(DefaultServlet.class);
            serve("*").with(GuiceContainer.class, new HashMap<String, String>() {

                {
                    put(PackagesResourceConfig.PROPERTY_PACKAGES, "com.ning.metrics.meteo.server.resources");
                }
            });
        }
    });
    final SubscribersCompiler subscribersCompiler = injector.getInstance(SubscribersCompiler.class);
    subscribersCompiler.startAll();
    final JettyServer jetty = injector.getInstance(JettyServer.class);
    jetty.start(injector);
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            subscribersCompiler.stopAll();
            jetty.stop();
        }
    });
}
Also used : RealtimeSystemModule(com.ning.metrics.meteo.binder.RealtimeSystemModule) HashMap(java.util.HashMap) SubscribersCompiler(com.ning.metrics.meteo.subscribers.SubscribersCompiler) Injector(com.google.inject.Injector) JettyServer(com.ning.metrics.meteo.server.JettyServer) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) GuiceContainer(com.sun.jersey.guice.spi.container.servlet.GuiceContainer) ServletModule(com.google.inject.servlet.ServletModule)

Example 7 with ServletModule

use of com.google.inject.servlet.ServletModule in project API by ca-cwds.

the class JerseyGuiceRule method before.

@Override
protected void before() throws Throwable {
    Injector baseInjector = Guice.createInjector(Stage.PRODUCTION, new ServletModule());
    JerseyGuiceUtils.install(new ServiceLocatorGenerator() {

        @Override
        public ServiceLocator create(String name, ServiceLocator parent) {
            if (!name.startsWith("__HK2_Generated_")) {
                return null;
            }
            return baseInjector.createChildInjector(new JerseyGuiceModule(name)).getInstance(ServiceLocator.class);
        }
    });
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) ServiceLocatorGenerator(org.glassfish.hk2.extension.ServiceLocatorGenerator) Injector(com.google.inject.Injector) JerseyGuiceModule(com.squarespace.jersey2.guice.JerseyGuiceModule) ServletModule(com.google.inject.servlet.ServletModule)

Aggregations

ServletModule (com.google.inject.servlet.ServletModule)7 AbstractModule (com.google.inject.AbstractModule)3 Injector (com.google.inject.Injector)2 HashMap (java.util.HashMap)2 Configuration (org.apache.hadoop.conf.Configuration)2 RealtimeSystemModule (com.ning.metrics.meteo.binder.RealtimeSystemModule)1 JettyServer (com.ning.metrics.meteo.server.JettyServer)1 SubscribersCompiler (com.ning.metrics.meteo.subscribers.SubscribersCompiler)1 JerseyGuiceModule (com.squarespace.jersey2.guice.JerseyGuiceModule)1 ClientResponse (com.sun.jersey.api.client.ClientResponse)1 WebResource (com.sun.jersey.api.client.WebResource)1 GuiceContainer (com.sun.jersey.guice.spi.container.servlet.GuiceContainer)1 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)1 AppContext (org.apache.hadoop.mapreduce.v2.app.AppContext)1 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)1 HistoryContext (org.apache.hadoop.mapreduce.v2.hs.HistoryContext)1 MockHistoryContext (org.apache.hadoop.mapreduce.v2.hs.MockHistoryContext)1 XFrameOptionsFilter (org.apache.hadoop.security.http.XFrameOptionsFilter)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 MockRM (org.apache.hadoop.yarn.server.resourcemanager.MockRM)1