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.transport.stomp; 018 019import org.apache.activemq.command.MessageAck; 020import org.apache.activemq.command.MessageDispatch; 021import org.apache.activemq.command.MessageId; 022import org.apache.activemq.command.TransactionId; 023 024/** 025 * Tracker object for Messages that carry STOMP v1.2 ACK IDs 026 */ 027public class StompAckEntry { 028 029 private final String ackId; 030 private final MessageId messageId; 031 private final StompSubscription subscription; 032 private final MessageDispatch dispatch; 033 034 public StompAckEntry(MessageDispatch dispatch, String ackId, StompSubscription subscription) { 035 this.messageId = dispatch.getMessage().getMessageId(); 036 this.subscription = subscription; 037 this.ackId = ackId; 038 this.dispatch = dispatch; 039 } 040 041 public MessageAck onMessageAck(TransactionId transactionId) { 042 return subscription.onStompMessageAck(messageId.toString(), transactionId); 043 } 044 045 public MessageAck onMessageNack(TransactionId transactionId) throws ProtocolException { 046 return subscription.onStompMessageNack(messageId.toString(), transactionId); 047 } 048 049 public MessageId getMessageId() { 050 return this.messageId; 051 } 052 053 public MessageDispatch getMessageDispatch() { 054 return this.dispatch; 055 } 056 057 public String getAckId() { 058 return this.ackId; 059 } 060 061 public StompSubscription getSubscription() { 062 return this.subscription; 063 } 064 065 @Override 066 public String toString() { 067 return "AckEntry[ msgId:" + messageId + ", ackId:" + ackId + ", sub:" + subscription + " ]"; 068 } 069 070 @Override 071 public int hashCode() { 072 final int prime = 31; 073 int result = 1; 074 result = prime * result + ((messageId == null) ? 0 : messageId.hashCode()); 075 return result; 076 } 077 078 @Override 079 public boolean equals(Object obj) { 080 if (this == obj) { 081 return true; 082 } 083 if (obj == null) { 084 return false; 085 } 086 if (getClass() != obj.getClass()) { 087 return false; 088 } 089 090 StompAckEntry other = (StompAckEntry) obj; 091 if (messageId == null) { 092 if (other.messageId != null) { 093 return false; 094 } 095 } else if (!messageId.equals(other.messageId)) { 096 return false; 097 } 098 099 return true; 100 } 101}