Example usage for com.google.common.collect ImmutableSet equals

List of usage examples for com.google.common.collect ImmutableSet equals

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet equals.

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:com.ikanow.aleph2.analytics.services.AnalyticsContext.java

/** Returns a config object containing:
 *  - set up for any of the services described
 *  - all the rest of the configuration/*from w  w  w  .  j av  a2s .  c  o m*/
 *  - the bucket bean ID
 *  SIDE EFFECT - SETS UP THE SERVICES SET 
 * @param services
 * @return
 */
protected Config setupServices(final Optional<DataBucketBean> maybe_bucket,
        final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) {
    // 
    // - set up for any of the services described
    // - all the rest of the configuration
    // - the bucket bean ID

    final Config full_config = ModuleUtils.getStaticConfig()
            .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME)
            .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service)
    ;

    final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = ImmutableSet
            .<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder()
            .addAll(services.orElse(Collections.emptySet()))
            .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty()))
            .add(Tuples._2T(IManagementDbService.class, Optional.empty()))
            .add(Tuples._2T(ISearchIndexService.class, Optional.empty())) //(need this because logging doesn't correctly report its service set, should fix at some point)
            .add(Tuples._2T(IStorageService.class, Optional.empty()))
            .add(Tuples._2T(ISecurityService.class, Optional.empty()))
            .add(Tuples._2T(ILoggingService.class, Optional.empty()))
            .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB))
            .addAll(_mutable_state.extra_auto_context_libs)
            .addAll(maybe_bucket
                    .map(bucket -> DataServiceUtils.listUnderlyingServiceProviders(bucket.data_schema()))
                    .orElse(Collections.emptyList()))
            .build();

    if (_mutable_state.service_manifest_override.isSet()) {
        if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) {
            throw new RuntimeException(ErrorUtils.SERVICE_RESTRICTIONS);
        }
    } else {
        _mutable_state.service_manifest_override.set(complete_services_set);
    }
    return full_config;
}

From source file:com.ikanow.aleph2.data_import.services.HarvestContext.java

@Override
public String getHarvestContextSignature(final Optional<DataBucketBean> bucket,
        final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) {
    if (_state_name == State.IN_TECHNOLOGY) {
        // Returns a config object containing:
        // - set up for any of the services described
        // - all the rest of the configuration
        // - the bucket bean ID

        final Config full_config = ModuleUtils.getStaticConfig()
                .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME)
                .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service)
        ;//w  w  w  . j  a  v  a 2 s .  com

        final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service");

        final Optional<DataBucketBean> maybe_bucket = bucket.map(Optional::of)
                .orElseGet(() -> _mutable_state.bucket.optional());

        final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = Optional
                .of(ImmutableSet.<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder()
                        .addAll(services.orElse(Collections.emptySet()))
                        .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty()))
                        .add(Tuples._2T(IManagementDbService.class, Optional.empty()))
                        .add(Tuples._2T(IStorageService.class, Optional.empty()))
                        .add(Tuples._2T(ISecurityService.class, Optional.empty()))
                        .add(Tuples._2T(ILoggingService.class, Optional.empty())) //doesn't pull in ES via getUnderlyingArtefacts, relies on the one here
                        .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)))
                // Optional services:
                //TODO (ALEPH-19): 1) should port this across to the more comprehensive/centralized CSL, 2) Do I need a "support direct output" flag, and not do this if not set?
                // seems like a waste to stick these JARs on the classpath when the Harvester is normally only writing to real-time/file-based queue?
                // (see AnalyticsContext/DataServiceUtils for more details on point #1)
                .map(sb -> (maybe_bucket.map(b -> hasSearchIndexOutput(b)).orElse(false))
                        ? sb.add(Tuples._2T(ISearchIndexService.class, Optional.empty()))
                                .add(Tuples._2T(ITemporalService.class, Optional.empty())).add(
                                        Tuples._2T(IColumnarService.class, Optional.empty()))
                        : sb)
                .map(sb -> (maybe_bucket.map(b -> hasDocumentOutput(b)).orElse(false))
                        ? sb.add(Tuples._2T(IDocumentService.class, Optional.empty()))
                        : sb)
                .map(sb -> sb.build()).get();

        final Config config_no_services = full_config.withoutPath("service");

        if (_mutable_state.service_manifest_override.isSet()) {
            if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) {
                throw new RuntimeException(ErrorUtils.SERVICE_RESTRICTIONS);
            }
        } else {
            _mutable_state.service_manifest_override.set(complete_services_set);
        }

        // Ugh need to add: core deps, core + underlying management db to this list

        final Config service_defn_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW
                .map(clazz_name -> {
                    final String config_path = clazz_name._2()
                            .orElse(clazz_name._1().getSimpleName().substring(1));
                    return Lambdas
                            .wrap_u(__ -> service_config.get().hasPath(config_path)
                                    ? Tuples._2T(config_path, service_config.get().getConfig(config_path))
                                    : null)
                            //(could add extra transforms here if we wanted)
                            .apply(Unit.unit());
                }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(),
                        (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        // Service configuration:
        final Config service_cfgn_subset = _mutable_state.service_manifest_override.get().stream() // DON'T MAKE PARALLEL SEE BELOW
                .reduce(config_no_services, // (leave other configurations, we just transform service specific configuration)
                        (acc, clazz_name) -> {
                            final Optional<? extends IUnderlyingService> underlying_service = _service_context
                                    .getService(clazz_name._1(), clazz_name._2());
                            return underlying_service.map(ds -> ds.createRemoteConfig(bucket, acc)).orElse(acc);
                        }, (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        final Config config_subset_services = service_cfgn_subset.withValue("service",
                service_defn_subset.root());

        final Config last_call = Lambdas
                .get(() -> _mutable_state.library_configs.isSet()
                        ? config_subset_services
                                .withValue(__MY_MODULE_LIBRARY_ID,
                                        ConfigValueFactory
                                                .fromAnyRef(BeanTemplateUtils
                                                        .toJson(new LibraryContainerBean(
                                                                _mutable_state.library_configs.get().entrySet()
                                                                        .stream()
                                                                        .filter(kv -> kv.getValue().path_name()
                                                                                .equals(kv.getKey()))
                                                                        .map(kv -> kv.getValue())
                                                                        .collect(Collectors.toList())))
                                                        .toString()))
                        : config_subset_services)
                .withValue(__MY_BUCKET_ID,
                        ConfigValueFactory.fromAnyRef(
                                maybe_bucket.map(b -> BeanTemplateUtils.toJson(b).toString()).orElse("{}")))
                .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef(_mutable_state.technology_config
                        .optional().map(l -> BeanTemplateUtils.toJson(l).toString()).orElse("{}")));

        return this.getClass().getName() + ":" + last_call.root().render(ConfigRenderOptions.concise());
    } else {
        throw new RuntimeException(ErrorUtils.TECHNOLOGY_NOT_MODULE);
    }
}