Changeset 1332
- Timestamp:
- Sep 7, 2010, 1:53:52 PM (11 years ago)
- Location:
- cpc/trunk/project
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpc/trunk/project/lib/model/solr/SolrCommands.class.php
r1323 r1332 7 7 } 8 8 9 protected static$semaphore = null;10 protected static$file = null;9 protected $semaphore = null; 10 protected $file = null; 11 11 12 protected static function getSemaphore() { 13 if (! self::$semaphore) { 14 self::$semaphore = sem_get(rand()); 12 protected static $instance = null; 13 protected static $semaphore_id = "99999910823498202340982340982340981678"; 14 public static function getInstance() { 15 if (!self::$instance) { 16 self::$instance = new SolrCommands(); 15 17 } 16 return self::$ semaphore;18 return self::$instance; 17 19 } 18 20 19 public static function addCommand($status, $json) { 20 sem_acquire(self::getSemaphore()); 21 if (! self::$file) { 22 self::$file = fopen(self::getFileCommands(), 'a+'); 21 public function __construct() { 22 $this->semaphore = sem_get(self::$semaphore_id); 23 } 24 25 public function __destruct() { 26 sem_remove($this->semaphore); 27 $this->semaphore = null; 28 } 29 30 public function addCommand($status, $json) { 31 sem_acquire($this->semaphore); 32 if (! $this->file) { 33 $this->file = fopen($this->getFileCommands(), 'a+'); 23 34 } 24 35 $str = $status.' : '.json_encode($json)."\n"; 25 fwrite( self::$file, $str, strlen($str));26 sem_release( self::getSemaphore());36 fwrite($this->file, $str, strlen($str)); 37 sem_release($this->semaphore); 27 38 } 28 39 29 public staticfunction getCommandContent() {30 $lockfile = self::getFileCommands().'.lock';40 public function getCommandContent() { 41 $lockfile = $this->getFileCommands().'.lock'; 31 42 if (file_exists($lockfile)) { 32 43 return $lockfile; 33 44 } 34 sem_acquire( self::getSemaphore());35 if (! self::$file) {45 sem_acquire($this->semaphore); 46 if (!$this->file) { 36 47 touch($lockfile); 37 sem_release( self::getSemaphore());48 sem_release($this->semaphore); 38 49 return $lockfile; 39 50 } 40 fclose( self::$file);41 self::$file = null;42 rename( self::getFileCommands(), self::getFileCommands().'.lock');43 sem_release( self::getSemaphore());51 fclose($this->file); 52 $this->file = null; 53 rename($this->getFileCommands(), $this->getFileCommands().'.lock'); 54 sem_release($this->semaphore); 44 55 return $lockfile; 45 56 } 46 public staticfunction releaseCommandContent() {47 sem_acquire( self::getSemaphore());48 unlink( self::getFileCommands().'.lock');49 sem_release( self::getSemaphore());57 public function releaseCommandContent() { 58 sem_acquire($this->semaphore); 59 unlink($this->getFileCommands().'.lock'); 60 sem_release($this->semaphore); 50 61 } 51 62 } -
cpc/trunk/project/lib/model/solr/SolrConnector.class.php
r1330 r1332 29 29 30 30 public function updateFromCommands() { 31 $file = SolrCommands::get CommandContent();31 $file = SolrCommands::getInstance()->getCommandContent(); 32 32 foreach(file($file) as $line) { 33 33 if (preg_match('/(UPDATE|DELETE) : (.+)/', $line, $matches)) { … … 40 40 } 41 41 } 42 SolrCommands:: releaseCommandContent();42 SolrCommands::getInstance()->releaseCommandContent(); 43 43 } 44 44 -
cpc/trunk/project/lib/model/solr/SolrListener.php
r1324 r1332 9 9 */ 10 10 protected $_options = array(); 11 12 protected static $fileCommand = null;13 protected static $fileDispatcher = null;14 15 protected static function getFileCommand() {16 if (!self::$fileDispatcher) {17 self::$fileDispatcher = new sfEventDispatcher();18 }19 if (!self::$fileCommand) {20 self::$fileCommand = new sfFileLogger(self::$fileDispatcher, array('file' => SolrConnector::getFileCommands()));21 }22 return self::$fileCommand;23 }24 11 25 12 private $command = null; … … 145 132 $json['tags']['weight'] = $extra_weight; 146 133 147 SolrCommands:: addCommand('UPDATE', $json);134 SolrCommands::getInstance()->addCommand('UPDATE', $json); 148 135 } 149 136 … … 154 141 $json = new stdClass(); 155 142 $json->id = $this->getLuceneObjId($obj); 156 SolrCommands:: addCommand('DELETE', $json);143 SolrCommands::getInstance()->addCommand('DELETE', $json); 157 144 } 158 145 -
cpc/trunk/project/test/unit/solrableTest.php
r1323 r1332 54 54 $q->save(); 55 55 56 $i = Doctrine::getTable('Intervention')->find(392980);57 $i ->save();56 $iexists = Doctrine::getTable('Intervention')->find(3); 57 $iexists->save(); 58 58 59 59 $s->updateFromCommands();
Note: See TracChangeset
for help on using the changeset viewer.