AppserverIo\Appserver\PersistenceContainer\PersistenceManager::invoke PHP Méthode

invoke() public méthode

Invoke the passed remote method on the described session bean and return the result.
public invoke ( AppserverIo\RemoteMethodInvocation\RemoteMethodInterface $remoteMethod, AppserverIo\Collections\CollectionInterface $sessions ) : mixed
$remoteMethod AppserverIo\RemoteMethodInvocation\RemoteMethodInterface The remote method description
$sessions AppserverIo\Collections\CollectionInterface The collection with the sessions
Résultat mixed The result of the remote method invocation
    public function invoke(RemoteMethodInterface $remoteMethod, CollectionInterface $sessions)
    {
        // prepare method name and parameters and invoke method
        $className = $remoteMethod->getClassName();
        $methodName = $remoteMethod->getMethodName();
        $parameters = $remoteMethod->getParameters();
        $sessionId = $remoteMethod->getSessionId();
        // load the application instance
        $application = $this->getApplication();
        // try to load the session with the ID passed in the remote method
        $session = CollectionUtils::find($sessions, new FilterSessionPredicate($sessionId));
        // query whether the session is available or not
        if ($session instanceof CollectionInterface) {
            // query whether we already have an instance in the session container
            if ($instance = $session->exists($className)) {
                $instance = $session->get($className);
            }
        }
        // load a fresh bean instance and add it to the session container
        if ($instance == null) {
            $instance = $application->getNamingDirectory()->search($className);
        }
        // query whether we already have an instance in the session container
        if ($session instanceof CollectionInterface) {
            $session->add($className, $instance);
        }
        // invoke the remote method call on the local instance
        return call_user_func_array(array($instance, $methodName), $parameters);
    }