01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.geronimo.clustering.wadi;
17:
18: import org.apache.geronimo.gbean.GBeanInfo;
19: import org.apache.geronimo.gbean.GBeanInfoBuilder;
20: import org.apache.geronimo.gbean.GBeanLifecycle;
21: import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
22: import org.codehaus.wadi.replication.strategy.BackingStrategy;
23: import org.codehaus.wadi.replication.strategy.BackingStrategyFactory;
24: import org.codehaus.wadi.replication.strategy.RoundRobinBackingStrategyFactory;
25: import org.codehaus.wadi.servicespace.ServiceSpace;
26:
27: /**
28: *
29: * @version $Rev$ $Date$
30: */
31: public class RoundRobinBackingStrategyFactoryGBean implements
32: BackingStrategyFactory, GBeanLifecycle {
33: private final int nbReplica;
34:
35: private BackingStrategyFactory strategyFactory;
36: private ServiceSpace serviceSpace;
37:
38: public RoundRobinBackingStrategyFactoryGBean(int nbReplica) {
39: this .nbReplica = nbReplica;
40: }
41:
42: public BackingStrategy factory() {
43: return strategyFactory.factory();
44: }
45:
46: public void setServiceSpace(ServiceSpace serviceSpace) {
47: strategyFactory.setServiceSpace(serviceSpace);
48: }
49:
50: public void doFail() {
51: strategyFactory = null;
52: }
53:
54: public void doStart() throws Exception {
55: strategyFactory = new RoundRobinBackingStrategyFactory(
56: nbReplica);
57: }
58:
59: public void doStop() throws Exception {
60: strategyFactory = null;
61: }
62:
63: public static final GBeanInfo GBEAN_INFO;
64:
65: public static final String GBEAN_ATTR_NB_REPLICA = "nbReplica";
66:
67: static {
68: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
69: RoundRobinBackingStrategyFactoryGBean.class,
70: NameFactory.GERONIMO_SERVICE);
71:
72: infoBuilder
73: .addAttribute(GBEAN_ATTR_NB_REPLICA, int.class, true);
74:
75: infoBuilder.addInterface(BackingStrategyFactory.class);
76:
77: infoBuilder
78: .setConstructor(new String[] { GBEAN_ATTR_NB_REPLICA });
79:
80: GBEAN_INFO = infoBuilder.getBeanInfo();
81: }
82:
83: public static GBeanInfo getGBeanInfo() {
84: return GBEAN_INFO;
85: }
86: }
|