001 /**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one or more
004 * contributor license agreements. See the NOTICE file distributed with
005 * this work for additional information regarding copyright ownership.
006 * The ASF licenses this file to You under the Apache License, Version 2.0
007 * (the "License"); you may not use this file except in compliance with
008 * the License. You may obtain a copy of the License at
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018 package org.apache.geronimo.clustering.wadi;
019
020 import org.apache.geronimo.gbean.GBeanInfo;
021 import org.apache.geronimo.gbean.GBeanInfoBuilder;
022 import org.apache.geronimo.gbean.GBeanLifecycle;
023 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
024 import org.codehaus.wadi.replication.strategy.BackingStrategy;
025 import org.codehaus.wadi.replication.strategy.BackingStrategyFactory;
026 import org.codehaus.wadi.replication.strategy.RoundRobinBackingStrategyFactory;
027
028 /**
029 *
030 * @version $Rev$ $Date$
031 */
032 public class RoundRobinBackingStrategyFactoryGBean implements BackingStrategyFactory, GBeanLifecycle {
033 private final int nbReplica;
034
035 private BackingStrategyFactory strategyFactory;
036
037 public RoundRobinBackingStrategyFactoryGBean(int nbReplica) {
038 this.nbReplica = nbReplica;
039 }
040
041 public BackingStrategy factory() {
042 return strategyFactory.factory();
043 }
044
045 public void doFail() {
046 strategyFactory = null;
047 }
048
049 public void doStart() throws Exception {
050 strategyFactory = new RoundRobinBackingStrategyFactory(nbReplica);
051 }
052
053 public void doStop() throws Exception {
054 strategyFactory = null;
055 }
056
057
058 public static final GBeanInfo GBEAN_INFO;
059
060 public static final String GBEAN_ATTR_NB_REPLICA = "nbReplica";
061
062 static {
063 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(RoundRobinBackingStrategyFactoryGBean.class,
064 NameFactory.GERONIMO_SERVICE);
065
066 infoBuilder.addAttribute(GBEAN_ATTR_NB_REPLICA, int.class, true);
067
068 infoBuilder.addInterface(BackingStrategyFactory.class);
069
070 infoBuilder.setConstructor(new String[] {GBEAN_ATTR_NB_REPLICA});
071
072 GBEAN_INFO = infoBuilder.getBeanInfo();
073 }
074
075 public static GBeanInfo getGBeanInfo() {
076 return GBEAN_INFO;
077 }
078 }