com.elastisys.scale.cloudpool.api.types

## Class MachinePool

- java.lang.Object
- - com.elastisys.scale.cloudpool.api.types.MachinePool

    public class MachinePool
    extends Object

Represents a snapshot of the machine pool managed by a `CloudPool`.

See Also:
  `CloudPool`

### Constructor Summary

Constructors
Constructor and Description
`MachinePool(List<? extends Machine> machines, org.joda.time.DateTime timestamp)` Constructs a new `MachinePool` snapshot.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static MachinePool` `emptyPool(org.joda.time.DateTime timestamp)` Factory method for creating an empty machine pool.
`boolean` `equals(Object obj)`
`static MachinePool` `fromJson(String machinePoolAsJson)` Parses a JSON representation of a `MachinePool` to its Java counterpart.
`List<Machine>` `getActiveMachines()` Returns all active `Machine`s in the pool.
`List<Machine>` `getAllocatedMachines()` Returns all allocated `Machine`s in the pool.
`List<Machine>` `getMachines()` Returns all `Machine`s in the pool.
`List<Machine>` `getStartedMachines()` Returns all started `Machine`s in the pool.
`org.joda.time.DateTime` `getTimestamp()` Returns the time at which the pool observation was made.
`int` `hashCode()`
`com.google.gson.JsonObject` `toJson()` Returns the JSON representation for this `MachinePool`.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### MachinePool

    public MachinePool(List<? extends Machine> machines,
                       org.joda.time.DateTime timestamp)

Constructs a new `MachinePool` snapshot.

Parameters:
  `machines` - The machine instances that were part of the machine pool at the time of the snapshot.
  `timestamp` - The time when this snapshot of the resource pool was taken.

### Method Detail

#### getMachines

    public List<Machine> getMachines()

Returns all `Machine`s in the pool.

Note: the returned `Machine`s may be in any `MachineState` and may include both machines in non-terminal states (`MachineState.REQUESTED`, `MachineState.PENDING`, `MachineState.RUNNING`) as well as machines in terminal states ( `MachineState.REJECTED`, `MachineState.TERMINATING`, `MachineState.TERMINATED`).

Returns:

#### getActiveMachines

    public List<Machine> getActiveMachines()

Returns all active `Machine`s in the pool. See `Machine.isActiveMember()`.

Returns:

#### getAllocatedMachines

    public List<Machine> getAllocatedMachines()

Returns all allocated `Machine`s in the pool. See `Machine.isAllocated()`.

Returns:

#### getStartedMachines

    public List<Machine> getStartedMachines()

Returns all started `Machine`s in the pool. See `Machine.isStarted()`.

Returns:

#### getTimestamp

    public org.joda.time.DateTime getTimestamp()

Returns the time at which the pool observation was made. Note that in case the cloud pool serves locally cached data, this field may be used by the client to determine if the data is fresh enough to be acted upon.

Returns:

#### emptyPool

    public static MachinePool emptyPool(org.joda.time.DateTime timestamp)

Factory method for creating an empty machine pool.

Parameters:
  `timestamp` - The timestamp of the machine pool.
Returns:

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### fromJson

    public static MachinePool fromJson(String machinePoolAsJson)
                                throws IOException

Parses a JSON representation of a `MachinePool` to its Java counterpart. Any failure to parse the JSON representation into a valid `MachinePool` instance results in an exception being thrown.

Parameters:
  `machinePoolAsJson` -
Returns:
Throws:
  `IOException`

#### toJson

    public com.google.gson.JsonObject toJson()

Returns the JSON representation for this `MachinePool`.

Returns:
  A `JsonObject` representation of this `MachinePool`.