|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.networkupstools.jnut.Client
public class Client
A jNut client is start point to dialog to UPSD. It can connect to an UPSD then retrieve its device list. It support authentication by login/password.
You can directly create and connect a client by using the Client(String host, int port, String login, String passwd) constructor or use a three phase construction:
Objects retrieved by Client are attached (directly or indirectly) to it. If the connection is closed, attached objects must not be used anymore (GC).
Note: The jNut Client does not support any reconnection nor ping mechanism, so the calling application must know the UPSD can timeout the connection.
Note: Retrieved values are not valid along the time, they are valid at the precise moment they are retrieved.
Constructor Summary | |
---|---|
Client()
Default constructor. |
|
Client(java.lang.String host,
int port,
java.lang.String login,
java.lang.String passwd)
Connection constructor. |
Method Summary | |
---|---|
void |
authenticate()
Intend to authenticate with alread set login and password. |
void |
authenticate(java.lang.String login,
java.lang.String passwd)
Intend to authenticate with specified login and password, overriding already defined ones. |
void |
connect()
Connection to UPSD with already specified parameters. |
void |
connect(java.lang.String host,
int port)
Intent to connect to an UPSD with specified parameters without authentication. |
void |
connect(java.lang.String host,
int port,
java.lang.String login,
java.lang.String passwd)
Intent to connect and authenticate to an UPSD with specified parameters. |
void |
disconnect()
Disconnect. |
protected java.lang.String |
get(java.lang.String subcmd,
java.lang.String param)
Send a GET query line then read the reply and validate the response. |
protected java.lang.String |
get(java.lang.String subcmd,
java.lang.String[] params)
Send a GET query line then read the reply and validate the response. |
Device |
getDevice(java.lang.String name)
Intend to retrieve a device by its name. |
Device[] |
getDeviceList()
Returns the list of available devices from the NUT server. |
java.lang.String |
getHost()
Get the host name or address to which client is (or will be) connected. |
java.lang.String |
getLogin()
Get the login with which the client is (or will be connected). |
java.lang.String |
getPasswd()
Get the password with which the client is (or will be connected). |
int |
getPort()
Get the port to which client is (or will be) connected. |
boolean |
isConnected()
Test if the client is connected to the UPSD. |
protected java.lang.String[] |
list(java.lang.String subcmd)
Send a LIST query line then read replies and validate them. |
protected java.lang.String[] |
list(java.lang.String subcmd,
java.lang.String param)
Send a LIST query line then read replies and validate them. |
protected java.lang.String[] |
list(java.lang.String subcmd,
java.lang.String[] params)
Send a LIST query line then read replies and validate them. |
void |
logout()
Log out. |
protected java.lang.String |
query(java.lang.String query)
Send a query line then read the response. |
protected java.lang.String |
query(java.lang.String query,
java.lang.String subquery)
Send a query line then read the response. |
protected java.lang.String |
query(java.lang.String query,
java.lang.String[] params)
Send a query line then read the response. |
protected java.lang.String |
query(java.lang.String query,
java.lang.String subquery,
java.lang.String[] params)
Send a query line then read the response. |
void |
setHost(java.lang.String host)
Set the host name (or address) to which the client will intend to connect to at next connection. |
void |
setLogin(java.lang.String login)
Set the login with which the client will intend to connect. |
void |
setPasswd(java.lang.String passwd)
Set the password with which the client will intend to connect. |
void |
setPort(int port)
Set the port to which client is (or will be) connected. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Client()
public Client(java.lang.String host, int port, java.lang.String login, java.lang.String passwd) throws java.io.IOException, java.net.UnknownHostException, NutException
host
- Host to which connect.port
- IP port.login
- Login to use to connect to UPSD.passwd
- Password to use to connect to UPSD.
java.io.IOException
java.net.UnknownHostException
NutException
Method Detail |
---|
public java.lang.String getHost()
public void setHost(java.lang.String host)
host
- New host name or address.public java.lang.String getLogin()
public void setLogin(java.lang.String login)
login
- New login.public java.lang.String getPasswd()
public void setPasswd(java.lang.String passwd)
passwd
- New password.public int getPort()
public void setPort(int port)
port
- Port number.public void connect(java.lang.String host, int port, java.lang.String login, java.lang.String passwd) throws java.io.IOException, java.net.UnknownHostException, NutException
host
- Host to which connect.port
- IP port.login
- Login to use to connect to UPSD.passwd
- Password to use to connect to UPSD.
java.io.IOException
java.net.UnknownHostException
NutException
public void connect(java.lang.String host, int port) throws java.io.IOException, java.net.UnknownHostException, NutException
host
- Host to which connect.port
- IP port.
java.io.IOException
java.net.UnknownHostException
NutException
public void connect() throws java.io.IOException, java.net.UnknownHostException, NutException
java.io.IOException
java.net.UnknownHostException
NutException
public void authenticate(java.lang.String login, java.lang.String passwd) throws java.io.IOException, NutException
login
- passwd
-
java.io.IOException
NutException
public void authenticate() throws java.io.IOException, NutException
java.io.IOException
NutException
public boolean isConnected()
public void disconnect()
public void logout()
protected java.lang.String query(java.lang.String query, java.lang.String subquery) throws java.io.IOException, NutException
query
- Query to send.subquery
- Sub query to send.
java.io.IOException
NutException
protected java.lang.String query(java.lang.String query, java.lang.String subquery, java.lang.String[] params) throws java.io.IOException, NutException
query
- Query to send.subquery
- Sub query to send.params
- Optionnal additionnal parameters.
java.io.IOException
NutException
protected java.lang.String query(java.lang.String query, java.lang.String[] params) throws java.io.IOException, NutException
query
- Query to send.params
- Optionnal additionnal parameters.
java.io.IOException
NutException
protected java.lang.String query(java.lang.String query) throws java.io.IOException, NutException
query
- Query to send.
java.io.IOException
NutException
protected java.lang.String get(java.lang.String subcmd, java.lang.String param) throws java.io.IOException, NutException
subcmd
- GET subcommand to send.param
- Extra parameters
java.io.IOException
NutException
protected java.lang.String get(java.lang.String subcmd, java.lang.String[] params) throws java.io.IOException, NutException
subcmd
- GET subcommand to send.params
- Eventual extra parameters.
java.io.IOException
NutException
protected java.lang.String[] list(java.lang.String subcmd) throws java.io.IOException, NutException
subcmd
- LIST subcommand to send.
java.io.IOException
NutException
protected java.lang.String[] list(java.lang.String subcmd, java.lang.String param) throws java.io.IOException, NutException
subcmd
- LIST subcommand to send.param
- Extra parameters.
java.io.IOException
NutException
protected java.lang.String[] list(java.lang.String subcmd, java.lang.String[] params) throws java.io.IOException, NutException
subcmd
- LIST subcommand to send.params
- Eventual extra parameters.
java.io.IOException
NutException
public Device[] getDeviceList() throws java.io.IOException, NutException
java.io.IOException
NutException
public Device getDevice(java.lang.String name) throws java.io.IOException, NutException
name
- Name of the device to look at.
java.io.IOException
NutException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |