001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.broker.region.policy;
018
019 import javax.jms.MessageListener;
020
021 import org.apache.activemq.command.ActiveMQDestination;
022 import org.apache.activemq.command.Message;
023
024 /**
025 * Represents some kind of query which will load initial messages from some source for a new topic subscriber.
026 *
027 *
028 */
029 public interface MessageQuery {
030
031 /**
032 * Executes the query for messages; each message is passed into the listener
033 *
034 * @param destination the destination on which the query is to be performed
035 * @param listener is the listener to notify as each message is created or loaded
036 */
037 void execute(ActiveMQDestination destination, MessageListener listener) throws Exception;
038
039 /**
040 * Returns true if the given update is valid and does not overlap with the initial message query.
041 * When performing an initial load from some source, there is a chance that an update may occur which is logically before
042 * the message sent on the initial load - so this method provides a hook where the query instance can keep track of the version IDs
043 * of the messages sent so that if an older version is sent as an update it can be excluded to avoid going backwards in time.
044 *
045 * e.g. if the execute() method creates version 2 of an object and then an update message is sent for version 1, this method should return false to
046 * hide the old update message.
047 *
048 * @param message the update message which may have been sent before the query actually completed
049 * @return true if the update message is valid otherwise false in which case the update message will be discarded.
050 */
051 boolean validateUpdate(Message message);
052
053 }