01: /*
02: * Copyright (C) The Apache Software Foundation. All rights reserved.
03: *
04: * This software is published under the terms of the Apache Software License
05: * version 1.1, a copy of which has been included with this distribution in
06: * the LICENSE file.
07: */
08: package org.jivesoftware.util.log.output.io.rotate;
09:
10: import java.io.File;
11:
12: /**
13: * Hierarchical Rotation stragety.
14: * This object is initialised with several rotation strategy objects.
15: * The <code>isRotationNeeded</code> method checks the first rotation
16: * strategy object. If a rotation is needed, this result is returned.
17: * If not the next rotation strategy object is asked and so on.
18: *
19: * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
20: */
21: public class OrRotateStrategy implements RotateStrategy {
22: private RotateStrategy[] m_strategies;
23:
24: /**
25: * The rotation strategy used. This marker is required for the reset()
26: * method.
27: */
28: private int m_usedRotation = -1;
29:
30: /**
31: * Constructor
32: */
33: public OrRotateStrategy(final RotateStrategy[] strategies) {
34: this .m_strategies = strategies;
35: }
36:
37: /**
38: * reset.
39: */
40: public void reset() {
41: if (-1 != m_usedRotation) {
42: m_strategies[m_usedRotation].reset();
43: m_usedRotation = -1;
44: }
45: }
46:
47: /**
48: * check if now a log rotation is neccessary.
49: * This object is initialised with several rotation strategy objects.
50: * The <code>isRotationNeeded</code> method checks the first rotation
51: * strategy object. If a rotation is needed, this result is returned.
52: * If not the next rotation strategy object is asked and so on.
53: *
54: * @param data the last message written to the log system
55: * @return boolean return true if log rotation is neccessary, else false
56: */
57: public boolean isRotationNeeded(final String data, final File file) {
58: m_usedRotation = -1;
59:
60: if (null != m_strategies) {
61: final int length = m_strategies.length;
62: for (int i = 0; i < length; i++) {
63: if (true == m_strategies[i]
64: .isRotationNeeded(data, file)) {
65: m_usedRotation = i;
66: return true;
67: }
68: }
69: }
70:
71: return false;
72: }
73: }
|