001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.axis2;
019
020 import java.util.Timer;
021 import java.util.TimerTask;
022
023 import org.apache.commons.logging.Log;
024 import org.apache.commons.logging.LogFactory;
025 import org.apache.geronimo.gbean.GBeanInfo;
026 import org.apache.geronimo.gbean.GBeanInfoBuilder;
027 import org.apache.geronimo.gbean.GBeanLifecycle;
028 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
029
030 import org.apache.axis2.jaxws.description.impl.DescriptionFactoryImpl;
031
032 public class ClearCacheGBean implements GBeanLifecycle {
033
034 private static final Log LOG = LogFactory.getLog(ClearCacheGBean.class);
035
036 private Timer timer;
037 private long period;
038
039 public ClearCacheGBean(long period) {
040 this.period = period;
041 }
042
043 public void doStart() throws Exception {
044 if (timer == null) {
045 timer = new Timer(true);
046 }
047 timer.schedule(new ClearCacheTask(), 0, this.period);
048 }
049
050 public void doStop() throws Exception {
051 if (timer != null) {
052 timer.cancel();
053 timer = null;
054 }
055 }
056
057 public void doFail() {
058 }
059
060 private static class ClearCacheTask extends TimerTask {
061 public void run() {
062 LOG.debug("Clearing Axis2 cache");
063 DescriptionFactoryImpl.clearServiceDescriptionCache();
064 }
065 }
066
067 public static final GBeanInfo GBEAN_INFO;
068
069 static {
070 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(ClearCacheGBean.class, NameFactory.GERONIMO_SERVICE);
071 infoBuilder.addAttribute("period", long.class, true, true);
072
073 infoBuilder.setConstructor(new String[]{
074 "period"
075 });
076
077 GBEAN_INFO = infoBuilder.getBeanInfo();
078 }
079
080 public static GBeanInfo getGBeanInfo() {
081 return GBEAN_INFO;
082 }
083 }