org.rhq.enterprise.clientapi
Class RemoteClient

java.lang.Object
  extended by org.rhq.enterprise.clientapi.RemoteClient
All Implemented Interfaces:
RhqFacade

public class RemoteClient
extends Object
implements RhqFacade

A remote access client that provides transparent servlet-based proxies to an RHQ Server.

Author:
Greg Hinkle, Simeon Pinder, Jay Shaughnessy, John Mazzitelli

Field Summary
static String NONSECURE_TRANSPORT
           
static String SECURE_TRANSPORT
           
 
Constructor Summary
RemoteClient(String host, int port)
          Creates a client that will communicate with the server running on the given host listening on the given port.
RemoteClient(String transport, String host, int port)
          Creates a client that will communicate with the server running on the given host listening on the given port over the given transport.
RemoteClient(String transport, String host, int port, String subsystem)
           
 
Method Summary
 void connect()
          Connects to the remote server but does not establish a user session.
 void disconnect()
          Disconnect from the server.
 String getHost()
           
 int getPort()
           
<T> T
getProxy(Class<T> remoteApiIface)
           
 URI getRemoteURI()
           
 Map<RhqManager,Object> getScriptingAPI()
          Returns the map of all remote managers running in the server that this client can talk to.
 String getServerBuildNumber()
          If the client is connected, this is build number of the server that the client is talking to.
 String getServerVersion()
          If the client is connected, this is version of the server that the client is talking to.
 org.rhq.core.domain.auth.Subject getSubject()
          Returns the information on the user that is logged in.
 String getTransport()
           
protected  String guessTransport(int port)
           
 boolean isConnected()
          Returns true if and only if this client successfully connected to the remote server.
 boolean isLoggedIn()
          Returns true if and only if this client successfully connected to the remote server and the user successfully logged in.
 org.rhq.core.domain.auth.Subject login(String user, String password)
          Connects to the remote server and logs in with the given credentials.
 void logout()
          Logs out from the server and disconnects this client.
<T> T
remoteInvoke(RhqManager manager, Method method, Class<T> expectedReturnType, Object... parameters)
           
 void setTransport(String transport)
          Sets the underlying transport to use to communicate with the server.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NONSECURE_TRANSPORT

public static final String NONSECURE_TRANSPORT
See Also:
Constant Field Values

SECURE_TRANSPORT

public static final String SECURE_TRANSPORT
See Also:
Constant Field Values
Constructor Detail

RemoteClient

public RemoteClient(String host,
                    int port)
Creates a client that will communicate with the server running on the given host listening on the given port. This constructor will not attempt to connect or login to the remote server - use login(String, String) for that.

Parameters:
host -
port -

RemoteClient

public RemoteClient(String transport,
                    String host,
                    int port)
Creates a client that will communicate with the server running on the given host listening on the given port over the given transport. This constructor will not attempt to connect or login to the remote server - use login(String, String) for that.

Parameters:
transport - valid values are "servlet" and "sslservlet" - if null, sslservlet will be used for ports that end with "443", servlet otherwise
host -
port -

RemoteClient

public RemoteClient(String transport,
                    String host,
                    int port,
                    String subsystem)
Method Detail

remoteInvoke

public <T> T remoteInvoke(RhqManager manager,
                          Method method,
                          Class<T> expectedReturnType,
                          Object... parameters)
               throws Throwable
Throws:
Throwable

login

public org.rhq.core.domain.auth.Subject login(String user,
                                              String password)
                                       throws Exception
Connects to the remote server and logs in with the given credentials. After successfully executing this, isLoggedIn() will be true and getSubject() will return the subject that this method returns.

Specified by:
login in interface RhqFacade
Parameters:
user -
password -
Returns:
the logged in user
Throws:
Exception - if failed to connect to the server or log in

logout

public void logout()
Logs out from the server and disconnects this client.

Specified by:
logout in interface RhqFacade

connect

public void connect()
             throws Exception
Connects to the remote server but does not establish a user session. This can be used with the limited API that does not require a Subject. After successfully executing this, isConnected() will be true and getSubject() will return the subject that this method returns.

Throws:
Exception - if failed to connect to the server or log in

disconnect

public void disconnect()
Disconnect from the server.


isLoggedIn

public boolean isLoggedIn()
Returns true if and only if this client successfully connected to the remote server and the user successfully logged in.

Specified by:
isLoggedIn in interface RhqFacade
Returns:
if the user was able to connect and log into the server

isConnected

public boolean isConnected()
Returns true if and only if this client successfully connected to the remote server.

Returns:
if the user was able to connect and log into the server

getSubject

public org.rhq.core.domain.auth.Subject getSubject()
Returns the information on the user that is logged in. May be null if the user never logged in successfully.

Specified by:
getSubject in interface RhqFacade
Returns:
user information or null

getRemoteURI

public URI getRemoteURI()

getHost

public String getHost()

getPort

public int getPort()

getTransport

public String getTransport()

guessTransport

protected String guessTransport(int port)

setTransport

public void setTransport(String transport)
Sets the underlying transport to use to communicate with the server. Available transports are "servlet" and "sslservlet". If you set it to null, then the transport to be used will be set appropriately for the getPort() (e.g. a secure transport will be used for ports that end with 443, a non-secure transport will be used for all other ports).

Parameters:
transport -

getScriptingAPI

public Map<RhqManager,Object> getScriptingAPI()
Returns the map of all remote managers running in the server that this client can talk to.

Specified by:
getScriptingAPI in interface RhqFacade
Returns:
Map K=manager name V=remote proxy

getProxy

public <T> T getProxy(Class<T> remoteApiIface)
Specified by:
getProxy in interface RhqFacade

toString

public String toString()
Overrides:
toString in class Object

getServerVersion

public String getServerVersion()
If the client is connected, this is version of the server that the client is talking to.

Returns:
remote server version

getServerBuildNumber

public String getServerBuildNumber()
If the client is connected, this is build number of the server that the client is talking to.

Returns:
remote server build number


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.