1 23 24 package com.sun.ejb.base.sfsb; 25 26 import java.util.ArrayList ; 27 28 import java.io.File ; 29 30 import java.util.logging.*; 31 import com.sun.logging.*; 32 33 import com.sun.ejb.spi.sfsb.SFSBUUIDUtil; 34 import com.sun.ejb.spi.container.ContainerService; 35 36 import com.sun.ejb.containers.ContainerFactoryImpl; 37 38 39 42 43 public class PersistentFileStoreManager 44 extends AbstractFileStoreManager 45 { 46 private SFSBUUIDUtil uuidGenerator; 47 48 51 public PersistentFileStoreManager() { 52 } 53 54 protected void onInitialization() { 55 56 try { 57 uuidGenerator = new SimpleKeyGenerator(); 58 59 if (baseDir.isDirectory()) { 60 String [] fileNames = baseDir.list(); 61 _logger.log(Level.FINE, storeManagerName 62 + "; removing: " + fileNames.length + " sessions"); 63 64 removeExpiredPassivatedSessions(fileNames); 65 } 66 } catch (Exception ex) { 67 _logger.log(Level.WARNING, "ejb.sfsb_persistmgr_oninit_failed", 68 new Object [] {storeManagerName}); 69 _logger.log(Level.WARNING, "ejb.sfsb_persistmgr_oninit_failed_exception", ex); 70 } 71 } 72 73 public SFSBUUIDUtil getUUIDUtil() { 74 return uuidGenerator; 75 } 76 77 public void shutdown() { 78 super.shutdown(); 79 } 80 81 private void removeExpiredPassivatedSessions(String [] fileNames) { 82 if (fileNames.length > 0) { 83 AsyncFileRemovalTask task = new AsyncFileRemovalTask( 84 this, fileNames); 85 try { 86 ContainerService service = ContainerFactoryImpl.getContainerService(); 87 88 service.scheduleWork(super.getClassLoader(), task); 91 } catch (Throwable th) { 92 94 _logger.log(Level.FINE, storeManagerName 95 + ": Cannot execute file removal aynchronously", th); 96 97 task.run(); } 100 } 101 } 102 103 private static class AsyncFileRemovalTask 104 implements Runnable 105 { 106 AbstractFileStoreManager storeManager; 107 String [] fileNames; 108 109 AsyncFileRemovalTask(AbstractFileStoreManager manager, 110 String [] fileNames) 111 { 112 this.storeManager = manager; 113 this.fileNames = fileNames; 114 } 115 116 public void run() { 117 try { 118 int sz = fileNames.length; 119 for (int i=0; i<sz; i++) { 120 storeManager.remove(fileNames[i]); 121 } 122 } catch (Exception ex) { 123 _logger.log(Level.FINE, "Error while removing expired " 124 + "file during startup", ex); 125 } 126 } 127 } 128 } 129 | Popular Tags |