private void commitMessage() { MemCachedMessage<T> msg = null; if ((msg = lastMsg.getAndSet(null)) != null) { meta.updateRead(msg.getPos(), msg.getFile()); // 如果是文件的第一个消息,触发备份和删除老文件事件 if (msg.isFirstMessageInFile()) { dataFile.archiveAndRemoveOldFile(msg.getFile()); } } }
/** @see FileQueue#get() */ public T get() { MemCachedMessage<T> msg = null; getLock.lock(); try { msg = memcacheQueue.take(); lastMsg.set(msg); commitMessage(); } catch (InterruptedException e) { log.warn("interrupted when taking messsage from SeqFileStorage"); Thread.currentThread().interrupt(); } finally { getLock.unlock(); } return msg == null ? null : msg.getData(); }
/* * (non-Javadoc) * * @see com.dp.hippo.queue.FileQueue#get(long, * java.util.concurrent.TimeUnit) */ @Override public T get(long timeout, TimeUnit timeUnit) { MemCachedMessage<T> msg = null; getLock.lock(); try { msg = memcacheQueue.poll(timeout, timeUnit); if (msg == null) { return null; } lastMsg.set(msg); commitMessage(); } catch (InterruptedException e) { log.warn("interrupted when taking messsage from SeqFileStorage"); Thread.currentThread().interrupt(); } finally { getLock.unlock(); } return msg == null ? null : msg.getData(); }