1 24 package org.objectweb.jalisto.se.storage.raf.log.asynraf; 25 26 import org.objectweb.jalisto.se.exception.JalistoException; 27 import org.objectweb.jalisto.se.impl.trace.Trace; 28 29 import java.util.List ; 30 31 public class LogDemon implements Runnable { 32 public LogDemon(AsynrafLogger minilog, PhysicalFileAccessLogAsynrafImpl physical) { 33 this.minilog = minilog; 34 this.physical = physical; 35 trace = physical.getTrace(); 36 } 37 38 public void run() { 39 while (!mustClose) { 40 try { 41 Thread.yield(); 42 if (isWorking) { 43 List list = minilog.getSortedInfos(); 44 if (!list.isEmpty()) { 45 while (!list.isEmpty()) { 46 LogInfo info = (LogInfo) list.remove(0); 47 if ((!list.isEmpty()) && (info.toString().equals(list.get(0).toString()))) { 48 throw new JalistoException("pbm during test"); 49 } 50 short type = info.getActionType(); 51 if (type == LogInfo.INSERT_TYPE) { 52 byte[] datas = minilog.readBytes(info.getValueAddress(), 53 (int) info.getValueLength()); 54 physical.internalInsert(info.getIfa(), datas); 55 } else if (type == LogInfo.UPDATE_TYPE) { 56 byte[] datas = minilog.readBytes(info.getValueAddress(), 57 (int) info.getValueLength()); 58 physical.internalUpdateFileObject(info.getIfa(), datas); 59 } else if (type == LogInfo.DELETE_TYPE) { 60 physical.internalDeleteFileObject(info.getIfa()); 61 } else { 62 throw new JalistoException("unknow action type : " + type); 63 } 64 minilog.removeInfo(info); 65 } 66 minilog.setLength(2); 67 minilog.writeStatus(AsynrafLogger.NOBODY_WORKING); 68 isWorking = false; 69 } else { 70 if (isWorking) { 71 isWorking = false; 72 } 73 } 74 } 75 } catch (Exception e) { 76 isWorking = false; 77 throw new JalistoException(e); 78 } 79 } 80 } 81 82 public boolean isWorking() { 83 return isWorking; 84 } 85 86 public void setWorking() { 87 isWorking = true; 88 } 89 90 public void open() { 91 mustClose = false; 92 demon = new Thread (this); 93 demon.start(); 94 } 95 96 public void close() { 97 mustClose = true; 98 while (demon.isAlive()) { 99 Thread.yield(); 100 } 101 demon = null; 102 } 103 104 private PhysicalFileAccessLogAsynrafImpl physical; 105 private AsynrafLogger minilog; 106 private Trace trace; 107 private boolean mustClose = false; 108 private boolean isWorking = false; 109 private Thread demon; 110 } 111 | Popular Tags |