Class Device

java.lang.Object
org.networkupstools.jnut.Device

public class Device extends Object
Class representing a device attached to a Client session.

It can retrieve its description, its number of logins, its variable and command lists.

A Device object can be retrieved from a Client instance, and cannot be constructed directly.

Author:
Emilien Kia
  • Constructor Details

    • Device

      protected Device(String name, Client client)
      Internally create a device.
      Parameters:
      name - Device name.
      client - Client to which the device is attached.
  • Method Details

    • getClient

      public Client getClient()
      Return the client to which the device is connected.
      Returns:
      Attached client.
    • getName

      public String getName()
      Return the device name.
      Returns:
      Device name.
    • getDescription

      public String getDescription() throws IOException, NutException
      Retrieve the device description from UPSD and store it in a cache.
      Returns:
      Device description
      Throws:
      IOException
      NutException
    • login

      public void login() throws IOException, NutException
      Log in to the UPS to assume a special role which matters to orchestration of the server lifecycle and its other clients. NOTE: Call Client.authenticate() first.

      Use this to log the fact that a system is drawing power from this UPS. The upsmon primary system will wait until the count of attached systems reaches 1 - itself. This allows the secondaries to shut down first.

      NOTE: You probably shouldn't send this command unless you are upsmon, or an upsmon replacement.

      Throws:
      IOException
      NutException
      See Also:
    • becomePrimary

      public void becomePrimary() throws IOException, NutException
      This function does little by itself. It is used by upsmon to make sure that master-level functions like FSD are available if necessary.

      NOTE: API changed since NUT 2.8.0 to replace MASTER with PRIMARY (and backwards-compatible alias handling)

      Throws:
      IOException
      NutException
      See Also:
    • master

      @Deprecated public void master() throws IOException, NutException
      Deprecated.
      Use becomePrimary() instead
      Throws:
      IOException
      NutException
      See Also:
    • becomeSecondary

      public void becomeSecondary() throws IOException, NutException
      This function does little by itself. It is used by upsmon to make sure that slave instances are known and waited for by the master instance to disconnect from the data server in case of FSD and mass shutdown.

      NOTE: API changed since NUT 2.8.0 to replace SLAVE with SECONDARY (and backwards-compatible alias handling)

      Throws:
      IOException
      NutException
      See Also:
    • setForcedShutdown

      public void setForcedShutdown() throws IOException, NutException
      Set the "forced shutdown" flag.

      upsmon in PRIMARY mode is the main user of this function. On the data server side, it sets the "forced shutdown" flag on any UPS when it plans to power it off. This is done so that SECONDARY systems will know about it, and would shut down before the power disappears.

      Setting this flag makes "FSD" appear in a STATUS request for this UPS. Finding "FSD" in a status request should be treated just like an "OB LB".

      It should be noted that FSD is currently a latch - once set, there is no way to clear it short of restarting upsd or dropping then re-adding it in the ups.conf. This may cause issues when upsd is running on a system that is not shut down due to the UPS event.

      Throws:
      IOException
      NutException
    • getNumLogin

      public int getNumLogin() throws IOException, NutException
      Return the number of clients which have done LOGIN for this UPS. Force to retrieve it from UPSD and store it in a cache.
      Returns:
      Number of clients, -1 if error.
      Throws:
      IOException
      NutException
    • getClients

      public String[] getClients() throws IOException, NutException
      Return the list of clients which have done LOGIN for this UPS.
      Returns:
      List of client hostnames.
      Throws:
      IOException
      NutException
    • getVariableList

      public Variable[] getVariableList() throws IOException, NutException
      Return the list of device variables from the NUT server.
      Returns:
      List of variables, empty if nothing, null if not connected or failed.
      Throws:
      IOException
      NutException
    • getRWVariableList

      public Variable[] getRWVariableList() throws IOException, NutException
      Return the list of device RW variables from the NUT server.
      Returns:
      List of variables, empty if nothing, null if not connected or failed.
      Throws:
      IOException
      NutException
    • getVariable

      public Variable getVariable(String name) throws IOException, NutException
      Return a variable from its name.
      Parameters:
      name - Name of the queried variable.
      Returns:
      The corresponding variable object if exists.
      Throws:
      IOException
      NutException
    • getCommandList

      public Command[] getCommandList() throws IOException, NutException
      Return the list of device commands from the NUT server.
      Returns:
      List of commands, empty if nothing, null if not connected or failed.
      Throws:
      IOException
      NutException
    • getCommand

      public Command getCommand(String name) throws IOException, NutException
      Return a command from its name.
      Parameters:
      name - Name of the queried command.
      Returns:
      The corresponding command object if exists.
      Throws:
      IOException
      NutException