{-# 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.ServerProcess
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.GameLift.Types.ServerProcess where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A set of instructions for launching server processes on each instance in
-- a fleet. Server processes run either an executable in a custom game
-- build or a Realtime Servers script. Server process configurations are
-- part of a fleet\'s RuntimeConfiguration.
--
-- /See:/ 'newServerProcess' smart constructor.
data ServerProcess = ServerProcess'
  { -- | An optional list of parameters to pass to the server executable or
    -- Realtime script on launch.
    ServerProcess -> Maybe Text
parameters :: Prelude.Maybe Prelude.Text,
    -- | The location of a game build executable or the Realtime script file that
    -- contains the @Init()@ function. Game builds and Realtime scripts are
    -- installed on instances at the root:
    --
    -- -   Windows (custom game builds only): @C:\\game@. Example:
    --     \"@C:\\game\\MyGame\\server.exe@\"
    --
    -- -   Linux: @\/local\/game@. Examples:
    --     \"@\/local\/game\/MyGame\/server.exe@\" or
    --     \"@\/local\/game\/MyRealtimeScript.js@\"
    ServerProcess -> Text
launchPath :: Prelude.Text,
    -- | The number of server processes using this configuration that run
    -- concurrently on each instance.
    ServerProcess -> Natural
concurrentExecutions :: Prelude.Natural
  }
  deriving (ServerProcess -> ServerProcess -> Bool
(ServerProcess -> ServerProcess -> Bool)
-> (ServerProcess -> ServerProcess -> Bool) -> Eq ServerProcess
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ServerProcess -> ServerProcess -> Bool
$c/= :: ServerProcess -> ServerProcess -> Bool
== :: ServerProcess -> ServerProcess -> Bool
$c== :: ServerProcess -> ServerProcess -> Bool
Prelude.Eq, ReadPrec [ServerProcess]
ReadPrec ServerProcess
Int -> ReadS ServerProcess
ReadS [ServerProcess]
(Int -> ReadS ServerProcess)
-> ReadS [ServerProcess]
-> ReadPrec ServerProcess
-> ReadPrec [ServerProcess]
-> Read ServerProcess
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ServerProcess]
$creadListPrec :: ReadPrec [ServerProcess]
readPrec :: ReadPrec ServerProcess
$creadPrec :: ReadPrec ServerProcess
readList :: ReadS [ServerProcess]
$creadList :: ReadS [ServerProcess]
readsPrec :: Int -> ReadS ServerProcess
$creadsPrec :: Int -> ReadS ServerProcess
Prelude.Read, Int -> ServerProcess -> ShowS
[ServerProcess] -> ShowS
ServerProcess -> String
(Int -> ServerProcess -> ShowS)
-> (ServerProcess -> String)
-> ([ServerProcess] -> ShowS)
-> Show ServerProcess
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ServerProcess] -> ShowS
$cshowList :: [ServerProcess] -> ShowS
show :: ServerProcess -> String
$cshow :: ServerProcess -> String
showsPrec :: Int -> ServerProcess -> ShowS
$cshowsPrec :: Int -> ServerProcess -> ShowS
Prelude.Show, (forall x. ServerProcess -> Rep ServerProcess x)
-> (forall x. Rep ServerProcess x -> ServerProcess)
-> Generic ServerProcess
forall x. Rep ServerProcess x -> ServerProcess
forall x. ServerProcess -> Rep ServerProcess x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ServerProcess x -> ServerProcess
$cfrom :: forall x. ServerProcess -> Rep ServerProcess x
Prelude.Generic)

-- |
-- Create a value of 'ServerProcess' 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:
--
-- 'parameters', 'serverProcess_parameters' - An optional list of parameters to pass to the server executable or
-- Realtime script on launch.
--
-- 'launchPath', 'serverProcess_launchPath' - The location of a game build executable or the Realtime script file that
-- contains the @Init()@ function. Game builds and Realtime scripts are
-- installed on instances at the root:
--
-- -   Windows (custom game builds only): @C:\\game@. Example:
--     \"@C:\\game\\MyGame\\server.exe@\"
--
-- -   Linux: @\/local\/game@. Examples:
--     \"@\/local\/game\/MyGame\/server.exe@\" or
--     \"@\/local\/game\/MyRealtimeScript.js@\"
--
-- 'concurrentExecutions', 'serverProcess_concurrentExecutions' - The number of server processes using this configuration that run
-- concurrently on each instance.
newServerProcess ::
  -- | 'launchPath'
  Prelude.Text ->
  -- | 'concurrentExecutions'
  Prelude.Natural ->
  ServerProcess
newServerProcess :: Text -> Natural -> ServerProcess
newServerProcess Text
pLaunchPath_ Natural
pConcurrentExecutions_ =
  ServerProcess' :: Maybe Text -> Text -> Natural -> ServerProcess
ServerProcess'
    { $sel:parameters:ServerProcess' :: Maybe Text
parameters = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:launchPath:ServerProcess' :: Text
launchPath = Text
pLaunchPath_,
      $sel:concurrentExecutions:ServerProcess' :: Natural
concurrentExecutions = Natural
pConcurrentExecutions_
    }

-- | An optional list of parameters to pass to the server executable or
-- Realtime script on launch.
serverProcess_parameters :: Lens.Lens' ServerProcess (Prelude.Maybe Prelude.Text)
serverProcess_parameters :: (Maybe Text -> f (Maybe Text)) -> ServerProcess -> f ServerProcess
serverProcess_parameters = (ServerProcess -> Maybe Text)
-> (ServerProcess -> Maybe Text -> ServerProcess)
-> Lens ServerProcess ServerProcess (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Maybe Text
parameters :: Maybe Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
parameters} -> Maybe Text
parameters) (\s :: ServerProcess
s@ServerProcess' {} Maybe Text
a -> ServerProcess
s {$sel:parameters:ServerProcess' :: Maybe Text
parameters = Maybe Text
a} :: ServerProcess)

-- | The location of a game build executable or the Realtime script file that
-- contains the @Init()@ function. Game builds and Realtime scripts are
-- installed on instances at the root:
--
-- -   Windows (custom game builds only): @C:\\game@. Example:
--     \"@C:\\game\\MyGame\\server.exe@\"
--
-- -   Linux: @\/local\/game@. Examples:
--     \"@\/local\/game\/MyGame\/server.exe@\" or
--     \"@\/local\/game\/MyRealtimeScript.js@\"
serverProcess_launchPath :: Lens.Lens' ServerProcess Prelude.Text
serverProcess_launchPath :: (Text -> f Text) -> ServerProcess -> f ServerProcess
serverProcess_launchPath = (ServerProcess -> Text)
-> (ServerProcess -> Text -> ServerProcess)
-> Lens ServerProcess ServerProcess Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Text
launchPath :: Text
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
launchPath} -> Text
launchPath) (\s :: ServerProcess
s@ServerProcess' {} Text
a -> ServerProcess
s {$sel:launchPath:ServerProcess' :: Text
launchPath = Text
a} :: ServerProcess)

-- | The number of server processes using this configuration that run
-- concurrently on each instance.
serverProcess_concurrentExecutions :: Lens.Lens' ServerProcess Prelude.Natural
serverProcess_concurrentExecutions :: (Natural -> f Natural) -> ServerProcess -> f ServerProcess
serverProcess_concurrentExecutions = (ServerProcess -> Natural)
-> (ServerProcess -> Natural -> ServerProcess)
-> Lens ServerProcess ServerProcess Natural Natural
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ServerProcess' {Natural
concurrentExecutions :: Natural
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
concurrentExecutions} -> Natural
concurrentExecutions) (\s :: ServerProcess
s@ServerProcess' {} Natural
a -> ServerProcess
s {$sel:concurrentExecutions:ServerProcess' :: Natural
concurrentExecutions = Natural
a} :: ServerProcess)

instance Core.FromJSON ServerProcess where
  parseJSON :: Value -> Parser ServerProcess
parseJSON =
    String
-> (Object -> Parser ServerProcess)
-> Value
-> Parser ServerProcess
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"ServerProcess"
      ( \Object
x ->
          Maybe Text -> Text -> Natural -> ServerProcess
ServerProcess'
            (Maybe Text -> Text -> Natural -> ServerProcess)
-> Parser (Maybe Text) -> Parser (Text -> Natural -> ServerProcess)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Parameters")
            Parser (Text -> Natural -> ServerProcess)
-> Parser Text -> Parser (Natural -> ServerProcess)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"LaunchPath")
            Parser (Natural -> ServerProcess)
-> Parser Natural -> Parser ServerProcess
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Natural
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"ConcurrentExecutions")
      )

instance Prelude.Hashable ServerProcess

instance Prelude.NFData ServerProcess

instance Core.ToJSON ServerProcess where
  toJSON :: ServerProcess -> Value
toJSON ServerProcess' {Natural
Maybe Text
Text
concurrentExecutions :: Natural
launchPath :: Text
parameters :: Maybe Text
$sel:concurrentExecutions:ServerProcess' :: ServerProcess -> Natural
$sel:launchPath:ServerProcess' :: ServerProcess -> Text
$sel:parameters:ServerProcess' :: ServerProcess -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Parameters" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
parameters,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"LaunchPath" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
launchPath),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              ( Text
"ConcurrentExecutions"
                  Text -> Natural -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Natural
concurrentExecutions
              )
          ]
      )