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.management.state;
022    
023    import cascading.cascade.Cascade;
024    import cascading.flow.Flow;
025    import cascading.flow.FlowStep;
026    import cascading.stats.CascadingStats;
027    
028    /**
029     *
030     */
031    public abstract class ClientState extends BaseState
032      {
033      public static final String STATE_SERVICE_CLASS_PROPERTY = "cascading.management.state.service.classname";
034    
035      public static ClientState NULL = new ClientState()
036      {
037      @Override
038      public void start( long time )
039        {
040        }
041    
042      @Override
043      public void run( long time )
044        {
045        }
046    
047      @Override
048      public void stop( long time )
049        {
050        }
051    
052      @Override
053      String[] getContext( String group, String metric )
054        {
055        return new String[ 0 ];
056        }
057    
058      @Override
059      public void recordStats( CascadingStats stats )
060        {
061        }
062    
063      @Override
064      public void recordFlowStep( FlowStep flowStep )
065        {
066        }
067    
068      @Override
069      public void recordFlow( Flow flow )
070        {
071        }
072    
073      @Override
074      public void recordCascade( Cascade cascade )
075        {
076        }
077      };
078    
079      public ClientState()
080        {
081        }
082    
083      @Override
084      String[] getContext( String group, String metric )
085        {
086        return asArray( group, metric );
087        }
088    
089      public void setStatus( Enum status, long time )
090        {
091        setMetric( status, time );
092        }
093    
094      public abstract void recordStats( CascadingStats stats );
095    
096      public abstract void recordFlowStep( FlowStep flowStep );
097    
098      public abstract void recordFlow( Flow flow );
099    
100      public abstract void recordCascade( Cascade cascade );
101    
102      public void record( String id, Object object )
103        {
104        store( id, object );
105        }
106    
107      public void start( long time )
108        {
109        setMetric( "state", "start", time );
110        }
111    
112      public void submit( long time )
113        {
114        setMetric( "state", "submit", time );
115        }
116    
117      public void run( long time )
118        {
119        setMetric( "state", "run", time );
120        }
121    
122      public void stop( long time )
123        {
124        setMetric( "state", "stop", time );
125        }
126      }