//------------------------------------------------------------------------------
// <copyright file="Timeout.java" company="Microsoft">
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
// <summary>
//      Representative value of Timeout
// </summary>
//------------------------------------------------------------------------------

package com.microsoft.hpc.scheduler.session;

/**
 * Representative value of Timeout
 * <p>If using custom, be sure to call setTimeout, or else it will use the DEFAULT_TIMEOUT of 1 minute</p>
 */
public enum Timeout
{
    
    Infinite,
    Default,
    Custom;
   
    final static int DEFAULT_TIMEOUT = 60*1000;
    private long timeout;
    
    Timeout()
    {
        timeout = DEFAULT_TIMEOUT;
    }
    
    public long getTimeout()
    {
        switch(this)
        {
            case Infinite:
                return Integer.MAX_VALUE;
            case Default:
                return DEFAULT_TIMEOUT;
            case Custom:
                return timeout;
        }
        throw new AssertionError();
    }
    
    public void setTimeout(long timeout)
    {
        switch(this)
        {
            case Infinite:
            case Default:
                break; //cannot change existing values 
            case Custom:
                this.timeout = timeout;
        }
        throw new AssertionError();
    }
}
