Class DataServiceRuntime


  • public final class DataServiceRuntime
    extends DataClayRuntime
    This class contains functions for node to interact with other nodes.
    • Field Detail

      • dsRef

        public DataService dsRef
        Ref to DS if this lib serves to a DS.
      • tasksScheduled

        public boolean tasksScheduled
        Indicates if tasks (garbage collectors,...) were scheduled or not. This is done to manage. multiple initializations.
    • Constructor Detail

      • DataServiceRuntime

        public DataServiceRuntime​(DataService newdsRef)
        Constructor.
        Parameters:
        newdsRef - DS reference
    • Method Detail

      • initialize

        public void initialize​(String logicModuleHost,
                               int logicModulePort,
                               String originHostName)
                        throws Exception
        Initialize connections.
        Overrides:
        initialize in class DataClayRuntime
        Parameters:
        logicModuleHost - Name of the host of the logic module
        logicModulePort - Port of the logic module
        originHostName - Name of the host using the lib.
        Throws:
        Exception - if connection could not be done for some reason.
      • getOrNewPersistentInstance

        public DataClayExecutionObject getOrNewPersistentInstance​(MetaClassID classID,
                                                                  ObjectID objectID,
                                                                  BackendID hint)
        Description copied from class: DataClayRuntime
        Check if instance exists in Heap or create a new PERSISTENT instance if needed
        Specified by:
        getOrNewPersistentInstance in class DataClayRuntime
        Parameters:
        classID - ID of the class in case it is needed (not need to query) if null, look for class id in metadata.
        objectID - ID of object
        hint - Can be null. Hint in case object is a volatile in another DS and we need information.
        Returns:
        Instance
      • getOrNewInstanceFromDB

        public DataClayExecutionObject getOrNewInstanceFromDB​(ObjectID objectID,
                                                              boolean retry)
        Get object from memory or database and WAIT in case we are still waiting for it to be persisted.
        Parameters:
        objectID - ID of the object to get
        retry - Indicates if we should retry and wait.
        Returns:
        The the object.
      • checkSession

        public void checkSession​(DataSetID dataSetID,
                                 SessionID sessionID)
        Checks session is valid.
        Parameters:
        dataSetID - dataSetID to be accessed
        sessionID - id of the session
      • makePersistent

        public BackendID makePersistent​(DataClayObject dcObject,
                                        BackendID optionalDestBackendID,
                                        boolean recursive,
                                        String alias)
        Description copied from class: DataClayRuntime
        This method creates a new Persistent Object using the provided stub instance and, if indicated, all its associated objects also Logic module API used for communication
        Specified by:
        makePersistent in class DataClayRuntime
        Parameters:
        dcObject - Instance to make persistent
        optionalDestBackendID - Indicates which is the destination backend
        recursive - Indicates if make persistent is recursive
        alias - Alias for the object
        Returns:
        ID of the backend in which te object was persisted.
      • setCurrentThreadSessionID

        public void setCurrentThreadSessionID​(SessionID sessionID)
        Set session ID for thread
        Parameters:
        sessionID - ID of session
      • removeCurrentThreadSessionID

        public void removeCurrentThreadSessionID()
        Remove session ID for thread
      • getExecutionEnvironmentIDOfDS

        public ExecutionEnvironmentID getExecutionEnvironmentIDOfDS()
        Get ID of execution environment of this node.
        Returns:
        execution environment id
      • storeObjects

        public void storeObjects​(SessionID sessionID,
                                 List<ObjectWithDataParamOrReturn> objsToStore)
        Directly store objects in DS.
        Parameters:
        sessionID - ID of session
        objsToStore - serialized objects to store.
      • retainInHeap

        public void retainInHeap​(DataClayObject object)
        Add a new Hard reference to the object provided. All code in stubs/exec classes using objects in dataClayheap are using weak references. In order to avoid objects to be GC without a flush in DB, HeapManager has hard-references to them and is the only one able to release them. This function creates the hard-reference.
        Parameters:
        object - Object to add
      • releaseFromHeap

        public void releaseFromHeap​(ObjectID objectID)
        Release hard reference to object with ID provided. Without hard reference, the object can be Garbage collected by Java GC.
        Parameters:
        objectID - ID of the object
      • detachObjectFromSession

        public void detachObjectFromSession​(ObjectID objectID,
                                            ExecutionEnvironmentID hint)
        Description copied from class: DataClayRuntime
        Detach object from current session in use, i.e. remove reference from current session provided to object, "dear garbage-collector, current session is not using the object anymore"
        Specified by:
        detachObjectFromSession in class DataClayRuntime
        Parameters:
        objectID - ID of the object to detach
        hint - Hint of the object to detach (can be null)
      • federateToBackend

        public void federateToBackend​(DataClayObject dcObject,
                                      ExecutionEnvironmentID externalExecutionEnvironmentID,
                                      boolean recursive)
        Description copied from class: DataClayRuntime
        Federate an object with an external dataClay
        Specified by:
        federateToBackend in class DataClayRuntime
        Parameters:
        dcObject - object to federate
        externalExecutionEnvironmentID - id of the external execution environment id
        recursive - Indicates if subobjects should be federated as well
      • unfederateFromBackend

        public void unfederateFromBackend​(DataClayObject dcObject,
                                          ExecutionEnvironmentID externalExecutionEnvironmentID,
                                          boolean recursive)
        Description copied from class: DataClayRuntime
        Unfederate an object with an external backend
        Specified by:
        unfederateFromBackend in class DataClayRuntime
        Parameters:
        dcObject - object to unfederate
        externalExecutionEnvironmentID - id of the external execution environment id
        recursive - Indicates if subobjects should be unfederated as well
      • isDSLib

        public boolean isDSLib()
        Specified by:
        isDSLib in class DataClayRuntime
        Returns:
        TRUE if library is for DataClay, FALSE for clients.
      • getDataService

        public DataService getDataService()
        Get DataService reference
        Returns:
        DataService reference
      • addSessionReference

        public void addSessionReference​(ObjectID objectID)
        Add +1 reference associated to thread session
        Overrides:
        addSessionReference in class DataClayRuntime
        Parameters:
        objectID - ID of the object
      • closeSessionInEE

        public void closeSessionInEE​(SessionID sessionID)
        Close session in EE. Subtract session references for GC.
        Parameters:
        sessionID - ID of session closing.
      • getRetainedReferences

        public Set<ObjectID> getRetainedReferences()
        Get IDs of references retained by EE.
        Returns:
        References retained by EE (sessions, alias...)
      • finishCacheThreads

        public void finishCacheThreads()
        Finish cache threads.
      • cleanCaches

        public void cleanCaches()
        Clean caches.