%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jcs.auxiliary.lateral.LateralCacheRestore |
|
|
1 | package org.apache.jcs.auxiliary.lateral; |
|
2 | ||
3 | /* |
|
4 | * Licensed to the Apache Software Foundation (ASF) under one |
|
5 | * or more contributor license agreements. See the NOTICE file |
|
6 | * distributed with this work for additional information |
|
7 | * regarding copyright ownership. The ASF licenses this file |
|
8 | * to you under the Apache License, Version 2.0 (the |
|
9 | * "License"); you may not use this file except in compliance |
|
10 | * with the License. You may obtain a copy of the License at |
|
11 | * |
|
12 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
13 | * |
|
14 | * Unless required by applicable law or agreed to in writing, |
|
15 | * software distributed under the License is distributed on an |
|
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
|
17 | * KIND, either express or implied. See the License for the |
|
18 | * specific language governing permissions and limitations |
|
19 | * under the License. |
|
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 | 0 | private final static Log log = LogFactory.getLog( LateralCacheRestore.class ); |
38 | ||
39 | private final ILateralCacheManager lcm; |
|
40 | ||
41 | 0 | 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 | 0 | { |
52 | 0 | this.lcm = lcm; |
53 | 0 | } |
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 | 0 | if ( !canFix ) |
64 | { |
|
65 | 0 | return canFix; |
66 | } |
|
67 | ||
68 | try |
|
69 | { |
|
70 | 0 | lateralObj = lcm.fixService(); |
71 | } |
|
72 | 0 | catch ( Exception ex ) |
73 | { |
|
74 | 0 | log.error( "Can't fix " + ex.getMessage() ); |
75 | 0 | canFix = false; |
76 | 0 | } |
77 | ||
78 | 0 | return canFix; |
79 | } |
|
80 | ||
81 | /** |
|
82 | * Fixes up all the caches managed by the associated cache manager. |
|
83 | */ |
|
84 | public void fix() |
|
85 | { |
|
86 | 0 | if ( !canFix ) |
87 | { |
|
88 | 0 | return; |
89 | } |
|
90 | 0 | lcm.fixCaches( (ILateralCacheService) lateralObj, (ILateralCacheObserver) lateralObj ); |
91 | 0 | String msg = "Lateral connection resumed."; |
92 | 0 | log.info( msg ); |
93 | 0 | log.debug( msg ); |
94 | 0 | } |
95 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |