001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.types; 028 029 030 031 import org.opends.server.api.Backend; 032 033 034 035 /** 036 * This class defines a Directory Server cache entry, which is simply 037 * used to store an entry with its associated backend and entry ID. 038 */ 039 @org.opends.server.types.PublicAPI( 040 stability=org.opends.server.types.StabilityLevel.VOLATILE, 041 mayInstantiate=true, 042 mayExtend=false, 043 mayInvoke=true, 044 notes="This should only be used within a backend") 045 public final class CacheEntry 046 { 047 // The backend with which this cache entry is associated. 048 private Backend backend; 049 050 // The entry itself. 051 private Entry entry; 052 053 // The entry ID for the entry within the backend. 054 private long entryID; 055 056 057 058 /** 059 * Creates a new cache entry with the provided information. 060 * 061 * @param entry The entry for this cache entry. 062 * @param backend The backend for this cache entry. 063 * @param entryID The entry ID for this cache entry. 064 */ 065 public CacheEntry(Entry entry, Backend backend, long entryID) 066 { 067 this.entry = entry; 068 this.backend = backend; 069 this.entryID = entryID; 070 } 071 072 073 074 /** 075 * Retrieves the entry for this cache entry. 076 * 077 * @return The entry for this cache entry. 078 */ 079 public Entry getEntry() 080 { 081 return entry; 082 } 083 084 085 086 /** 087 * Specifies the entry for this cache entry. 088 * 089 * @param entry The entry for this cache entry. 090 */ 091 public void setEntry(Entry entry) 092 { 093 this.entry = entry; 094 } 095 096 097 098 /** 099 * Retrieves the backend for this cache entry. 100 * 101 * @return The backend for this cache entry. 102 */ 103 public Backend getBackend() 104 { 105 return backend; 106 } 107 108 109 110 /** 111 * Specifies the backend for this cache entry. 112 * 113 * @param backend The backend for this cache entry. 114 */ 115 public void setBackend(Backend backend) 116 { 117 this.backend = backend; 118 } 119 120 121 122 /** 123 * Retrieves the entry ID for this cache entry. 124 * 125 * @return The entry ID for this cache entry. 126 */ 127 public long getEntryID() 128 { 129 return entryID; 130 } 131 132 133 134 /** 135 * Specifies the entry ID for this cache entry. 136 * 137 * @param entryID The entryID for this cache entry. 138 */ 139 public void setEntryID(long entryID) 140 { 141 this.entryID = entryID; 142 } 143 144 145 146 /** 147 * Retrieves the DN for this cache entry. 148 * 149 * @return The DN for this cache entry. 150 */ 151 public DN getDN() 152 { 153 return entry.getDN(); 154 } 155 156 157 158 /** 159 * Retrieves the hash code for this cache entry. It will be the 160 * integer representation of the entry ID. 161 * 162 * @return The hash code for this cache entry. 163 */ 164 public int hashCode() 165 { 166 return (int) entryID; 167 } 168 169 170 171 /** 172 * Indicates whether this cache entry is equal to the provided \ 173 * object. They will be considered equal if the provided object is 174 * a cache entry with the same entry and entry ID. 175 * 176 * @param o The object for which to make the determination. 177 * 178 * @return <CODE>true</CODE> if the provided object is equal to 179 * this cache entry, or <CODE>false</CODE> if not. 180 */ 181 public boolean equals(Object o) 182 { 183 if (o == null) 184 { 185 return false; 186 } 187 188 if (o == this) 189 { 190 return true; 191 } 192 193 if (! (o instanceof CacheEntry)) 194 { 195 return false; 196 } 197 198 CacheEntry e = (CacheEntry) o; 199 return ((e.entryID == entryID) && (e.entry.equals(entry))); 200 } 201 } 202