    001/*
    002 * Copyright (c) 2007-2016 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
    021package cascading.tuple.collect;
    022
    023import cascading.tuple.Tuple;
    024import org.slf4j.Logger;
    025import org.slf4j.LoggerFactory;
    026
    027/**
    028 *
    029 */
    030public interface Spillable
    031  {
    032  interface SpillStrategy
    033    {
    034    boolean doSpill( Spillable spillable, int size );
    035
    036    String getSpillReason( Spillable spillable );
    037    }
    038
    039  interface SpillListener
    040    {
    041    SpillListener NULL = new SpillListener()
    042    {
    043    private final Logger LOG = LoggerFactory.getLogger( SpillListener.class );
    044
    045    @Override
    046    public void notifyWriteSpillBegin( Spillable spillable, int spillSize, String spillReason )
    047      {
    048      LOG.info( "spilling {} tuples in list to spill number {}", spillSize, spillable.spillCount() + 1 );
    049      }
    050
    051    @Override
    052    public void notifyReadSpillBegin( Spillable spillable )
    053      {
    054      }
    055
    056    @Override
    057    public void notifyWriteSpillEnd( SpillableTupleList spillableTupleList, long duration )
    058      {
    059      }
    060    };
    061
    062    void notifyWriteSpillBegin( Spillable spillable, int spillSize, String spillReason );
    063
    064    void notifyWriteSpillEnd( SpillableTupleList spillableTupleList, long duration );
    065
    066    void notifyReadSpillBegin( Spillable spillable );
    067    }
    068
    069  void setGrouping( Tuple group );
    070
    071  Tuple getGrouping();
    072
    073  void setSpillStrategy( SpillStrategy spillStrategy );
    074
    075  void setSpillListener( SpillListener spillListener );
    076
    077  /**
    078   * The number of times this container has spilled data to disk.
    079   *
    080   * @return in int
    081   */
    082  int spillCount();
    083  }