001/*
002 * Copyright (c) 2007-2017 Xplenty, 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
021package cascading.stats;
022
023import cascading.flow.FlowNode;
024import cascading.flow.planner.BaseFlowNode;
025import cascading.management.state.ClientState;
026import cascading.util.ProcessLogger;
027
028/** Class FlowNodeStats collects {@link cascading.flow.FlowNode} specific statistics. */
029public abstract class FlowNodeStats extends CascadingStats<FlowSliceStats>
030  {
031  private final FlowNode flowNode;
032
033  protected boolean hasCapturedFinalDetail = false;
034
035  protected FlowNodeStats( FlowNode flowNode, ClientState clientState )
036    {
037    super( flowNode.getName(), clientState );
038    this.flowNode = flowNode;
039
040    ( (BaseFlowNode) this.flowNode ).setFlowNodeStats( this );
041    }
042
043  public abstract String getKind();
044
045  @Override
046  protected ProcessLogger getProcessLogger()
047    {
048    if( flowNode != null && flowNode instanceof ProcessLogger )
049      return (ProcessLogger) flowNode;
050
051    return ProcessLogger.NULL;
052    }
053
054  @Override
055  public String getID()
056    {
057    return flowNode.getID();
058    }
059
060  @Override
061  public Type getType()
062    {
063    return Type.NODE;
064    }
065
066  public FlowNode getFlowNode()
067    {
068    return flowNode;
069    }
070
071  public int getOrdinal()
072    {
073    return flowNode.getOrdinal();
074    }
075
076  @Override
077  public synchronized void recordInfo()
078    {
079    clientState.recordFlowNode( flowNode );
080    }
081
082  @Override
083  public String toString()
084    {
085    return "Node{" + getStatsString() + '}';
086    }
087
088  public abstract void recordChildStats();
089
090  public boolean hasCapturedFinalDetail()
091    {
092    return hasCapturedFinalDetail;
093    }
094  }