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.command;
018
019 import java.io.IOException;
020
021 import org.apache.activemq.state.CommandVisitor;
022
023 /**
024 * Used to create and destroy destinations on the broker.
025 *
026 * @openwire:marshaller code="8"
027 *
028 */
029 public class DestinationInfo extends BaseCommand {
030
031 public static final byte DATA_STRUCTURE_TYPE = CommandTypes.DESTINATION_INFO;
032
033 public static final byte ADD_OPERATION_TYPE = 0;
034 public static final byte REMOVE_OPERATION_TYPE = 1;
035
036 protected ConnectionId connectionId;
037 protected ActiveMQDestination destination;
038 protected byte operationType;
039 protected long timeout;
040 protected BrokerId[] brokerPath;
041
042 public DestinationInfo() {
043 }
044
045 public DestinationInfo(ConnectionId connectionId, byte operationType, ActiveMQDestination destination) {
046 this.connectionId = connectionId;
047 this.operationType = operationType;
048 this.destination = destination;
049 }
050
051 public byte getDataStructureType() {
052 return DATA_STRUCTURE_TYPE;
053 }
054
055 public boolean isAddOperation() {
056 return operationType == ADD_OPERATION_TYPE;
057 }
058
059 public boolean isRemoveOperation() {
060 return operationType == REMOVE_OPERATION_TYPE;
061 }
062
063 /**
064 * @openwire:property version=1 cache=true
065 */
066 public ConnectionId getConnectionId() {
067 return connectionId;
068 }
069
070 public void setConnectionId(ConnectionId connectionId) {
071 this.connectionId = connectionId;
072 }
073
074 /**
075 * @openwire:property version=1 cache=true
076 */
077 public ActiveMQDestination getDestination() {
078 return destination;
079 }
080
081 public void setDestination(ActiveMQDestination destination) {
082 this.destination = destination;
083 }
084
085 /**
086 * @openwire:property version=1
087 */
088 public byte getOperationType() {
089 return operationType;
090 }
091
092 public void setOperationType(byte operationType) {
093 this.operationType = operationType;
094 }
095
096 /**
097 * @openwire:property version=1
098 */
099 public long getTimeout() {
100 return timeout;
101 }
102
103 public void setTimeout(long timeout) {
104 this.timeout = timeout;
105 }
106
107 /**
108 * The route of brokers the command has moved through.
109 *
110 * @openwire:property version=1 cache=true
111 */
112 public BrokerId[] getBrokerPath() {
113 return brokerPath;
114 }
115
116 public void setBrokerPath(BrokerId[] brokerPath) {
117 this.brokerPath = brokerPath;
118 }
119
120 public Response visit(CommandVisitor visitor) throws Exception {
121 if (isAddOperation()) {
122 return visitor.processAddDestination(this);
123 } else if (isRemoveOperation()) {
124 return visitor.processRemoveDestination(this);
125 }
126 throw new IOException("Unknown operation type: " + getOperationType());
127 }
128
129 public DestinationInfo copy() {
130 DestinationInfo result = new DestinationInfo();
131 super.copy(result);
132 result.connectionId = connectionId;
133 result.destination = destination;
134 result.operationType = operationType;
135 result.brokerPath = brokerPath;
136 return result;
137 }
138 }