1 package org.enhydra.shark; 2 3 import org.enhydra.shark.api.client.wfbase.BaseException; 4 import org.enhydra.shark.api.client.wfservice.CacheAdministration; 5 import org.enhydra.shark.api.internal.caching.CacheMgr; 6 import org.enhydra.shark.api.internal.caching.ProcessCache; 7 import org.enhydra.shark.api.internal.caching.ResourceCache; 8 9 15 public class CacheAdmin implements CacheAdministration { 16 17 private String userId="Unknown"; 18 19 protected CacheAdmin () { 20 } 21 22 public void connect (String userId) { 23 this.userId=userId; 24 } 25 26 public int getProcessCacheSize () throws BaseException { 27 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 28 if (mgr==null) { 29 throw new BaseException("Working without internal cache API implementation!"); 30 } 31 try { 32 return mgr.getProcessCache().getSize(); 33 } catch (Exception ex) { 34 throw new BaseException(ex); 35 } 36 } 37 38 public void setProcessCacheSize (int size) throws BaseException { 39 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 40 if (mgr==null) { 41 throw new BaseException("Working without internal cache API implementation!"); 42 } 43 try { 44 mgr.getProcessCache().setSize(size); 45 } catch (Exception ex) { 46 throw new BaseException(ex); 47 } 48 } 49 50 public int howManyCachedProcesses() throws BaseException { 51 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 52 if (mgr==null) { 53 throw new BaseException("Working without internal cache API implementation!"); 54 } 55 try { 56 return mgr.getProcessCache().howManyEntries(); 57 } catch (Exception ex) { 58 throw new BaseException(ex); 59 } 60 } 61 62 public void clearProcessCache () throws BaseException { 63 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 64 if (mgr==null) { 65 throw new BaseException("Working without internal cache API implementation!"); 66 } 67 try { 68 ProcessCache pc=mgr.getProcessCache(); 69 int size=pc.getSize(); 70 pc.setSize(0); 71 pc.setSize(size); 72 } catch (Exception ex) { 73 throw new BaseException(ex); 74 } 75 } 76 77 public int getResourceCacheSize () throws BaseException { 78 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 79 if (mgr==null) { 80 throw new BaseException("Working without internal cache API implementation!"); 81 } 82 try { 83 return mgr.getResourceCache().getSize(); 84 } catch (Exception ex) { 85 throw new BaseException(ex); 86 } 87 } 88 89 public void setResourceCacheSize (int size) throws BaseException { 90 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 91 if (mgr==null) { 92 throw new BaseException("Working without internal cache API implementation!"); 93 } 94 try { 95 mgr.getResourceCache().setSize(size); 96 } catch (Exception ex) { 97 throw new BaseException(ex); 98 } 99 } 100 101 public int howManyCachedResources () throws BaseException { 102 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 103 if (mgr==null) { 104 throw new BaseException("Working without internal cache API implementation!"); 105 } 106 try { 107 return mgr.getResourceCache().howManyEntries(); 108 } catch (Exception ex) { 109 throw new BaseException(ex); 110 } 111 } 112 113 public void clearResourceCache () throws BaseException { 114 CacheMgr mgr=SharkEngineManager.getInstance().getCacheManager(); 115 if (mgr==null) { 116 throw new BaseException("Working without internal cache API implementation!"); 117 } 118 try { 119 ResourceCache rc=mgr.getResourceCache(); 120 int size=rc.getSize(); 121 rc.setSize(0); 122 rc.setSize(size); 123 } catch (Exception ex) { 124 throw new BaseException(ex); 125 } 126 } 127 128 } 129 130 | Popular Tags |