Clover coverage report - ActiveCluster - 1.1-SNAPSHOT
Coverage timestamp: Tue May 24 2005 08:48:28 BST
file stats: LOC: 115   Methods: 12
NCLOC: 55   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Group.java 0% 0% 0% 0%
coverage
 1   
 /** 
 2   
  * 
 3   
  * Copyright 2004 Protique Ltd
 4   
  * 
 5   
  * Licensed under the Apache License, Version 2.0 (the "License"); 
 6   
  * you may not use this file except in compliance with the License. 
 7   
  * 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   
  **/
 18   
 package org.activecluster.group;
 19   
 
 20   
 import org.activecluster.Node;
 21   
 
 22   
 import java.util.ArrayList;
 23   
 import java.util.List;
 24   
 
 25   
 /**
 26   
  * Represents a logical group of nodes in a cluster,
 27   
  * such as a Master and a number of Slaves which operate as a
 28   
  * logical unit.
 29   
  * <p/>
 30   
  * A cluster can be divided into a single group, or many groups
 31   
  * depending on the policy required.
 32   
  * <p/>
 33   
  * The number of groups could be application defined; created on demand
 34   
  * or there could even be one group for each node, with other nodes acting
 35   
  * as buddy nodes in each nodes' group (i.e. each node is a master with N
 36   
  * buddies/slaves)
 37   
  *
 38   
  * @version $Revision: 1.1 $
 39   
  */
 40   
 public class Group {
 41   
     private int minimumMemberCount;
 42   
     private int maximumMemberCount;
 43   
     private List members = new ArrayList();
 44   
     private int memberCount;
 45   
 
 46  0
     public Group() {
 47   
     }
 48   
 
 49  0
     public Group(int minimumMemberCount, int maximumMemberCount) {
 50  0
         this.minimumMemberCount = minimumMemberCount;
 51  0
         this.maximumMemberCount = maximumMemberCount;
 52   
     }
 53   
 
 54  0
     public synchronized List getMembers() {
 55  0
         return new ArrayList(members);
 56   
     }
 57   
 
 58   
     /**
 59   
      * Adds a node to the given group
 60   
      *
 61   
      * @return the index of the node in the group (0 = master, 1..N = slave)
 62   
      */
 63  0
     public synchronized int addMember(Node node) {
 64  0
         int index = members.indexOf(node);
 65  0
         if (index >= 0) {
 66  0
             return index;
 67   
         }
 68  0
         members.add(node);
 69  0
         return memberCount++;
 70   
     }
 71   
 
 72  0
     public synchronized boolean removeMember(Node node) {
 73  0
         boolean answer = members.remove(node);
 74  0
         if (answer) {
 75  0
             memberCount--;
 76   
         }
 77  0
         return answer;
 78   
     }
 79   
 
 80   
 
 81   
     /**
 82   
      * Returns true if the group is usable, that it has enough members to be used.
 83   
      */
 84  0
     public boolean isUsable() {
 85  0
         return memberCount >= minimumMemberCount;
 86   
     }
 87   
 
 88   
     /**
 89   
      * Returns true if the group cannot accept any more new members
 90   
      */
 91  0
     public boolean isFull() {
 92  0
         return memberCount >= maximumMemberCount;
 93   
     }
 94   
 
 95  0
     public int getMemberCount() {
 96  0
         return memberCount;
 97   
     }
 98   
 
 99  0
     public int getMaximumMemberCount() {
 100  0
         return maximumMemberCount;
 101   
     }
 102   
 
 103  0
     public void setMaximumMemberCount(int maximumMemberCount) {
 104  0
         this.maximumMemberCount = maximumMemberCount;
 105   
     }
 106   
 
 107  0
     public int getMinimumMemberCount() {
 108  0
         return minimumMemberCount;
 109   
     }
 110   
 
 111  0
     public void setMinimumMemberCount(int minimumMemberCount) {
 112  0
         this.minimumMemberCount = minimumMemberCount;
 113   
     }
 114   
 }
 115