io.micronaut.core.order.OrderUtil Java Examples

The following examples show how to use io.micronaut.core.order.OrderUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionSynchronizationManager.java    From micronaut-data with Apache License 2.0 6 votes vote down vote up
/**
 * Return an unmodifiable snapshot list of all registered synchronizations
 * for the current thread.
 * @return unmodifiable List of TransactionSynchronization instances
 * @throws IllegalStateException if synchronization is not active
 * @see TransactionSynchronization
 */
public static List<TransactionSynchronization> getSynchronizations() throws IllegalStateException {
    Set<TransactionSynchronization> synchs = SYNCHRONIZATIONS.get();
    if (synchs == null) {
        throw new IllegalStateException("Transaction synchronization is not active");
    }
    // Return unmodifiable snapshot, to avoid ConcurrentModificationExceptions
    // while iterating and invoking synchronization callbacks that in turn
    // might register further synchronizations.
    if (synchs.isEmpty()) {
        return Collections.emptyList();
    } else {
        // Sort lazily here, not in registerSynchronization.
        List<TransactionSynchronization> sortedSynchs = new ArrayList<>(synchs);
        OrderUtil.sort(sortedSynchs);
        return Collections.unmodifiableList(sortedSynchs);
    }
}
 
Example #2
Source File: AlexaFunction.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor.
 */
public AlexaFunction() {
    buildApplicationContext();
    applicationContext.inject(this);
    this.skillStreamHandler = new MicronautSkillStreamHandler(
            applicationContext.getBeansOfType(AlexaSkill.class)
                    .stream()
                    .sorted(OrderUtil.COMPARATOR)
                    .toArray(AlexaSkill[]::new));
}
 
Example #3
Source File: DefaultAlexaSkillBuilder.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
 public AlexaSkill<RequestEnvelope, ResponseEnvelope> buildSkill(@Nonnull @NotNull SkillBuilder<?> skillBuilder,
                                                                 @Nullable AlexaSkillConfiguration alexaSkillConfiguration) {

    SkillBeans skillBeans = alexaSkillConfiguration == null ? unqualifiedSkillBeans : this.skillBeans.get(alexaSkillConfiguration.getName());
    skillBeans.getRequestHandlers()
            .stream()
            .sorted(OrderUtil.COMPARATOR)
            .forEach(skillBuilder::addRequestHandler);

    skillBeans.getExceptionHandlers()
            .stream()
            .sorted(OrderUtil.COMPARATOR)
            .forEach(skillBuilder::addExceptionHandler);

    skillBeans.getRequestInterceptors()
            .stream()
            .sorted(OrderUtil.COMPARATOR)
            .forEach(skillBuilder::addRequestInterceptor);

    skillBeans.getResponseInterceptors()
            .stream()
            .sorted(OrderUtil.COMPARATOR)
            .forEach(skillBuilder::addResponseInterceptor);

    if (alexaSkillConfiguration != null) {
        skillBuilder = skillBuilder.withSkillId(alexaSkillConfiguration.getSkillId());
    }
    return skillBuilder.build();
}
 
Example #4
Source File: CompositeSerdeRegistry.java    From micronaut-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * The default constructor.
 *
 * @param registries The other registries
 */
public CompositeSerdeRegistry(SerdeRegistry... registries) {
    this.registries = new ArrayList<>(
            registries != null ? Arrays.asList(registries) : Collections.emptyList()
    );

    OrderUtil.sort(registries);
}
 
Example #5
Source File: RepositoryTypeElementVisitor.java    From micronaut-data with Apache License 2.0 5 votes vote down vote up
private List<MethodCandidate> initializeMethodCandidates(VisitorContext context) {
    List<MethodCandidate> finderList = Arrays.asList(
            new FindByFinder(),
            new ExistsByFinder(),
            new SaveEntityMethod(),
            new SaveOneMethod(),
            new SaveAllMethod(),
            new ListMethod(),
            new CountMethod(),
            new DeleteByMethod(),
            new DeleteMethod(),
            new CountByMethod(),
            new UpdateMethod(),
            new UpdateEntityMethod(),
            new UpdateByMethod(),
            new ListSliceMethod(),
            new FindSliceByMethod(),
            new ListSliceMethod(),
            new FindPageByMethod(),
            new ListPageMethod(),
            new FindOneMethod(),
            new FindByIdsMethod(),
            new FindOneSpecificationMethod(),
            new CountSpecificationMethod(),
            new FindAllSpecificationMethod(),
            new FindPageSpecificationMethod()
    );
    SoftServiceLoader<MethodCandidate> otherCandidates = SoftServiceLoader.load(MethodCandidate.class);
    for (ServiceDefinition<MethodCandidate> definition : otherCandidates) {
        if (definition.isPresent()) {
            try {
                finderList.add(definition.load());
            } catch (Exception e) {
                context.warn("Could not load Data method candidate [" + definition.getName() + "]: " + e.getMessage(), null);
            }
        }
    }
    OrderUtil.sort(finderList);
    return finderList;
}
 
Example #6
Source File: DefaultRequestEnvelopeService.java    From micronaut-aws with Apache License 2.0 2 votes vote down vote up
/**
 *
 * @param skills List of available Skills
 */
public DefaultRequestEnvelopeService(List<Skill> skills) {
    this.skills = skills.stream().sorted(OrderUtil.COMPARATOR).collect(Collectors.toList());
}