@Override public void contextDestroyed(ServletContextEvent servletContextEvent) { SPIProvider spiProvider = spiProviderReference.getAndSet(null); if (spiProvider != null) { MPIHelperUtil.unregisterSPIProvider(spiProvider); } }
private static void _invalidate(long companyId) { for (SPI spi : MPIHelperUtil.getSPIs()) { try { RegistrationReference registrationReference = spi.getRegistrationReference(); IntrabandRPCUtil.execute(registrationReference, new InvalidateProcessCallable(companyId)); } catch (Exception e) { _log.error("Unable to invalidate SPI " + spi + " for company " + companyId, e); } } }
protected void doRun(String[] ids) throws Exception { // Print release information System.out.println("Starting " + ReleaseInfo.getReleaseInfo()); // Portal resiliency DistributedRegistry.registerDistributed( ComponentConstants.COMPONENT_CONTEXT, Direction.DUPLEX, MatchType.POSTFIX); DistributedRegistry.registerDistributed( MimeResponse.MARKUP_HEAD_ELEMENT, Direction.DUPLEX, MatchType.EXACT); DistributedRegistry.registerDistributed( PortletRequest.LIFECYCLE_PHASE, Direction.DUPLEX, MatchType.EXACT); DistributedRegistry.registerDistributed(WebKeys.class); Intraband intraband = MPIHelperUtil.getIntraband(); intraband.registerDatagramReceiveHandler( SystemDataType.MAILBOX.getValue(), new MailboxDatagramReceiveHandler()); MessageBus messageBus = (MessageBus) PortalBeanLocatorUtil.locate(MessageBus.class.getName()); intraband.registerDatagramReceiveHandler( SystemDataType.MESSAGE.getValue(), new MessageDatagramReceiveHandler(messageBus)); intraband.registerDatagramReceiveHandler( SystemDataType.PROXY.getValue(), new IntrabandProxyDatagramReceiveHandler()); intraband.registerDatagramReceiveHandler( SystemDataType.RPC.getValue(), new RPCDatagramReceiveHandler()); // Shutdown hook if (_log.isDebugEnabled()) { _log.debug("Add shutdown hook"); } Runtime runtime = Runtime.getRuntime(); runtime.addShutdownHook(new Thread(new ShutdownHook())); // Template manager if (_log.isDebugEnabled()) { _log.debug("Initialize template manager"); } TemplateManagerUtil.init(); // Indexers IndexerRegistryUtil.register(new MBMessageIndexer()); IndexerRegistryUtil.register(new PluginPackageIndexer()); // Upgrade if (_log.isDebugEnabled()) { _log.debug("Upgrade database"); } DBUpgrader.upgrade(); // Clear locks if (_log.isDebugEnabled()) { _log.debug("Clear locks"); } try { LockLocalServiceUtil.clear(); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to clear locks because Lock table does not exist"); } } // Messaging if (_log.isDebugEnabled()) { _log.debug("Initialize message bus"); } MessageSender messageSender = (MessageSender) PortalBeanLocatorUtil.locate(MessageSender.class.getName()); SynchronousMessageSender synchronousMessageSender = (SynchronousMessageSender) PortalBeanLocatorUtil.locate(SynchronousMessageSender.class.getName()); MessageBusUtil.init( DoPrivilegedUtil.wrap(messageBus), DoPrivilegedUtil.wrap(messageSender), DoPrivilegedUtil.wrap(synchronousMessageSender)); // Cluster executor ClusterExecutorUtil.initialize(); if (!SPIUtil.isSPI()) { ClusterMasterExecutorUtil.initialize(); } // Ehache bootstrap EhcacheStreamBootstrapCacheLoader.start(); // Scheduler if (_log.isDebugEnabled()) { _log.debug("Initialize scheduler engine lifecycle"); } SchedulerEngineHelperUtil.initialize(); // Verify if (_log.isDebugEnabled()) { _log.debug("Verify database"); } DBUpgrader.verify(); // Background tasks if (!ClusterMasterExecutorUtil.isEnabled()) { BackgroundTaskLocalServiceUtil.cleanUpBackgroundTasks(); } // Liferay JspFactory JspFactorySwapper.swap(); // Jericho CachedLoggerProvider.install(); }
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext servletContext = servletContextEvent.getServletContext(); String contextPath = servletContext.getRealPath(StringPool.BLANK); String spiEmbeddedLibDirName = servletContext.getInitParameter("spiEmbeddedLibDir"); Set<File> jarFiles = new LinkedHashSet<File>(); // Load embedded Tomcat File spiEmbeddedLibDir = new File(contextPath, spiEmbeddedLibDirName); addJarFiles(jarFiles, spiEmbeddedLibDir); // Load portal-service.jar from MPI addJarFiles(jarFiles, PortalClassLoaderUtil.getClassLoader(), PortalException.class.getName()); // Load JDBC driver jars from MPI addJarFiles( jarFiles, PortalClassLoaderUtil.getClassLoader(), PropsUtil.get(PropsKeys.JDBC_DEFAULT_DRIVER_CLASS_NAME)); // Load ext jars addJarFiles(jarFiles, new File(spiEmbeddedLibDir, "ext")); StringBundler sb = new StringBundler(jarFiles.size() * 2 + 4); for (File file : jarFiles) { sb.append(file.getAbsolutePath()); sb.append(File.pathSeparator); } sb.append(contextPath); sb.append("/WEB-INF/classes"); SPI_CLASS_PATH = sb.toString(); if (_log.isDebugEnabled()) { _log.debug("SPI class path " + SPI_CLASS_PATH); } String spiProviderClassName = servletContext.getInitParameter("spiProviderClassName"); Thread currentThread = Thread.currentThread(); ClassLoader contextClassLoader = currentThread.getContextClassLoader(); try { Class<SPIProvider> spiProviderClass = null; if (SPIUtil.isSPI()) { spiProviderClass = (Class<SPIProvider>) loadClassDirectly(contextClassLoader, spiProviderClassName); } else { spiProviderClass = (Class<SPIProvider>) contextClassLoader.loadClass(spiProviderClassName); } SPIProvider spiProvider = spiProviderClass.newInstance(); boolean result = spiProviderReference.compareAndSet(null, spiProvider); if (!result) { _log.error( "Duplicate SPI provider " + spiProvider + " is already registered in servlet context " + servletContext.getContextPath()); } else { MPIHelperUtil.registerSPIProvider(spiProvider); } } catch (Exception e) { _log.error("Unable to create SPI provider with name " + spiProviderClassName, e); } }