Acspy.Clients.SimpleClient
index
/alma/ACS-2016.6/ACSSW/lib/python/site-packages/Acspy/Clients/SimpleClient.py

PySimpleClient - An extension to the BaseClient class.
 
This module is designed to provide easy access to the majority of CORBA services
and ACS components. Essentially it is used to manipulate components.
 
TODO:
- in general more argument type checking is needed for all functions.
- integrate with the ACS Error System

 
Modules
       
ACS
os
pwd
signal
socket
threading

 
Classes
       
Acspy.Clients.BaseClient.BaseClient(maci__POA.Client)
PySimpleClient(Acspy.Clients.BaseClient.BaseClient, Acspy.Servants.ContainerServices.ContainerServices)
Acspy.Servants.ContainerServices.ContainerServices(__builtin__.object)
PySimpleClient(Acspy.Clients.BaseClient.BaseClient, Acspy.Servants.ContainerServices.ContainerServices)

 
class PySimpleClient(Acspy.Clients.BaseClient.BaseClient, Acspy.Servants.ContainerServices.ContainerServices)
    PySimpleClient class provides access to ACS components, CORBA services, etc.
Furthermore, it provides access to the same ContainerServices provided by
the Container to components. This makes it almost trivial to test components as
PySimpleClients and vice versa.
 
 
Method resolution order:
PySimpleClient
Acspy.Clients.BaseClient.BaseClient
maci__POA.Client
omniORB.PortableServer.Servant
Acspy.Servants.ContainerServices.ContainerServices
__builtin__.object

Methods defined here:
__init__(self, name='Python Client')
Initialize the client.
 
Parameters:
- name is what manager will refer to this client instance as
- runAsSingleton True if the client is a singleton
 
Returns: Nothing
 
Raises: CORBAProblemExImpl

Static methods defined here:
getInstance(name='PySingletonClient')
Returns a singleton instance of the PySimpleClient class.
 
Parameters:
- name is what manager will refer to this client singleton instance as
 
Returns: Nothing
 
Raises: CORBAProblemExImpl

Methods inherited from Acspy.Clients.BaseClient.BaseClient:
authenticate(self, execution_id, question)
Authentication method. Method authenticate is the challenge issued to
the client after it tries to login. The login will be successful if the
clients authenticate() produces the expected result. Only in this case
will the Managers login method return a valid handle, which the client
will later use as the id parameter with all calls to the Manager.
 
Parameters: question this string does not currently matter
 
Return Answer - first character of the answer identifies the type of
the client, and can be one of:
- C = a regular client (implements just the Client interface).
- A = a container (implements the Container interface).
- AR = a container with recovery capability (implements the Container interface).
- S = Supervisor (implements the Administrator interface).
 
Raises: Nothing
 
string authenticate (in string question);
components_available(self, components)
Notify client about the change (availability) of the components currently
in use by this client. For administrative clients, notification is issued
for the change of availability of any component in the domain.
 
Parameters:
- components is a sequence of ComponentInfo structures
 
Returns: None
 
Raises: Nothing
 
oneway void components_available(in ComponentInfoSeq components)
components_unavailable(self, component_names)
Notify client that some of the Components currently in use by client
have become unavailable.
 
Parameters:
- component_names names of various unavailable components
 
Returns: None
 
Raises: Nothing
 
oneway void Components_unavailable (in stringSeq component_names)
disconnect(self)
Disconnect notification. The disconnect method is called by the Manager
to notify the client that it will be unavailable and that the client
should log off.
 
Also, the client developer is required to disconnect all connected clients
before exiting the Python interpreter.
 
Parameters: None
 
Returns: None
 
Raises: Nothing
 
oneway void disconnect ();
getCode(self)
Returns the code to be used when manager tries to authenticate this
object
 
Parameters: None
 
Returns: the code to be returned to manager.
 
Raises: Nothing
getMyCorbaRef(self)
Helper method which returns this Python objects underlying CORBA servant
reference.
 
This implementation implicityly activates the client using the default
POA if it has not been activated before.
 
Parameters: None
 
Returns: a CORBA reference to this object
 
Raises: CORBAProblemExImpl
isLoggedIn(self)
Returns True is the client is logged into the manager
and False otherwise
 
Parameters: None
 
Raises: Nothing
managerLogin(self)
Login into the manager
 
Parameters: None
 
Returns: The token received from the manager
 
Raises: CORBAProblemExImpl If the login failed
managerLogout(self)
Logout from manager
 
Parameters: None
 
Returns: None
 
Raises: Nothing
message(self, message_type, message)
The Manager and administrators use this method for sending textual messages
to the client.
 
This implementation first attempts to use the ACS logging mechanism to
display the message and if that fails for any reason, it is only sent
to standard out.
 
Parameters:
- message_type is an integer defined as a constant in the Client interface
- message is a string
 
Returns: Nothing
 
Raises: Nothing
 
oneway void message (in short message_type, in string message)
ping(self)
Manager pings its clients to verify they still exist.
 
Parameters: None
 
Returns: CORBA.TRUE (i.e., 1)
 
Raises: Nothing
 
boolean ping ();
setToken(self, newToken)
This method is called by the thread when it tries to 
reconnect to the manager.
 
This method does not do anything if the connection failed: 
it must be overridden to customize (the Container wants to terminate 
in that case for example).
 
Parameters: newToken The newToken returned by the manager
            A value of None means that the thread failed to reconnect
 
Returns None
 
Raises: Nothing

Data descriptors inherited from omniORB.PortableServer.Servant:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Methods inherited from Acspy.Servants.ContainerServices.ContainerServices:
activateOffShoot(self, py_obj)
Activates an OffShoot derived object as a CORBA object.
 
Parameters:
- py_obj is (non-CORBA) Python object.
 
Return: a reference to the CORBA object that almost definitely needs to
be narrowed to the correct type.  If anything goes wrong though, returns
None.
 
Raises: ???
availableComponents(self, name_wildcard='*', type_wildcard='*', activated=0)
Returns a list of ComponentInfos consisting of all Components known 
to manager.
 
Parameters:
- name_wildcard is a wildcard that the components name must match in 
order for its information to be returned
- type_wildcard is a wildcard that the components type must match in
order for its information to be returned.
- activated is a boolean value which specifies whether the search 
should be limited to components which have already been activated.
 
Returns: a list consisting of ComponentInfo structures for every
component manager knows of
 
Raises: ???
corbaObjectFromString(self, obj_uri)
Converts a string to a CORBA object reference.
 
Parameters:
- obj_uri is the address to the CORBA object
 
Return: a CORBA reference to obj_uri
 
Raises: ???
corbaObjectToString(self, comp_ref)
Converts a CORBA object its string representation.
 
Parameters: comp_ref is a reference to the CORBA object.
 
Return: the string representation (an IOR)
 
Raises: ???
findComponents(self, curl_wildcard='*', type_wildcard='*', activated=False)
Finds components by their instance name and/or by their type.
 
    Wildcards can be used for the curl and type.
    This method returns a possibly empty array of component curls; 
    for each curl, you may use getComponent to obtain the reference.
 
Parameters:
- name_wildcard (None is understood as "*")
- type_wildcard (None is understood as "*")
- activated is a boolean value which specifies whether the search 
should be limited to components which have already been activated.
 
Return: the curls of the component(s) that match the search.
 
Raises: ???
forceReleaseComponent(self, comp_name)
Forcefully releases the component defined by comp_name.
 
Parameter: comp_name is the name of the component to be released.
 
Returns: The number of objects still attached to the released component
 
Raises: Nothing
getCDBElement(self, record_name, ele_name)
This method returns all of the attributes in the form of a dictionary
for a given XML element within an XML file.
 
Parameters:
- record_name is the name of the XML file (e.g., "alma/MOUNT1")
- ele_name is the name of the element (e.g, "MOUNT/actAz")
- element_name is the name of the element (e.g, "MOUNT/actAz",
  where acsAz is an XML element contianing all attributes
  representing the characteristics of a BACI property).
 
Return: a dictionary
 
Raises: ???
getCDBRecord(self, record_name)
Returns the stringified version of an XML record in the ACS
configuration database defined by record_name.
 
Parameters:
- record_name is the full name of an XML record in the CDB.  An
example would be "alma/MOUNT1".
 
Return: the stringified XML record 
 
Raises: ???
getCollocatedComp(self, comp_spec, mark_as_default, target_comp)
Activation of a component so that it runs in the same process as
another given component.
 
Parameters:
- comp_spec (maci.ComponentSpec) Component to be obtained.
- mark_as_default (bool) Mark component as default component of its type
- target_comp Name of the target component (where to activate component)
 
Returns: a narrowed reference to the component or None if
that reference cannot be obtained.
 
Raises:
- IncompleteComponentSpec
- InvalidComponentSpec
- ComponentSpecIncompatibleWithActiveComponent
getComponent(self, comp_name=None, activate=True, comp_idl_type=None, comp_code=None, container_name=None, is_dynamic=0)
NOTE: all keyword parameters with the exception of comp_name are
deprecated!
 
Get a component reference from the Manager.
 
This seemingly simple method is actually quite complicated. First, its
important to note that this method narrows the reference for the
developer and even imports the proper IDL Python stub. Under certain
circumstances though, the IDL Python stub may NOT exist in the correct
place which has led some developers to believe this method was broken
in the past. So if you see an error message beginning with
"Unable to import...", please check that you really CAN import the
CORBA stubs for the component you are trying to access using the
infamous "python -i" command.
 
The next important thing to realize is this method does not just
retrieve named components as its own name implies - based on the
parameters passed it could return default and dynamic components
also.
 
Parameters:
- name is the components name. If not None and the rest of the
default parameters are left as-is, this is assumed to be a static
component.
- activate tells manager whether the component should be activated
if it has not already been instantiated. Not too useful.
- comp_idl_type is the interface repository IDL location of the
component. If not None and the rest of the default parameters are
left as-is, it is assumed the developer wants a default component.
- comp_code is a shared library implementing component. If not
None, it is assumed the developer wants a dynamic component.
- container_name is the name of the container to activate component.
If not None, it is assumed the developer wants a dynamic component.
- is_dynamic states whether a component should be retrieved as
default or dynamic. In simple terms, when this parameter and
comp_idl_type are the only params that have been changed from their
original values, this is the difference between retrieving a reference
to a dynamic component or a default component.
 
Returns: a narrowed reference to the component or None if
that reference cannot be obtained.
 
Raises: CannotGetComponentExImpl if the component stubs cannot be loaded
        or found
getComponentNonSticky(self, comp_name)
Gets the component in a non stick way.
The comp_name is a name of the component.
 
Parameters:
- comp_name is the name of the component.
 
Returns: a narrowed reference to the component or None if
that reference cannot be obtained.
 
Raises: CannotGetComponentExImpl if the component stubs cannot be loaded
        or found
getContName(self)
Returns our container name.
 
Parameters: None
 
Return: name of the container the component was started by.
 
Raises: Nothing
getDefaultComponent(self, comp_type)
Gets the default component specified by the component type.
The type is the IDL type, such as "IDL:alma/PS/PowerSupply:1.0"
 
Parameters:
- comp_type is the interface repository IDL location of the
component.
 
Returns: a narrowed reference to the component or None if
that reference cannot be obtained.
 
Raises: CannotGetComponentExImpl if the component stubs cannot be loaded
        or found
getDynamicComponent(self, name, comp_type, code, container)
Gets a component whose instance is not registered in the CDB 
at deployment time.
 
Parameters:
- name is the components name in string format
- comp_type is the interface repository IDL location of the component
- code is a shared library implementing component
- container is the name of the container to activate component.
 
Returns: a narrowed reference to the component or None if
that reference cannot be obtained.
 
Raises: CannotGetComponentExImpl if the component stubs cannot be loaded
        or found
getLogger(self)
Returns the component/client logger.
 
Parameters: None
 
Return: a logger
 
Raises: Nothing
getName(self)
Returns our name.
 
Parameters: None
 
Return: name of the component or client derived from ContainerServices.
 
Raises: Nothing
getThread(self, target, name, args=None, kwargs=None)
This method returns a Python threading.Thread object.
 
Parameters:
- target callable object to be invoked by the run() method
- name the thread name. Must be unique
- args is the argument tuple for the target invocation. Defaults to ()
- kwargs is a dictionary of keyword arguments for the target
invocation. Defaults to {}
 
Return: a threading.Thread object
 
Raises: ???
makeCompImmortal(self, comp_name, state)
Change mortality state of a component.
Compnent must be already active.
The caller must be owner of the component or have administator rights.
 
Parameters:
- comp_name name of the component
- state new mortality state
 
Returns: None
 
Raises: ???
releaseComponent(self, comp_name)
Release the component defined by comp_name.
 
Parameter: comp_name is the name of the component to be released.
 
Returns: The number of objects still attached to the released component
 
Raises: Nothing
releaseComponentAsync(self, comp_name, callback=None)
Release the component defined by comp_name in asynchronous way.
 
Parameters: 
 - comp_name is the name of the component to be released.
 - callback by default is None or it must be a subclass of relaseCallback
 
Returns: The number of objects still attached to the released component
 
Raises: TypeError if callback is not instance of ComponentReleaseCallback
restartComp(self, comp_name)
Restarts a component.
 
Parameters:
- comp_name name of the component
 
Returns: Reference to the restarted component.
 
Raises: ???
setAll(self, name, token, handle, activate_offshoot_method, contname=None)
This method should only be invoked by the container and provides the
component with all container services. DO NOT INVOKE FROM YOUR CODE!!!

 
Functions
       
handlerSIGCONT(signum, frame)
The handler for the SIGCONT signal runs when the user wakes up the script
previously suspended with a CTRL-Z.
 
This handler restores the handler for the SIGSTP
handlerSIGSTP(signum, frame)
The handler for the SIGSTP signal runs when the user 
presses CTRL-Z and suspends the script.
 
This handler flushes the logs before suspending.

 
Data
        __revision__ = '$Id: SimpleClient.py,v 1.14 2011/11/29 18:43:17 nsaez Exp $'
origHandlerSIGCONT = 0
origHandlerSIGSTP = 0