Merge branch 'master' into 5.6-global
# Conflicts: # service/src/main/java/com/yoho/search/consumer/service/logic/tools/ForbiddenPageIdsLogicService.java
Showing
1 changed file
with
18 additions
and
15 deletions
service/src/main/java/com/yoho/search/consumer/service/logic/tools/ForbiddenPageIdsLogicService.java
@@ -21,20 +21,20 @@ import com.yoho.search.core.personalized.BigDataRedisOper; | @@ -21,20 +21,20 @@ import com.yoho.search.core.personalized.BigDataRedisOper; | ||
21 | public class ForbiddenPageIdsLogicService { | 21 | public class ForbiddenPageIdsLogicService { |
22 | 22 | ||
23 | private static final Logger logger = LoggerFactory.getLogger(ForbiddenPageIdsLogicService.class); | 23 | private static final Logger logger = LoggerFactory.getLogger(ForbiddenPageIdsLogicService.class); |
24 | - | ||
25 | private final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER"); | 24 | private final Logger INDEX_REBUILD_LOG = LoggerFactory.getLogger("INDEX_REBULDER"); |
26 | - | ||
27 | @Autowired | 25 | @Autowired |
28 | private BigDataRedisOper<String, String> bigDataRedisOper; | 26 | private BigDataRedisOper<String, String> bigDataRedisOper; |
29 | - | ||
30 | private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s"; | 27 | private static final String key = "SEARCH_FORBIDDEN_SKNLIST_%s"; |
31 | 28 | ||
32 | private Map<String, List<String>> sknForbiddenPageIdsMap = null; | 29 | private Map<String, List<String>> sknForbiddenPageIdsMap = null; |
33 | private Map<String, Integer> pageForbiddenSknCountMap = null; | 30 | private Map<String, Integer> pageForbiddenSknCountMap = null; |
34 | 31 | ||
32 | + private volatile boolean isReloading = false; | ||
33 | + | ||
35 | public synchronized void reloadForbiddenPageIds() { | 34 | public synchronized void reloadForbiddenPageIds() { |
36 | try { | 35 | try { |
37 | INDEX_REBUILD_LOG.info("do reloadForbiddenPageIds ........."); | 36 | INDEX_REBUILD_LOG.info("do reloadForbiddenPageIds ........."); |
37 | + isReloading = true; | ||
38 | List<String> allPageIds = SearchPageIdDefine.getAllPgeIds(); | 38 | List<String> allPageIds = SearchPageIdDefine.getAllPgeIds(); |
39 | Map<String, List<String>> sknForbiddenPageIdsMap_temp = new HashMap<String, List<String>>(); | 39 | Map<String, List<String>> sknForbiddenPageIdsMap_temp = new HashMap<String, List<String>>(); |
40 | Map<String, Integer> pageForbiddenSknCountMap_temp = new HashMap<String, Integer>(); | 40 | Map<String, Integer> pageForbiddenSknCountMap_temp = new HashMap<String, Integer>(); |
@@ -54,6 +54,8 @@ public class ForbiddenPageIdsLogicService { | @@ -54,6 +54,8 @@ public class ForbiddenPageIdsLogicService { | ||
54 | pageForbiddenSknCountMap = pageForbiddenSknCountMap_temp; | 54 | pageForbiddenSknCountMap = pageForbiddenSknCountMap_temp; |
55 | } catch (Exception e) { | 55 | } catch (Exception e) { |
56 | INDEX_REBUILD_LOG.error(e.getMessage(), e); | 56 | INDEX_REBUILD_LOG.error(e.getMessage(), e); |
57 | + } finally { | ||
58 | + isReloading = false; | ||
57 | } | 59 | } |
58 | } | 60 | } |
59 | 61 | ||
@@ -69,29 +71,30 @@ public class ForbiddenPageIdsLogicService { | @@ -69,29 +71,30 @@ public class ForbiddenPageIdsLogicService { | ||
69 | } | 71 | } |
70 | } | 72 | } |
71 | 73 | ||
72 | - private boolean isNeedReload() { | ||
73 | - if (sknForbiddenPageIdsMap == null) { | ||
74 | - return true; | 74 | + public Map<String, Integer> getPageForbiddenSknCountMap() { |
75 | + if (sknForbiddenPageIdsMap == null || sknForbiddenPageIdsMap.isEmpty()) { | ||
76 | + reloadForbiddenPageIds(); | ||
75 | } | 77 | } |
76 | - return false; | 78 | + return this.pageForbiddenSknCountMap; |
77 | } | 79 | } |
78 | 80 | ||
79 | private void checkAndInit() { | 81 | private void checkAndInit() { |
80 | - if (!isNeedReload()) { | 82 | + while (isReloading) { |
83 | + try { | ||
84 | + Thread.sleep(1000); | ||
85 | + } catch (Exception e) { | ||
86 | + } | ||
87 | + } | ||
88 | + if (sknForbiddenPageIdsMap != null) { | ||
81 | return; | 89 | return; |
82 | } | 90 | } |
83 | synchronized (ForbiddenPageIdsLogicService.class) { | 91 | synchronized (ForbiddenPageIdsLogicService.class) { |
84 | - if (isNeedReload()) { | 92 | + if (sknForbiddenPageIdsMap == null) { |
85 | reloadForbiddenPageIds(); | 93 | reloadForbiddenPageIds(); |
86 | } | 94 | } |
87 | } | 95 | } |
88 | } | 96 | } |
89 | - | ||
90 | - public Map<String, Integer> getPageForbiddenSknCountMap() { | ||
91 | - checkAndInit(); | ||
92 | - return this.pageForbiddenSknCountMap; | ||
93 | - } | ||
94 | - | 97 | + |
95 | public String getSknForbiddenPageIds(String productSkn) { | 98 | public String getSknForbiddenPageIds(String productSkn) { |
96 | checkAndInit(); | 99 | checkAndInit(); |
97 | if (StringUtils.isBlank(productSkn)) { | 100 | if (StringUtils.isBlank(productSkn)) { |
-
Please register or login to post a comment