src/Graviton/RestBundle/Listener/WriteLockListener.php
public function onKernelController(FilterControllerEvent $event)
    {
        $currentMethod = $this->requestStack->getCurrentRequest()->getMethod();

        // ignore not defined methods..
        if (!in_array($currentMethod, $this->interestedMethods)) {
            return;
        }

        $url = $this->requestStack->getCurrentRequest()->getPathInfo();
        $cacheKey = $this->cacheKeyPrefix.$url;

        // should we do a random delay here? only applies to writing methods!
        if (in_array($currentMethod, $this->lockingMethods) &&
            $this->doRandomDelay($url)
        ) {
            $delay = rand($this->randomDelayMin, $this->randomDelayMax) * 1000;
            $this->logger->info("LOCK CHECK DELAY BY ".$delay." = ".$cacheKey);

            usleep(rand($this->randomDelayMin, $this->randomDelayMax) * 1000);
        }

        $this->logger->info("LOCK CHECK START = ".$cacheKey);

        // check for existing one
        while ($this->cache->fetch($cacheKey) === true) {
            usleep(250000);
        }

        $this->logger->info("LOCK CHECK FINISHED = ".$cacheKey);

        if (in_array($currentMethod, $this->waitingMethods)) {
            // current method just wants to wait..
            return;
        }

        // create new
        $this->cache->save($cacheKey, true, $this->maxTime);
        $this->logger->info("LOCK ADD = ".$cacheKey);

        $event->getRequest()->attributes->set('writeLockOn', $cacheKey);
    }
public function onKernelController(FilterControllerEvent $event)
    {
        $currentMethod = $this->requestStack->getCurrentRequest()->getMethod();

        // ignore not defined methods..
        if (!in_array($currentMethod, $this->interestedMethods)) {
            return;
        }

        $url = $this->requestStack->getCurrentRequest()->getPathInfo();
        $cacheKey = $this->cacheKeyPrefix.$url;

        // should we do a random delay here? only applies to writing methods!
        if (in_array($currentMethod, $this->lockingMethods) &&
            $this->doRandomDelay($url)
        ) {
            $delay = rand($this->randomDelayMin, $this->randomDelayMax) * 1000;
            $this->logger->info("LOCK CHECK DELAY BY ".$delay." = ".$cacheKey);

            usleep(rand($this->randomDelayMin, $this->randomDelayMax) * 1000);
        }

        $this->logger->info("LOCK CHECK START = ".$cacheKey);

        // check for existing one
        while ($this->cache->fetch($cacheKey) === true) {
            usleep(250000);
        }

        $this->logger->info("LOCK CHECK FINISHED = ".$cacheKey);

        if (in_array($currentMethod, $this->waitingMethods)) {
            // current method just wants to wait..
            return;
        }

        // create new
        $this->cache->save($cacheKey, true, $this->maxTime);
        $this->logger->info("LOCK ADD = ".$cacheKey);

        $event->getRequest()->attributes->set('writeLockOn', $cacheKey);
    }
public function onKernelController ( FilterControllerEvent $ event ) { $ currentMethod = $ this -> requestStack -> getCurrentRequest ( ) -> getMethod ( ) ; // ignore not defined methods.. if ( ! in_array ( $ currentMethod , $ this -> interestedMethods ) ) { return ; } $ url = $ this -> requestStack -> getCurrentRequest ( ) -> getPathInfo ( ) ; $ cacheKey = $ this -> cacheKeyPrefix . $ url ; // should we do a random delay here? only applies to writing methods! if ( in_array ( $ currentMethod , $ this -> lockingMethods ) && $ this -> doRandomDelay ( $ url ) ) { $ delay = rand ( $ this -> randomDelayMin , $ this -> randomDelayMax ) * 1000 ; $ this -> logger -> info ( "LOCK CHECK DELAY BY " . $ delay . " = " . $ cacheKey ) ; usleep ( rand ( $ this -> randomDelayMin , $ this -> randomDelayMax ) * 1000 ) ; } $ this -> logger -> info ( "LOCK CHECK START = " . $ cacheKey ) ; // check for existing one while ( $ this -> cache -> fetch ( $ cacheKey ) === true ) { usleep ( 250000 ) ; } $ this -> logger -> info ( "LOCK CHECK FINISHED = " . $ cacheKey ) ; if ( in_array ( $ currentMethod , $ this -> waitingMethods ) ) { // current method just wants to wait.. return ; } // create new $ this -> cache -> save ( $ cacheKey , true , $ this -> maxTime ) ; $ this -> logger -> info ( "LOCK ADD = " . $ cacheKey ) ; $ event -> getRequest ( ) -> attributes -> set ( 'writeLockOn' , $ cacheKey ) ; }
all "waiting" methods wait until no lock is around.. "writelock" methods wait and create a lock

@param FilterControllerEvent $event response listener event

@return void
all waiting methods wait until no lock is around .. writelock methods wait and create a lock