001 /** 002 * 003 * Copyright 2005 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * 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 **/ 018 package org.activemq.pool; 019 020 /** 021 * A cache key for the session details 022 * 023 * @version $Revision: 1.1 $ 024 */ 025 public class SessionKey { 026 private boolean transacted; 027 private int ackMode; 028 private int hash; 029 030 public SessionKey(boolean transacted, int ackMode) { 031 this.transacted = transacted; 032 this.ackMode = ackMode; 033 hash = ackMode; 034 if (transacted) { 035 hash = 31 * hash + 1; 036 } 037 } 038 039 public int hashCode() { 040 return hash; 041 } 042 043 public boolean equals(Object that) { 044 if (this == that) { 045 return true; 046 } 047 if (that instanceof SessionKey) { 048 return equals((SessionKey) that); 049 } 050 return false; 051 } 052 053 public boolean equals(SessionKey that) { 054 return this.transacted == that.transacted && this.ackMode == that.ackMode; 055 } 056 057 public boolean isTransacted() { 058 return transacted; 059 } 060 061 public int getAckMode() { 062 return ackMode; 063 } 064 }