{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.GameLift.Types.RuntimeConfiguration
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.GameLift.Types.RuntimeConfiguration where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.GameLift.Types.ServerProcess
import qualified Amazonka.Prelude as Prelude

-- | A collection of server process configurations that describe the set of
-- processes to run on each instance in a fleet. Server processes run
-- either an executable in a custom game build or a Realtime Servers
-- script. GameLift launches the configured processes, manages their life
-- cycle, and replaces them as needed. Each instance checks regularly for
-- an updated runtime configuration.
--
-- A GameLift instance is limited to 50 processes running concurrently. To
-- calculate the total number of processes in a runtime configuration, add
-- the values of the @ConcurrentExecutions@ parameter for each server
-- process. Learn more about
-- <https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-multiprocess.html Running Multiple Processes on a Fleet>.
--
-- /See:/ 'newRuntimeConfiguration' smart constructor.
data RuntimeConfiguration = RuntimeConfiguration'
  { -- | The maximum amount of time (in seconds) allowed to launch a new game
    -- session and have it report ready to host players. During this time, the
    -- game session is in status @ACTIVATING@. If the game session does not
    -- become active before the timeout, it is ended and the game session
    -- status is changed to @TERMINATED@.
    RuntimeConfiguration -> Maybe Natural
gameSessionActivationTimeoutSeconds :: Prelude.Maybe Prelude.Natural,
    -- | The number of game sessions in status @ACTIVATING@ to allow on an
    -- instance. This setting limits the instance resources that can be used
    -- for new game activations at any one time.
    RuntimeConfiguration -> Maybe Natural
maxConcurrentGameSessionActivations :: Prelude.Maybe Prelude.Natural,
    -- | A collection of server process configurations that identify what server
    -- processes to run on each instance in a fleet.
    RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
serverProcesses :: Prelude.Maybe (Prelude.NonEmpty ServerProcess)
  }
  deriving (RuntimeConfiguration -> RuntimeConfiguration -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
$c/= :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
== :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
$c== :: RuntimeConfiguration -> RuntimeConfiguration -> Bool
Prelude.Eq, ReadPrec [RuntimeConfiguration]
ReadPrec RuntimeConfiguration
Int -> ReadS RuntimeConfiguration
ReadS [RuntimeConfiguration]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RuntimeConfiguration]
$creadListPrec :: ReadPrec [RuntimeConfiguration]
readPrec :: ReadPrec RuntimeConfiguration
$creadPrec :: ReadPrec RuntimeConfiguration
readList :: ReadS [RuntimeConfiguration]
$creadList :: ReadS [RuntimeConfiguration]
readsPrec :: Int -> ReadS RuntimeConfiguration
$creadsPrec :: Int -> ReadS RuntimeConfiguration
Prelude.Read, Int -> RuntimeConfiguration -> ShowS
[RuntimeConfiguration] -> ShowS
RuntimeConfiguration -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RuntimeConfiguration] -> ShowS
$cshowList :: [RuntimeConfiguration] -> ShowS
show :: RuntimeConfiguration -> String
$cshow :: RuntimeConfiguration -> String
showsPrec :: Int -> RuntimeConfiguration -> ShowS
$cshowsPrec :: Int -> RuntimeConfiguration -> ShowS
Prelude.Show, forall x. Rep RuntimeConfiguration x -> RuntimeConfiguration
forall x. RuntimeConfiguration -> Rep RuntimeConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RuntimeConfiguration x -> RuntimeConfiguration
$cfrom :: forall x. RuntimeConfiguration -> Rep RuntimeConfiguration x
Prelude.Generic)

-- |
-- Create a value of 'RuntimeConfiguration' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'gameSessionActivationTimeoutSeconds', 'runtimeConfiguration_gameSessionActivationTimeoutSeconds' - The maximum amount of time (in seconds) allowed to launch a new game
-- session and have it report ready to host players. During this time, the
-- game session is in status @ACTIVATING@. If the game session does not
-- become active before the timeout, it is ended and the game session
-- status is changed to @TERMINATED@.
--
-- 'maxConcurrentGameSessionActivations', 'runtimeConfiguration_maxConcurrentGameSessionActivations' - The number of game sessions in status @ACTIVATING@ to allow on an
-- instance. This setting limits the instance resources that can be used
-- for new game activations at any one time.
--
-- 'serverProcesses', 'runtimeConfiguration_serverProcesses' - A collection of server process configurations that identify what server
-- processes to run on each instance in a fleet.
newRuntimeConfiguration ::
  RuntimeConfiguration
newRuntimeConfiguration :: RuntimeConfiguration
newRuntimeConfiguration =
  RuntimeConfiguration'
    { $sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: Maybe Natural
gameSessionActivationTimeoutSeconds =
        forall a. Maybe a
Prelude.Nothing,
      $sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: Maybe Natural
maxConcurrentGameSessionActivations =
        forall a. Maybe a
Prelude.Nothing,
      $sel:serverProcesses:RuntimeConfiguration' :: Maybe (NonEmpty ServerProcess)
serverProcesses = forall a. Maybe a
Prelude.Nothing
    }

-- | The maximum amount of time (in seconds) allowed to launch a new game
-- session and have it report ready to host players. During this time, the
-- game session is in status @ACTIVATING@. If the game session does not
-- become active before the timeout, it is ended and the game session
-- status is changed to @TERMINATED@.
runtimeConfiguration_gameSessionActivationTimeoutSeconds :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe Prelude.Natural)
runtimeConfiguration_gameSessionActivationTimeoutSeconds :: Lens' RuntimeConfiguration (Maybe Natural)
runtimeConfiguration_gameSessionActivationTimeoutSeconds = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe Natural
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
gameSessionActivationTimeoutSeconds} -> Maybe Natural
gameSessionActivationTimeoutSeconds) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe Natural
a -> RuntimeConfiguration
s {$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: Maybe Natural
gameSessionActivationTimeoutSeconds = Maybe Natural
a} :: RuntimeConfiguration)

-- | The number of game sessions in status @ACTIVATING@ to allow on an
-- instance. This setting limits the instance resources that can be used
-- for new game activations at any one time.
runtimeConfiguration_maxConcurrentGameSessionActivations :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe Prelude.Natural)
runtimeConfiguration_maxConcurrentGameSessionActivations :: Lens' RuntimeConfiguration (Maybe Natural)
runtimeConfiguration_maxConcurrentGameSessionActivations = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe Natural
maxConcurrentGameSessionActivations :: Maybe Natural
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
maxConcurrentGameSessionActivations} -> Maybe Natural
maxConcurrentGameSessionActivations) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe Natural
a -> RuntimeConfiguration
s {$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: Maybe Natural
maxConcurrentGameSessionActivations = Maybe Natural
a} :: RuntimeConfiguration)

-- | A collection of server process configurations that identify what server
-- processes to run on each instance in a fleet.
runtimeConfiguration_serverProcesses :: Lens.Lens' RuntimeConfiguration (Prelude.Maybe (Prelude.NonEmpty ServerProcess))
runtimeConfiguration_serverProcesses :: Lens' RuntimeConfiguration (Maybe (NonEmpty ServerProcess))
runtimeConfiguration_serverProcesses = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RuntimeConfiguration' {Maybe (NonEmpty ServerProcess)
serverProcesses :: Maybe (NonEmpty ServerProcess)
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
serverProcesses} -> Maybe (NonEmpty ServerProcess)
serverProcesses) (\s :: RuntimeConfiguration
s@RuntimeConfiguration' {} Maybe (NonEmpty ServerProcess)
a -> RuntimeConfiguration
s {$sel:serverProcesses:RuntimeConfiguration' :: Maybe (NonEmpty ServerProcess)
serverProcesses = Maybe (NonEmpty ServerProcess)
a} :: RuntimeConfiguration) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Data.FromJSON RuntimeConfiguration where
  parseJSON :: Value -> Parser RuntimeConfiguration
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"RuntimeConfiguration"
      ( \Object
x ->
          Maybe Natural
-> Maybe Natural
-> Maybe (NonEmpty ServerProcess)
-> RuntimeConfiguration
RuntimeConfiguration'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"GameSessionActivationTimeoutSeconds")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"MaxConcurrentGameSessionActivations")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"ServerProcesses")
      )

instance Prelude.Hashable RuntimeConfiguration where
  hashWithSalt :: Int -> RuntimeConfiguration -> Int
hashWithSalt Int
_salt RuntimeConfiguration' {Maybe Natural
Maybe (NonEmpty ServerProcess)
serverProcesses :: Maybe (NonEmpty ServerProcess)
maxConcurrentGameSessionActivations :: Maybe Natural
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
gameSessionActivationTimeoutSeconds
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Natural
maxConcurrentGameSessionActivations
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (NonEmpty ServerProcess)
serverProcesses

instance Prelude.NFData RuntimeConfiguration where
  rnf :: RuntimeConfiguration -> ()
rnf RuntimeConfiguration' {Maybe Natural
Maybe (NonEmpty ServerProcess)
serverProcesses :: Maybe (NonEmpty ServerProcess)
maxConcurrentGameSessionActivations :: Maybe Natural
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
gameSessionActivationTimeoutSeconds
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Natural
maxConcurrentGameSessionActivations
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (NonEmpty ServerProcess)
serverProcesses

instance Data.ToJSON RuntimeConfiguration where
  toJSON :: RuntimeConfiguration -> Value
toJSON RuntimeConfiguration' {Maybe Natural
Maybe (NonEmpty ServerProcess)
serverProcesses :: Maybe (NonEmpty ServerProcess)
maxConcurrentGameSessionActivations :: Maybe Natural
gameSessionActivationTimeoutSeconds :: Maybe Natural
$sel:serverProcesses:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe (NonEmpty ServerProcess)
$sel:maxConcurrentGameSessionActivations:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
$sel:gameSessionActivationTimeoutSeconds:RuntimeConfiguration' :: RuntimeConfiguration -> Maybe Natural
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"GameSessionActivationTimeoutSeconds" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
gameSessionActivationTimeoutSeconds,
            (Key
"MaxConcurrentGameSessionActivations" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Natural
maxConcurrentGameSessionActivations,
            (Key
"ServerProcesses" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty ServerProcess)
serverProcesses
          ]
      )