1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.es.config.exbhv;
17
18 import java.util.regex.Pattern;
19
20 import org.apache.commons.lang3.RandomUtils;
21 import org.codelibs.fess.es.config.bsbhv.BsScheduledJobBhv;
22 import org.codelibs.fess.es.config.exentity.ScheduledJob;
23 import org.codelibs.fess.util.ComponentUtil;
24 import org.dbflute.optional.OptionalEntity;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28
29
30
31 public class ScheduledJobBhv extends BsScheduledJobBhv {
32
33 private static final Logger logger = LoggerFactory.getLogger(ScheduledJobBhv.class);
34
35 private String indexName = null;
36
37 @Override
38 protected String asEsIndex() {
39 if (indexName == null) {
40 final String name = ComponentUtil.getFessConfig().getIndexConfigIndex();
41 indexName = super.asEsIndex().replaceFirst(Pattern.quote(".fess_config"), name);
42 }
43 return indexName;
44 }
45
46 @Override
47 public OptionalEntity<ScheduledJob> selectByPK(final String id) {
48 Exception lastException = null;
49 for (int i = 0; i < 30; i++) {
50 try {
51 return super.selectByPK(id);
52 } catch (final Exception e) {
53 if (logger.isDebugEnabled()) {
54 logger.debug("Failed to select a job by " + id, e);
55 }
56 lastException = e;
57 try {
58 Thread.sleep(RandomUtils.nextLong(500, 5000));
59 } catch (final InterruptedException e1) {
60
61 }
62 }
63 }
64 logger.warn("Failed to select a job by " + id, lastException);
65 return OptionalEntity.empty();
66 }
67 }