Panda3D
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
AsyncRequest Class Reference
Inheritance diagram for AsyncRequest:
DirectObject

Public Member Functions

 __init__ (self, air, replyToChannelId=None, timeoutTime=ASYNC_REQUEST_DEFAULT_TIMEOUT_IN_SECONDS, numRetries=ASYNC_REQUEST_DEFAULT_NUM_RETRIES)
 
 askForObject (self, doId, context=None)
 
 askForObjectField (self, dclassName, fieldName, doId, key=None, context=None)
 
 askForObjectFields (self, dclassName, fieldNames, doId, key=None, context=None)
 
 askForObjectFieldsByString (self, dbId, dclassName, objString, fieldNames, key=None, context=None)
 
 createObject (self, name, className, databaseId=None, values=None, context=None)
 
 createObjectId (self, name, className, values=None, context=None)
 
 delete (self)
 
 finish (self)
 
 timeout (self, task)
 
- Public Member Functions inherited from DirectObject
 accept (self, event, method, extraArgs=[])
 
 acceptOnce (self, event, method, extraArgs=[])
 
 addTask (self, *args, **kwargs)
 
 detectLeaks (self)
 
 doMethodLater (self, *args, **kwargs)
 
 getAllAccepting (self)
 
 ignore (self, event)
 
 ignoreAll (self)
 
 isAccepting (self, event)
 
 isIgnoring (self, event)
 
 removeAllTasks (self)
 
 removeTask (self, taskOrName)
 

Public Attributes

 air
 
 avatarId
 
 deletingMessage
 
 neededObjects
 
 numRetries
 
 replyToChannelId
 
 timeout
 
 timeoutTask
 

Static Public Attributes

 notify = DirectNotifyGlobal.directNotify.newCategory('AsyncRequest')
 
- Static Public Attributes inherited from DirectObject
 accept_once = acceptOnce
 
 add_task = addTask
 
 detect_leaks = detectLeaks
 
 do_method_later = doMethodLater
 
 get_all_accepting = getAllAccepting
 
 ignore_all = ignoreAll
 
 is_accepting = isAccepting
 
 is_ignoring = isIgnoring
 
 remove_all_tasks = removeAllTasks
 
 remove_task = removeTask
 

Protected Member Functions

 _checkCompletion (self, name, context, distObj)
 
 _doCreateObject (self, name, className, values, doId)
 
 _resetTimeoutTask (self, createAnew=True)
 
- Protected Member Functions inherited from DirectObject
 _addTask (self, task)
 
 _clearTask (self, task)
 

Protected Attributes

 _checkCompletion
 
 _doCreateObject
 
 _initialNumRetries
 
 _timeoutTime
 
- Protected Attributes inherited from DirectObject
 _taskList
 

Static Protected Attributes

dict _asyncRequests = {}
 

Detailed Description

This class is used to make asynchronous reads and creates to a database.

You can create a list of self.neededObjects and then ask for each to be
read or created, or if you only have one object that you need you can
skip the self.neededObjects because calling askForObject or createObject
will set the self.neededObjects value for you.

Once all the objects have been read or created, the self.finish() method
will be called.  You may override this function to run your code in a
derived class.

If you wish to queue up several items that you all need before the finish
method is called, you can put items in self.neededObjects and then call
askForObject or createObject afterwards.  That way the _checkCompletion
will not call finish until after all the requests have been done.

If you need to chain serveral object reads or creates, just add more
entries to the self.neededObjects dictionary in the self.finish function
and return without calling AsyncRequest.finish().  Your finish method
will be called again when the new self.neededObjects is complete.  You
may repeat this as necessary.

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
air,
replyToChannelId = None,
timeoutTime = ASYNC_REQUEST_DEFAULT_TIMEOUT_IN_SECONDS,
numRetries = ASYNC_REQUEST_DEFAULT_NUM_RETRIES )
air is the AI Respository.
replyToChannelId may be an avatarId, an accountId, or a channelId.
timeoutTime is how many seconds to wait before aborting the request.
numRetries is the number of times to retry the request before giving up.

Reimplemented from DirectObject.

Member Function Documentation

◆ _checkCompletion()

_checkCompletion ( self,
name,
context,
distObj )
protected
This checks whether we have all the needed objects and calls
finish() if we do.

◆ _doCreateObject()

_doCreateObject ( self,
name,
className,
values,
doId )
protected

◆ _resetTimeoutTask()

_resetTimeoutTask ( self,
createAnew = True )
protected

◆ askForObject()

askForObject ( self,
doId,
context = None )
Request an already created object, i.e. read from database.

◆ askForObjectField()

askForObjectField ( self,
dclassName,
fieldName,
doId,
key = None,
context = None )
Request an already created object, i.e. read from database.

◆ askForObjectFields()

askForObjectFields ( self,
dclassName,
fieldNames,
doId,
key = None,
context = None )
Request an already created object, i.e. read from database.

◆ askForObjectFieldsByString()

askForObjectFieldsByString ( self,
dbId,
dclassName,
objString,
fieldNames,
key = None,
context = None )

◆ createObject()

createObject ( self,
name,
className,
databaseId = None,
values = None,
context = None )
Create a new database object.  You can get the doId from within
your self.finish() function.

This functions is different from createObjectId in that it does
generate the object when the response comes back.  The object is
added to the doId2do and so forth and treated as a full regular
object (which it is).  This is useful on the AI where we really
do want the object on the AI.

◆ createObjectId()

createObjectId ( self,
name,
className,
values = None,
context = None )
Create a new database object.  You can get the doId from within
your self.finish() function.

This functions is different from createObject in that it does not
generate the object when the response comes back.  It only tells you
the doId.  This is useful on the UD where we don't really want the
object on the UD, we just want the object created and the UD wants
to send messages to it using the ID.

◆ delete()

delete ( self)

◆ finish()

finish ( self)
This is the function that gets called when all of the needed objects
are in (i.e. all the askForObject and createObject requests have
been satisfied).
If the other requests timeout, finish will not be called.

◆ timeout()

timeout ( self,
task )

Member Data Documentation

◆ _asyncRequests

dict _asyncRequests = {}
staticprotected

◆ _checkCompletion

_checkCompletion
protected

◆ _doCreateObject

_doCreateObject
protected

◆ _initialNumRetries

_initialNumRetries
protected

◆ _timeoutTime

_timeoutTime
protected

◆ air

air

◆ avatarId

avatarId

◆ deletingMessage

deletingMessage

◆ neededObjects

neededObjects

◆ notify

notify = DirectNotifyGlobal.directNotify.newCategory('AsyncRequest')
static

◆ numRetries

numRetries

◆ replyToChannelId

replyToChannelId

◆ timeout

timeout

◆ timeoutTask

timeoutTask