1 package org.apache.jcs.auxiliary.lateral;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheManager;
25 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheObserver;
26 import org.apache.jcs.auxiliary.lateral.behavior.ILateralCacheService;
27 import org.apache.jcs.engine.behavior.ICacheRestore;
28
29 /***
30 * Used to repair the lateral caches managed by the associated instance of
31 * LateralCacheManager.
32 *
33 */
34 public class LateralCacheRestore
35 implements ICacheRestore
36 {
37 private final static Log log = LogFactory.getLog( LateralCacheRestore.class );
38
39 private final ILateralCacheManager lcm;
40
41 private boolean canFix = true;
42
43 private Object lateralObj;
44
45 /***
46 * Constructs with the given instance of LateralCacheManager.
47 *
48 * @param lcm
49 */
50 public LateralCacheRestore( ILateralCacheManager lcm )
51 {
52 this.lcm = lcm;
53 }
54
55 /***
56 * Returns true iff the connection to the lateral host for the corresponding
57 * cache manager can be successfully re-established.
58 *
59 * @return whether or not the cache can be fixed.
60 */
61 public boolean canFix()
62 {
63 if ( !canFix )
64 {
65 return canFix;
66 }
67
68 try
69 {
70 lateralObj = lcm.fixService();
71 }
72 catch ( Exception ex )
73 {
74 log.error( "Can't fix " + ex.getMessage() );
75 canFix = false;
76 }
77
78 return canFix;
79 }
80
81 /***
82 * Fixes up all the caches managed by the associated cache manager.
83 */
84 public void fix()
85 {
86 if ( !canFix )
87 {
88 return;
89 }
90 lcm.fixCaches( (ILateralCacheService) lateralObj, (ILateralCacheObserver) lateralObj );
91 String msg = "Lateral connection resumed.";
92 log.info( msg );
93 log.debug( msg );
94 }
95 }