Transaction t = cat.newTransaction("BucketService", getClass().getSimpleName());
t.setStatus(Message.SUCCESS);
try {
MessageId id = MessageId.parse(messageId);
final String path = m_pathBuilder.getPath(new Date(id.getTimestamp()), "");
final File dir = new File(m_baseDir, path);
final String key = id.getDomain() + '-' + id.getIpAddress();
final List<String> paths = new ArrayList<String>();
Scanners.forDir().scan(dir, new FileMatcher() {
@Override
public Direction matches(File base, String name) {
if (name.contains(key) && !name.endsWith(".idx")) {
paths.add(path + name);
}
return Direction.NEXT;
}
});
for (String dataFile : paths) {
LocalMessageBucket bucket = m_buckets.get(dataFile);
if (bucket != null) {
MessageBlock block = bucket.flushBlock();
if (block != null) {
m_messageBlocks.offer(block);
LockSupport.parkNanos(200 * 1000 * 1000L); // wait 50 ms
}
MessageTree tree = bucket.findByIndex(id.getIndex());
if (tree != null && tree.getMessageId().equals(messageId)) {
t.addData("path", dataFile);
return tree;
}
} else {
File file = new File(m_baseDir, dataFile);
if (file.exists()) {
try {
bucket = (LocalMessageBucket) lookup(MessageBucket.class, LocalMessageBucket.ID);
bucket.setBaseDir(m_baseDir);
bucket.initialize(dataFile);
MessageTree tree = bucket.findByIndex(id.getIndex());
if (tree != null && tree.getMessageId().equals(messageId)) {
t.addData("path", dataFile);
return tree;
}