1 19 package org.fjank.jcache; 20 21 import java.text.SimpleDateFormat ; 22 import java.util.Date ; 23 import javax.util.jcache.Attributes; 24 import javax.util.jcache.CacheObjectInfo; 25 26 27 33 final class CacheObjectInfoImpl implements CacheObjectInfo { 34 35 private final int refCount; 36 37 38 private final int accesses; 39 40 41 private long expires; 42 43 44 private String group; 45 46 49 50 private String type; 51 52 53 private final Object name; 54 55 58 59 private Object region; 60 61 66 CacheObjectInfoImpl(final CacheObject object) { 67 CacheGroup ownerGroup = object.getGroup(); 68 if ((ownerGroup != null) && (ownerGroup.getName() != null)) { 69 this.group = ownerGroup.getName().toString(); 70 } 71 this.name = object.getKey(); 72 Attributes attribs = object.getAttributes(); 73 if (attribs != null) { 74 long TTL = attribs.getTimeToLive(); 75 this.expires = TTL>0 ? TTL * 1000 + attribs.getCreateTime() 76 : -1; 77 78 } 80 this.accesses = object.getAccesses(); 81 this.refCount = object.getRefCount(); 82 this.region = object.getRegion(); 83 this.type = "Memory object"; 84 } 85 86 91 public String getRegion() { 92 return ((region != null) ? region.toString() : "Default region"); 93 } 94 95 100 public String getName() { 101 return name.toString(); 102 } 103 104 110 public String getType() { 111 return type; 112 } 113 114 119 public String getGroup() { 120 return ((group != null) ? group : ""); 121 } 122 123 128 public int getRefCount() { 129 return refCount; 130 } 131 132 137 public int getAccesses() { 138 return accesses; 139 } 140 141 146 public String getExpire() { 147 if(expires!=-1) { 148 SimpleDateFormat form = new SimpleDateFormat ("EEE MMM dd HH:mm:ss zzz yyyy"); 149 Date date = new Date (expires); 150 return form.format(date); 151 } 152 return NEVER_EXPIRES; 153 } 154 155 160 public String toString() { 161 StringBuffer ret = new StringBuffer ("name:" + getName()); 162 ret.append(", region:" + getRegion()); 163 ret.append(", type:" + getType()); 164 if (!getGroup().equals("")) { 165 ret.append(", group:" + getGroup()); 166 } 167 ret.append(", refCount:" + getRefCount()); 168 ret.append(", accesses:" + getAccesses()); 169 ret.append(", expires:" + getExpire()); 170 return ret.toString(); 171 } 172 } 173 | Popular Tags |