List of usage examples for org.springframework.context ApplicationContext publishEvent
default void publishEvent(ApplicationEvent event)
From source file:org.dspace.app.cris.batch.ScriptDeleteRP.java
/** * Batch script to delete a RP. See the technical documentation for further * details.//ww w . j ava2 s.co m */ public static void main(String[] args) { log.info("#### START DELETE: -----" + new Date() + " ----- ####"); Context dspaceContext = null; ApplicationContext context = null; try { dspaceContext = new Context(); dspaceContext.turnOffAuthorisationSystem(); DSpace dspace = new DSpace(); ApplicationService applicationService = dspace.getServiceManager() .getServiceByName("applicationService", ApplicationService.class); CommandLineParser parser = new PosixParser(); Options options = new Options(); options.addOption("h", "help", false, "help"); options.addOption("r", "researcher", true, "RP id to delete"); options.addOption("s", "silent", false, "no interactive mode"); CommandLine line = parser.parse(options, args); if (line.hasOption('h')) { HelpFormatter myhelp = new HelpFormatter(); myhelp.printHelp("ScriptHKURPDelete \n", options); System.out.println("\n\nUSAGE:\n ScriptHKURPDelete -r <id> \n"); System.out.println("Please note: add -s for no interactive mode"); System.exit(0); } Integer rpId = null; boolean delete = false; boolean silent = line.hasOption('s'); Item[] items = null; if (line.hasOption('r')) { rpId = ResearcherPageUtils.getRealPersistentIdentifier(line.getOptionValue("r"), ResearcherPage.class); ResearcherPage rp = applicationService.get(ResearcherPage.class, rpId); if (rp == null) { if (!silent) { System.out.println("RP not exist...exit"); } log.info("RP not exist...exit"); System.exit(0); } log.info("Use browse indexing"); BrowseIndex bi = BrowseIndex.getBrowseIndex(plugInBrowserIndex); // now start up a browse engine and get it to do the work for us BrowseEngine be = new BrowseEngine(dspaceContext); String authKey = ResearcherPageUtils.getPersistentIdentifier(rp); // set up a BrowseScope and start loading the values into it BrowserScope scope = new BrowserScope(dspaceContext); scope.setBrowseIndex(bi); // scope.setOrder(order); scope.setFilterValue(authKey); scope.setAuthorityValue(authKey); scope.setResultsPerPage(Integer.MAX_VALUE); scope.setBrowseLevel(1); BrowseInfo binfo = be.browse(scope); log.debug("Find " + binfo.getResultCount() + "item(s) for the reseracher " + authKey); items = binfo.getItemResults(dspaceContext); if (!silent && rp != null) { System.out.println(MESSAGE_ONE); // interactive mode System.out.println("Attempting to remove Researcher Page:"); System.out.println("StaffNo:" + rp.getSourceID()); System.out.println("FullName:" + rp.getFullName()); System.out .println("the researcher has " + items.length + " relation(s) with item(s) in the HUB"); System.out.println(); System.out.println(QUESTION_ONE); InputStreamReader isr = new InputStreamReader(System.in); BufferedReader reader = new BufferedReader(isr); String answer = reader.readLine(); if (answer.equals("yes")) { delete = true; } else { System.out.println("Exit without delete"); log.info("Exit without delete"); System.exit(0); } } else { delete = true; } } else { System.out.println("\n\nUSAGE:\n ScriptHKURPDelete <-v> -r <RPid> \n"); System.out.println("-r option is mandatory"); log.error("-r option is mandatory"); System.exit(1); } if (delete) { if (!silent) { System.out.println("Deleting..."); } log.info("Deleting..."); cleanAuthority(dspaceContext, items, rpId); applicationService.delete(ResearcherPage.class, rpId); dspaceContext.complete(); } if (!silent) { System.out.println("Ok...Bye"); } } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } finally { if (dspaceContext != null && dspaceContext.isValid()) { dspaceContext.abort(); } if (context != null) { context.publishEvent(new ContextClosedEvent(context)); } } log.info("#### END: -----" + new Date() + " ----- ####"); System.exit(0); }
From source file:com.newlandframework.rpc.spring.NettyRpcService.java
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; applicationContext.publishEvent(new ServerStartEvent(new Object())); }
From source file:it.geosolutions.geoserver.jms.impl.web.ClusterPage.java
private void addToggle(final String configKey, final ToggleType type, final String textFieldId, final String buttonId, final Form<?> form, final FeedbackPanel fp) { final TextField<String> toggleInfo = new TextField<String>(textFieldId); // https://issues.apache.org/jira/browse/WICKET-2426 toggleInfo.setType(String.class); toggleInfo.setOutputMarkupId(true);//from w w w . j av a 2 s. com toggleInfo.setOutputMarkupPlaceholderTag(true); toggleInfo.setEnabled(false); form.add(toggleInfo); final AjaxButton toggle = new AjaxButton(buttonId) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form<?> form) { fp.error("ERROR"); target.addComponent(fp); }; @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { final boolean switchTo = !Boolean.parseBoolean(toggleInfo.getModel().getObject()); final ApplicationContext ctx = getGeoServerApplication().getApplicationContext(); ctx.publishEvent(new ToggleEvent(switchTo, type)); // getConfig().putConfiguration(configKey, // Boolean.toString(switchTo)); if (switchTo) { fp.info("The " + type + " toggle is now ENABLED"); } else { fp.warn("The " + type + " toggle is now DISABLED no event will be posted/received to/from the broker"); fp.info("Note that the " + type + " is still registered to the topic destination"); } toggleInfo.getModel().setObject(Boolean.toString(switchTo)); target.addComponent(toggleInfo); target.addComponent(fp); } }; toggle.setRenderBodyOnly(false); form.add(toggle); // add(new Monitor(Duration.seconds(10))); }
From source file:org.alfresco.util.exec.RuntimeExecBeansTest.java
public void testBootstrapAndShutdown() throws Exception { // now bring up the bootstrap ApplicationContext ctx = new ClassPathXmlApplicationContext(APP_CONTEXT_XML); // the folder should be gone assertFalse("Folder was not deleted by bootstrap", dir.exists()); // now create the folder again dir.mkdir();//from w w w . jav a2 s . c o m assertTrue("Directory not created", dir.exists()); // announce that the context is closing ctx.publishEvent(new ContextClosedEvent(ctx)); // the folder should be gone assertFalse("Folder was not deleted by shutdown", dir.exists()); }
From source file:com.hazelcast.web.spring.SpringAwareWebFilter.java
@Override protected void destroySession(HazelcastHttpSession session, boolean invalidate) { super.destroySession(session, invalidate); if (invalidate) { ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); if (appContext != null) { ensureSessionRegistryInitialized(appContext); if (sessionRegistry != null) { String originalSessionId = session.getOriginalSessionId(); // If original session id is registered already, we don't need it. // So, we should remove it also. sessionRegistry.removeSessionInformation(originalSessionId); /**//from w w w. j a v a2 s. c om * Publish an event to notify * {@link org.springframework.security.core.session.SessionRegistry} instance. * So Spring clears information about our Hazelcast session. */ appContext.publishEvent(new HttpSessionDestroyedEvent(session)); LOGGER.finest( "Published destroy session event for Spring for session with id " + session.getId()); } } } }
From source file:com.hazelcast.web.spring.SpringAwareWebFilter.java
@Override protected HazelcastHttpSession createNewSession(HazelcastRequestWrapper requestWrapper, String existingSessionId) { HazelcastHttpSession session = super.createNewSession(requestWrapper, existingSessionId); ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); if (appContext != null) { ensureSessionRegistryInitialized(appContext); if (sessionRegistry != null) { String originalSessionId = session.getOriginalSessionId(); // If original session id is registered already, we don't need it. // So, we should remove it. sessionRegistry.removeSessionInformation(originalSessionId); // Publish event if this session is not registered if (!isSessionRegistered(session.getId())) { /**//from ww w. j av a 2s .c o m * Publish an event to notify * {@link org.springframework.security.core.session.SessionRegistry} instance. * So Spring knows our Hazelcast session. * * If session is already exist * ( * possibly added by * {@link org.springframework.security.web.session.HttpSessionEventPublisher} instance * which is defined in {@code web.xml} before * {@link com.hazelcast.web.SessionListener} to * {@link org.springframework.security.core.session.SessionRegistry} * ), * it will be just updated. */ appContext.publishEvent(new HttpSessionCreatedEvent(session)); LOGGER.finest( "Published create session event for Spring for session with id " + session.getId()); } } } return session; }
From source file:grails.core.DefaultGrailsApplication.java
protected GrailsClass addArtefact(String artefactType, Class<?> artefactClass, boolean overrideable) { ArtefactHandler handler = artefactHandlersByName.get(artefactType); if (handler != null && handler.isArtefact(artefactClass)) { GrailsClass artefactGrailsClass = handler.newArtefactClass(artefactClass); artefactGrailsClass.setGrailsApplication(this); // Store the GrailsClass in cache DefaultArtefactInfo info = getArtefactInfo(artefactType, true); if (overrideable) { info.addOverridableGrailsClass(artefactGrailsClass); } else {/*from w ww . ja v a 2 s. c o m*/ info.addGrailsClass(artefactGrailsClass); } info.updateComplete(); addToLoaded(artefactClass); if (isInitialised()) { initializeArtefacts(artefactType); ApplicationContext context = getMainContext(); if (context instanceof ConfigurableApplicationContext && contextInitialized && ((ConfigurableApplicationContext) context).isActive()) { context.publishEvent(new ArtefactAdditionEvent(artefactGrailsClass)); } } return artefactGrailsClass; } throw new GrailsConfigurationException( "Cannot add " + artefactType + " class [" + artefactClass + "]. It is not a " + artefactType + "!"); }
From source file:org.alfresco.repo.content.filestore.FileContentStore.java
/** * Publishes an event to the application context that will notify any interested parties of the existence of this * content store./* ww w. j a v a2 s.co m*/ * * @param context * the application context * @param extendedEventParams */ private void publishEvent(ApplicationContext context, Map<String, Serializable> extendedEventParams) { context.publishEvent(new ContentStoreCreatedEvent(this, extendedEventParams)); }
From source file:org.craftercms.engine.service.context.SiteContextManager.java
protected void publishEvent(ApplicationEvent event, SiteContext siteContext) { ApplicationContext siteApplicationContext = siteContext.getApplicationContext(); if (siteApplicationContext != null) { siteApplicationContext.publishEvent(event); } else {//from w ww .j a v a 2 s . co m applicationContext.publishEvent(event); } }
From source file:org.springframework.cloud.bootstrap.encrypt.EnvironmentDecryptApplicationInitializer.java
@Override public void initialize(ConfigurableApplicationContext applicationContext) { ConfigurableEnvironment environment = applicationContext.getEnvironment(); MapPropertySource decrypted = new MapPropertySource(DECRYPTED_PROPERTY_SOURCE_NAME, decrypt(environment.getPropertySources())); if (!decrypted.getSource().isEmpty()) { // We have some decrypted properties insert(environment.getPropertySources(), decrypted); ApplicationContext parent = applicationContext.getParent(); if (parent != null && (parent.getEnvironment() instanceof ConfigurableEnvironment)) { ConfigurableEnvironment mutable = (ConfigurableEnvironment) parent.getEnvironment(); // The parent is actually the bootstrap context, and it is fully // initialized, so we can fire an EnvironmentChangeEvent there to rebind // @ConfigurationProperties, in case they were encrypted. insert(mutable.getPropertySources(), decrypted); parent.publishEvent(new EnvironmentChangeEvent(decrypted.getSource().keySet())); }/* w ww .j ava 2s. com*/ } }