com.sun.n1.sps.client
Interface CommandManager


public interface CommandManager

The CommandManager interface is used to execute CLI commands and query information from the Master Server.


Method Summary
 void clearSession()
          Clears the current SessionID so that a subsequent call to this CommandManager will be unauthenticated.
 void close()
          Shutdown connection to the MS.
 java.lang.Object convert(java.lang.String inStringToConvert, java.lang.Class desiredClass)
          Acquire an SPS Object based on the CLI string synatx specified in the "CLI Input Types" documentation Example: HostID hostID = (HostID) manager.convert("NM:myhost", HostID.class); This method uses the current SessionID as returned by getSessionID() for authentication to the Master Server.
 TypedList createEmptyList(java.lang.Class inPublicIfaceClass)
          Create an empty TypedList of the desired type Example: HostIDSet hostSet = (HostIDSet) manager.createEmptySet(HostIDSet.class);
 TypedSet createEmptySet(java.lang.Class inPublicIfaceClass)
          Create an empty TypedSet of the desired type Example: HostIDSet hostSet = (HostIDSet) manager.createEmptySet(HostIDSet.class);
 java.lang.Object execute(java.lang.String command, java.util.Map arguments)
          Execute CLI commands on the MasterServer.
 SessionID getSessionID()
          Gets the current SessionID associated with this CommandManager.
 java.lang.String getVersionString()
          Returns the version of the CLUI that the CommandManager is connected to.
 void setLocalOutputStream(java.io.OutputStream inOutputStream)
          Associates the specified output stream with the current thread such that any commands executed which write to an output stream will use the specified stream for such output.
 void setSessionID(SessionID inSessionID)
          Sets the Session for this CommandManager to the specified SessionID.
 

Method Detail

execute

java.lang.Object execute(java.lang.String command,
                         java.util.Map arguments)
                         throws ClientException
Execute CLI commands on the MasterServer. The commands are documented in the CLI User Documentation while the argument and return types are documented in the Public API Javadocs. Example: Host[ ] hosts = (Host[ ]) manager.execute("hdb.h.la", new HashMap()); This method uses the current SessionID as returned by getSessionID() for authenitication to the Master Server. The SessionID may also be specified with an argument of "-s" and a SessionID as defined in the CLI User Documentation.

Parameters:
command - The CLI command to execute
arguments - The collection of arguments to pass to the command, or null if there are no arguments.
Returns:
The result Object of the command. May be cast to the type documented in the CLI documentation.
Throws:
AuthenticationException - the user could not be authenticated to the Master Server
NetworkException - the Master Server could not be reached
CommandException - The command was not found, did not have the correct arguments, or failed during execution
ConversionException - There was a problem converting some of the supplied arguments or the result
ClientException

convert

java.lang.Object convert(java.lang.String inStringToConvert,
                         java.lang.Class desiredClass)
                         throws ClientException
Acquire an SPS Object based on the CLI string synatx specified in the "CLI Input Types" documentation Example: HostID hostID = (HostID) manager.convert("NM:myhost", HostID.class); This method uses the current SessionID as returned by getSessionID() for authentication to the Master Server.

Parameters:
inStringToConvert - The string representation of the desired object
desiredClass - The Class to convert to
Returns:
A public object of the desiredClass type or null if the conversion failed. May be cast to the specific Object requested.
Throws:
ClientException - if the user could not be authenticated to the Master Server, or the Master Server could not be reached, or an unexpected error occurs.

createEmptyList

TypedList createEmptyList(java.lang.Class inPublicIfaceClass)
                          throws ClientException
Create an empty TypedList of the desired type Example: HostIDSet hostSet = (HostIDSet) manager.createEmptySet(HostIDSet.class);

Parameters:
inPublicIfaceClass - A class of type TypedSet
Returns:
an empty TypedList of the desired type. May also be cast to the requested type.
Throws:
IllegalArgumentsException - if the typedSetClass argument does not extend TypedSet or is null
ClientException - if an error occurs.

createEmptySet

TypedSet createEmptySet(java.lang.Class inPublicIfaceClass)
                        throws ClientException
Create an empty TypedSet of the desired type Example: HostIDSet hostSet = (HostIDSet) manager.createEmptySet(HostIDSet.class);

Parameters:
inPublicIfaceClass - A class of type TypedSet
Returns:
an empty TypedSet of the desired type. May also be cast to the requested type.
Throws:
IllegalArgumentsException - if the typedSetClass argument does not extend TypedSet or is null
ClientException - if an error occurs.

getSessionID

SessionID getSessionID()
                       throws ClientException
Gets the current SessionID associated with this CommandManager.

Returns:
the current SessionID or null if there is no sessionID
Throws:
ClientException - if an error occurs.

setSessionID

void setSessionID(SessionID inSessionID)
                  throws ClientException
Sets the Session for this CommandManager to the specified SessionID. A SessionID can be acquired from the result of a LoginCommand. Running a Login command also implicitly sets the SessionID for this CommandManager as the SessionID is stored on a local thread variable. The SessionID is maintained for the entire thread, so subsequent execute(...) calls will use the same SessionID. This means that it is important to call clearSession() if you do not want subsequent uses of this instance to reuse authentication.

Parameters:
inSessionID - the id of the session to use for this CommandManager
Throws:
ClientException - if an error occurs.

clearSession

void clearSession()
                  throws ClientException
Clears the current SessionID so that a subsequent call to this CommandManager will be unauthenticated.

Throws:
ClientException - if an error occurs.

setLocalOutputStream

void setLocalOutputStream(java.io.OutputStream inOutputStream)
Associates the specified output stream with the current thread such that any commands executed which write to an output stream will use the specified stream for such output. If inOutputStream is null, command output will be discarded. The thread-based setting enacted by this call will persist until the next invocation of this call.

Parameters:
inOutputStream - OutputStream to be used in the local thread for any commands which write output to a stream. May be null, in which case command stream output will be discarded.

getVersionString

java.lang.String getVersionString()
Returns the version of the CLUI that the CommandManager is connected to.

Returns:
the version string

close

void close()
           throws ClientException
Shutdown connection to the MS. All background threads will be stopped and this CommandManager will not be useable after this method is called

Throws:
ClientException