001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.ping;
022
023 import org.apache.log4j.Logger;
024
025 import org.apache.qpid.requestreply.PingPongProducer;
026
027 import javax.jms.Destination;
028
029 import java.util.List;
030 import java.util.Properties;
031
032 /**
033 * PingClient is a {@link PingPongProducer} that does not need a {@link org.apache.qpid.requestreply.PingPongBouncer}
034 * to send replies to its pings. It simply listens to its own ping destinations, rather than seperate reply queues.
035 * It is an all in one ping client, that produces and consumes its own pings.
036 *
037 * <p/>The constructor increments a count of the number of ping clients created. It is assumed that where many
038 * are created they will all be run in parallel and be active in sending and consuming pings at the same time.
039 * If the unique destinations flag is not set and a pub/sub ping cycle is being run, this means that they will all hear
040 * pings sent by each other. The expected number of pings received will therefore be multiplied up by the number of
041 * active ping clients. The {@link #getConsumersPerDestination()} method is used to supply this multiplier under these
042 * conditions.
043 *
044 * <p/><table id="crc"><caption>CRC Card</caption>
045 * <tr><th> Responsibilities <th> Collaborations
046 * <tr><td> Create a ping producer that listens to its own pings <td> {@link PingPongProducer}
047 * <tr><td> Count the number of ping producers and produce multiplier for scaling up messages expected over topic pings.
048 * </table>
049 */
050 public class PingClient extends PingPongProducer
051 {
052 /** Used for debugging. */
053 private final Logger log = Logger.getLogger(PingClient.class);
054
055 /** Used to count the number of ping clients created. */
056 private static int _pingClientCount;
057
058 /**
059 * Creates a ping producer with the specified parameters, of which there are many. See the class level comments
060 * for {@link PingPongProducer} for details. This constructor creates a connection to the broker and creates
061 * producer and consumer sessions on it, to send and recieve its pings and replies on.
062 *
063 * @param overrides Properties containing any desired overrides to the defaults.
064 *
065 * @throws Exception Any exceptions are allowed to fall through.
066 */
067 public PingClient(Properties overrides) throws Exception
068 {
069 super(overrides);
070
071 _pingClientCount++;
072 }
073
074 /**
075 * Returns the ping destinations themselves as the reply destinations for this pinger to listen to. This has the
076 * effect of making this pinger listen to its own pings.
077 *
078 * @return The ping destinations.
079 */
080 public List<Destination> getReplyDestinations()
081 {
082 return _pingDestinations;
083 }
084
085 /**
086 * Supplies the multiplier for the number of ping clients that will hear each ping when doing pub/sub pinging.
087 *
088 * @return The scaling up of the number of expected pub/sub pings.
089 */
090 public int getConsumersPerDestination()
091 {
092 log.debug("public int getConsumersPerDestination(): called");
093
094 if (_isUnique)
095 {
096 log.debug(_noOfConsumers + " consumer per destination.");
097
098 return _noOfConsumers;
099 }
100 else
101 {
102 log.debug((_pingClientCount * _noOfConsumers) + " consumers per destination.");
103
104 return _pingClientCount * _noOfConsumers;
105 }
106 }
107 }
|