001 /* 002 * Copyright (c) 2007-2015 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.hadoop; 022 023 import java.util.Collection; 024 import java.util.Collections; 025 import java.util.HashSet; 026 import java.util.Map; 027 import java.util.Set; 028 029 import cascading.management.state.ClientState; 030 import cascading.stats.FlowStepStats; 031 032 /** 033 * ProcessStepStats is an implementation of FlowStepStats used in non-hadoop based flows like ProcessFlow. 034 * 035 * @deprecated ProcessStepStats will be moved to a different package in Cascading 3.0. 036 */ 037 @Deprecated 038 public class ProcessStepStats extends FlowStepStats 039 { 040 /** 041 * The counters of the step as a Map. 042 */ 043 private final Map<String, Map<String, Long>> counters; 044 045 /** 046 * Constructs a new ProcessStepStats instance. 047 * 048 * @param clientState 049 * @param counters 050 * @param step 051 */ 052 public ProcessStepStats( ClientState clientState, Map<String, Map<String, Long>> counters, ProcessFlowStep step ) 053 { 054 super( step, clientState ); 055 this.counters = counters; 056 } 057 058 @Override 059 public void recordChildStats() 060 { 061 062 } 063 064 @Override 065 public Collection<String> getCounterGroups() 066 { 067 return counters.keySet(); 068 } 069 070 @Override 071 public Collection<String> getCountersFor( String group ) 072 { 073 Map<String, Long> groupCollection = counters.get( group ); 074 075 if( groupCollection == null ) 076 return Collections.emptySet(); 077 078 return groupCollection.keySet(); 079 } 080 081 @Override 082 public long getCounterValue( Enum counter ) 083 { 084 Map<String, Long> counterMap = counters.get( counter.getDeclaringClass().getName() ); 085 086 String counterString = counter.toString(); 087 088 if( counterMap == null || !counterMap.containsKey( counterString ) ) 089 return 0; 090 091 return counterMap.get( counterString ); 092 } 093 094 @Override 095 public long getCounterValue( String group, String counter ) 096 { 097 Map<String, Long> counterMap = counters.get( group ); 098 099 if( counterMap == null || !counterMap.containsKey( counter ) ) 100 return 0; 101 102 return counterMap.get( counter ); 103 } 104 105 @Override 106 public void captureDetail() 107 { 108 109 } 110 111 @Override 112 public Collection<String> getCounterGroupsMatching( String regex ) 113 { 114 Collection<String> counters = getCounterGroups(); 115 116 Set<String> results = new HashSet<String>(); 117 118 for( String counter : counters ) 119 { 120 if( counter.matches( regex ) ) 121 results.add( counter ); 122 } 123 124 return Collections.unmodifiableCollection( results ); 125 } 126 127 @Override 128 public Collection getChildren() 129 { 130 return Collections.emptyList(); 131 } 132 }