Package org.springframework.context

Examples of org.springframework.context.ApplicationListener


  }


  public void multicastEvent(final ApplicationEvent event) {
    for (Iterator it = getApplicationListeners().iterator(); it.hasNext();) {
      final ApplicationListener listener = (ApplicationListener) it.next();
      getTaskExecutor().execute(new Runnable() {
        public void run() {
          listener.onApplicationEvent(event);
        }
      });
    }
  }
View Full Code Here


    assertEquals(0, mc.getApplicationListeners().size());
  }

  public void testMulticasterRemoveOne() {
    AbstractApplicationEventMulticaster mc = getMulticaster();
    ApplicationListener one = new NoOpApplicationListener();
    ApplicationListener two = new NoOpApplicationListener();
    mc.addApplicationListener(one);
    mc.addApplicationListener(two);

    mc.removeApplicationListener(one);
View Full Code Here

    assertTrue("Remaining listener present", mc.getApplicationListeners().contains(two));
  }

  public void testSimpleApplicationEventMulticaster() {
    MockControl ctrl = MockControl.createControl(ApplicationListener.class);
    ApplicationListener listener = (ApplicationListener) ctrl.getMock();

    ApplicationEvent evt = new ContextClosedEvent(new StaticApplicationContext());
    listener.onApplicationEvent(evt);
    ctrl.setMatcher(new EqualsMatcher());

    SimpleApplicationEventMulticaster smc = new SimpleApplicationEventMulticaster();
    smc.addApplicationListener(listener);
View Full Code Here

    // Trigger lazy initialization.
    pfb.getObject();
    // 2 globals + 2 explicit
    assertEquals("Have 2 globals and 2 explicit advisors", 3, pfb.getAdvisors().length);
   
    ApplicationListener l = (ApplicationListener) factory.getBean("validGlobals");
    agi = (AddedGlobalInterface) l;
    assertTrue(agi.globalsAdded() == -1);
   
    try {
      agi = (AddedGlobalInterface) factory.getBean("test1");
View Full Code Here

    }
   
    /** {@inheritDoc}*/
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx = (AbstractApplicationContext)applicationContext;
        @SuppressWarnings("rawtypes")
        ApplicationListener listener = new ApplicationListener() {
            public void onApplicationEvent(ApplicationEvent event) {
                SpringBus.this.onApplicationEvent(event);
            }
        };
        ctx.addApplicationListener(listener);
View Full Code Here

    }
   
    /** {@inheritDoc}*/
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx = (AbstractApplicationContext)applicationContext;
        @SuppressWarnings("rawtypes")
        ApplicationListener listener = new ApplicationListener() {
            public void onApplicationEvent(ApplicationEvent event) {
                SpringBus.this.onApplicationEvent(event);
            }
        };
        ctx.addApplicationListener(listener);
View Full Code Here

    }
   
    /** {@inheritDoc}*/
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx = (AbstractApplicationContext)applicationContext;
        @SuppressWarnings("rawtypes")
        ApplicationListener listener = new ApplicationListener() {
            public void onApplicationEvent(ApplicationEvent event) {
                SpringBus.this.onApplicationEvent(event);
            }
        };
        ctx.addApplicationListener(listener);
View Full Code Here

    }
   
    /** {@inheritDoc}*/
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx = (AbstractApplicationContext)applicationContext;
        @SuppressWarnings("rawtypes")
        ApplicationListener listener = new ApplicationListener() {
            public void onApplicationEvent(ApplicationEvent event) {
                SpringBus.this.onApplicationEvent(event);
            }
        };
        ctx.addApplicationListener(listener);
View Full Code Here

    @Override
    public void removeApplicationListener(ApplicationListener listener)
    {
        for (Iterator iterator = listeners.iterator(); iterator.hasNext();)
        {
            ApplicationListener applicationListener = (ApplicationListener) iterator.next();
            if (applicationListener instanceof AsynchronousEventListener)
            {
                if (((AsynchronousEventListener) applicationListener).getListener().equals(listener))
                {
                    listeners.remove(applicationListener);
                    return;
                }
            }
            else
            {
                if (applicationListener.equals(listener))
                {
                    listeners.remove(applicationListener);
                    return;
                }
            }
View Full Code Here

            }
        }

        for (Iterator iterator = listeners.iterator(); iterator.hasNext();)
        {
            ApplicationListener listener = (ApplicationListener) iterator.next();
            if (muleEvent != null)
            {
                // As the asynchronous listener wraps the real listener we need
                // to check the type of the wrapped listener, but invoke the Async
                // listener
                if (listener instanceof AsynchronousEventListener)
                {
                    AsynchronousEventListener asyncListener = (AsynchronousEventListener) listener;
                    if (asyncListener.getListener() instanceof MuleSubscriptionEventListener)
                    {
                        if (isSubscriptionMatch(muleEvent.getEndpoint(),
                            ((MuleSubscriptionEventListener) asyncListener.getListener()).getSubscriptions()))
                        {
                            asyncListener.onApplicationEvent(muleEvent);
                        }
                    }
                    else if (asyncListener.getListener() instanceof MuleEventListener)
                    {
                        asyncListener.onApplicationEvent(muleEvent);
                    }
                    else if (!(asyncListener.getListener() instanceof MuleEventListener))
                    {
                        asyncListener.onApplicationEvent(e);
                    }
                    // Synchronous MuleEvent listener Checks
                }
                else if (listener instanceof MuleSubscriptionEventListener)
                {
                    if (isSubscriptionMatch(muleEvent.getEndpoint(),
                        ((MuleSubscriptionEventListener) listener).getSubscriptions()))
                    {
                        listener.onApplicationEvent(muleEvent);
                    }
                }
                else if (listener instanceof MuleEventListener)
                {
                    listener.onApplicationEvent(muleEvent);
                }
            }
            else if (listener instanceof AsynchronousEventListener
                     && !(((AsynchronousEventListener) listener).getListener() instanceof MuleEventListener))
            {
                listener.onApplicationEvent(e);
            }
            else if (!(listener instanceof MuleEventListener))
            {
                listener.onApplicationEvent(e);
            }
            else
            {
                // Finally only propagate the Application event if the
                // ApplicationEvent interface is explicitly implemented
                for (int i = 0; i < listener.getClass().getInterfaces().length; i++)
                {
                    if (listener.getClass().getInterfaces()[i].equals(ApplicationListener.class))
                    {
                        listener.onApplicationEvent(e);
                        break;
                    }
                }

            }
View Full Code Here

TOP

Related Classes of org.springframework.context.ApplicationListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.