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