Method from org.apache.activemq.broker.region.cursors.FilePendingMessageCursor Detail: |
public synchronized void addMessageFirst(MessageReference node) {
if (!node.isExpired()) {
try {
regionDestination = node.getMessage().getRegionDestination();
if (isDiskListEmpty()) {
if (hasSpace()) {
memoryList.addFirst(node);
node.incrementReferenceCount();
return;
}
}
if (!hasSpace()) {
if (isDiskListEmpty()) {
expireOldMessages();
if (hasSpace()) {
memoryList.addFirst(node);
node.incrementReferenceCount();
return;
} else {
flushToDisk();
}
}
}
systemUsage.getTempUsage().waitForSpace();
node.decrementReferenceCount();
getDiskList().addFirst(node);
} catch (Exception e) {
LOG.error("Caught an Exception adding a message: " + node
+ " first to FilePendingMessageCursor ", e);
throw new RuntimeException(e);
}
} else {
discard(node);
}
}
add message to await dispatch |
public synchronized void addMessageLast(MessageReference node) {
if (!node.isExpired()) {
try {
regionDestination = node.getMessage().getRegionDestination();
if (isDiskListEmpty()) {
if (hasSpace() || this.store==null) {
memoryList.add(node);
node.incrementReferenceCount();
return;
}
}
if (!hasSpace()) {
if (isDiskListEmpty()) {
expireOldMessages();
if (hasSpace()) {
memoryList.add(node);
node.incrementReferenceCount();
return;
} else {
flushToDisk();
}
}
}
systemUsage.getTempUsage().waitForSpace();
getDiskList().add(node);
} catch (Exception e) {
LOG.error("Caught an Exception adding a message: " + node
+ " first to FilePendingMessageCursor ", e);
throw new RuntimeException(e);
}
} else {
discard(node);
}
}
add message to await dispatch |
public synchronized void clear() {
memoryList.clear();
if (!isDiskListEmpty()) {
getDiskList().clear();
}
last=null;
}
clear all pending messages |
public synchronized void destroy() throws Exception {
stop();
for (Iterator< MessageReference > i = memoryList.iterator(); i.hasNext();) {
Message node = (Message)i.next();
node.decrementReferenceCount();
}
memoryList.clear();
destroyDiskList();
}
|
protected void discard(MessageReference message) {
message.decrementReferenceCount();
if (LOG.isDebugEnabled()) {
LOG.debug("Discarding message " + message);
}
broker.getRoot().sendToDeadLetterQueue(new ConnectionContext(new NonCachedMessageEvaluationContext()), message);
}
|
protected synchronized void expireOldMessages() {
if (!memoryList.isEmpty()) {
LinkedList< MessageReference > tmpList = new LinkedList< MessageReference >(this.memoryList);
this.memoryList = new LinkedList< MessageReference >();
while (!tmpList.isEmpty()) {
MessageReference node = tmpList.removeFirst();
if (node.isExpired()) {
discard(node);
}else {
memoryList.add(node);
}
}
}
}
|
protected synchronized void flushToDisk() {
if (!memoryList.isEmpty()) {
while (!memoryList.isEmpty()) {
MessageReference node = memoryList.removeFirst();
node.decrementReferenceCount();
getDiskList().addLast(node);
}
memoryList.clear();
}
}
|
protected ListContainer<MessageReference> getDiskList() {
if (diskList == null) {
try {
diskList = store.getListContainer(name, "TopicSubscription", true);
diskList.setMarshaller(new CommandMarshaller(new OpenWireFormat()));
} catch (IOException e) {
LOG.error("Caught an IO Exception getting the DiskList " + name, e);
throw new RuntimeException(e);
}
}
return diskList;
}
|
public boolean hasMessagesBufferedToDeliver() {
return !isEmpty();
}
|
public synchronized boolean hasNext() {
return iter.hasNext();
}
|
protected boolean isDiskListEmpty() {
return diskList == null || diskList.isEmpty();
}
|
public synchronized boolean isEmpty() {
if(memoryList.isEmpty() && isDiskListEmpty()){
return true;
}
for (Iterator< MessageReference > iterator = memoryList.iterator(); iterator.hasNext();) {
MessageReference node = iterator.next();
if (node== QueueMessageReference.NULL_MESSAGE){
continue;
}
if (!node.isDropped()) {
return false;
}
// We can remove dropped references.
iterator.remove();
}
return isDiskListEmpty();
}
|
public synchronized boolean isFull() {
return super.isFull()
|| (systemUsage != null && systemUsage.getTempUsage().isFull());
}
|
protected boolean isSpaceInMemoryList() {
return hasSpace() && isDiskListEmpty();
}
|
public boolean isTransient() {
return true;
}
|
public synchronized MessageReference next() {
Message message = (Message)iter.next();
last = message;
if (!isDiskListEmpty()) {
// got from disk
message.setRegionDestination(regionDestination);
message.setMemoryUsage(this.getSystemUsage().getMemoryUsage());
}
message.incrementReferenceCount();
return message;
}
|
public void onUsageChanged(Usage usage,
int oldPercentUsage,
int newPercentUsage) {
if (newPercentUsage >= getMemoryUsageHighWaterMark()) {
synchronized (this) {
flushRequired = true;
if (!iterating) {
expireOldMessages();
if (!hasSpace()) {
flushToDisk();
flushRequired = false;
}
}
}
}
}
|
public synchronized LinkedList<MessageReference> pageInList(int maxItems) {
LinkedList< MessageReference > result = new LinkedList< MessageReference >();
int count = 0;
for (Iterator< MessageReference > i = memoryList.iterator(); i.hasNext() && count < maxItems;) {
MessageReference ref = i.next();
ref.incrementReferenceCount();
result.add(ref);
count++;
}
if (count < maxItems && !isDiskListEmpty()) {
for (Iterator< MessageReference > i = getDiskList().iterator(); i.hasNext() && count < maxItems;) {
Message message = (Message)i.next();
message.setRegionDestination(regionDestination);
message.setMemoryUsage(this.getSystemUsage().getMemoryUsage());
message.incrementReferenceCount();
result.add(message);
count++;
}
}
return result;
}
|
public synchronized void release() {
iterating = false;
if (flushRequired) {
flushRequired = false;
flushToDisk();
}
}
|
public synchronized void remove() {
iter.remove();
if (last != null) {
last.decrementReferenceCount();
}
}
remove the message at the cursor position |
public synchronized void remove(MessageReference node) {
if (memoryList.remove(node)) {
node.decrementReferenceCount();
}
if (!isDiskListEmpty()) {
getDiskList().remove(node);
}
}
|
public synchronized void reset() {
iterating = true;
last = null;
iter = isDiskListEmpty() ? memoryList.iterator() : getDiskList().listIterator();
}
|
public void setSystemUsage(SystemUsage usageManager) {
super.setSystemUsage(usageManager);
}
|
public synchronized int size() {
return memoryList.size() + (isDiskListEmpty() ? 0 : getDiskList().size());
}
|
public void start() throws Exception {
if (started.compareAndSet(false, true)) {
super.start();
if (systemUsage != null) {
systemUsage.getMemoryUsage().addUsageListener(this);
}
}
}
|
public void stop() throws Exception {
if (started.compareAndSet(true, false)) {
super.stop();
if (systemUsage != null) {
systemUsage.getMemoryUsage().removeUsageListener(this);
}
}
}
|