@Override protected void onBootstrap(ApplicationEvent event) { PropertyCheck.mandatory(this, "moduleService", moduleService); final RetryingTransactionCallback<Object> startModulesCallback = new RetryingTransactionCallback<Object>() { public Object execute() throws Throwable { moduleService.startModules(); return null; } }; AuthenticationUtil.runAs(new RunAsWork<Object>() { @Override public Object doWork() throws Exception { transactionService.getRetryingTransactionHelper().doInTransaction(startModulesCallback, transactionService.isReadOnly()); return null; } }, AuthenticationUtil.getSystemUserName()); }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void multicastEvent(final ApplicationEvent event) { for (final ApplicationListener listener : getApplicationListeners(event)) { Executor executor = getTaskExecutor(); if (executor != null) { executor.execute(new Runnable() { @Override public void run() { listener.onApplicationEvent(event); } }); } else { listener.onApplicationEvent(event); } } }
@Override protected void onShutdown(ApplicationEvent event) { // remove shutdown hook and execute if (shutdownHook != null) { // execute execute(); // remove hook try { Runtime.getRuntime().removeShutdownHook(shutdownHook); } catch (IllegalStateException e) { // VM is already shutting down } shutdownHook = null; if (logger.isDebugEnabled()) { logger.debug("Deregistered shutdown hook"); } } }
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void multicastEvent(ApplicationEvent event, ResolvableType eventType) { ResolvableType type = eventType == null ? ResolvableType.forInstance(event) : eventType; Collection<ApplicationListener<?>> listeners = getApplicationListeners(event, type); if (listeners.isEmpty()) { return; } List<ApplicationListener<?>> transactionalListeners = listeners.stream()// .filter(PersistentApplicationEventMulticaster::isTransactionalApplicationEventListener)// .collect(Collectors.toList()); if (!transactionalListeners.isEmpty()) { Object eventToPersist = getEventToPersist(event); registry.getObject().store(eventToPersist, transactionalListeners); // EventStore.persist(eventThis) // SpringMVC Controller Atom Feed } for (ApplicationListener listener : listeners) { listener.onApplicationEvent(event); } }
/** * {@inheritDoc} */ @Override protected void onBootstrap(ApplicationEvent event) { if (!enabled) { return; } // Check properties PropertyCheck.mandatory(this, "domain", domain); if (port <= 0 || port > 65535) { throw new AlfrescoRuntimeException("Property 'port' is incorrect"); } PropertyCheck.mandatory(this, "emailService", emailService); // Startup startup(); }
@Override protected void onBootstrap(ApplicationEvent event) { // Reset the dictionary (destroy and reload) in order to ensure that we have a basic version of // the dictionary (static models) loaded at least dictionaryDAO.reset(); // Register listeners, which will be called when the dictionary is next reloaded register(); // Trigger a reload. The callbacks will occur immediately on the current thread, however, // the model created in reset() will still be available for the basic necessities dictionaryDAO.init(); // The listeners can now know about this // However, the listeners will be needing to access the dictionary themselves, hence the earlier 'reset' // to ensure that there is no deadlock waiting for a new dictionary ((ApplicationContext) event.getSource()).publishEvent(new DictionaryRepositoryBootstrappedEvent(this)); }
@Override protected void onBootstrap(ApplicationEvent event) { // Do an initial differential sync on startup, using transaction splitting. This ensures that on the very // first startup, we don't have to wait for a very long login operation to trigger the first sync! if (this.syncOnStartup) { AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() throws Exception { try { synchronizeInternal(false, false, true); } catch (Exception e) { ChainingUserRegistrySynchronizer.logger.warn("Failed initial synchronize with user registries", e); } return null; } }, AuthenticationUtil.getSystemUserName()); } }
public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextClosedEvent) { enabled = false; return; } if (event instanceof ContextRefreshedEvent) { initialized = true; return; } if (event instanceof OsgiServiceDependencyWaitStartingEvent) { if (enabled) { OsgiServiceDependencyWaitStartingEvent evt = (OsgiServiceDependencyWaitStartingEvent) event; String[] filter = new String[] { evt.getServiceDependency().getServiceFilter().toString() }; BlueprintEvent waitingEvent = new BlueprintEvent(BlueprintEvent.WAITING, bundleContext.getBundle(), extenderBundle, filter); listenerManager.blueprintEvent(waitingEvent); dispatcher.waiting(waitingEvent); } return; } }
@Override protected void onBootstrap(ApplicationEvent event) { Descriptor descriptor = descriptorService.getInstalledRepositoryDescriptor(); if (patch == null) { patchApplied = true; } else { AppliedPatch appliedPatch = patchService.getPatch(patch.getId()); if (appliedPatch == null) { patchApplied = patch.getFixesToSchema() < descriptor.getSchema(); } else { patchApplied = appliedPatch.getSucceeded(); } } }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ContextRefreshedEvent refreshEvent = (ContextRefreshedEvent)event; ApplicationContext refreshContext = refreshEvent.getApplicationContext(); if (refreshContext != null && refreshContext.equals(applicationContext)) { RunAsWork<Object> work = new RunAsWork<Object>() { public Object doWork() throws Exception { reset(); return null; } }; AuthenticationUtil.runAs(work, AuthenticationUtil.getSystemUserName()); } } }
@Override protected void onBootstrap(ApplicationEvent event) { RetryingTransactionCallback<Object> checkWork = new RetryingTransactionCallback<Object>() { public Object execute() throws Throwable { // run as System on bootstrap return AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() { check(); return null; } }, AuthenticationUtil.getSystemUserName()); } }; transactionService.getRetryingTransactionHelper().doInTransaction(checkWork, true); }
@Override protected void onShutdown(ApplicationEvent event) { AuthenticationUtil.runAs(new RunAsWork<Void>() { @Override public Void doWork() throws Exception { if (service.getImapServerEnabled()) { service.shutdown(); } return null; } }, AuthenticationUtil.getSystemUserName()); }
@Override protected void onBootstrap(ApplicationEvent event) { String majorVersion = I18NUtil.getMessage("version.major"); String minorVersion = I18NUtil.getMessage("version.minor"); // Internationalizes the message String errorMsg = I18NUtil.getMessage("system.err.lucene_not_supported", majorVersion + "." + minorVersion); log.error(errorMsg); List<StoreRef> storeRefs = nodeService.getStores(); for (StoreRef storeRef : storeRefs) { fullTextSearchIndexer.requiresIndex(storeRef); } }
@Override protected void onBootstrap(ApplicationEvent event) { RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); txnHelper.setForceWritable(true); // Force write in case server is read-only txnHelper.doInTransaction(new RetryingTransactionCallback<Void>() { public Void execute() throws Throwable { try { keyStoreChecker.validateKeyStores(); } catch(Throwable e) { // Just throw as a runtime exception throw new AlfrescoRuntimeException("Keystores are invalid", e); } return null; } }); }
@Override protected void onBootstrap(ApplicationEvent event) { RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper(); txnHelper.setForceWritable(true); txnHelper.doInTransaction(new RetryingTransactionCallback<Object>() { @Override public Object execute() throws Throwable { // run as System on bootstrap return AuthenticationUtil.runAs(new RunAsWork<Object>() { public Object doWork() { init(); return null; } }, AuthenticationUtil.getSystemUserName()); } }, false, true); tenantAdminService.register(this); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (!ContextClosedEvent.class.isInstance(event) || httpServer == null) { return; } httpServer.stop(); httpServer = null; LOGGER.info("Prometheus httpServer stopped."); }
public void onApplicationEvent(ApplicationEvent event) { try { if (event instanceof InteractiveAuthenticationSuccessEvent) { this.logLoginSuccess(event); } if (event instanceof AuthenticationFailureBadCredentialsEvent) { this.logBadCredential(event); } if (event instanceof AuthenticationFailureLockedEvent) { this.logLocked(event); } if (event instanceof AuthenticationFailureDisabledEvent) { this.logDisabled(event); } if (event instanceof AuthenticationFailureExpiredEvent) { this.logAccountExpired(event); } if (event instanceof AuthenticationFailureCredentialsExpiredEvent) { this.logCredentialExpired(event); } } catch (Exception ex) { logger.error(ex.getMessage(), ex); } }
@Override protected void onBootstrap(ApplicationEvent event) { // register shutdown hook shutdownHook = new ShutdownThread(); Runtime.getRuntime().addShutdownHook(shutdownHook); if (logger.isDebugEnabled()) { logger.debug("Registered shutdown hook"); } }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event.getClass() == ContextRefreshedEvent.class) { extensionLoader.loadExtension(Registry.class).subscribe(); extensionLoader.loadExtension(ProtocolFactory.class).client().open(); extensionLoader.loadExtension(Selector.class).start(); logger.info("subscribe:" + extensionLoader.loadExtension(Registry.class).getDirectory().list()); latch.countDown(); } else if (event.getClass() == ContextClosedEvent.class) { logger.info("unSubscribe task"); extensionLoader.loadExtension(Registry.class).unSubscribe(); extensionLoader.loadExtension(ProtocolFactory.class).client().close(); extensionLoader.loadExtension(Selector.class).close(); } }
/** * {@inheritDoc} */ public void onApplicationEvent(ApplicationEvent event) { if (failFast && event instanceof ContextRefreshedEvent) { // fail-fast -> check all statements are completed this.sqlSessionFactory.getConfiguration().getMappedStatementNames(); } }
/** * Publish CAS events. * * @param e the event */ protected void doPublishEvent(final ApplicationEvent e) { if (applicationEventPublisher != null) { LOGGER.debug("Publishing [{}]", e); this.applicationEventPublisher.publishEvent(e); } }
public void logCredentialExpired(ApplicationEvent event) throws Exception { AuthenticationFailureCredentialsExpiredEvent authenticationFailureCredentialsExpiredEvent = (AuthenticationFailureCredentialsExpiredEvent) event; Authentication authentication = authenticationFailureCredentialsExpiredEvent .getAuthentication(); logger.info("{}", authentication); String tenantId = this.getTenantId(authentication); Object principal = authentication.getPrincipal(); String userId = null; if (principal instanceof SpringSecurityUserAuth) { userId = ((SpringSecurityUserAuth) principal).getId(); } else { userId = authentication.getName(); } AuditDTO auditDto = new AuditDTO(); auditDto.setUserId(userId); auditDto.setAuditTime(new Date()); auditDto.setAction("login"); auditDto.setResult("failure"); auditDto.setApplication("lemon"); auditDto.setClient(getUserIp(authentication)); auditDto.setServer(InetAddress.getLocalHost().getHostAddress()); auditDto.setDescription(authenticationFailureCredentialsExpiredEvent .getException().getMessage()); auditDto.setTenantId(tenantId); auditConnector.log(auditDto); ctx.publishEvent(new LoginEvent(authentication, userId, this .getSessionId(authentication), "credentialExpired", "default", tenantId)); }
private <T extends ApplicationEvent> void publish(Supplier<T> eventSupplier) { if (applicationEventPublisher != null) { T event = eventSupplier.get(); logger.debug("Publishing {} with source {}", event.getClass().getSimpleName(), event.getSource()); applicationEventPublisher.publishEvent(event); } }
@Override public void onApplicationEvent(ApplicationEvent event) { if(event instanceof ApplicationStartedEvent) { System.out.println("===== custom started event in initializer"); } else if(event instanceof ApplicationReadyEvent) { System.out.println("===== custom ready event in initializer"); } }
@Override protected void onShutdown(ApplicationEvent event) { stopServer(); // Clear the configuration m_filesysConfig = null; }
/** * {@inheritDoc} */ @Override protected void onShutdown(ApplicationEvent event) { if (enabled) { shutdown(); } }
public void logBadCredential(ApplicationEvent event) throws Exception { AuthenticationFailureBadCredentialsEvent authenticationFailureBadCredentialsEvent = (AuthenticationFailureBadCredentialsEvent) event; Authentication authentication = authenticationFailureBadCredentialsEvent .getAuthentication(); logger.info("{}", authentication); String tenantId = this.getTenantId(authentication); Object principal = authentication.getPrincipal(); String userId = null; if (principal instanceof SpringSecurityUserAuth) { userId = ((SpringSecurityUserAuth) principal).getId(); } else { userId = authentication.getName(); } AuditDTO auditDto = new AuditDTO(); auditDto.setUserId(userId); auditDto.setAuditTime(new Date()); auditDto.setAction("login"); auditDto.setResult("failure"); auditDto.setApplication("lemon"); auditDto.setClient(getUserIp(authentication)); auditDto.setServer(InetAddress.getLocalHost().getHostAddress()); auditDto.setDescription(authenticationFailureBadCredentialsEvent .getException().getMessage()); auditDto.setTenantId(tenantId); auditConnector.log(auditDto); ctx.publishEvent(new LoginEvent(authentication, userId, this .getSessionId(authentication), "badCredentials", "default", tenantId)); }
@Override protected void onBootstrap(ApplicationEvent event) { try { log.info("Scheduler started"); scheduler.start(); } catch (SchedulerException e) { throw new AlfrescoRuntimeException("Scheduler failed to start", e); } }
private void publishEvent(ApplicationEvent event) { try { this.eventPublisher.publishEvent(event); } catch (Throwable ex) { logger.error("Error publishing " + event + ".", ex); } }
@Override protected void onBootstrap(ApplicationEvent event) { log.info("Checking person permissions ..."); int count = checkandFixPermissions(); log.info("... updated " + count); }
@Test public void testOverrideOrder() throws Exception { ApplicationEvent applicationEvent = new ApplicationEvent(this) { private static final long serialVersionUID = 1L; }; /* * Override order: default,custom */ SolrFacetConfig config = new SolrFacetConfig(rawProperties, "default,custom"); config.setNamespaceService(context.getBean("namespaceService", NamespaceService.class)); config.onBootstrap(applicationEvent); SolrFacetProperties creatorFP = config.getDefaultFacets().get("test_filter_creator"); assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}creator", creatorFP.getFacetQName().toString()); assertEquals(10, creatorFP.getMaxFilters()); assertEquals(5, creatorFP.getHitThreshold()); assertEquals(14, creatorFP.getMinFilterValueLength()); assertEquals(1, creatorFP.getScopedSites().size()); assertEquals("site1", creatorFP.getScopedSites().iterator().next()); /* * Override order: custom,default */ config = new SolrFacetConfig(rawProperties, "custom,default"); config.setNamespaceService(context.getBean("namespaceService", NamespaceService.class)); config.onBootstrap(applicationEvent); creatorFP = config.getDefaultFacets().get("test_filter_creator"); assertEquals("Incorrect QNAME", "{http://www.alfresco.org/model/content/1.0}creator", creatorFP.getFacetQName().toString()); assertEquals(5, creatorFP.getMaxFilters()); assertEquals(1, creatorFP.getHitThreshold()); assertEquals(4, creatorFP.getMinFilterValueLength()); assertEquals(0, creatorFP.getScopedSites().size()); }
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ApplicationStartedEvent) { update(); } }
@Override public void onApplicationEvent(ApplicationEvent applicationEvent) { //spring 容器加载完毕 if ( applicationEvent instanceof ContextRefreshedEvent){ initWorker(); if ( workers.size() > 0 ){ createScheduleManager(); startScanMasterStatTask(); } } }
public void logLocked(ApplicationEvent event) throws Exception { AuthenticationFailureLockedEvent authenticationFailureLockedEvent = (AuthenticationFailureLockedEvent) event; Authentication authentication = authenticationFailureLockedEvent .getAuthentication(); logger.info("{}", authentication); String tenantId = this.getTenantId(authentication); Object principal = authentication.getPrincipal(); String userId = null; if (principal instanceof SpringSecurityUserAuth) { userId = ((SpringSecurityUserAuth) principal).getId(); } else { userId = authentication.getName(); } AuditDTO auditDto = new AuditDTO(); auditDto.setUserId(userId); auditDto.setAuditTime(new Date()); auditDto.setAction("login"); auditDto.setResult("failure"); auditDto.setApplication("lemon"); auditDto.setClient(getUserIp(authentication)); auditDto.setServer(InetAddress.getLocalHost().getHostAddress()); auditDto.setDescription(authenticationFailureLockedEvent.getException() .getMessage()); auditDto.setTenantId(tenantId); auditConnector.log(auditDto); ctx.publishEvent(new LoginEvent(authentication, userId, this .getSessionId(authentication), "locked", "default", tenantId)); }
/** * Set the application event class to publish. * <p>The event class <b>must</b> have a constructor with a single * {@code Object} argument for the event source. The interceptor * will pass in the invoked object. * @throws IllegalArgumentException if the supplied {@code Class} is * {@code null} or if it is not an {@code ApplicationEvent} subclass or * if it does not expose a constructor that takes a single {@code Object} argument */ public void setApplicationEventClass(Class<?> applicationEventClass) { if (ApplicationEvent.class.equals(applicationEventClass) || !ApplicationEvent.class.isAssignableFrom(applicationEventClass)) { throw new IllegalArgumentException("applicationEventClass needs to extend ApplicationEvent"); } try { this.applicationEventClassConstructor = applicationEventClass.getConstructor(new Class<?>[] {Object.class}); } catch (NoSuchMethodException ex) { throw new IllegalArgumentException("applicationEventClass [" + applicationEventClass.getName() + "] does not have the required Object constructor: " + ex); } }
protected void onBootstrap(ApplicationEvent event) { if (imapServerEnabled) { startup(); } else { if (logger.isDebugEnabled()) { logger.debug("IMAP service is disabled."); } } }
@Override protected void onBootstrap(ApplicationEvent event) { PropertyCheck.mandatory(this, "tenantAdminService", tenantAdminService); PropertyCheck.mandatory(this, "patchService", patchService); PropertyCheck.mandatory(this, "descriptorService", descriptorService); // TODO: Is it really necessary to count the tenants? if (tenantAdminService.getAllTenants().size() > 0) { tenantAdminService.startTenants(); } }
private void publishDiscoveryEvent() { if (this.config == null) { return; } final IndexEvent discoveryEvent = new IndexEvent(this, "Discovery", 1); final ConfigurableApplicationContext applicationContext = this.config.getApplicationContext(); try { applicationContext.publishEvent(discoveryEvent); } catch (IllegalStateException e) { // There's a possibility that the application context hasn't fully refreshed yet, so register a listener // that will fire when it has applicationContext.addApplicationListener(new ApplicationListener() { public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { applicationContext.publishEvent(discoveryEvent); } } }); } }
@Override protected void onBootstrap(ApplicationEvent event) { // Do logging here for side effect of initialising log object. if (log.isDebugEnabled()) { log.debug("Shutdown backstop onBootstrap"); } // Nothing to do here }
@Override protected void onBootstrap(ApplicationEvent event) { afterDictionaryInit(); // TODO revisit (for KS and/or 1.1) if (dictionaryDAO != null) { dictionaryDAO.registerListener(this); } else { logger.error("DictionaryDAO is null - hence CMIS Dictionary not registered for updates"); } }