/* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ using log4net; using Apache.Qpid.Messaging; //using javax.jms.Message; //using javax.jms.MessageListener; //using java.util.concurrent.atomic.AtomicInteger; namespace Apache.Qpid.Integration.Tests.framework { /// /// MessageMonitor is used to record information about messages received. This will provide methods to check various /// properties, such as the type, number and content of messages received in order to verify the correct behaviour of /// tests. /// ///

///
CRC Card
Responsibilities Collaborations ///
Count incoming messages. ///
Record time ellapsed since the arrival of the first message. ///
Reset all counts and timings. ///
///

public class MessageMonitor : MessageListener { /// Used for debugging. private static ILog log = LogManager.GetLogger(typeof(MessageMonitor)); /// Holds the count of messages received since the last query. protected AtomicInteger numMessages = new AtomicInteger(); /// Holds the time of arrival of the first message. protected Long firstMessageTime = null; /// /// Handles received messages. Does Nothing. /// /// The message. Ignored. public void onMessage(Message message) { // log.debug("public void onMessage(Message message): called"); numMessages.getAndIncrement(); } /// /// Gets the count of messages. /// /// The count of messages. public int getNumMessage() { if (firstMessageTime == null) { firstMessageTime = System.nanoTime(); } return numMessages.get(); } /// /// Gets the time elapsed since the first message arrived, in nanos, or zero if no messages have arrived yet. /// /// The time elapsed since the first message arrived, in nanos, or zero if no messages have arrived yet. public long getTime() { if (firstMessageTime != null) { return System.nanoTime() - firstMessageTime; } else { return 0L; } } /// Resets the message count and timer to zero. public void reset() { numMessages.set(0); firstMessageTime = null; } } }