1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.mycore.oai;
20
21 import java.time.Instant;
22 import java.util.Optional;
23 import java.util.Random;
24
25 import org.apache.logging.log4j.LogManager;
26 import org.apache.logging.log4j.Logger;
27 import org.mycore.oai.pmh.Header;
28 import org.mycore.oai.pmh.MetadataFormat;
29 import org.mycore.oai.set.MCRSet;
30
31
32
33
34
35
36
37
38
39
40
41 public abstract class MCROAISearcher {
42
43 protected static final Logger LOGGER = LogManager.getLogger(MCROAISearcher.class);
44
45 protected MCROAIIdentify identify;
46
47 protected MetadataFormat metadataFormat;
48
49
50 protected final String id;
51
52 protected long expire;
53
54
55
56
57 protected long runningExpirationTimer;
58
59 protected int partitionSize;
60
61 protected MCROAISetManager setManager;
62
63 private MCROAIObjectManager objectManager;
64
65 public MCROAISearcher() {
66 Random random = new Random(System.currentTimeMillis());
67 this.id = Long.toString(random.nextLong(), 36) + Long.toString(System.currentTimeMillis(), 36);
68 }
69
70 public void init(MCROAIIdentify identify, MetadataFormat format, long expire, int partitionSize,
71 MCROAISetManager setManager, MCROAIObjectManager objectManager) {
72 this.identify = identify;
73 this.metadataFormat = format;
74 this.expire = expire;
75 this.partitionSize = partitionSize;
76 this.setManager = setManager;
77 this.objectManager = objectManager;
78 updateRunningExpirationTimer();
79 }
80
81 public abstract Optional<Header> getHeader(String mcrId);
82
83 public abstract MCROAIResult query(String cursor);
84
85 public abstract MCROAIResult query(MCRSet set, Instant from, Instant until);
86
87
88
89
90
91
92
93 public abstract Optional<Instant> getEarliestTimestamp();
94
95 public boolean isExpired() {
96 return System.currentTimeMillis() > runningExpirationTimer;
97 }
98
99 public Instant getExpirationTime() {
100 return Instant.ofEpochMilli(runningExpirationTimer);
101 }
102
103 public MetadataFormat getMetadataFormat() {
104 return metadataFormat;
105 }
106
107 public String getID() {
108 return id;
109 }
110
111 public MCROAISetManager getSetManager() {
112 return setManager;
113 }
114
115 public MCROAIObjectManager getObjectManager() {
116 return objectManager;
117 }
118
119 protected String getConfigPrefix() {
120 return this.identify.getConfigPrefix();
121 }
122
123
124
125
126 protected void updateRunningExpirationTimer() {
127 this.runningExpirationTimer = System.currentTimeMillis() + this.expire;
128 }
129
130 public int getPartitionSize() {
131 return partitionSize;
132 }
133
134 }