KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > clustering > wadi > RoundRobinBackingStrategyFactoryGBean


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.clustering.wadi;
18
19 import org.apache.geronimo.gbean.GBeanInfo;
20 import org.apache.geronimo.gbean.GBeanInfoBuilder;
21 import org.apache.geronimo.gbean.GBeanLifecycle;
22 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
23 import org.codehaus.wadi.replication.strategy.BackingStrategy;
24 import org.codehaus.wadi.replication.strategy.BackingStrategyFactory;
25 import org.codehaus.wadi.replication.strategy.RoundRobinBackingStrategyFactory;
26
27 /**
28  *
29  * @version $Rev$ $Date$
30  */

31 public class RoundRobinBackingStrategyFactoryGBean implements BackingStrategyFactory, GBeanLifecycle {
32     private final int nbReplica;
33     
34     private BackingStrategyFactory strategyFactory;
35     
36     public RoundRobinBackingStrategyFactoryGBean(int nbReplica) {
37         this.nbReplica = nbReplica;
38     }
39
40     public BackingStrategy factory() {
41         return strategyFactory.factory();
42     }
43
44     public void doFail() {
45         strategyFactory = null;
46     }
47
48     public void doStart() throws Exception JavaDoc {
49         strategyFactory = new RoundRobinBackingStrategyFactory(nbReplica);
50     }
51
52     public void doStop() throws Exception JavaDoc {
53         strategyFactory = null;
54     }
55
56     
57     public static final GBeanInfo GBEAN_INFO;
58     
59     public static final String JavaDoc GBEAN_ATTR_NB_REPLICA = "nbReplica";
60     
61     static {
62         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(RoundRobinBackingStrategyFactoryGBean.class,
63                 NameFactory.GERONIMO_SERVICE);
64         
65         infoBuilder.addAttribute(GBEAN_ATTR_NB_REPLICA, int.class, true);
66         
67         infoBuilder.addInterface(BackingStrategyFactory.class);
68
69         infoBuilder.setConstructor(new String JavaDoc[] {GBEAN_ATTR_NB_REPLICA});
70         
71         GBEAN_INFO = infoBuilder.getBeanInfo();
72     }
73     
74     public static GBeanInfo getGBeanInfo() {
75         return GBEAN_INFO;
76     }
77 }
78
Popular Tags