Search in sources :

Example 16 with Ordered

use of org.springframework.core.Ordered in project BroadleafCommerce by BroadleafCommerce.

the class SortedListFactoryBean method createInstance.

@Override
protected List createInstance() {
    List response = super.createInstance();
    Collections.sort(response, new Comparator<Ordered>() {

        @Override
        public int compare(Ordered o1, Ordered o2) {
            return new Integer(o1.getOrder()).compareTo(o2.getOrder());
        }
    });
    return response;
}
Also used : Ordered(org.springframework.core.Ordered) List(java.util.List)

Example 17 with Ordered

use of org.springframework.core.Ordered in project grails-core by grails.

the class DefaultGrailsCodecClass method initializeCodec.

private void initializeCodec() {
    if (initialized)
        return;
    initialized = true;
    Integer orderSetting = getStaticPropertyValue("order", Integer.class);
    if (orderSetting != null) {
        order = orderSetting;
    }
    Object instance = getReferenceInstance();
    if (Encoder.class.isAssignableFrom(getClazz())) {
        encoder = (Encoder) instance;
        encoder = (Encoder) autowireCodecBean(encoder);
        if (encoder instanceof Ordered) {
            order = ((Ordered) encoder).getOrder();
        }
    }
    if (Decoder.class.isAssignableFrom(getClazz())) {
        decoder = (Decoder) instance;
        decoder = (Decoder) autowireCodecBean(decoder);
        if (decoder instanceof Ordered) {
            order = ((Ordered) decoder).getOrder();
        }
    }
    if (encoder == null && decoder == null) {
        CodecFactory codecFactory = null;
        if (CodecFactory.class.isAssignableFrom(getClazz())) {
            codecFactory = (CodecFactory) instance;
            codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
        }
        if (codecFactory == null) {
            codecFactory = getStaticPropertyValue("codecFactory", CodecFactory.class);
            codecFactory = (CodecFactory) autowireCodecBean(codecFactory);
        }
        if (codecFactory == null) {
            codecFactory = new ClosureCodecFactory(instance);
        }
        encoder = codecFactory.getEncoder();
        decoder = codecFactory.getDecoder();
        if (codecFactory instanceof Ordered) {
            order = ((Ordered) codecFactory).getOrder();
        }
    }
    if (encoder != null) {
        if (encoder instanceof StreamingEncoder) {
            encoder = new StreamingStateAwareEncoderWrapper((StreamingEncoder) encoder);
        } else {
            encoder = new StateAwareEncoderWrapper(encoder);
        }
    }
}
Also used : Ordered(org.springframework.core.Ordered) CodecFactory(org.grails.encoder.CodecFactory) StreamingEncoder(org.grails.encoder.StreamingEncoder)

Example 18 with Ordered

use of org.springframework.core.Ordered in project pentaho-platform by pentaho.

the class OrderedApplicationEventMulticaster method multicastEvent.

@SuppressWarnings("unchecked")
@Override
public void multicastEvent(final ApplicationEvent event) {
    List<ApplicationListener> listeners = new ArrayList<ApplicationListener>(getApplicationListeners());
    // sort listeners
    Collections.sort(listeners, new Comparator<ApplicationListener>() {

        public int compare(final ApplicationListener o1, final ApplicationListener o2) {
            if (o1 instanceof Ordered && o2 instanceof Ordered) {
                return new Integer(((Ordered) o1).getOrder()).compareTo(new Integer(((Ordered) o2).getOrder()));
            } else if (o1 instanceof Ordered) {
                return -1;
            } else if (o2 instanceof Ordered) {
                return 1;
            } else {
                return 0;
            }
        }
    });
    // iterate over sorted listeners
    for (final ApplicationListener listener : listeners) {
        getTaskExecutor().execute(new Runnable() {

            public void run() {
                listener.onApplicationEvent(event);
            }
        });
    }
}
Also used : ApplicationListener(org.springframework.context.ApplicationListener) ArrayList(java.util.ArrayList) Ordered(org.springframework.core.Ordered)

Aggregations

Ordered (org.springframework.core.Ordered)18 Test (org.junit.jupiter.api.Test)7 InOrder (org.mockito.InOrder)5 ServletContext (jakarta.servlet.ServletContext)4 Servlet (jakarta.servlet.Servlet)3 ArrayList (java.util.ArrayList)3 MockServletWebServerFactory (org.springframework.boot.web.servlet.server.MockServletWebServerFactory)3 OrderedGatewayFilter (org.springframework.cloud.gateway.filter.OrderedGatewayFilter)2 ApplicationListener (org.springframework.context.ApplicationListener)2 PriorityOrdered (org.springframework.core.PriorityOrdered)2 Filter (jakarta.servlet.Filter)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Set (java.util.Set)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 Supplier (java.util.function.Supplier)1 CodecFactory (org.grails.encoder.CodecFactory)1 StreamingEncoder (org.grails.encoder.StreamingEncoder)1