1 18 package org.apache.activemq.filter; 19 20 import java.io.IOException ; 21 22 import org.apache.activemq.broker.region.MessageReference; 23 import org.apache.activemq.command.ActiveMQDestination; 24 import org.apache.activemq.command.Message; 25 26 36 public class MessageEvaluationContext { 37 38 private MessageReference messageReference; 39 private boolean loaded=false; 40 private boolean dropped; 41 private Message message; 42 private ActiveMQDestination destination; 43 44 public MessageEvaluationContext() { 45 } 46 47 public boolean isDropped() throws IOException { 48 getMessage(); 49 return dropped; 50 } 51 52 public Message getMessage() throws IOException { 53 if( !dropped && !loaded ) { 54 loaded=true; 55 messageReference.incrementReferenceCount(); 56 message = messageReference.getMessage(); 57 if(message==null) { 58 messageReference.decrementReferenceCount(); 59 dropped=true; 60 loaded=false; 61 } 62 } 63 return message; 64 } 65 66 public void setMessageReference(MessageReference messageReference) { 67 if (this.messageReference != messageReference) { 68 clearMessageCache(); 69 } 70 this.messageReference = messageReference; 71 } 72 73 public void clear() { 74 clearMessageCache(); 75 destination = null; 76 } 77 78 public ActiveMQDestination getDestination() { 79 return destination; 80 } 81 82 public void setDestination(ActiveMQDestination destination) { 83 this.destination = destination; 84 } 85 86 89 protected void clearMessageCache() { 90 if( loaded ) { 91 messageReference.decrementReferenceCount(); 92 } 93 message=null; 94 dropped=false; 95 loaded=false; 96 } 97 } 98 | Popular Tags |