001 /* 002 * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved. 003 * 004 * Project and contact information: http://www.cascading.org/ 005 * 006 * This file is part of the Cascading project. 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020 021 package cascading.stats; 022 023 import java.util.Collection; 024 import java.util.HashSet; 025 import java.util.LinkedList; 026 import java.util.List; 027 import java.util.Set; 028 029 import cascading.cascade.Cascade; 030 import cascading.management.state.ClientState; 031 032 /** Class CascadeStats collects {@link Cascade} specific statistics. */ 033 public class CascadeStats extends CascadingStats 034 { 035 private Cascade cascade; 036 /** Field flowStatsList */ 037 final List<FlowStats> flowStatsList = new LinkedList<FlowStats>(); // maintain order 038 039 public CascadeStats( Cascade cascade, ClientState clientState ) 040 { 041 super( cascade.getName(), clientState ); 042 this.cascade = cascade; 043 } 044 045 @Override 046 public String getID() 047 { 048 return cascade.getID(); 049 } 050 051 @Override 052 public synchronized void recordInfo() 053 { 054 clientState.recordCascade( cascade ); 055 } 056 057 /** 058 * Method addFlowStats add a child {@link cascading.flow.Flow} {2link FlowStats} instance. 059 * 060 * @param flowStats of type FlowStats 061 */ 062 public void addFlowStats( FlowStats flowStats ) 063 { 064 flowStatsList.add( flowStats ); 065 } 066 067 /** 068 * Method getFlowCount returns the number of {@link cascading.flow.Flow}s executed by the Cascade. 069 * 070 * @return the flowCount (type int) of this CascadeStats object. 071 */ 072 public int getFlowCount() 073 { 074 return flowStatsList.size(); 075 } 076 077 @Override 078 public Collection<String> getCounterGroups() 079 { 080 Set<String> results = new HashSet<String>(); 081 082 for( FlowStats flowStats : flowStatsList ) 083 results.addAll( flowStats.getCounterGroups() ); 084 085 return results; 086 } 087 088 @Override 089 public Collection<String> getCounterGroupsMatching( String regex ) 090 { 091 Set<String> results = new HashSet<String>(); 092 093 for( FlowStats flowStats : flowStatsList ) 094 results.addAll( flowStats.getCounterGroupsMatching( regex ) ); 095 096 return results; 097 } 098 099 @Override 100 public Collection<String> getCountersFor( String group ) 101 { 102 Set<String> results = new HashSet<String>(); 103 104 for( FlowStats flowStats : flowStatsList ) 105 results.addAll( flowStats.getCountersFor( group ) ); 106 107 return results; 108 } 109 110 @Override 111 public long getCounterValue( Enum counter ) 112 { 113 long value = 0; 114 115 for( FlowStats flowStats : flowStatsList ) 116 value += flowStats.getCounterValue( counter ); 117 118 return value; 119 } 120 121 @Override 122 public long getCounterValue( String group, String counter ) 123 { 124 long value = 0; 125 126 for( FlowStats flowStats : flowStatsList ) 127 value += flowStats.getCounterValue( group, counter ); 128 129 return value; 130 } 131 132 @Override 133 public void captureDetail() 134 { 135 for( FlowStats flowStats : flowStatsList ) 136 flowStats.captureDetail(); 137 } 138 139 @Override 140 public Collection getChildren() 141 { 142 return flowStatsList; 143 } 144 145 @Override 146 public String toString() 147 { 148 return "Cascade{" + "flowStatsList=" + flowStatsList + '}'; 149 } 150 }