List of usage examples for org.springframework.beans.factory.config ConfigurableBeanFactory getBean
Object getBean(String name) throws BeansException;
From source file:org.red5.server.plugin.definst.DefinstPlugin.java
@Override public void doStart() throws Exception { super.doStart(); // add the context to the parent, this will be red5.xml ConfigurableBeanFactory factory = ((ConfigurableApplicationContext) context).getBeanFactory(); // if parent context was not set then lookup red5.common log.debug("Lookup common - bean:{} local:{} singleton:{}", new Object[] { factory.containsBean("red5.common"), factory.containsLocalBean("red5.common"), factory.containsSingleton("red5.common"), }); parentContext = (ApplicationContext) factory.getBean("red5.common"); //create app context appContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/definst.xml" }, true, parentContext);/* w w w . ja v a2 s . c om*/ //get a ref to the "default" global scope GlobalScope global = (GlobalScope) server.getGlobal("default"); //create a scope resolver ScopeResolver scopeResolver = new ScopeResolver(); scopeResolver.setGlobalScope(global); //create a context - this takes the place of the previous web context Context ctx = new Context(appContext, appName); ctx.setClientRegistry(new ClientRegistry()); ctx.setMappingStrategy(new MappingStrategy()); ctx.setPersistanceStore(global.getStore()); ctx.setScopeResolver(scopeResolver); ctx.setServiceInvoker(new ServiceInvoker()); //create a handler handler = new DefinstHandler(); //create a scope for the admin // Scope scope = new Scope.Builder((IScope) global, "scope", appName, false).build(); // scope.setContext(ctx); // scope.setHandler(handler); server.addMapping(hostName, appName, "default"); // if (global.addChildScope(scope)) { // log.info("Scope was added to global (default) scope"); // } else { // log.warn("Scope was not added to global (default) scope"); // } // // //start the scope // scope.start(); }
From source file:fr.certu.chouette.gui.command.Command.java
/** * @param factory//w w w . j ava 2s . c o m */ public static void initDao() { ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory"); Session session = SessionFactoryUtils.getSession(sessionFactory, true); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); }
From source file:fr.certu.chouette.gui.command.Command.java
/** * @param factory/* w w w . j a va2 s . c o m*/ */ public static void closeDao() { ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory"); SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager .unbindResource(sessionFactory); SessionFactoryUtils.closeSession(sessionHolder.getSession()); }
From source file:org.red5.server.war.RootContextLoaderServlet.java
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); logger.info("Registering subcontext for servlet context: " + ctx.getContextPath()); if (registeredContexts.contains(ctx)) { logger.debug("Context is already registered: " + webAppKey); return;//w w w .j a v a2s.c o m } ContextLoader loader = new ContextLoader(); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader .initWebApplicationContext(ctx); appCtx.setParent(applicationContext); appCtx.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx); ConfigurableBeanFactory appFactory = appCtx.getBeanFactory(); logger.debug("About to grab Webcontext bean for " + webAppKey); Context webContext = (Context) appCtx.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) appFactory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // register the context so we dont try to reinitialize it registeredContexts.add(ctx); }
From source file:fr.certu.chouette.command.Command.java
/** * @param factory/*from w w w.j av a 2 s . c o m*/ */ public static void initDao() { if (dao) { ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory"); Session session = SessionFactoryUtils.getSession(sessionFactory, true); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); } }
From source file:fr.certu.chouette.command.Command.java
/** * @param factory//from ww w . j ava 2 s . c om */ public static void closeDao() { if (dao) { ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory"); SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager .unbindResource(sessionFactory); SessionFactoryUtils.closeSession(sessionHolder.getSession()); } }
From source file:org.red5.server.war.RootContextLoaderServlet.java
/** * Main entry point for the Red5 Server as a war *//*from w w w . j av a 2s.c o m*/ // Notification that the web application is ready to process requests @Override public void contextInitialized(ServletContextEvent sce) { if (null != servletContext) { return; } instance = this; System.setProperty("red5.deployment.type", "war"); myClassloader = getClass().getClassLoader(); servletContext = sce.getServletContext(); String prefix = servletContext.getRealPath("/"); servletContext.setAttribute("root.classloader", myClassloader); initRegistry(servletContext); long time = System.currentTimeMillis(); logger.info("RED5 Server (http://www.osflash.org/red5)"); logger.info("Root context loader"); logger.debug("Path: " + prefix); try { // instance the context loader ContextLoader loader = createContextLoader(); applicationContext = (ConfigurableWebApplicationContext) loader .initWebApplicationContext(servletContext); logger.debug("Root context path: " + applicationContext.getServletContext().getContextPath()); ConfigurableBeanFactory factory = applicationContext.getBeanFactory(); // register default factory.registerSingleton("default.context", applicationContext); // get the main factory parentFactory = (DefaultListableBeanFactory) factory.getParentBeanFactory(); // create a wrapper around our primary context BeanFactoryReference beanfactoryRef = new ContextBeanFactoryReference(applicationContext); // set it in the root servlet context servletContext.setAttribute("bean.factory.ref", beanfactoryRef); // set a remoting codec factory for AMF use servletContext.setAttribute("remoting.codec.factory", parentFactory.getBean("remotingCodecFactory")); server = (Server) parentFactory.getBean("red5.server"); clientRegistry = (ClientRegistry) factory.getBean("global.clientRegistry"); globalInvoker = (ServiceInvoker) factory.getBean("global.serviceInvoker"); globalStrategy = (MappingStrategy) factory.getBean("global.mappingStrategy"); global = (GlobalScope) factory.getBean("global.scope"); logger.debug("GlobalScope: " + global); global.setServer(server); global.register(); global.start(); globalResolver = new ScopeResolver(); globalResolver.setGlobalScope(global); logger.debug("About to grab Webcontext bean for Global"); Context globalContext = (Context) factory.getBean("global.context"); globalContext.setCoreBeanFactory(parentFactory); globalContext.setClientRegistry(clientRegistry); globalContext.setServiceInvoker(globalInvoker); globalContext.setScopeResolver(globalResolver); globalContext.setMappingStrategy(globalStrategy); logger.debug("About to grab Webcontext bean for ROOT"); Context webContext = (Context) factory.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) factory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // grab the scope list (other war/webapps) IRemotableList remote = (IRemotableList) Naming .lookup("rmi://localhost:" + rmiPort + "/subContextList"); logger.debug("Children: " + remote.numChildren()); if (remote.hasChildren()) { logger.debug("Children were detected"); for (int i = 0; i < remote.numChildren(); i++) { logger.debug("Enumerating children"); WebSettings settings = remote.getAt(i); registerSubContext(settings.getWebAppKey()); } logger.debug("End of children..."); } } catch (Throwable t) { logger.error(t); } finally { timer = new Timer(); checkScopeList = new CheckScopeListTask(); timer.scheduleAtFixedRate(checkScopeList, 1000, 30000); } long startupIn = System.currentTimeMillis() - time; logger.info("Startup done in: " + startupIn + " ms"); }
From source file:org.red5.server.war.WarLoaderServlet.java
public void registerSubContext(String webAppKey) { // get the sub contexts - servlet context ServletContext ctx = servletContext.getContext(webAppKey); if (ctx == null) { ctx = servletContext;/*from ww w . j av a 2 s. c om*/ } ContextLoader loader = new ContextLoader(); ConfigurableWebApplicationContext appCtx = (ConfigurableWebApplicationContext) loader .initWebApplicationContext(ctx); appCtx.setParent(applicationContext); appCtx.refresh(); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx); ConfigurableBeanFactory appFactory = appCtx.getBeanFactory(); logger.debug("About to grab Webcontext bean for " + webAppKey); Context webContext = (Context) appCtx.getBean("web.context"); webContext.setCoreBeanFactory(parentFactory); webContext.setClientRegistry(clientRegistry); webContext.setServiceInvoker(globalInvoker); webContext.setScopeResolver(globalResolver); webContext.setMappingStrategy(globalStrategy); WebScope scope = (WebScope) appFactory.getBean("web.scope"); scope.setServer(server); scope.setParent(global); scope.register(); scope.start(); // register the context so we dont try to reinitialize it registeredContexts.add(ctx); }