Package com.netflix.governator.lifecycle

Examples of com.netflix.governator.lifecycle.LifecycleManager$StateKey


        }
        else {
            builder = LifecycleInjector.builder();
            injector = builder.build().createInjector();
        }
        LifecycleManager manager = injector.getInstance(LifecycleManager.class);
        try {
            manager.start();
        } catch (Exception e) {
            Assert.fail(e.getMessage());
        }
        return injector;
    }
View Full Code Here


    /**
     * Override to tear down your specific external resource.
     */
    protected void after() {
        if (injector != null) {
            LifecycleManager manager = injector.getInstance(LifecycleManager.class);
            try {
                manager.close();
            } catch (Exception e) {
                Assert.fail(e.getMessage());
            }
        }
    }
View Full Code Here

            }
        );
    }

    private <T> void processInjectedObject(T obj, TypeLiteral<T> type){
        LifecycleManager manager = lifecycleManager.get();
        if ( manager != null ) {
            for ( LifecycleListener listener : manager.getListeners() ) {
                listener.objectInjected(type, obj);
            }

            Class<?> clazz = obj.getClass();
            LifecycleMethods methods = getLifecycleMethods(clazz);

            if ( warmUpIsInDag(clazz, type) ) {
                addDependencies(manager, obj, type, methods);
            }

            if ( methods.hasLifecycleAnnotations() ) {
                try {
                    manager.add(obj, methods);
                }
                catch ( Exception e ) {
                    throw new Error(e);
                }
            }
View Full Code Here

            else
            {
                injector = LifecycleInjector.builder().withBootstrapModule(new ParavirtualBootstrapModule()).createInjector();
            }

            LifecycleManager manager = injector.getInstance(LifecycleManager.class);

            manager.start();

            Bootstrapper bootstrapper = injector.getInstance(Bootstrapper.class);

            bootstrapper.execute();

            manager.close();
        }
        catch (Throwable t)
        {
            log.error(t.getMessage(), t);
        }
View Full Code Here

                        bind(ObjectMapper.class).to(DefaultObjectMapper.class);
                    }
                }
        ).build().createInjector();

        LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
        lifecycleManager.start();

        InputManager inputManager = new InputManager();
        List<SuroInput> inputList = injector.getInstance(ObjectMapper.class).readValue(
                inputConfig,
                new TypeReference<List<SuroInput>>() {
View Full Code Here

                        bind(ObjectMapper.class).to(DefaultObjectMapper.class);
                    }
                }
            ).build().createInjector();

        LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
        lifecycleManager.start();

        String desc = "{\n" +
                "    \"default\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"defaultTestSink\"\n" +
                "    },\n" +
                "    \"topic1\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"topic1TestSink\"\n" +
                "    }\n" +
                "}";
       
        SinkManager sinkManager = injector.getInstance(SinkManager.class);
        ObjectMapper mapper = injector.getInstance(ObjectMapper.class);
       
        sinkManager.set(getSinkMap(mapper, desc));
        assertEquals(sinkManager.getSink("topic1").getStat(), "topic1TestSink open");
        assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("topic7").getStat(), "defaultTestSink open");
        assertTrue(
                sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic1:topic1TestSink open\n\n") ||
                sinkManager.reportSinkStat().equals("topic1:topic1TestSink open\n\ndefault:defaultTestSink open\n\n"));
        assertEquals(TestSink.getNumOfSinks(), 2);


        // change desc - test removal
        desc = "{\n" +
                "    \"default\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"defaultTestSink\"\n" +
                "    }\n" +
                "}";
        sinkManager.set(getSinkMap(mapper, desc));
        assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.reportSinkStat(),
                String.format("default:defaultTestSink open\n\n"));
        assertEquals(TestSink.getNumOfSinks(), 1);

        // change desc - test addition
        desc = "{\n" +
                "    \"default\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"defaultTestSink\"\n" +
                "    },\n" +
                "    \"topic2\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"topic2TestSink\"\n" +
                "    }\n" +
                "}";
        sinkManager.set(getSinkMap(mapper, desc));
        assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("topic2").getStat(), "topic2TestSink open");
        assertTrue(
                sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic2:topic2TestSink open\n\n") ||
                        sinkManager.reportSinkStat().equals("topic2:topic2TestSink open\n\ndefault:defaultTestSink open\n\n")
        );
        assertEquals(TestSink.getNumOfSinks(), 2);

        // test exception - nothing changed
        desc = "{\n" +
                "    \"default\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"defaultTestSink\"\n" +
                "    },\n" +
                "    \"topic2\": {\n" +
                "        \"type\": \"TestSink\",\n" +
                "        \"message\": \"topic2TestSink\"\n" +
                "    }\n" +
                "},";
        sinkManager.set(getSinkMap(mapper, desc));
        assertEquals(sinkManager.getSink("topic1").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("default").getStat(), "defaultTestSink open");
        assertEquals(sinkManager.getSink("topic2").getStat(), "topic2TestSink open");
        assertTrue(
                sinkManager.reportSinkStat().equals("default:defaultTestSink open\n\ntopic2:topic2TestSink open\n\n") ||
                        sinkManager.reportSinkStat().equals("topic2:topic2TestSink open\n\ndefault:defaultTestSink open\n\n")
        );
        assertEquals(TestSink.getNumOfSinks(), 2);

        // test destroy
        lifecycleManager.close();
        assertEquals(TestSink.getNumOfSinks(), 0);
        assertNull(sinkManager.getSink("any"));
    }
View Full Code Here

                        }
                    }
                )
                .withModules(new SuroClientModule())
                .build().createInjector();
        LifecycleManager manager = injector.getInstance(LifecycleManager.class);

        try {
            manager.start();
        } catch (Exception e) {
            throw new RuntimeException("LifecycleManager cannot start with an exception: " + e.getMessage(), e);
        }
        return injector;
    }
View Full Code Here

      System.setProperty("archaius.deployment.applicationId", "middletier");
      System.setProperty("archaius.deployment.environment", "ci");
       
      Injector injector = LifecycleInjector.builder().withModules(new RSSModule()).createInjector();

      LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class);
      lifecycleManager.start();

      middleTierServer = injector.getInstance(MiddleTierServer.class);
      middleTierServer.start();
    }
View Full Code Here

TOP

Related Classes of com.netflix.governator.lifecycle.LifecycleManager$StateKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.