public void onApplicationEvent(ApplicationEvent event) { try { threadPool.execute(new Worker(event)); } catch (InterruptedException e) { logger.error("Failed to process event: " + event.toString(), e); } }
@SuppressWarnings("deprecation") public void onApplicationEvent(ApplicationEvent event) { // 如果事件类型是ChatMessageEvent就执行下面操作 if (event instanceof ChatMessageEvent) { Message msg = (Message) event.getSource(); ServerContext context = ServerContextFactory.get(); // 获得客户端所有chat页面script session连接数 Collection<ScriptSession> sessions = context.getAllScriptSessions(); for (ScriptSession session : sessions) { ScriptBuffer sb = new ScriptBuffer(); Date time = msg.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); /*String s = time.getYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate() + " " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds();*/ // 执行setMessage方法 String s = sdf.format(time); sb.appendScript("index.showMessage({msg: '") .appendScript(msg.getMsg()) .appendScript("', time: '") .appendScript(s) .appendScript("'})"); // 执行客户端script session方法,相当于浏览器执行JavaScript代码 // 上面就会执行客户端浏览器中的showMessage方法,并且传递一个对象过去 session.addScript(sb); } } }
@Override public void onApplicationEvent(ApplicationEvent event) { System.out.println(event.getClass().getName()); if (event instanceof ContextRefreshedEvent) { subscribe(); } }
public void onApplicationEvent(ApplicationEvent event) { if (ContextRefreshedEvent.class.getName().equals(event.getClass().getName())) { if (isDelay() && !isExported() && !isUnexported()) { if (logger.isInfoEnabled()) { logger.info("The service ready on spring started. service: " + getInterface()); } export(); } } }
@Override protected void onBootstrap(ApplicationEvent event) { // Reset the dictionary (destroy and reload) dictionaryDAO.reset(); // Register listeners register(); // The listeners can now know about this ((ApplicationContext) event.getSource()) .publishEvent(new DictionaryRepositoryBootstrappedEvent(this)); }
/** * Handle an application event. * * @param event the event to respond to */ @Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof AuthenticationSuccessEvent) { Object source = event.getSource(); if (source instanceof UsernamePasswordAuthenticationToken) { UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) source; Object principal = token.getPrincipal(); if (principal instanceof OrcidProfileUserDetails) { OrcidProfileUserDetails userDetails = (OrcidProfileUserDetails) principal; String orcid = userDetails.getOrcid(); String email = userDetails.getPrimaryEmail(); String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId(); LOGGER.info( "User logged in with orcid={}, email={}, sessionid={}", new Object[] {orcid, email, sessionId}); } } } }
private ResolvableType getResolvableType(ApplicationEvent event) { ResolvableType payloadType = null; if (event instanceof PayloadApplicationEvent) { PayloadApplicationEvent<?> payloadEvent = (PayloadApplicationEvent<?>) event; payloadType = payloadEvent.getResolvableType().as(PayloadApplicationEvent.class).getGeneric(0); } for (ResolvableType declaredEventType : this.declaredEventTypes) { if (!ApplicationEvent.class.isAssignableFrom(declaredEventType.getRawClass()) && payloadType != null) { if (declaredEventType.isAssignableFrom(payloadType)) { return declaredEventType; } } if (declaredEventType.getRawClass().isAssignableFrom(event.getClass())) { return declaredEventType; } } return null; }
@Test @RedisAvailable @SuppressWarnings("unchecked") @Ignore // JedisConnectionFactory doesn't support proper 'destroy()' and allows to create new fresh Redis // connection public void testInt3196Recovery() throws Exception { String queueName = "test.si.Int3196Recovery"; QueueChannel channel = new QueueChannel(); final List<ApplicationEvent> exceptionEvents = new ArrayList<ApplicationEvent>(); final CountDownLatch exceptionsLatch = new CountDownLatch(2); RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName, this.connectionFactory); endpoint.setBeanFactory(Mockito.mock(BeanFactory.class)); endpoint.setApplicationEventPublisher( new ApplicationEventPublisher() { @Override public void publishEvent(ApplicationEvent event) { exceptionEvents.add(event); exceptionsLatch.countDown(); } }); endpoint.setOutputChannel(channel); endpoint.setReceiveTimeout(100); endpoint.setRecoveryInterval(200); endpoint.afterPropertiesSet(); endpoint.start(); int n = 0; do { n++; if (n == 100) { break; } Thread.sleep(100); } while (!endpoint.isListening()); assertTrue(n < 100); ((DisposableBean) this.connectionFactory).destroy(); assertTrue(exceptionsLatch.await(10, TimeUnit.SECONDS)); for (ApplicationEvent exceptionEvent : exceptionEvents) { assertThat(exceptionEvent, Matchers.instanceOf(RedisExceptionEvent.class)); assertSame(endpoint, exceptionEvent.getSource()); assertThat( ((IntegrationEvent) exceptionEvent).getCause().getClass(), Matchers.isIn( Arrays.<Class<? extends Throwable>>asList( RedisSystemException.class, RedisConnectionFailureException.class))); } ((InitializingBean) this.connectionFactory).afterPropertiesSet(); RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>(); redisTemplate.setConnectionFactory(this.getConnectionFactoryForTest()); redisTemplate.setEnableDefaultSerializer(false); redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer()); redisTemplate.afterPropertiesSet(); String payload = "testing"; redisTemplate.boundListOps(queueName).leftPush(payload); Message<?> receive = channel.receive(1000); assertNotNull(receive); assertEquals(payload, receive.getPayload()); endpoint.stop(); }
@Override public void onApplicationEvent(ApplicationEvent event) { System.out.println("Event Name: " + event.toString()); System.out.println("Event Source: " + event.getSource()); }
/** Handle events that influence the session/user context. */ public void onApplicationEvent(ApplicationEvent event) { if ((event instanceof LoginEvent) && (event.getSource() != LoginEvent.NO_AUTHENTICATION)) handleLoginEvent((LoginEvent) event); else if ((event instanceof LogoutEvent)) handleLogoutEvent((LogoutEvent) event); }
public void onApplicationEvent(ApplicationEvent event) { System.out.println(event.toString()); }