Package org.impalaframework.file

Examples of org.impalaframework.file.FileMonitor


       
        assertNotNull(p11);
        noServiceException(plugin2);
        noServiceException(plugin3);

        FileMonitor f1 = (FileMonitor) context1.getBean("bean1");
        FileMonitor f2 = (FileMonitor) context1.getBean("bean2");
        FileMonitor f3 = (FileMonitor) context1.getBean("bean3");
       
        FileMonitor pluginBean = Impala.getModuleBean(plugin1, "bean1", FileMonitor.class);
        assertEquals("classes.FileMonitorBean1", pluginBean.getClass().getName());
       
        noServiceException("unknownPlugin");

        service(f1);
        noService(f2);
        noService(f3);

        final Test2 test2 = new Test2();
        Impala.init(test2);
        assertEquals(test2.getModuleDefinition(), Impala.getRootModuleDefinition());

        assertTrue(Impala.hasModule(plugin1));
        assertTrue(Impala.hasModule(plugin2));
        final ApplicationContext context2 = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
        final ConfigurableApplicationContext p12 = getModule(plugin1);
        assertNotNull(p12);
        assertSame(p11, p12);
        final ConfigurableApplicationContext p22 = getModule(plugin2);
        assertNotNull(p22);
        noServiceException(plugin3);

        f1 = (FileMonitor) context2.getBean("bean1");
        f2 = (FileMonitor) context2.getBean("bean2");
        f3 = (FileMonitor) context2.getBean("bean3");

        service(f1);
        service(f2);
        noService(f3);

        // context still same
        assertSame(context1, context2);
        assertTrue(Impala.hasModule(plugin1));
        assertTrue(Impala.hasModule(plugin2));

        // now load plugin 3 as well
        final Test3 test3 = new Test3();
        Impala.init(test3);
        assertEquals(test3.getModuleDefinition(), Impala.getRootModuleDefinition());

        final ApplicationContext context3 = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
        final ConfigurableApplicationContext p13 = getModule(plugin1);
        assertSame(p11, p13);
        final ConfigurableApplicationContext p23 = getModule(plugin2);
        assertSame(p22, p23);
        final ConfigurableApplicationContext p33 = getModule(plugin3);
        assertNotNull(p33);

        f1 = (FileMonitor) context3.getBean("bean1");
        f2 = (FileMonitor) context3.getBean("bean2");
        f3 = (FileMonitor) context3.getBean("bean3");

        FileMonitor f3PluginBean = Impala.getModuleBean(plugin1, "bean3", FileMonitor.class);
        assertSame(f3, f3PluginBean);

        // context still same
        assertSame(context1, context3);

        service(f3);
        assertTrue(Impala.hasModule(plugin1));
        assertTrue(Impala.hasModule(plugin2));
        assertTrue(Impala.hasModule(plugin3));
       
        assertTrue(Impala.hasModule(plugin1));
        assertTrue(Impala.hasModule(plugin2));
        assertTrue(Impala.hasModule(plugin3));

        // show that this will return false
        assertFalse(Impala.reloadModule("unknown"));

        // now reload plugin1
        assertTrue(Impala.reloadModule(plugin1));
        assertTrue(Impala.hasModule(plugin1));

        final ConfigurableApplicationContext p13reloaded = getModule(plugin1);
        assertNotSame(p13reloaded, p13);
        FileMonitor f1reloaded = (FileMonitor) context3.getBean("bean1");

        assertEquals(f1.lastModified((File) null), f1reloaded.lastModified((File) null));
        service(f1reloaded);
        assertSame(f1reloaded, f1);

        // now reload plugin2, which will also reload plugin3
        assertTrue(Impala.reloadModule(plugin2));
        assertTrue(Impala.hasModule(plugin2));

        final ConfigurableApplicationContext p23reloaded = getModule(plugin2);
        assertNotSame(p23reloaded, p23);

        final ConfigurableApplicationContext p33reloaded = getModule(plugin3);
        assertNotSame(p33reloaded, p33);

        FileMonitor f3reloaded = (FileMonitor) context3.getBean("bean3");

        assertEquals(f3.lastModified((File) null), f3reloaded.lastModified((File) null));
        service(f3reloaded);
        assertSame(f3reloaded, f3);

        // show that this will return null
        assertNull(Impala.reloadModuleLike("unknown"));

        // now test reloadLike
        assertEquals(plugin2, Impala.reloadModuleLike("module2"));
        f3reloaded = (FileMonitor) context3.getBean("bean3");
        service(f3reloaded);

        // now remove plugin2 (and by implication, child plugin3)
        assertFalse(Impala.removeModule("unknown"));
        assertTrue(Impala.removeModule(plugin2));
        assertFalse(Impala.hasModule(plugin2));
        // check that the child is gone too
        assertFalse(Impala.hasModule(plugin3));

        final ModuleDefinition test3RootDefinition = Impala.getRootModuleDefinition();
        assertTrue(test3RootDefinition.hasChildModuleDefinition(plugin1));
        assertFalse(test3RootDefinition.hasChildModuleDefinition(plugin2));

        f3reloaded = (FileMonitor) context3.getBean("bean3");
        FileMonitor f2reloaded = (FileMonitor) context3.getBean("bean2");
        noService(f3reloaded);
        noService(f2reloaded);
    }
View Full Code Here


    public void testAdd() {
        final Test1 test1 = new Test1();
        Impala.init(test1);

        final ApplicationContext context1 = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
        FileMonitor f1 = (FileMonitor) context1.getBean("bean1");
        FileMonitor f2 = (FileMonitor) context1.getBean("bean2");

        service(f1);
        noService(f2);
        Impala.addModule(new SimpleModuleDefinition(plugin2));
        service(f1);
View Full Code Here

    public void testReloadParent() {
        final Test1 test1 = new Test1();
        Impala.init(test1);

        final ApplicationContext context1a = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
        FileMonitor f1 = Impala.getBean("bean1", FileMonitor.class);
        service(f1);
        Impala.reloadRootModule();
        final ApplicationContext context1b = SpringModuleUtils.getModuleSpringContext(Impala.getRootRuntimeModule());
        f1 = Impala.getBean("bean1", FileMonitor.class);
        service(f1);
View Full Code Here

       
        ConfigurableApplicationContext parent = SpringModuleUtils.getRootSpringContext(moduleStateHolder);

        // the implementing FileMonitorBean3 will find the monitor.properties
        // file
        FileMonitor bean3 = (FileMonitor) parent.getBean("bean3");
        assertEquals(333L, bean3.lastModified((File) null));
   
        //module3's class loader is set as the context class loader
        assertEquals(333L, bean3.lastModified(new File("./")));
       
        //now override this
        Thread.currentThread().setContextClassLoader(originalClassLoader);

        //still, using bean class loader, so finds 333L again
        assertEquals(333L, bean3.lastModified(new File("./")));
    }
View Full Code Here

        }
    }

    private void executeBean(String moduleName, String beanName) {
        RuntimeModule runtimeModule = Impala.getRuntimeModule(moduleName);
        FileMonitor bean = (FileMonitor) runtimeModule.getBean(beanName);
        bean.lastModified(new File("./"));
    }
View Full Code Here

        ConfigurableApplicationContext parent = SpringModuleUtils.getRootSpringContext(moduleStateHolder);
        assertNotNull(parent);
        assertEquals(3, moduleStateHolder.getRuntimeModules().size());

        FileMonitor bean1 = (FileMonitor) parent.getBean("bean1");
        assertEquals(999L, bean1.lastModified((File) null));

        FileMonitor bean2 = (FileMonitor) parent.getBean("bean2");
        assertEquals(100L, bean2.lastModified((File) null));

        // shutdown module and check behaviour has gone
        removeModule(plugin2);

        try {
            bean2.lastModified((File) null);
            fail();
        }
        catch (NoServiceException e) {
        }

        // bean 2 still works
        assertEquals(999L, bean1.lastModified((File) null));

        removeModule(plugin1);

        try {
            bean1.lastModified((File) null);
            fail();
        }
        catch (NoServiceException e) {
        }

        // now reload the module, and see that behaviour returns
       
        addModule(new SimpleModuleDefinition(plugin2));
        bean2 = (FileMonitor) parent.getBean("bean2");
        assertEquals(100L, bean2.lastModified((File) null));

        addModule(new SimpleModuleDefinition(plugin1));
        bean1 = (FileMonitor) parent.getBean("bean1");
        assertEquals(999L, bean1.lastModified((File) null));

        FileMonitor bean3 = (FileMonitor) parent.getBean("bean3");
        try {
            bean3.lastModified((File) null);
            fail();
        }
        catch (NoServiceException e) {
        }

        ModuleDefinition p2 = root.getChildModuleDefinition(plugin2);
        addModule(new SimpleModuleDefinition(p2, plugin3));
        assertEquals(333L, bean3.lastModified((File) null));

        final ConfigurableApplicationContext applicationPlugin3 = SpringModuleUtils.getModuleSpringContext(moduleStateHolder, plugin3);
        applicationPlugin3.close();

        try {
            bean3.lastModified((File) null);
            fail();
        }
        catch (NoServiceException e) {
        }
    }
View Full Code Here

        ConfigurableApplicationContext parent = SpringModuleUtils.getRootSpringContext(moduleStateHolder);
        assertNotNull(parent);
        ModuleTestUtils.checkHasPostProcessor(true, parent, ServiceRegistryPostProcessor.class);
        ModuleTestUtils.checkHasPostProcessor(true, parent, ModuleDefinitionPostProcessor.class);

        FileMonitor bean3 = (FileMonitor) parent.getBean("bean3");
        bean3.lastModified((File) null);

        // check that all three modules have loaded
        assertEquals(4, moduleStateHolder.getRuntimeModules().size());
    }
View Full Code Here

       
        ModuleStateHolder moduleStateHolder = application.getModuleStateHolder();
        transitionManager.processTransitions(moduleStateHolder, application, transitions);

        ConfigurableApplicationContext parentContext = SpringModuleUtils.getRootSpringContext(moduleStateHolder);
        FileMonitor bean = (FileMonitor) parentContext.getBean("bean1");
        bean.lastModified((File) null);
    }
View Full Code Here

TOP

Related Classes of org.impalaframework.file.FileMonitor

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.