001/* 002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Anahide Tchertchian 016 */ 017package org.nuxeo.ecm.platform.ui.web.rest.services; 018 019import org.apache.commons.logging.Log; 020import org.apache.commons.logging.LogFactory; 021import org.nuxeo.ecm.platform.ui.web.rest.api.URLPolicyService; 022import org.nuxeo.runtime.api.Framework; 023import org.nuxeo.runtime.reload.ReloadEventNames; 024import org.nuxeo.runtime.services.event.Event; 025import org.nuxeo.runtime.services.event.EventListener; 026 027/** 028 * Event listener that flushes the {@link URLPolicyService} cache. 029 * 030 * @since 5.5 031 */ 032public class URLPolicyServiceCacheFlusher implements EventListener { 033 034 private static final Log log = LogFactory.getLog(URLPolicyServiceCacheFlusher.class); 035 036 @Override 037 public boolean aboutToHandleEvent(Event event) { 038 return false; 039 } 040 041 @Override 042 public void handleEvent(Event event) { 043 if (!Framework.isDevModeSet()) { 044 log.info("Do not flush the URL policy service: dev mode is not set"); 045 return; 046 } 047 if (!ReloadEventNames.FLUSH_EVENT_ID.equals(event.getId())) { 048 return; 049 } 050 Framework.getService(URLPolicyService.class).flushCache(); 051 } 052 053}