001    /*
002     * Copyright 2011 The Kuali Foundation.
003     * 
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     * 
008     * http://www.opensource.org/licenses/ecl2.php
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.kfs.sys.batch.service.impl;
017    
018    import java.util.List;
019    
020    import org.kuali.kfs.sys.batch.service.CacheService;
021    import org.kuali.kfs.sys.service.NonTransactional;
022    import org.kuali.rice.kew.service.KEWServiceLocator;
023    import org.kuali.rice.kim.service.IdentityManagementService;
024    import org.kuali.rice.kim.service.RoleManagementService;
025    import org.kuali.rice.kns.lookup.keyvalues.CampusValuesFinder;
026    import org.kuali.rice.kns.service.ParameterService;
027    
028    import com.opensymphony.oscache.general.GeneralCacheAdministrator;
029    
030    /**
031     * @see org.kuali.kfs.sys.batch.service.CacheService
032     */
033    @NonTransactional
034    public class CacheServiceImpl implements CacheService {
035        private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CacheServiceImpl.class);
036    
037        private List<GeneralCacheAdministrator> cacheAdminstrators;
038        private RoleManagementService roleManagementService;
039        private IdentityManagementService identityManagementService;
040        private ParameterService parameterService;
041    
042        /**
043         * @see org.kuali.kfs.sys.batch.service.CacheService#clearSystemCache()
044         */
045        public void clearSystemCache() {
046            clearMethodCache();
047            clearKIMCache();
048            clearParameterCache();
049            new CampusValuesFinder().clearInternalCache();
050        }
051    
052        /**
053         * Clears out service methods cache by calling adminstrators flushAll
054         */
055        protected void clearMethodCache() {
056            LOG.info("clearing spring method cache ...");
057    
058            if (cacheAdminstrators != null) {
059                for (GeneralCacheAdministrator cache : cacheAdminstrators) {
060                    cache.flushAll();
061                }
062            }
063        }
064    
065        /**
066         * Clears out KIM cache by calling flush methods on role and identity services
067         */
068        protected void clearKIMCache() {
069            LOG.info("clearing KIM role & identity service cache ...");
070    
071            roleManagementService.flushRoleCaches();
072            identityManagementService.flushAllCaches();
073            KEWServiceLocator.getCacheAdministrator().flushGroup("ResponsibilityImpl");
074        }
075    
076        /**
077         * Clears out parameter cache by calling flush method on parameter service
078         */
079        protected void clearParameterCache() {
080            LOG.info("clearing parameter cache ...");
081    
082            parameterService.clearCache();
083        }
084    
085        /**
086         * Gets the cacheAdminstrators attribute.
087         * 
088         * @return Returns the cacheAdminstrators.
089         */
090        protected List<GeneralCacheAdministrator> getCacheAdminstrators() {
091            return cacheAdminstrators;
092        }
093    
094        /**
095         * Sets the cacheAdminstrators attribute value.
096         * 
097         * @param cacheAdminstrators The cacheAdminstrators to set.
098         */
099        public void setCacheAdminstrators(List<GeneralCacheAdministrator> cacheAdminstrators) {
100            this.cacheAdminstrators = cacheAdminstrators;
101        }
102    
103        /**
104         * Gets the roleManagementService attribute.
105         * 
106         * @return Returns the roleManagementService.
107         */
108        protected RoleManagementService getRoleManagementService() {
109            return roleManagementService;
110        }
111    
112        /**
113         * Sets the roleManagementService attribute value.
114         * 
115         * @param roleManagementService The roleManagementService to set.
116         */
117        public void setRoleManagementService(RoleManagementService roleManagementService) {
118            this.roleManagementService = roleManagementService;
119        }
120    
121        /**
122         * Gets the identityManagementService attribute.
123         * 
124         * @return Returns the identityManagementService.
125         */
126        protected IdentityManagementService getIdentityManagementService() {
127            return identityManagementService;
128        }
129    
130        /**
131         * Sets the identityManagementService attribute value.
132         * 
133         * @param identityManagementService The identityManagementService to set.
134         */
135        public void setIdentityManagementService(IdentityManagementService identityManagementService) {
136            this.identityManagementService = identityManagementService;
137        }
138    
139        /**
140         * Gets the parameterService attribute.
141         * 
142         * @return Returns the parameterService.
143         */
144        protected ParameterService getParameterService() {
145            return parameterService;
146        }
147    
148        /**
149         * Sets the parameterService attribute value.
150         * 
151         * @param parameterService The parameterService to set.
152         */
153        public void setParameterService(ParameterService parameterService) {
154            this.parameterService = parameterService;
155        }
156    }