8080 * point contains information about CRL issuing and publishing parameters
8181 * as well as state information which includes last issued CRL, next CRL
8282 * serial number, time of the next update etc.
83+ *
8384 * If autoUpdateInterval is set to non-zero value then worker thread
8485 * is created that will perform CRL update at scheduled intervals. Update
8586 * can also be triggered by invoking updateCRL method directly. Another
8687 * parameter minUpdateInterval can be used to prevent CRL
8788 * from being updated too often
88- * <P>
8989 *
9090 * @author awnuk
9191 * @author lhsiao
9292 * @author galperin
93- * @version $Revision$, $Date$
9493 */
9594
96- public class CRLIssuingPoint implements Runnable {
95+ public class CRLIssuingPoint {
9796
9897 public static final org .slf4j .Logger logger = org .slf4j .LoggerFactory .getLogger (CRLIssuingPoint .class );
9998
@@ -151,7 +150,7 @@ public enum CRLIssuingPointStatus {
151150 /**
152151 * Enable CRL issuing point.
153152 */
154- private boolean mEnable = true ;
153+ boolean mEnable = true ;
155154
156155 /**
157156 * Description of the issuing point
@@ -175,7 +174,7 @@ public enum CRLIssuingPointStatus {
175174 /**
176175 * Enable CRL cache.
177176 */
178- private boolean mEnableCRLCache = true ;
177+ boolean mEnableCRLCache = true ;
179178 private boolean mCRLCacheIsCleared = true ;
180179 private boolean mEnableCacheRecovery = false ;
181180 private String mFirstUnsaved = null ;
@@ -184,18 +183,18 @@ public enum CRLIssuingPointStatus {
184183 /**
185184 * Last CRL cache update
186185 */
187- private long mLastCacheUpdate = 0 ;
186+ long mLastCacheUpdate = 0 ;
188187
189188 /**
190189 * Time interval in milliseconds between consequential CRL cache
191190 * updates performed automatically.
192191 */
193- private long mCacheUpdateInterval ;
192+ long mCacheUpdateInterval ;
194193
195194 /**
196195 * Enable CRL updates.
197196 */
198- private boolean mEnableCRLUpdates = true ;
197+ boolean mEnableCRLUpdates = true ;
199198
200199 /**
201200 * CRL update schema.
@@ -206,23 +205,23 @@ public enum CRLIssuingPointStatus {
206205 /**
207206 * Enable CRL daily updates at listed times.
208207 */
209- private boolean mEnableDailyUpdates = false ;
210- private Vector <Vector <Integer >> mDailyUpdates = null ;
208+ boolean mEnableDailyUpdates = false ;
209+ Vector <Vector <Integer >> mDailyUpdates = null ;
211210 private int mCurrentDay = 0 ;
212211 private int mLastDay = 0 ;
213- private int mTimeListSize = 0 ;
212+ int mTimeListSize = 0 ;
214213 private boolean mExtendedTimeList = false ;
215214
216215 /**
217216 * Enable CRL auto update with interval
218217 */
219- private boolean mEnableUpdateFreq = false ;
218+ boolean mEnableUpdateFreq = false ;
220219
221220 /**
222221 * Time interval in milliseconds between consequential CRL Enable CRL daily update at updates
223222 * performed automatically.
224223 */
225- private long mAutoUpdateInterval ;
224+ long mAutoUpdateInterval ;
226225
227226 /**
228227 * Minimum time interval in milliseconds between consequential
@@ -243,14 +242,14 @@ public enum CRLIssuingPointStatus {
243242 /**
244243 * time to wait at the next loop if exception happens during CRL generation
245244 */
246- private long mUnexpectedExceptionWaitTime ;
245+ long mUnexpectedExceptionWaitTime ;
247246
248247 /**
249248 * Max number allowed to loop if exception happens during CRL generation.
250249 * When mUnexpectedExceptionLoopMax is reached, a slow down procedure
251250 * will be executed
252251 */
253- private int mUnexpectedExceptionLoopMax ;
252+ int mUnexpectedExceptionLoopMax ;
254253
255254 /**
256255 * next update as this update extension
@@ -304,18 +303,17 @@ public enum CRLIssuingPointStatus {
304303 /**
305304 * Worker thread doing auto-update
306305 */
307- private Thread mUpdateThread = null ;
306+ Thread mUpdateThread ;
308307
309308 /**
310309 * for going one more round when auto-interval is set to 0 (turned off)
311310 */
312- private boolean mDoLastAutoUpdate = false ;
311+ boolean mDoLastAutoUpdate = false ;
313312
314313 /**
315314 * whether issuing point has been initialized.
316315 */
317- private CRLIssuingPointStatus mInitialized =
318- CRLIssuingPointStatus .NotInitialized ;
316+ CRLIssuingPointStatus mInitialized = CRLIssuingPointStatus .NotInitialized ;
319317
320318 /**
321319 * number of entries in the CRL
@@ -340,8 +338,8 @@ public enum CRLIssuingPointStatus {
340338
341339 private int mUpdatingCRL = CRL_UPDATE_DONE ;
342340
343- private boolean mDoManualUpdate = false ;
344- private String mSignatureAlgorithmForManualUpdate = null ;
341+ boolean mDoManualUpdate = false ;
342+ String mSignatureAlgorithmForManualUpdate ;
345343
346344 private boolean mPublishOnStart = false ;
347345 private long [] mSplits = new long [10 ];
@@ -920,7 +918,7 @@ protected void initConfig(CRLIssuingPointConfig config) throws EBaseException {
920918 * Do not call it from init(), because it will block CMS on start.
921919 * @throws EBaseException
922920 */
923- private void initCRL () throws EBaseException {
921+ void initCRL () throws EBaseException {
924922 CRLIssuingPointRecord crlRecord = null ;
925923
926924 mLastCacheUpdate = System .currentTimeMillis () + mCacheUpdateInterval ;
@@ -1616,7 +1614,9 @@ private synchronized void setAutoUpdates() {
16161614
16171615 logger .info (CMS .getLogMessage ("CMSCORE_CA_ISSUING_START_CRL" , mId ));
16181616
1619- mUpdateThread = new Thread (this , "CRLIssuingPoint-" + mId );
1617+ CRLIssuingPointUpdateTask task = new CRLIssuingPointUpdateTask (this );
1618+
1619+ mUpdateThread = new Thread (task , "CRLIssuingPoint-" + mId );
16201620 mUpdateThread .setDaemon (true );
16211621 mUpdateThread .start ();
16221622 }
@@ -1691,7 +1691,7 @@ public long getNextUpdateGracePeriod() {
16911691 * otherwise returns the next update time for CRL.
16921692 * @return delay to the next update time or the next update time itself
16931693 */
1694- private long findNextUpdate (boolean fromLastUpdate , boolean delta ) {
1694+ long findNextUpdate (boolean fromLastUpdate , boolean delta ) {
16951695 long now = System .currentTimeMillis ();
16961696
16971697 //If we have already created a future thisUpdate value, make "now" this time in the future.
@@ -1921,164 +1921,10 @@ private long findNextUpdate(boolean fromLastUpdate, boolean delta) {
19211921 return (fromLastUpdate ) ? next - now : next ;
19221922 }
19231923
1924- public void handleUnexpectedFailure (int loopCounter , long timeOfUnexpectedFailure ) {
1925-
1926- logger .info ("CRLIssuingPoint: Handling unexpected failure" );
1927- logger .info ("CRLIssuingPoint: - loop counter: " + loopCounter );
1928-
1929- if (loopCounter <= mUnexpectedExceptionLoopMax ) {
1930- logger .info ("CRLIssuingPoint: Max loop not reached, no wait time" );
1931- return ;
1932- }
1933-
1934- logger .info ("CRLIssuingPoint: Max loop reached, slowdown procedure ensues" );
1935-
1936- long now = System .currentTimeMillis ();
1937- logger .info ("CRLIssuingPoint: - now: " + now );
1938- logger .info ("CRLIssuingPoint: - time of unexpected failure: " + timeOfUnexpectedFailure );
1939-
1940- long timeLapse = now - timeOfUnexpectedFailure ;
1941- logger .info ("CRLIssuingPoint: - time lapse: " + timeLapse );
1942-
1943- long waitTime = mUnexpectedExceptionWaitTime - timeLapse ;
1944- logger .info ("CRLIssuingPoint: Wait time after last failure:" + waitTime );
1945-
1946- if (waitTime <= 0 ) {
1947- logger .info ("CRLIssuingPoint: No wait after failure" );
1948- return ;
1949- }
1950-
1951- logger .info ("CRLIssuingPoint: Waiting for " + waitTime + " ms" );
1952-
1953- try {
1954- wait (waitTime );
1955-
1956- } catch (InterruptedException e ) {
1957- logger .error ("CRLIssuingPoint: " + e .getMessage (), e );
1958- }
1959-
1960- // timeOfUnexpectedFailure will be reset again if it still fails
1961- }
1962-
1963- /**
1964- * Implements Runnable interface. Defines auto-update
1965- * logic used by worker thread.
1966- * <P>
1967- */
1968- @ Override
1969- public void run () {
1970- /*
1971- * mechnism to slow down the infinite loop when depending
1972- * components are not available: e.g. Directory server, HSM
1973- */
1974- boolean unexpectedFailure = false ;
1975- long timeOfUnexpectedFailure = 0 ;
1976- int loopCounter = 0 ;
1977-
1978- try {
1979- while (mEnable && ((mEnableCRLCache && mCacheUpdateInterval > 0 ) ||
1980- (mInitialized == CRLIssuingPointStatus .NotInitialized ) ||
1981- mDoLastAutoUpdate || (mEnableCRLUpdates &&
1982- ((mEnableDailyUpdates && mDailyUpdates != null &&
1983- mTimeListSize > 0 ) ||
1984- (mEnableUpdateFreq && mAutoUpdateInterval > 0 ) ||
1985- mDoManualUpdate )))) {
1986-
1987- synchronized (this ) {
1988- long delay = 0 ;
1989- long delay2 = 0 ;
1990- boolean doCacheUpdate = false ;
1991- boolean scheduledUpdates = mEnableCRLUpdates &&
1992- ((mEnableDailyUpdates && mDailyUpdates != null &&
1993- mTimeListSize > 0 ) ||
1994- (mEnableUpdateFreq && mAutoUpdateInterval > 0 ));
1995-
1996- if (mInitialized == CRLIssuingPointStatus .NotInitialized ) {
1997- initCRL ();
1998- }
1999-
2000- if ((mEnableCRLUpdates && mDoManualUpdate ) || mDoLastAutoUpdate ) {
2001- delay = 0 ;
2002- } else if (scheduledUpdates ) {
2003- delay = findNextUpdate (true , false );
2004- }
2005-
2006- if (mEnableCRLCache && mCacheUpdateInterval > 0 ) {
2007- delay2 = mLastCacheUpdate + mCacheUpdateInterval -
2008- System .currentTimeMillis ();
2009- if (delay2 < delay ||
2010- (!(scheduledUpdates || mDoLastAutoUpdate ||
2011- (mEnableCRLUpdates && mDoManualUpdate )))) {
2012- delay = delay2 ;
2013- if (delay <= 0 ) {
2014- doCacheUpdate = true ;
2015- mLastCacheUpdate = System .currentTimeMillis ();
2016- }
2017- }
2018- }
2019-
2020- if (delay > 0 ) {
2021- try {
2022- wait (delay );
2023- } catch (InterruptedException e ) {
2024- }
2025- } else {
2026- /*
2027- * handle last failure so we don't get into
2028- * non-delayed loop
2029- */
2030- if (unexpectedFailure ) {
2031- // it gets mUnexpectedExceptionLoopMax tries
2032- loopCounter ++;
2033- handleUnexpectedFailure (loopCounter , timeOfUnexpectedFailure );
2034- }
2035-
2036- logger .debug ("CRLIssuingPoint: Before CRL generation" );
2037- try {
2038- if (doCacheUpdate ) {
2039- logger .info ("CRLIssuingPoint: Updating CRL cache" );
2040- updateCRLCacheRepository ();
2041- } else if (mAutoUpdateInterval > 0 || mDoLastAutoUpdate || mDoManualUpdate ) {
2042- logger .info ("CRLIssuingPoint: Updating CRL" );
2043- updateCRL ();
2044- }
2045- // reset if no exception
2046- if (unexpectedFailure ) {
2047- logger .debug ("CRLIssuingPoint: reset unexpectedFailure values if no exception" );
2048- unexpectedFailure = false ;
2049- timeOfUnexpectedFailure = 0 ;
2050- loopCounter = 0 ;
2051- }
2052- } catch (Exception e ) {
2053- logger .warn ("CRLIssuingPoint: Unable to update " + (doCacheUpdate ? "CRL cache" : "CRL" ) + ": " + e .getMessage (), e );
2054- unexpectedFailure = true ;
2055- timeOfUnexpectedFailure = System .currentTimeMillis ();
2056- }
2057- // put this here to prevent continuous loop if internal
2058- // db is down.
2059- if (mDoLastAutoUpdate )
2060- logger .debug ("CRLIssuingPoint: mDoLastAutoUpdate set to false" );
2061- mDoLastAutoUpdate = false ;
2062- if (mDoManualUpdate ) {
2063- logger .debug ("CRLIssuingPoint: mDoManualUpdate set to false" );
2064- mDoManualUpdate = false ;
2065- mSignatureAlgorithmForManualUpdate = null ;
2066- }
2067- }
2068-
2069- }
2070- }
2071- } catch (EBaseException e1 ) {
2072- e1 .printStackTrace ();
2073- }
2074- logger .debug ("CRLIssuingPoint: out of the while loop" );
2075- mUpdateThread = null ;
2076- }
2077-
20781924 /**
20791925 * Updates CRL and publishes it.
20801926 */
2081- private void updateCRL () throws EBaseException {
1927+ void updateCRL () throws EBaseException {
20821928 if (mDoManualUpdate && mSignatureAlgorithmForManualUpdate != null ) {
20831929 logger .info ("CRLIssuingPoint: Updating CRL now with " + mSignatureAlgorithmForManualUpdate );
20841930 updateCRLNow (mSignatureAlgorithmForManualUpdate );
0 commit comments