View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.message;
    19
    20  /***
    21   * Describes a Message consumer
    22   *
    23   * @version $Revision: 1.8 $
    24   */
    25  public class ConsumerInfo extends AbstractPacket {
    26      private ActiveMQDestination destination;
    27      private String consumerId;
    28      private String clientId;
    29      private String sessionId;
    30      private String consumerName;
    31      private String selector;
    32      private long startTime;
    33      private boolean started;
    34      private int consumerNo;
    35      private boolean noLocal;
    36      private boolean browser;
    37      private int prefetchNumber = 100;
    38
    39      /***
    40       * @return Returns the consumerId.
    41       */
    42      public String getConsumerId() {
    43          return consumerId;
    44      }
    45
    46      /***
    47       * @param consumerId The consumerId to set.
    48       */
    49      public void setConsumerId(String consumerId) {
    50          this.consumerId = consumerId;
    51      }
    52
    53      /***
    54       * @return Returns the sessionId.
    55       */
    56      public String getSessionId() {
    57          return sessionId;
    58      }
    59
    60      /***
    61       * @param sessionId The sessionId to set.
    62       */
    63      public void setSessionId(String sessionId) {
    64          this.sessionId = sessionId;
    65      }
    66
    67      /***
    68       * Return the type of Packet
    69       *
    70       * @return integer representation of the type of Packet
    71       */
    72      public int getPacketType() {
    73          return CONSUMER_INFO;
    74      }
    75
    76      /***
    77       * Test for equality
    78       *
    79       * @param obj object to test
    80       * @return true if equivalent
    81       */
    82      public boolean equals(Object obj) {
    83          boolean result = false;
    84          if (obj != null && obj instanceof ConsumerInfo) {
    85              ConsumerInfo that = (ConsumerInfo) obj;
    86              result = this.consumerId.equals(that.consumerId);
    87          }
    88          return result;
    89      }
    90
    91      /***
    92       * @return hash code for instance
    93       */
    94      public int hashCode() {
    95          return this.consumerId.hashCode();
    96      }
    97
    98      /***
    99       * @return a pretty print
    100      */
    101
    102     public String toString() {
    103         return super.toString() + " consumerId: " + consumerId + " clientId: " + clientId + " consumerName: " + consumerName + " destination: " + destination;
    104     }
    105
    106     /***
    107      * @return Returns the clientId.
    108      */
    109     public String getClientId() {
    110         return this.clientId;
    111     }
    112
    113     /***
    114      * @param newClientId The clientId to set.
    115      */
    116     public void setClientId(String newClientId) {
    117         this.clientId = newClientId;
    118     }
    119
    120     /***
    121      * @return Returns the destination.
    122      */
    123     public ActiveMQDestination getDestination() {
    124         return this.destination;
    125     }
    126
    127     /***
    128      * @param newDestination The destination to set.
    129      */
    130     public void setDestination(ActiveMQDestination newDestination) {
    131         this.destination = newDestination;
    132     }
    133
    134     /***
    135      * @return Returns the selector.
    136      */
    137     public String getSelector() {
    138         return this.selector;
    139     }
    140
    141     /***
    142      * @param newSelector The selector to set.
    143      */
    144     public void setSelector(String newSelector) {
    145         this.selector = newSelector;
    146     }
    147
    148     /***
    149      * @return Returns the started.
    150      */
    151     public boolean isStarted() {
    152         return this.started;
    153     }
    154
    155     /***
    156      * @param flag to indicate if started
    157      */
    158     public void setStarted(boolean flag) {
    159         this.started = flag;
    160     }
    161
    162     /***
    163      * @return Returns the startTime.
    164      */
    165     public long getStartTime() {
    166         return this.startTime;
    167     }
    168
    169     /***
    170      * @param newStartTime The startTime to set.
    171      */
    172     public void setStartTime(long newStartTime) {
    173         this.startTime = newStartTime;
    174     }
    175
    176     /***
    177      * @return Returns the consumerNo.
    178      */
    179     public int getConsumerNo() {
    180         return this.consumerNo;
    181     }
    182
    183     /***
    184      * @param newConsumerNo The consumerNo to set.
    185      */
    186     public void setConsumerNo(int newConsumerNo) {
    187         this.consumerNo = newConsumerNo;
    188     }
    189
    190     /***
    191      * @return Returns the consumer name.
    192      */
    193     public String getConsumerName() {
    194         return this.consumerName;
    195     }
    196
    197     /***
    198      * @param newconsumerName The consumerName to set.
    199      */
    200     public void setConsumerName(String newconsumerName) {
    201         this.consumerName = newconsumerName;
    202     }
    203
    204     /***
    205      * @return Returns true if the Consumer is a durable Topic subscriber
    206      */
    207     public boolean isDurableTopic() {
    208         return this.destination.isTopic() && !this.destination.isTemporary() && this.consumerName != null
    209                 && this.consumerName.length() > 0;
    210     }
    211
    212     /***
    213      * @return Returns the noLocal.
    214      */
    215     public boolean isNoLocal() {
    216         return noLocal;
    217     }
    218
    219     /***
    220      * @param noLocal The noLocal to set.
    221      */
    222     public void setNoLocal(boolean noLocal) {
    223         this.noLocal = noLocal;
    224     }
    225
    226     /***
    227      * @return Returns the browser.
    228      */
    229     public boolean isBrowser() {
    230         return browser;
    231     }
    232
    233     /***
    234      * @param browser The browser to set.
    235      */
    236     public void setBrowser(boolean browser) {
    237         this.browser = browser;
    238     }
    239
    240     /***
    241      * @return Returns the prefetchNumber.
    242      */
    243     public int getPrefetchNumber() {
    244         return prefetchNumber;
    245     }
    246
    247     /***
    248      * @param prefetchNumber The prefetchNumber to set.
    249      */
    250     public void setPrefetchNumber(int prefetchNumber) {
    251         this.prefetchNumber = prefetchNumber;
    252     }
    253
    254
    255     /***
    256      * Creates a primary key for the consumer info which uniquely
    257      * describes the consumer using a combination of clientID and
    258      * consumerName
    259      *
    260      * @return
    261      */
    262     public String getConsumerKey() {
    263         return "[" + getClientId() + ":" + getConsumerName() + "]";
    264     }
    265 }