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     * Removes a consumer, producer, session or connection.
025     * 
026     * @openwire:marshaller code="12"
027     * 
028     */
029    public class RemoveInfo extends BaseCommand {
030    
031        public static final byte DATA_STRUCTURE_TYPE = CommandTypes.REMOVE_INFO;
032    
033        protected DataStructure objectId;
034        protected long lastDeliveredSequenceId;
035    
036        public RemoveInfo() {
037        }
038    
039        public RemoveInfo(DataStructure objectId) {
040            this.objectId = objectId;
041        }
042    
043        public byte getDataStructureType() {
044            return DATA_STRUCTURE_TYPE;
045        }
046    
047        /**
048         * @openwire:property version=1 cache=true
049         */
050        public DataStructure getObjectId() {
051            return objectId;
052        }
053    
054        public void setObjectId(DataStructure objectId) {
055            this.objectId = objectId;
056        }
057    
058        /**
059         * @openwire:property version=5 cache=false
060         */
061        public long getLastDeliveredSequenceId() {
062            return lastDeliveredSequenceId;
063        }
064    
065        public void setLastDeliveredSequenceId(long lastDeliveredSequenceId) {
066            this.lastDeliveredSequenceId = lastDeliveredSequenceId;
067        }
068    
069        public Response visit(CommandVisitor visitor) throws Exception {
070            switch (objectId.getDataStructureType()) {
071            case ConnectionId.DATA_STRUCTURE_TYPE:
072                return visitor.processRemoveConnection((ConnectionId)objectId, lastDeliveredSequenceId);
073            case SessionId.DATA_STRUCTURE_TYPE:
074                return visitor.processRemoveSession((SessionId)objectId, lastDeliveredSequenceId);
075            case ConsumerId.DATA_STRUCTURE_TYPE:
076                return visitor.processRemoveConsumer((ConsumerId)objectId, lastDeliveredSequenceId);
077            case ProducerId.DATA_STRUCTURE_TYPE:
078                return visitor.processRemoveProducer((ProducerId)objectId);
079            default:
080                throw new IOException("Unknown remove command type: " + objectId.getDataStructureType());
081            }
082        }
083    
084        /**
085         * Returns true if this event is for a removed connection
086         */
087        public boolean isConnectionRemove() {
088            return objectId.getDataStructureType() == ConnectionId.DATA_STRUCTURE_TYPE;
089        }
090    
091        /**
092         * Returns true if this event is for a removed session
093         */
094        public boolean isSessionRemove() {
095            return objectId.getDataStructureType() == SessionId.DATA_STRUCTURE_TYPE;
096        }
097    
098        /**
099         * Returns true if this event is for a removed consumer
100         */
101        public boolean isConsumerRemove() {
102            return objectId.getDataStructureType() == ConsumerId.DATA_STRUCTURE_TYPE;
103        }
104    
105        /**
106         * Returns true if this event is for a removed producer
107         */
108        public boolean isProducerRemove() {
109            return objectId.getDataStructureType() == ProducerId.DATA_STRUCTURE_TYPE;
110        }
111    
112    }