1 16 package org.apache.cocoon.components.store.impl; 17 18 import org.apache.avalon.framework.activity.Disposable; 19 import org.apache.avalon.framework.component.Component; 20 import org.apache.avalon.framework.parameters.ParameterException; 21 import org.apache.avalon.framework.parameters.Parameterizable; 22 import org.apache.avalon.framework.parameters.Parameters; 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.avalon.framework.service.Serviceable; 26 27 import org.apache.cocoon.components.thread.RunnableManager; 28 29 37 public class CocoonStoreJanitor extends StoreJanitorImpl 38 implements Parameterizable, Serviceable, Disposable, Component { 39 40 42 43 private String threadPool; 44 45 46 private ServiceManager serviceManager; 47 48 49 private RunnableManager runnableManager; 50 51 52 private boolean m_firstRun = true; 53 54 55 private boolean m_secondRun = false; 56 57 59 public void parameterize(Parameters params) throws ParameterException { 60 super.parameterize(params); 61 this.threadPool = params.getParameter("thread-pool", "daemon"); 62 } 63 64 70 public void service(final ServiceManager serviceManager) 71 throws ServiceException { 72 this.serviceManager = serviceManager; 73 this.runnableManager = (RunnableManager) serviceManager.lookup(RunnableManager.ROLE); 74 } 75 76 79 public void dispose() { 80 this.serviceManager.release(this.runnableManager); 81 this.runnableManager = null; 82 this.serviceManager = null; 83 } 84 85 88 public void run() { 89 if (m_firstRun || m_secondRun) { 91 super.inUse = super.memoryInUse(); 92 m_secondRun = m_firstRun; 93 m_firstRun = false; 94 } 95 96 super.checkMemory(); 97 98 relaunch(super.interval); 100 } 101 102 106 public void start() { 107 relaunch(0); 108 } 109 110 116 private void relaunch(final long delay) { 117 getLogger().debug("(Re-)Start CocoonStoreJanitor"); 118 this.runnableManager.execute(this.threadPool, this, delay, 0); 119 } 120 } 121 | Popular Tags |