Changeset 1716
- Timestamp:
- 07/20/08 16:10:24 (1 month ago)
- Files:
-
- labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCProtocolHandler.php (modified) (2 diffs)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandler.php (modified) (2 diffs)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandlerFactory.php (modified) (6 diffs)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandlerPool.php (modified) (7 diffs)
- labs/incubator/src/test/AllTests.php (modified) (2 diffs)
- labs/incubator/src/test/php/net/stubbles/remote (added)
- labs/incubator/src/test/php/net/stubbles/remote/RemoteTestSuite.php (added)
- labs/incubator/src/test/php/net/stubbles/remote/protocol (added)
- labs/incubator/src/test/php/net/stubbles/remote/protocol/stubProtocolHandlerFactoryTestCase.php (added)
- labs/incubator/src/test/php/net/stubbles/remote/protocol/stubProtocolHandlerPoolTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCProtocolHandler.php
r1695 r1716 8 8 */ 9 9 stubClassLoader::load('net::stubbles::remote::protocol::stubProtocolHandler', 10 'net::stubbles:: util::net::stubBSDSocket'10 'net::stubbles::peer::stubBSDSocket' 11 11 ); 12 12 /** … … 101 101 * @throws stubRemoteException 102 102 */ 103 public function init (stubURL $url)103 public function initialize(stubURL $url) 104 104 { 105 105 sscanf($url->getParam('version', '1.0'), labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandler.php
r1695 r1716 6 6 * @package stubbles 7 7 * @subpackage remote_protocol 8 * @version $Id$ 8 9 */ 9 stubClassLoader::load('net::stubbles:: util::net::stubURL');10 stubClassLoader::load('net::stubbles::peer::stubURL'); 10 11 /** 11 12 * Interface for a protocol handler. … … 22 23 * @throws stubRemoteException 23 24 */ 24 public function init (stubURL $url);25 public function initialize(stubURL $url); 25 26 26 27 /** labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandlerFactory.php
r1695 r1716 1 1 <?php 2 2 /** 3 * Factory for creating protocol handlers .3 * Factory for creating protocol handlers and managing protocol handler classes. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 7 * @subpackage remote_protocol 8 * @version $Id$ 8 9 */ 9 stubClassLoader::load('net::stubbles::remote::protocol::stubProtocolHandler', 10 stubClassLoader::load('net::stubbles::lang::exceptions::stubMethodNotSupportedException', 11 'net::stubbles::remote::protocol::stubProtocolHandler', 10 12 'net::stubbles::remote::protocol::stubUnknownProtocolException' 11 13 ); 12 14 /** 13 * Factory for creating protocol handlers .15 * Factory for creating protocol handlers and managing protocol handler classes. 14 16 * 15 17 * @package stubbles … … 34 36 * static initializing 35 37 */ 38 // @codeCoverageIgnoreStart 36 39 public static function __static() 37 40 { … … 39 42 self::$instance->setHandler('easc', 'net::stubbles::remote::protocol::easc::stubEASCProtocolHandler'); 40 43 } 44 // @codeCoverageIgnoreEnd 41 45 42 46 /** … … 50 54 /** 51 55 * prevent cloning 56 * 57 * @throws stubMethodNotSupportedExceptions 52 58 */ 53 p rivatefunction __clone()59 public function __clone() 54 60 { 55 // intentionally empty61 throw new stubMethodNotSupportedException('Cloning the protocol handler factory is not supported.'); 56 62 } 57 63 … … 67 73 68 74 /** 75 * clears the protocol list 76 */ 77 public function clear() 78 { 79 $this->handlers = array(); 80 $this->setHandler('easc', 'net::stubbles::remote::protocol::easc::stubEASCProtocolHandler'); 81 } 82 83 /** 69 84 * sets a protocol handler class for a given protocol 70 85 * 71 * @param string $protocol the protocol to register the class for 72 * @param string $protocolHandlerClassName the name of the handler class 86 * @param string $protocol the protocol to register the class for 87 * @param string $protocolHandlerClassName the name of the handler class 88 * @return stubProtocolHandlerFactory 73 89 */ 74 90 public function setHandler($protocol, $protocolHandlerClassName) 75 91 { 76 92 $this->handlers[$protocol] = $protocolHandlerClassName; 93 return $this; 94 } 95 96 /** 97 * checks if a handler for a certain protocol is registered 98 * 99 * @param string $protocol 100 * @return bool 101 */ 102 public function hasHandler($protocol) 103 { 104 return isset($this->handlers[$protocol]); 77 105 } 78 106 … … 82 110 * @param string $protocol 83 111 */ 84 public function getHandler($protocol)112 public function createHandler($protocol) 85 113 { 86 114 if (isset($this->handlers[$protocol]) === false) { labs/incubator/src/main/php/net/stubbles/remote/protocol/stubProtocolHandlerPool.php
r1695 r1716 1 1 <?php 2 2 /** 3 * Factory for creating protocol handlers .3 * Factory for creating protocol handlers and managing protocol handler instances. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> … … 8 8 */ 9 9 stubClassLoader::load('net::stubbles::lang::exceptions::stubIllegalArgumentException', 10 'net::stubbles::lang::exceptions::stubMethodNotSupportedException', 10 11 'net::stubbles::remote::protocol::stubProtocolHandler', 11 12 'net::stubbles::remote::protocol::stubProtocolHandlerFactory', 12 'net::stubbles:: util::net::stubURL'13 'net::stubbles::peer::stubURL' 13 14 ); 14 15 /** 15 * Factory for creating protocol handlers .16 * Factory for creating protocol handlers and managing protocol handler instances. 16 17 * 17 18 * @package stubbles … … 27 28 protected static $instance; 28 29 /** 30 * protocol handler factory to be used 31 * 32 * @var stubProtocolHandlerFactory 33 */ 34 protected $protocolHandlerFactory; 35 /** 29 36 * the pool of protocol handlers 30 37 * 31 38 * @var array<string,stubProtocolHandler> 32 39 */ 33 protected $ pool= array();40 protected $handlers = array(); 34 41 35 42 /** … … 43 50 /** 44 51 * prevent cloning 52 * 53 * @throws stubMethodNotSupportedExceptions 45 54 */ 46 p rivatefunction __clone()55 public function __clone() 47 56 { 48 // intentionally empty57 throw new stubMethodNotSupportedException('Cloning the protocol handler pool is not supported.'); 49 58 } 50 59 … … 56 65 public function getInstance() 57 66 { 58 if ( isset(self::$instance) == false) {67 if (null === self::$instance) { 59 68 self::$instance = new self(); 69 self::$instance->protocolHandlerFactory = stubProtocolHandlerFactory::getInstance(); 60 70 } 61 71 … … 64 74 65 75 /** 66 * pool a handler76 * sets the protocol handler factory to be used 67 77 * 68 * @param string $url 69 * @param stubProtocolHandler $handler handler to pool 78 * @param stubProtocolHandlerFactory $protocolHandlerFactory 79 */ 80 public function setProtocolHandlerFactory(stubProtocolHandlerFactory $protocolHandlerFactory) 81 { 82 $this->protocolHandlerFactory = $protocolHandlerFactory; 83 } 84 85 /** 86 * clears all handlers from the pool 87 */ 88 public function clear() 89 { 90 $this->handlers = array(); 91 } 92 93 /** 94 * adds a handler to the pool 95 * 96 * @param string $url url to add handler for, this should be protocol and hostname 97 * @param stubProtocolHandler $handler handler to add to the pool 70 98 * @return stubProtocolHandler the pooled handler 71 99 */ 72 public function pool($url, stubProtocolHandler $handler)100 public function addHandler($url, stubProtocolHandler $handler) 73 101 { 74 $this-> pool[$url] = $handler;102 $this->handlers[$url] = $handler; 75 103 return $handler; 104 } 105 106 /** 107 * checks whether a handler is available for given url 108 * 109 * @param string $url 110 * @return bool 111 * @throws stubIllegalArgumentException 112 */ 113 public function hasHandler($url) 114 { 115 if (is_string($url) === true) { 116 $url = stubURL::fromString($url); 117 } elseif (($url instanceof stubURL) === false) { 118 throw new stubIllegalArgumentException('Param url must be an instance of net::stubbles::peer::stubURL or a string denoting an URL.'); 119 } 120 121 $key = $url->getScheme() . '://' . $url->getHost(); 122 if (isset($this->handlers[$key]) === true) { 123 return true; 124 } 125 126 return $this->protocolHandlerFactory->hasHandler($url->getScheme()); 76 127 } 77 128 … … 79 130 * acquire a handler 80 131 * 81 * @param string key 132 * @param string $url url to aquire a handler for 133 * @param bool $initialize optional if handler should be initialized 82 134 * @return stubProtocolHandler 83 * @throws stub MalformedURLException135 * @throws stubIllegalArgumentException 84 136 * @throws stubUnknownProtocolException 85 137 */ 86 public function acquire($key, $initialize = false)138 public function getHandler($url, $initialize = false) 87 139 { 88 $url = stubURL::fromString($key); 89 $key = $url->getScheme() .'://' . $url->getHost(); 90 if (isset($this->pool[$key]) === true) { 91 $handler = $this->pool[$key]; 140 if (is_string($url) === true) { 141 $url = stubURL::fromString($url); 142 } elseif (($url instanceof stubURL) === false) { 143 throw new stubIllegalArgumentException('Param url must be an instance of net::stubbles::peer::stubURL or a string denoting an URL.'); 144 } 145 146 $key = $url->getScheme() . '://' . $url->getHost(); 147 if (isset($this->handlers[$key]) === true) { 148 $handler = $this->handlers[$key]; 92 149 } else { 93 $handler = $this-> pool($key, stubProtocolHandlerFactory::getInstance()->getHandler($url->getScheme()));150 $handler = $this->addHandler($key, $this->protocolHandlerFactory->createHandler($url->getScheme())); 94 151 } 95 152 labs/incubator/src/test/AllTests.php
r1688 r1716 23 23 require_once TEST_SRC_PATH . '/php/net/stubbles/auth/AuthTestSuite.php'; 24 24 require_once TEST_SRC_PATH . '/php/net/stubbles/events/EventTestSuite.php'; 25 require_once TEST_SRC_PATH . '/php/net/stubbles/remote/RemoteTestSuite.php'; 25 26 /** 26 27 * Class to organize all tests. … … 49 50 $suite->addTestSuite('AuthTestSuite'); 50 51 $suite->addTestSuite('EventTestSuite'); 52 $suite->addTestSuite('RemoteTestSuite'); 51 53 return $suite; 52 54 }
