org.networkupstools.jnut
Class Device

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

public class Device
extends java.lang.Object

Class representing a device attached to a Client.

It can retrieve its description, its number of logins, its variable and command lists. A Device object can be retrieved from Client instance and can not be constructed directly.

Author:
Emilien Kia

Constructor Summary
protected Device(java.lang.String name, Client client)
          Internally create a device.
 
Method Summary
 Client getClient()
          Return the client to which the device is connected.
 Command getCommand(java.lang.String name)
          Return a command from its name.
 Command[] getCommandList()
          Return the list of device commands from the NUT server.
 java.lang.String getDescription()
          Retrieve the device description from UPSD and store it in cache.
 java.lang.String getName()
          Return the device name.
 int getNumLogin()
          Return the number of clients which have done LOGIN for this UPS.
 Variable[] getRWVariableList()
          Return the list of device RW variables from the NUT server.
 Variable getVariable(java.lang.String name)
          Return a variable from its name.
 Variable[] getVariableList()
          Return the list of device variables from the NUT server.
 void login()
          Log in to the ups.
 void master()
          This function doesn't do much by itself.
 void setForcedShutdown()
          Set the "forced shutdown" flag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Device

protected Device(java.lang.String name,
                 Client client)
Internally create a device.

Parameters:
name - Device name.
client - Client to which the device is attached.
Method Detail

getClient

public Client getClient()
Return the client to which the device is connected.

Returns:
Attached client.

getName

public java.lang.String getName()
Return the device name.

Returns:
Device name.

getDescription

public java.lang.String getDescription()
                                throws java.io.IOException,
                                       NutException
Retrieve the device description from UPSD and store it in cache.

Returns:
Device description
Throws:
java.io.IOException
NutException

login

public void login()
           throws java.io.IOException,
                  NutException
Log in to the ups.

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

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

Throws:
java.io.IOException
NutException

master

public void master()
            throws java.io.IOException,
                   NutException
This function doesn't do much by itself. It is used by upsmon to make sure that master-level functions like FSD are available if necessary

Throws:
java.io.IOException
NutException

setForcedShutdown

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

upsmon in master mode is the primary user of this function. It sets this "forced shutdown" flag on any UPS when it plans to power it off. This is done so that slave systems will know about it and 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 a "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:
java.io.IOException
NutException

getNumLogin

public int getNumLogin()
                throws java.io.IOException,
                       NutException
Return the number of clients which have done LOGIN for this UPS. Force to retrieve it from UPSD and store it in cache.

Returns:
Number of clients, -1 if error.
Throws:
java.io.IOException
NutException

getVariableList

public Variable[] getVariableList()
                           throws java.io.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:
java.io.IOException
NutException

getRWVariableList

public Variable[] getRWVariableList()
                             throws java.io.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:
java.io.IOException
NutException

getVariable

public Variable getVariable(java.lang.String name)
                     throws java.io.IOException,
                            NutException
Return a variable from its name.

Parameters:
name - Name of the queried variable.
Returns:
The corresponding variable object if exists.
Throws:
java.io.IOException
NutException

getCommandList

public Command[] getCommandList()
                         throws java.io.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:
java.io.IOException
NutException

getCommand

public Command getCommand(java.lang.String name)
                   throws java.io.IOException,
                          NutException
Return a command from its name.

Parameters:
name - Name of the queried command.
Returns:
The corresponding command object if exists.
Throws:
java.io.IOException
NutException


Copyright © 2011. All Rights Reserved.