1 24 package org.objectweb.jalisto.se.jmx; 25 26 import org.objectweb.jalisto.se.impl.server.oid.OidTableImpl; 27 import org.objectweb.jalisto.se.api.internal.SessionInternal; 28 import org.objectweb.jalisto.se.api.cache.JalistoCache; 29 30 import javax.management.*; 31 import java.util.Map ; 32 33 public class CacheAdmin extends JalistoAbstractDynamicMBean { 34 35 public CacheAdmin(String propertiesPath) { 36 this.propertiesPath = propertiesPath; 37 this.provider = SessionProvider.getInstance(); 38 } 39 40 41 public int getOidTableCurrentSize() throws MBeanException { 42 try { 43 SessionInternal session = provider.getSessionForMbean(propertiesPath); 44 OidTableImpl oidTable = (OidTableImpl) session.getOidTable(); 45 return oidTable.getTransactionalSize(session.getSessionId()); 46 } catch (Exception e) { 47 throw new MBeanException(e, "failed to get OidTableCurrentSize"); 48 } 49 } 50 51 public int getOidTableMaxSize() throws MBeanException { 52 try { 53 SessionInternal session = provider.getSessionForMbean(propertiesPath); 54 OidTableImpl oidTable = (OidTableImpl) session.getOidTable(); 55 return oidTable.getOidTableSize(); 56 } catch (Exception e) { 57 throw new MBeanException(e, "failed to get OidTableMaxSize"); 58 } 59 } 60 61 public int getPageCacheCurrentSize() throws MBeanException { 62 try { 63 SessionInternal session = provider.getSessionForMbean(propertiesPath); 64 return session.getFileAccess().getPhysicalAccess().getBaseImage().getReadObjects().size(); 65 } catch (Exception e) { 66 throw new MBeanException(e, "failed to get PageCacheCurrentSize"); 67 } 68 } 69 70 public int getPageCacheMaxSize() throws MBeanException { 71 try { 72 SessionInternal session = provider.getSessionForMbean(propertiesPath); 73 Map map = session.getFileAccess().getPhysicalAccess().getBaseImage().getReadObjects(); 74 if (map instanceof JalistoCache) { 75 return ((JalistoCache) map).getMaxSize(); 76 } else { 77 return -1; 78 } 79 } catch (Exception e) { 80 throw new MBeanException(e, "failed to get OidTableMaxSize"); 81 } 82 } 83 84 public void setOidTableMaxSize(int size) throws MBeanException { 85 try { 86 SessionInternal session = provider.getSessionForMbean(propertiesPath); 87 OidTableImpl oidTable = (OidTableImpl) session.getOidTable(); 88 oidTable.setOidTableSize(size); 89 } catch (Exception e) { 90 throw new MBeanException(e, "failed to set OidTableMaxSize"); 91 } 92 } 93 94 public void setPageCacheMaxSize(int size) throws MBeanException { 95 try { 96 SessionInternal session = provider.getSessionForMbean(propertiesPath); 97 Map map = session.getFileAccess().getPhysicalAccess().getBaseImage().getReadObjects(); 98 if (map instanceof JalistoCache) { 99 ((JalistoCache) map).setMaxSize(size); 100 } 101 } catch (Exception e) { 102 throw new MBeanException(e, "failed to set PageCacheMaxSize"); 103 } 104 } 105 106 public boolean getKeepInMemory() throws MBeanException { 107 try { 108 SessionInternal session = provider.getSessionForMbean(propertiesPath); 109 return session.getFileAccess().getPhysicalAccess().getBaseImage().isKeepInMemory(); 110 } catch (Exception e) { 111 throw new MBeanException(e, "failed to get KeepInMemory"); 112 } 113 } 114 115 public void setKeepInMemory(boolean keep) throws MBeanException { 116 try { 117 SessionInternal session = provider.getSessionForMbean(propertiesPath); 118 session.getFileAccess().getPhysicalAccess().getBaseImage().setKeepInMemory(keep); 119 } catch(Exception e) { 120 throw new MBeanException(e, "failed to set KeepInMemory"); 121 } 122 } 123 124 125 126 127 public MBeanInfo getMBeanInfo() { 128 if (infos == null) { 129 MBeanAttributeInfo[] attributesInfos = new MBeanAttributeInfo[5]; 130 attributesInfos[0] = new MBeanAttributeInfo( 131 "OidTableCurrentSize", 132 "java.lang.Integer", 133 "Number of page used in oid table's cache.", 134 true, 135 false, 136 false); 137 attributesInfos[1] = new MBeanAttributeInfo( 138 "OidTableMaxSize", 139 "java.lang.Integer", 140 "Maximum size of oid table's cache.", 141 true, 142 true, 143 false); 144 attributesInfos[2] = new MBeanAttributeInfo( 145 "PageCacheCurrentSize", 146 "java.lang.Integer", 147 "Number of page used in page cache.", 148 true, 149 false, 150 false); 151 attributesInfos[3] = new MBeanAttributeInfo( 152 "PageCacheMaxSize", 153 "java.lang.Integer", 154 "Maximum size of page cache.", 155 true, 156 true, 157 false); 158 attributesInfos[4] = new MBeanAttributeInfo( 159 "KeepInMemory", 160 "java.lang.Boolean", 161 "Tell if readed page are keep in memory after commit or rollback.", 162 true, 163 true, 164 false); 165 166 infos = new MBeanInfo(this.getClass().getName(), 167 "Administration MBean to watch caches used by Jalisto", 168 attributesInfos, 169 new MBeanConstructorInfo[0], 170 new MBeanOperationInfo[0], 171 new MBeanNotificationInfo[0]); 172 } 173 return infos; 174 } 175 176 protected Object internalGetAttribute(String attributeName) 177 throws AttributeNotFoundException, MBeanException, ReflectionException { 178 if (attributeName.equals("OidTableCurrentSize")) { 179 return new Integer (getOidTableCurrentSize()); 180 } 181 if (attributeName.equals("OidTableMaxSize")) { 182 return new Integer (getOidTableMaxSize()); 183 } 184 if (attributeName.equals("PageCacheCurrentSize")) { 185 return new Integer (getPageCacheCurrentSize()); 186 } 187 if (attributeName.equals("PageCacheMaxSize")) { 188 return new Integer (getPageCacheMaxSize()); 189 } 190 if (attributeName.equals("KeepInMemory")) { 191 return new Boolean (getKeepInMemory()); 192 } 193 194 throw(new AttributeNotFoundException( 195 "Cannot find " + attributeName + " attribute in " + this.getClass().getName())); 196 } 197 198 protected boolean internalSetAttribute(String name, Object value) 199 throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { 200 if (name.equals("OidTableCurrentSize")) { 201 throw(new AttributeNotFoundException( 202 "Cannot set attribute " + name + " because it is read-only")); 203 } else if (name.equals("OidTableMaxSize")) { 204 setOidTableMaxSize(((Integer )value).intValue()); 205 return true; 206 } else if (name.equals("PageCacheCurrentSize")) { 207 throw(new AttributeNotFoundException( 208 "Cannot set attribute " + name + " because it is read-only")); 209 } else if (name.equals("PageCacheMaxSize")) { 210 setPageCacheMaxSize(((Integer )value).intValue()); 211 return true; 212 } else if (name.equals("KeepInMemory")) { 213 setKeepInMemory(((Boolean )value).booleanValue()); 214 return true; 215 } 216 return false; 217 } 218 219 protected Object internalInvoke(String operationName, Object [] params, String [] signature) 220 throws MBeanException, ReflectionException { 221 throw new ReflectionException(new NoSuchMethodException (operationName), 222 "Cannot find the operation " + operationName + 223 " in " + this.getClass().getName()); 224 } 225 226 227 private MBeanInfo infos; 228 private String propertiesPath; 229 private SessionProvider provider; 230 } 231 | Popular Tags |