Method from org.apache.activemq.broker.region.cursors.AbstractStoreCursor Detail: |
public final synchronized void addMessageFirst(MessageReference node) throws Exception {
cacheEnabled=false;
size++;
}
|
public final synchronized void addMessageLast(MessageReference node) throws Exception {
if (cacheEnabled && hasSpace()) {
recoverMessage(node.getMessage(),true);
lastCachedId = node.getMessageId();
} else {
if (cacheEnabled) {
cacheEnabled=false;
if (LOG.isDebugEnabled()) {
LOG.debug(regionDestination.getActiveMQDestination().getPhysicalName() + " disabling cache on size:" + size
+ ", lastCachedIdSeq: " + (lastCachedId == null ? -1 : lastCachedId.getBrokerSequenceId())
+ " current node seqId: " + node.getMessageId().getBrokerSequenceId());
}
// sync with store on disabling the cache
if (lastCachedId != null) {
setBatch(lastCachedId);
}
}
}
size++;
}
|
public final synchronized void clear() {
gc();
}
|
abstract protected void doFillBatch() throws Exception
|
protected final synchronized void fillBatch() {
if (batchResetNeeded) {
resetBatch();
this.batchResetNeeded = false;
}
if( this.batchList.isEmpty() && (this.storeHasMessages ||this.size >0)) {
this.storeHasMessages = false;
try {
doFillBatch();
} catch (Exception e) {
LOG.error("Failed to fill batch", e);
throw new RuntimeException(e);
}
if (!this.batchList.isEmpty()) {
this.storeHasMessages=true;
}
}
}
|
public final void finished() {
}
|
public final synchronized void gc() {
for (Message msg : batchList.values()) {
rollback(msg.getMessageId());
msg.decrementReferenceCount();
}
batchList.clear();
clearIterator(false);
batchResetNeeded = true;
this.cacheEnabled=false;
if (isStarted()) {
size = getStoreSize();
} else {
size = 0;
}
}
|
abstract protected int getStoreSize()
|
public final synchronized boolean hasMessagesBufferedToDeliver() {
return !batchList.isEmpty();
}
|
public final synchronized boolean hasNext() {
if (batchList.isEmpty()) {
try {
fillBatch();
} catch (Exception e) {
LOG.error("Failed to fill batch", e);
throw new RuntimeException(e);
}
}
ensureIterator();
return this.iterator.hasNext();
}
|
public final synchronized boolean isEmpty() {
// negative means more messages added to store through queue.send since last reset
return size == 0;
}
|
abstract protected boolean isStoreEmpty()
|
public final synchronized MessageReference next() {
MessageReference result = null;
if (!this.batchList.isEmpty()&&this.iterator.hasNext()) {
result = this.iterator.next().getValue();
}
last = result;
if (result != null) {
result.incrementReferenceCount();
}
return result;
}
|
public final boolean recoverMessage(Message message) throws Exception {
return recoverMessage(message,false);
}
|
public synchronized boolean recoverMessage(Message message,
boolean cached) throws Exception {
boolean recovered = false;
if (recordUniqueId(message.getMessageId())) {
if (!cached) {
message.setRegionDestination(regionDestination);
if( message.getMemoryUsage()==null ) {
message.setMemoryUsage(this.getSystemUsage().getMemoryUsage());
}
}
message.incrementReferenceCount();
batchList.put(message.getMessageId(), message);
clearIterator(true);
recovered = true;
} else {
/*
* we should expect to get these - as the message is recorded as it before it goes into
* the cache. If subsequently, we pull out that message from the store (before its deleted)
* it will be a duplicate - but should be ignored
*/
//LOG.error(regionDestination.getActiveMQDestination().getPhysicalName() + " cursor got duplicate: " + message);
storeHasMessages = true;
}
return recovered;
}
|
public synchronized void release() {
clearIterator(false);
}
|
public final synchronized void remove() {
size--;
if (iterator!=null) {
iterator.remove();
}
if (last != null) {
last.decrementReferenceCount();
}
if (size==0 && isStarted() && useCache && hasSpace() && isStoreEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug(regionDestination.getActiveMQDestination().getPhysicalName() + " enabling cache on last remove");
}
cacheEnabled=true;
}
}
|
public final synchronized void remove(MessageReference node) {
size--;
cacheEnabled=false;
batchList.remove(node.getMessageId());
}
|
public final void reset() {
if (batchList.isEmpty()) {
try {
fillBatch();
} catch (Exception e) {
LOG.error("Failed to fill batch", e);
throw new RuntimeException(e);
}
}
clearIterator(true);
size();
}
|
abstract protected void resetBatch()
|
protected void setBatch(MessageId messageId) throws Exception {
}
|
public final synchronized int size() {
if (size < 0) {
this.size = getStoreSize();
}
return size;
}
|
public final synchronized void start() throws Exception {
if (!isStarted()) {
super.start();
clear();
resetBatch();
this.size = getStoreSize();
this.storeHasMessages=this.size > 0;
if (!this.storeHasMessages&&useCache) {
cacheEnabled=true;
}
}
}
|
public final synchronized void stop() throws Exception {
resetBatch();
super.stop();
gc();
}
|