
com.fizzgate.plugin.auth.ApiConfig2appsService Maven / Gradle / Ivy
/*
* Copyright (C) 2020 the original author or authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package com.fizzgate.plugin.auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.stereotype.Service;
import com.fizzgate.config.AggregateRedisConfig;
import com.fizzgate.util.Consts;
import com.fizzgate.util.JacksonUtils;
import com.fizzgate.util.ReactorUtils;
import com.fizzgate.util.ThreadContext;
import reactor.core.publisher.Mono;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.*;
/**
* @author hongqiaowei
*/
@Service
public class ApiConfig2appsService {
private static final Logger log = LoggerFactory.getLogger(ApiConfig2appsService.class);
private static final String fizzApiConfigAppSetSize = "fizz_api_config_app_set_size";
private static final String fizzApiConfigAppKeyPrefix = "fizz_api_config_app:";
private static final String fizzApiConfigAppChannel = "fizz_api_config_app_channel";
private Map > apiConfig2appsMap = new HashMap<>(128);
@Resource(name = AggregateRedisConfig.AGGREGATE_REACTIVE_REDIS_TEMPLATE)
private ReactiveStringRedisTemplate rt;
@PostConstruct
public void init() throws Throwable {
this.init(this::lsnChannel);
}
public void refreshLocalCache() throws Throwable {
this.init(null);
}
private void init(Runnable doAfterLoadCache) throws Throwable {
Map> apiConfig2appsMapTmp = new HashMap<>(128);
rt.opsForHash().entries(fizzApiConfigAppSetSize)
.collectList()
.map(
es -> {
log(es);
Mono initiateFlux = ReactorUtils.getInitiateMono();
for (Map.Entry
© 2015 - 2025 Weber Informatics LLC | Privacy Policy