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.jmx;
018
019 import org.apache.activemq.command.ActiveMQDestination;
020 import org.apache.activemq.command.ProducerInfo;
021
022 public class ProducerView implements ProducerViewMBean {
023
024 protected final ProducerInfo info;
025 protected final String clientId;
026 protected final String userName;
027 protected final ManagedRegionBroker broker;
028
029 protected ActiveMQDestination lastUsedDestination;
030
031 public ProducerView(ProducerInfo info, String clientId, String userName, ManagedRegionBroker broker) {
032 this.info = info;
033 this.clientId = clientId;
034 this.userName = userName;
035 this.broker = broker;
036 }
037
038 @Override
039 public String getClientId() {
040 return this.clientId;
041 }
042
043 @Override
044 public String getConnectionId() {
045 if (info != null) {
046 return info.getProducerId().getConnectionId();
047 }
048 return "NOTSET";
049 }
050
051 @Override
052 public long getSessionId() {
053 if (info != null) {
054 return info.getProducerId().getSessionId();
055 }
056 return 0;
057 }
058
059 @Override
060 public String getProducerId() {
061 if (info != null) {
062 return info.getProducerId().toString();
063 }
064 return "NOTSET";
065 }
066
067 @Override
068 public String getDestinationName() {
069 if (info != null && info.getDestination() != null) {
070 ActiveMQDestination dest = info.getDestination();
071 return dest.getPhysicalName();
072 } else if (this.lastUsedDestination != null) {
073 return this.lastUsedDestination.getPhysicalName();
074 }
075 return "NOTSET";
076 }
077
078 @Override
079 public boolean isDestinationQueue() {
080 if (info != null) {
081 if (info.getDestination() != null) {
082 ActiveMQDestination dest = info.getDestination();
083 return dest.isQueue();
084 } else if(lastUsedDestination != null) {
085 return lastUsedDestination.isQueue();
086 }
087 }
088 return false;
089 }
090
091 @Override
092 public boolean isDestinationTopic() {
093 if (info != null) {
094 if (info.getDestination() != null) {
095 ActiveMQDestination dest = info.getDestination();
096 return dest.isTopic();
097 } else if(lastUsedDestination != null) {
098 return lastUsedDestination.isTopic();
099 }
100 }
101 return false;
102 }
103
104 @Override
105 public boolean isDestinationTemporary() {
106 if (info != null) {
107 if (info.getDestination() != null) {
108 ActiveMQDestination dest = info.getDestination();
109 return dest.isTemporary();
110 } else if(lastUsedDestination != null) {
111 return lastUsedDestination.isTemporary();
112 }
113 }
114 return false;
115 }
116
117 @Override
118 public int getProducerWindowSize() {
119 if (info != null) {
120 return info.getWindowSize();
121 }
122 return 0;
123 }
124
125 @Override
126 public boolean isDispatchAsync() {
127 if (info != null) {
128 return info.isDispatchAsync();
129 }
130 return false;
131 }
132
133 /**
134 * @return pretty print
135 */
136 public String toString() {
137 return "ProducerView: " + getClientId() + ":" + getConnectionId();
138 }
139
140 /**
141 * Set the last used Destination name for a Dynamic Destination Producer.
142 */
143 void setLastUsedDestinationName(ActiveMQDestination destinationName) {
144 this.lastUsedDestination = destinationName;
145 }
146
147 @Override
148 public String getUserName() {
149 return userName;
150 }
151 }