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 */ 017package org.apache.activemq.command; 018 019import java.io.IOException; 020import java.util.Properties; 021import org.apache.activemq.state.CommandVisitor; 022import org.apache.activemq.util.MarshallingSupport; 023 024/** 025 * When a client connects to a broker, the broker send the client a BrokerInfo 026 * so that the client knows which broker node he's talking to and also any peers 027 * that the node has in his cluster. This is the broker helping the client out 028 * in discovering other nodes in the cluster. 029 * 030 * @openwire:marshaller code="2" 031 * 032 */ 033public class BrokerInfo extends BaseCommand { 034 private static final String PASSIVE_SLAVE_KEY = "passiveSlave"; 035 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.BROKER_INFO; 036 BrokerId brokerId; 037 String brokerURL; 038 boolean slaveBroker; 039 boolean masterBroker; 040 boolean faultTolerantConfiguration; 041 boolean networkConnection; 042 boolean duplexConnection; 043 BrokerInfo peerBrokerInfos[]; 044 String brokerName; 045 long connectionId; 046 String brokerUploadUrl; 047 String networkProperties; 048 transient int refCount = 0; 049 050 public BrokerInfo copy() { 051 BrokerInfo copy = new BrokerInfo(); 052 copy(copy); 053 return copy; 054 } 055 056 private void copy(BrokerInfo copy) { 057 super.copy(copy); 058 copy.brokerId = this.brokerId; 059 copy.brokerURL = this.brokerURL; 060 copy.slaveBroker = this.slaveBroker; 061 copy.masterBroker = this.masterBroker; 062 copy.faultTolerantConfiguration = this.faultTolerantConfiguration; 063 copy.networkConnection = this.networkConnection; 064 copy.duplexConnection = this.duplexConnection; 065 copy.peerBrokerInfos = this.peerBrokerInfos; 066 copy.brokerName = this.brokerName; 067 copy.connectionId = this.connectionId; 068 copy.brokerUploadUrl = this.brokerUploadUrl; 069 copy.networkProperties = this.networkProperties; 070 } 071 072 @Override 073 public boolean isBrokerInfo() { 074 return true; 075 } 076 077 @Override 078 public byte getDataStructureType() { 079 return DATA_STRUCTURE_TYPE; 080 } 081 082 /** 083 * @openwire:property version=1 cache=true 084 */ 085 public BrokerId getBrokerId() { 086 return brokerId; 087 } 088 089 public void setBrokerId(BrokerId brokerId) { 090 this.brokerId = brokerId; 091 } 092 093 /** 094 * @openwire:property version=1 095 */ 096 public String getBrokerURL() { 097 return brokerURL; 098 } 099 100 public void setBrokerURL(String brokerURL) { 101 this.brokerURL = brokerURL; 102 } 103 104 /** 105 * @openwire:property version=1 testSize=0 106 */ 107 public BrokerInfo[] getPeerBrokerInfos() { 108 return peerBrokerInfos; 109 } 110 111 public void setPeerBrokerInfos(BrokerInfo[] peerBrokerInfos) { 112 this.peerBrokerInfos = peerBrokerInfos; 113 } 114 115 /** 116 * @openwire:property version=1 117 */ 118 public String getBrokerName() { 119 return brokerName; 120 } 121 122 public void setBrokerName(String brokerName) { 123 this.brokerName = brokerName; 124 } 125 126 @Override 127 public Response visit(CommandVisitor visitor) throws Exception { 128 return visitor.processBrokerInfo(this); 129 } 130 131 /** 132 * @openwire:property version=1 133 */ 134 public boolean isSlaveBroker() { 135 return slaveBroker; 136 } 137 138 public void setSlaveBroker(boolean slaveBroker) { 139 this.slaveBroker = slaveBroker; 140 } 141 142 /** 143 * @openwire:property version=1 144 */ 145 public boolean isMasterBroker() { 146 return masterBroker; 147 } 148 149 /** 150 * @param masterBroker The masterBroker to set. 151 */ 152 public void setMasterBroker(boolean masterBroker) { 153 this.masterBroker = masterBroker; 154 } 155 156 /** 157 * @openwire:property version=1 158 * @return Returns the faultTolerantConfiguration. 159 */ 160 public boolean isFaultTolerantConfiguration() { 161 return faultTolerantConfiguration; 162 } 163 164 /** 165 * @param faultTolerantConfiguration The faultTolerantConfiguration to set. 166 */ 167 public void setFaultTolerantConfiguration(boolean faultTolerantConfiguration) { 168 this.faultTolerantConfiguration = faultTolerantConfiguration; 169 } 170 171 /** 172 * @openwire:property version=2 173 * @return the duplexConnection 174 */ 175 public boolean isDuplexConnection() { 176 return this.duplexConnection; 177 } 178 179 /** 180 * @param duplexConnection the duplexConnection to set 181 */ 182 public void setDuplexConnection(boolean duplexConnection) { 183 this.duplexConnection = duplexConnection; 184 } 185 186 /** 187 * @openwire:property version=2 188 * @return the networkConnection 189 */ 190 public boolean isNetworkConnection() { 191 return this.networkConnection; 192 } 193 194 /** 195 * @param networkConnection the networkConnection to set 196 */ 197 public void setNetworkConnection(boolean networkConnection) { 198 this.networkConnection = networkConnection; 199 } 200 201 /** 202 * The broker assigns a each connection it accepts a connection id. 203 * 204 * @openwire:property version=2 205 */ 206 public long getConnectionId() { 207 return connectionId; 208 } 209 210 public void setConnectionId(long connectionId) { 211 this.connectionId = connectionId; 212 } 213 214 /** 215 * The URL to use when uploading BLOBs to the broker or some other external 216 * file/http server 217 * 218 * @openwire:property version=3 219 */ 220 public String getBrokerUploadUrl() { 221 return brokerUploadUrl; 222 } 223 224 public void setBrokerUploadUrl(String brokerUploadUrl) { 225 this.brokerUploadUrl = brokerUploadUrl; 226 } 227 228 /** 229 * @openwire:property version=3 cache=false 230 * @return the networkProperties 231 */ 232 public String getNetworkProperties() { 233 return this.networkProperties; 234 } 235 236 /** 237 * @param networkProperties the networkProperties to set 238 */ 239 public void setNetworkProperties(String networkProperties) { 240 this.networkProperties = networkProperties; 241 } 242 243 public boolean isPassiveSlave() { 244 boolean result = false; 245 Properties props = getProperties(); 246 if (props != null) { 247 result = Boolean.parseBoolean(props.getProperty(PASSIVE_SLAVE_KEY, "false")); 248 } 249 return result; 250 } 251 252 public void setPassiveSlave(boolean value) { 253 Properties props = new Properties(); 254 props.put(PASSIVE_SLAVE_KEY, Boolean.toString(value)); 255 try { 256 this.networkProperties=MarshallingSupport.propertiesToString(props); 257 } catch (IOException e) { 258 e.printStackTrace(); 259 } 260 } 261 262 public Properties getProperties() { 263 Properties result = null; 264 try { 265 result = MarshallingSupport.stringToProperties(getNetworkProperties()); 266 } catch (IOException e) { 267 e.printStackTrace(); 268 } 269 return result; 270 } 271 272 public int getRefCount() { 273 return refCount; 274 } 275 276 public void incrementRefCount() { 277 refCount++; 278 } 279 public int decrementRefCount() { 280 return --refCount; 281 } 282}