PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/doc/html/Cassandra_8php_source.html

https://github.com/waue0920/Cassandra-PHP-Client-Library
HTML | 2384 lines | 2375 code | 5 blank | 4 comment | 0 complexity | 1e5381c0376801607401bda9c379acb0 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <title>Cassandra PHP Client Library: Cassandra.php Source File</title>
  6. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  7. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  8. <script type="text/javascript" src="search/search.js"></script>
  9. <link href="doxygen.css" rel="stylesheet" type="text/css"/>
  10. </head>
  11. <body onload='searchBox.OnSelectItem(0);'>
  12. <!-- Generated by Doxygen 1.7.3 -->
  13. <script type="text/javascript"><!--
  14. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  15. --></script>
  16. <script type="text/javascript">
  17. function hasClass(ele,cls) {
  18. return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
  19. }
  20. function addClass(ele,cls) {
  21. if (!this.hasClass(ele,cls)) ele.className += " "+cls;
  22. }
  23. function removeClass(ele,cls) {
  24. if (hasClass(ele,cls)) {
  25. var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
  26. ele.className=ele.className.replace(reg,' ');
  27. }
  28. }
  29. function toggleVisibility(linkObj) {
  30. var base = linkObj.getAttribute('id');
  31. var summary = document.getElementById(base + '-summary');
  32. var content = document.getElementById(base + '-content');
  33. var trigger = document.getElementById(base + '-trigger');
  34. if ( hasClass(linkObj,'closed') ) {
  35. summary.style.display = 'none';
  36. content.style.display = 'block';
  37. trigger.src = 'open.png';
  38. removeClass(linkObj,'closed');
  39. addClass(linkObj,'opened');
  40. } else if ( hasClass(linkObj,'opened') ) {
  41. summary.style.display = 'block';
  42. content.style.display = 'none';
  43. trigger.src = 'closed.png';
  44. removeClass(linkObj,'opened');
  45. addClass(linkObj,'closed');
  46. }
  47. return false;
  48. }
  49. </script>
  50. <div id="top">
  51. <div id="titlearea">
  52. <table cellspacing="0" cellpadding="0">
  53. <tbody>
  54. <tr style="height: 56px;">
  55. <td style="padding-left: 0.5em;">
  56. <div id="projectname">Cassandra PHP Client Library</div>
  57. <div id="projectbrief">Cassandra PHP-based client library for managing and querying your Cassandra cluster.</div>
  58. </td>
  59. </tr>
  60. </tbody>
  61. </table>
  62. </div>
  63. <div id="navrow1" class="tabs">
  64. <ul class="tablist">
  65. <li><a href="index.html"><span>Main&#160;Page</span></a></li>
  66. <li><a href="namespaces.html"><span>Namespaces</span></a></li>
  67. <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
  68. <li class="current"><a href="files.html"><span>Files</span></a></li>
  69. <li id="searchli">
  70. <div id="MSearchBox" class="MSearchBoxInactive">
  71. <span class="left">
  72. <img id="MSearchSelect" src="search/mag_sel.png"
  73. onmouseover="return searchBox.OnSearchSelectShow()"
  74. onmouseout="return searchBox.OnSearchSelectHide()"
  75. alt=""/>
  76. <input type="text" id="MSearchField" value="Search" accesskey="S"
  77. onfocus="searchBox.OnSearchFieldFocus(true)"
  78. onblur="searchBox.OnSearchFieldFocus(false)"
  79. onkeyup="searchBox.OnSearchFieldChange(event)"/>
  80. </span><span class="right">
  81. <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
  82. </span>
  83. </div>
  84. </li>
  85. </ul>
  86. </div>
  87. <div id="navrow2" class="tabs2">
  88. <ul class="tablist">
  89. <li><a href="files.html"><span>File&#160;List</span></a></li>
  90. </ul>
  91. </div>
  92. <div class="header">
  93. <div class="headertitle">
  94. <h1>Cassandra.php</h1> </div>
  95. </div>
  96. <div class="contents">
  97. <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
  98. <a name="l00036"></a>00036 <span class="comment">// set the globals that the thrift library uses</span>
  99. <a name="l00037"></a>00037 $GLOBALS[<span class="stringliteral">&#39;THRIFT_ROOT&#39;</span>] = dirname(__FILE__) . <span class="stringliteral">&#39;/thrift/&#39;</span>;
  100. <a name="l00038"></a>00038 define(<span class="stringliteral">&#39;THRIFT_PATH&#39;</span>, $GLOBALS[<span class="stringliteral">&#39;THRIFT_ROOT&#39;</span>]);
  101. <a name="l00039"></a>00039
  102. <a name="l00040"></a>00040 <span class="comment">// require thrift packages</span>
  103. <a name="l00041"></a>00041 require_once $GLOBALS[<span class="stringliteral">&#39;THRIFT_ROOT&#39;</span>].<span class="stringliteral">&#39;/packages/cassandra/Cassandra.php&#39;</span>;
  104. <a name="l00042"></a>00042 require_once $GLOBALS[<span class="stringliteral">&#39;THRIFT_ROOT&#39;</span>].<span class="stringliteral">&#39;/transport/TSocket.php&#39;</span>;
  105. <a name="l00043"></a>00043 require_once $GLOBALS[<span class="stringliteral">&#39;THRIFT_ROOT&#39;</span>].<span class="stringliteral">&#39;/protocol/TBinaryProtocol.php&#39;</span>;
  106. <a name="l00044"></a>00044
  107. <a name="l00050"></a><a class="code" href="classCassandraConnection.html">00050</a> <span class="keyword">class </span><a class="code" href="classCassandraConnection.html">CassandraConnection</a> {
  108. <a name="l00051"></a>00051
  109. <a name="l00057"></a>00057 <span class="keyword">protected</span> $host;
  110. <a name="l00058"></a>00058
  111. <a name="l00064"></a>00064 <span class="keyword">protected</span> $port;
  112. <a name="l00065"></a>00065
  113. <a name="l00071"></a>00071 <span class="keyword">protected</span> $useFramedTransport;
  114. <a name="l00072"></a>00072
  115. <a name="l00078"></a>00078 <span class="keyword">protected</span> $sendTimeoutMs;
  116. <a name="l00079"></a>00079
  117. <a name="l00085"></a>00085 <span class="keyword">protected</span> $receiveTimeoutMs;
  118. <a name="l00086"></a>00086
  119. <a name="l00092"></a>00092 <span class="keyword">protected</span> $socket;
  120. <a name="l00093"></a>00093
  121. <a name="l00099"></a>00099 <span class="keyword">protected</span> $transport;
  122. <a name="l00100"></a>00100
  123. <a name="l00106"></a>00106 <span class="keyword">protected</span> $protocol;
  124. <a name="l00107"></a>00107
  125. <a name="l00113"></a>00113 <span class="keyword">protected</span> $client;
  126. <a name="l00114"></a>00114
  127. <a name="l00120"></a>00120 <span class="keyword">protected</span> $isOpen;
  128. <a name="l00121"></a>00121
  129. <a name="l00131"></a><a class="code" href="classCassandraConnection.html#a7f75a298bf9fb6362d38f4aeb42ceb28">00131</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#a7f75a298bf9fb6362d38f4aeb42ceb28">__construct</a>(
  130. <a name="l00132"></a>00132 $host = <span class="stringliteral">&#39;127.0.0.1&#39;</span>,
  131. <a name="l00133"></a>00133 $port = 9160,
  132. <a name="l00134"></a>00134 $useFramedTransport = <span class="keyword">true</span>,
  133. <a name="l00135"></a>00135 $sendTimeoutMs = null,
  134. <a name="l00136"></a>00136 $receiveTimeoutMs = null
  135. <a name="l00137"></a>00137 ) {
  136. <a name="l00138"></a>00138 $this-&gt;host = $host;
  137. <a name="l00139"></a>00139 $this-&gt;port = $port;
  138. <a name="l00140"></a>00140 $this-&gt;useFramedTransport = $useFramedTransport;
  139. <a name="l00141"></a>00141 $this-&gt;sendTimeoutMs = $sendTimeoutMs;
  140. <a name="l00142"></a>00142 $this-&gt;receiveTimeoutMs = $receiveTimeoutMs;
  141. <a name="l00143"></a>00143 $this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a> = <span class="keyword">false</span>;
  142. <a name="l00144"></a>00144
  143. <a name="l00145"></a>00145 $this-&gt;socket = $this-&gt;<a class="code" href="classCassandraConnection.html#a6886c992c6b7cbc24deb801fb8ee52db">createSocket</a>(
  144. <a name="l00146"></a>00146 $host,
  145. <a name="l00147"></a>00147 $port,
  146. <a name="l00148"></a>00148 $sendTimeoutMs,
  147. <a name="l00149"></a>00149 $receiveTimeoutMs
  148. <a name="l00150"></a>00150 );
  149. <a name="l00151"></a>00151
  150. <a name="l00152"></a>00152 <span class="keywordflow">if</span> ($useFramedTransport) {
  151. <a name="l00153"></a>00153 $this-&gt;transport = $this-&gt;<a class="code" href="classCassandraConnection.html#a00c2d10e54028d15cfb5ef8bde3468d3">createFramedTransport</a>($this-&gt;socket);
  152. <a name="l00154"></a>00154 } <span class="keywordflow">else</span> {
  153. <a name="l00155"></a>00155 $this-&gt;transport = $this-&gt;<a class="code" href="classCassandraConnection.html#a3e3b2e2318ff07ee56bcae235634c2e4">createBufferedTransport</a>($this-&gt;socket);
  154. <a name="l00156"></a>00156 }
  155. <a name="l00157"></a>00157
  156. <a name="l00158"></a>00158 $this-&gt;transport-&gt;open();
  157. <a name="l00159"></a>00159 $this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a> = <span class="keyword">true</span>;
  158. <a name="l00160"></a>00160
  159. <a name="l00161"></a>00161 $this-&gt;protocol = <span class="keyword">new</span> TBinaryProtocolAccelerated($this-&gt;transport);
  160. <a name="l00162"></a>00162 $this-&gt;client = <span class="keyword">new</span> CassandraClient($this-&gt;protocol);
  161. <a name="l00163"></a>00163 }
  162. <a name="l00164"></a>00164
  163. <a name="l00168"></a><a class="code" href="classCassandraConnection.html#ab491ef3fe8550d70856e708e528cb570">00168</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#ab491ef3fe8550d70856e708e528cb570">__destruct</a>() {
  164. <a name="l00169"></a>00169 $this-&gt;<a class="code" href="classCassandraConnection.html#abd8bbd3ef94126f1e6a274b5ad512ece">close</a>();
  165. <a name="l00170"></a>00170 }
  166. <a name="l00171"></a>00171
  167. <a name="l00178"></a><a class="code" href="classCassandraConnection.html#abd8bbd3ef94126f1e6a274b5ad512ece">00178</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#abd8bbd3ef94126f1e6a274b5ad512ece">close</a>() {
  168. <a name="l00179"></a>00179 <span class="keywordflow">if</span> ($this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a>) {
  169. <a name="l00180"></a>00180 $this-&gt;transport-&gt;flush();
  170. <a name="l00181"></a>00181 $this-&gt;transport-&gt;close();
  171. <a name="l00182"></a>00182
  172. <a name="l00183"></a>00183 $this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a> = <span class="keyword">false</span>;
  173. <a name="l00184"></a>00184 }
  174. <a name="l00185"></a>00185 }
  175. <a name="l00186"></a>00186
  176. <a name="l00192"></a><a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">00192</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a>() {
  177. <a name="l00193"></a>00193 <span class="keywordflow">return</span> $this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a>;
  178. <a name="l00194"></a>00194 }
  179. <a name="l00195"></a>00195
  180. <a name="l00201"></a><a class="code" href="classCassandraConnection.html#a9333243e248f73414e25d5fe143250df">00201</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#a9333243e248f73414e25d5fe143250df">getClient</a>() {
  181. <a name="l00202"></a>00202 <span class="keywordflow">if</span> (!$this-&gt;<a class="code" href="classCassandraConnection.html#aed004bd39c88a8aea40292f9c5271512">isOpen</a>) {
  182. <a name="l00203"></a>00203 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraConnectionClosedException.html">CassandraConnectionClosedException</a>(
  183. <a name="l00204"></a>00204 <span class="stringliteral">&#39;The connection has been closed&#39;</span>
  184. <a name="l00205"></a>00205 );
  185. <a name="l00206"></a>00206 }
  186. <a name="l00207"></a>00207
  187. <a name="l00208"></a>00208 <span class="keywordflow">return</span> $this-&gt;client;
  188. <a name="l00209"></a>00209 }
  189. <a name="l00210"></a>00210
  190. <a name="l00216"></a><a class="code" href="classCassandraConnection.html#a7f12a9a108ea4d89083a48bbebdb8a60">00216</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#a7f12a9a108ea4d89083a48bbebdb8a60">getTransport</a>() {
  191. <a name="l00217"></a>00217 <span class="keywordflow">return</span> $this-&gt;transport;
  192. <a name="l00218"></a>00218 }
  193. <a name="l00219"></a>00219
  194. <a name="l00225"></a><a class="code" href="classCassandraConnection.html#adb1d52d166f36506ab94605b260e821f">00225</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#adb1d52d166f36506ab94605b260e821f">getProtocol</a>() {
  195. <a name="l00226"></a>00226 <span class="keywordflow">return</span> $this-&gt;transport;
  196. <a name="l00227"></a>00227 }
  197. <a name="l00228"></a>00228
  198. <a name="l00238"></a><a class="code" href="classCassandraConnection.html#a9bb32ec133d74c18a5ab142a33b96539">00238</a> <span class="keyword">public</span> function <a class="code" href="classCassandraConnection.html#a9bb32ec133d74c18a5ab142a33b96539">useKeyspace</a>(
  199. <a name="l00239"></a>00239 $keyspace,
  200. <a name="l00240"></a>00240 $username = null,
  201. <a name="l00241"></a>00241 $password = null
  202. <a name="l00242"></a>00242 ) {
  203. <a name="l00243"></a>00243 $attempts = 3;
  204. <a name="l00244"></a>00244 $success = <span class="keyword">false</span>;
  205. <a name="l00245"></a>00245
  206. <a name="l00246"></a>00246 <span class="keywordflow">while</span>($attempts-- &gt; 0 &amp;&amp; !$success) {
  207. <a name="l00247"></a>00247 <span class="keywordflow">try</span> {
  208. <a name="l00248"></a>00248 $this-&gt;client-&gt;set_keyspace($keyspace);
  209. <a name="l00249"></a>00249 $success = <span class="keyword">true</span>;
  210. <a name="l00250"></a>00250 } <span class="keywordflow">catch</span> (cassandra_InvalidRequestException $e) {
  211. <a name="l00251"></a>00251 <span class="keywordflow">continue</span>;
  212. <a name="l00252"></a>00252 }
  213. <a name="l00253"></a>00253 }
  214. <a name="l00254"></a>00254
  215. <a name="l00255"></a>00255 <span class="keywordflow">if</span> (!$success) {
  216. <a name="l00256"></a>00256 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraSettingKeyspaceFailedException.html">CassandraSettingKeyspaceFailedException</a>(
  217. <a name="l00257"></a>00257 <span class="stringliteral">&#39;Using keyspace &quot;&#39;</span>.$keyspace.<span class="stringliteral">&#39;&quot; failed after several attempts&#39;</span>
  218. <a name="l00258"></a>00258 );
  219. <a name="l00259"></a>00259 }
  220. <a name="l00260"></a>00260
  221. <a name="l00261"></a>00261 <span class="keywordflow">if</span> ($username !== null) {
  222. <a name="l00262"></a>00262 $request = <span class="keyword">new</span> cassandra_AuthenticationRequest(
  223. <a name="l00263"></a>00263 array(<span class="stringliteral">&#39;credentials&#39;</span> =&gt; array($username, $password))
  224. <a name="l00264"></a>00264 );
  225. <a name="l00265"></a>00265
  226. <a name="l00266"></a>00266 $this-&gt;client-&gt;login($request);
  227. <a name="l00267"></a>00267 }
  228. <a name="l00268"></a>00268 }
  229. <a name="l00269"></a>00269
  230. <a name="l00279"></a><a class="code" href="classCassandraConnection.html#a6886c992c6b7cbc24deb801fb8ee52db">00279</a> <span class="keyword">protected</span> function <a class="code" href="classCassandraConnection.html#a6886c992c6b7cbc24deb801fb8ee52db">createSocket</a>(
  231. <a name="l00280"></a>00280 $host,
  232. <a name="l00281"></a>00281 $port,
  233. <a name="l00282"></a>00282 $sendTimeoutMs,
  234. <a name="l00283"></a>00283 $receiveTimeoutMs
  235. <a name="l00284"></a>00284 ) {
  236. <a name="l00285"></a>00285 $socket = <span class="keyword">new</span> TSocket($host, $port);
  237. <a name="l00286"></a>00286
  238. <a name="l00287"></a>00287 <span class="keywordflow">if</span> ($sendTimeoutMs !== null) {
  239. <a name="l00288"></a>00288 $socket-&gt;setSendTimeout($sendTimeoutMs);
  240. <a name="l00289"></a>00289 }
  241. <a name="l00290"></a>00290
  242. <a name="l00291"></a>00291 <span class="keywordflow">if</span> ($receiveTimeoutMs !== null) {
  243. <a name="l00292"></a>00292 $socket-&gt;setRecvTimeout($receiveTimeoutMs);
  244. <a name="l00293"></a>00293 }
  245. <a name="l00294"></a>00294
  246. <a name="l00295"></a>00295 <span class="keywordflow">return</span> $socket;
  247. <a name="l00296"></a>00296 }
  248. <a name="l00297"></a>00297
  249. <a name="l00304"></a><a class="code" href="classCassandraConnection.html#a00c2d10e54028d15cfb5ef8bde3468d3">00304</a> <span class="keyword">protected</span> function <a class="code" href="classCassandraConnection.html#a00c2d10e54028d15cfb5ef8bde3468d3">createFramedTransport</a>(TSocket $socket) {
  250. <a name="l00305"></a>00305 require_once THRIFT_PATH.<span class="stringliteral">&#39;/transport/TFramedTransport.php&#39;</span>;
  251. <a name="l00306"></a>00306
  252. <a name="l00307"></a>00307 <span class="keywordflow">return</span> <span class="keyword">new</span> TFramedTransport($socket, <span class="keyword">true</span>, <span class="keyword">true</span>);
  253. <a name="l00308"></a>00308 }
  254. <a name="l00309"></a>00309
  255. <a name="l00316"></a><a class="code" href="classCassandraConnection.html#a3e3b2e2318ff07ee56bcae235634c2e4">00316</a> <span class="keyword">protected</span> function <a class="code" href="classCassandraConnection.html#a3e3b2e2318ff07ee56bcae235634c2e4">createBufferedTransport</a>(TSocket $socket) {
  256. <a name="l00317"></a>00317 require_once THRIFT_PATH.<span class="stringliteral">&#39;/transport/TBufferedTransport.php&#39;</span>;
  257. <a name="l00318"></a>00318
  258. <a name="l00319"></a>00319 <span class="keywordflow">return</span> <span class="keyword">new</span> TBufferedTransport($socket, 512, 512);
  259. <a name="l00320"></a>00320 }
  260. <a name="l00321"></a>00321 }
  261. <a name="l00322"></a>00322
  262. <a name="l00328"></a><a class="code" href="classCassandraCluster.html">00328</a> <span class="keyword">class </span><a class="code" href="classCassandraCluster.html">CassandraCluster</a> {
  263. <a name="l00329"></a>00329
  264. <a name="l00335"></a>00335 <span class="keyword">protected</span> $keyspace;
  265. <a name="l00336"></a>00336
  266. <a name="l00342"></a>00342 <span class="keyword">protected</span> $username;
  267. <a name="l00343"></a>00343
  268. <a name="l00349"></a>00349 <span class="keyword">protected</span> $password;
  269. <a name="l00350"></a>00350
  270. <a name="l00356"></a>00356 <span class="keyword">protected</span> $servers = array();
  271. <a name="l00357"></a>00357
  272. <a name="l00365"></a>00365 <span class="keyword">protected</span> $connections = array();
  273. <a name="l00366"></a>00366
  274. <a name="l00375"></a><a class="code" href="classCassandraCluster.html#a6ca88a787d742b39e43b6a5fefabc633">00375</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a6ca88a787d742b39e43b6a5fefabc633">__construct</a>(array $servers = array()) {
  275. <a name="l00376"></a>00376 <span class="keywordflow">foreach</span> ($servers as $server) {
  276. <a name="l00377"></a>00377 $this-&gt;<a class="code" href="classCassandraCluster.html#a49baa9fac921644a5ba10f98c4a7412d">registerServer</a>(
  277. <a name="l00378"></a>00378 isset($server[<span class="stringliteral">&#39;host&#39;</span>]) ? $server[<span class="stringliteral">&#39;host&#39;</span>] : <span class="stringliteral">&#39;127.0.0.1&#39;</span>,
  278. <a name="l00379"></a>00379 isset($server[<span class="stringliteral">&#39;port&#39;</span>]) ? $server[<span class="stringliteral">&#39;port&#39;</span>] : 9160,
  279. <a name="l00380"></a>00380 isset($server[<span class="stringliteral">&#39;use-framed-transport&#39;</span>]) ? $server[<span class="stringliteral">&#39;use-framed-transport&#39;</span>] : <span class="keyword">true</span>,
  280. <a name="l00381"></a>00381 isset($server[<span class="stringliteral">&#39;send-timeout-ms&#39;</span>]) ? $server[<span class="stringliteral">&#39;send-timeout-ms&#39;</span>] : null,
  281. <a name="l00382"></a>00382 isset($server[<span class="stringliteral">&#39;receive-timeout-ms&#39;</span>]) ? $server[<span class="stringliteral">&#39;receive-timeout-ms&#39;</span>] : null
  282. <a name="l00383"></a>00383 );
  283. <a name="l00384"></a>00384 }
  284. <a name="l00385"></a>00385 }
  285. <a name="l00386"></a>00386
  286. <a name="l00390"></a><a class="code" href="classCassandraCluster.html#a4ce9e28f647bbbbb253273c3e0fa377a">00390</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a4ce9e28f647bbbbb253273c3e0fa377a">__destruct</a>() {
  287. <a name="l00391"></a>00391 $this-&gt;<a class="code" href="classCassandraCluster.html#afbff3180c5d4bb74c8b230436349d460">closeConnections</a>();
  288. <a name="l00392"></a>00392 }
  289. <a name="l00393"></a>00393
  290. <a name="l00407"></a><a class="code" href="classCassandraCluster.html#a49baa9fac921644a5ba10f98c4a7412d">00407</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a49baa9fac921644a5ba10f98c4a7412d">registerServer</a>(
  291. <a name="l00408"></a>00408 $host = <span class="stringliteral">&#39;127.0.0.1&#39;</span>,
  292. <a name="l00409"></a>00409 $port = 9160,
  293. <a name="l00410"></a>00410 $useFramedTransport = <span class="keyword">true</span>,
  294. <a name="l00411"></a>00411 $sendTimeoutMs = null,
  295. <a name="l00412"></a>00412 $receiveTimeoutMs = null
  296. <a name="l00413"></a>00413 ) {
  297. <a name="l00414"></a>00414 $this-&gt;servers[] = array(
  298. <a name="l00415"></a>00415 <span class="stringliteral">&#39;host&#39;</span> =&gt; $host,
  299. <a name="l00416"></a>00416 <span class="stringliteral">&#39;port&#39;</span> =&gt; $port,
  300. <a name="l00417"></a>00417 <span class="stringliteral">&#39;use-framed-transport&#39;</span> =&gt; $useFramedTransport,
  301. <a name="l00418"></a>00418 <span class="stringliteral">&#39;send-timeout-ms&#39;</span> =&gt; $sendTimeoutMs,
  302. <a name="l00419"></a>00419 <span class="stringliteral">&#39;receive-timeout-ms&#39;</span> =&gt; $receiveTimeoutMs
  303. <a name="l00420"></a>00420 );
  304. <a name="l00421"></a>00421
  305. <a name="l00422"></a>00422 <span class="keywordflow">return</span> $this;
  306. <a name="l00423"></a>00423 }
  307. <a name="l00424"></a>00424
  308. <a name="l00433"></a><a class="code" href="classCassandraCluster.html#a1044f6f79a82fbb33aa6dd0374cac07a">00433</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a1044f6f79a82fbb33aa6dd0374cac07a">useKeyspace</a>($keyspace, $username = null, $password = null) {
  309. <a name="l00434"></a>00434 $this-&gt;keyspace = $keyspace;
  310. <a name="l00435"></a>00435 $this-&gt;username = $username;
  311. <a name="l00436"></a>00436 $this-&gt;password = $password;
  312. <a name="l00437"></a>00437
  313. <a name="l00438"></a>00438 $this-&gt;<a class="code" href="classCassandraCluster.html#a27ec1b4718ca21a87a791035130d0746">getConnection</a>();
  314. <a name="l00439"></a>00439
  315. <a name="l00440"></a>00440 <span class="keywordflow">foreach</span> ($this-&gt;connections as $connection) {
  316. <a name="l00441"></a>00441 $connection-&gt;useKeyspace(
  317. <a name="l00442"></a>00442 $keyspace,
  318. <a name="l00443"></a>00443 $username,
  319. <a name="l00444"></a>00444 $password
  320. <a name="l00445"></a>00445 );
  321. <a name="l00446"></a>00446 }
  322. <a name="l00447"></a>00447
  323. <a name="l00448"></a>00448 <span class="keywordflow">return</span> $this;
  324. <a name="l00449"></a>00449 }
  325. <a name="l00450"></a>00450
  326. <a name="l00456"></a><a class="code" href="classCassandraCluster.html#a0cc3add750920cad51b03676b549e256">00456</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a0cc3add750920cad51b03676b549e256">getCurrentKeyspace</a>() {
  327. <a name="l00457"></a>00457 <span class="keywordflow">return</span> $this-&gt;keyspace;
  328. <a name="l00458"></a>00458 }
  329. <a name="l00459"></a>00459
  330. <a name="l00465"></a><a class="code" href="classCassandraCluster.html#af213845fa6bfb0e6a986fb671be28552">00465</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#af213845fa6bfb0e6a986fb671be28552">getServers</a>() {
  331. <a name="l00466"></a>00466 <span class="keywordflow">return</span> $this-&gt;servers;
  332. <a name="l00467"></a>00467 }
  333. <a name="l00468"></a>00468
  334. <a name="l00484"></a><a class="code" href="classCassandraCluster.html#a27ec1b4718ca21a87a791035130d0746">00484</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#a27ec1b4718ca21a87a791035130d0746">getConnection</a>() {
  335. <a name="l00485"></a>00485 <span class="keywordflow">if</span> (empty($this-&gt;servers)) {
  336. <a name="l00486"></a>00486 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraConnectionFailedException.html">CassandraConnectionFailedException</a>(
  337. <a name="l00487"></a>00487 <span class="stringliteral">&#39;Unable to create connection, the cluster server pool is empty&#39;</span>
  338. <a name="l00488"></a>00488 );
  339. <a name="l00489"></a>00489 }
  340. <a name="l00490"></a>00490
  341. <a name="l00491"></a>00491 $serverCount = count($this-&gt;servers);
  342. <a name="l00492"></a>00492 $attemptsLeft = $serverCount * 2;
  343. <a name="l00493"></a>00493
  344. <a name="l00494"></a>00494 <span class="keywordflow">while</span> ($attemptsLeft-- &gt; 0) {
  345. <a name="l00495"></a>00495 $randomServerIndex = mt_rand(0, $serverCount - 1);
  346. <a name="l00496"></a>00496
  347. <a name="l00497"></a>00497 <span class="keywordflow">if</span> (isset($this-&gt;connections[$randomServerIndex])) {
  348. <a name="l00498"></a>00498 <span class="keywordflow">if</span> (!$this-&gt;connections[$randomServerIndex]-&gt;isOpen()) {
  349. <a name="l00499"></a>00499 unset($this-&gt;connections[$randomServerIndex]);
  350. <a name="l00500"></a>00500
  351. <a name="l00501"></a>00501 <span class="keywordflow">continue</span>;
  352. <a name="l00502"></a>00502 }
  353. <a name="l00503"></a>00503
  354. <a name="l00504"></a>00504 <span class="keywordflow">return</span> $this-&gt;connections[$randomServerIndex];
  355. <a name="l00505"></a>00505 } <span class="keywordflow">else</span> {
  356. <a name="l00506"></a>00506 $server = $this-&gt;servers[$randomServerIndex];
  357. <a name="l00507"></a>00507
  358. <a name="l00508"></a>00508 <span class="keywordflow">try</span> {
  359. <a name="l00509"></a>00509 $this-&gt;connections[$randomServerIndex] = <span class="keyword">new</span> <a class="code" href="classCassandraConnection.html">CassandraConnection</a>(
  360. <a name="l00510"></a>00510 $server[<span class="stringliteral">&#39;host&#39;</span>],
  361. <a name="l00511"></a>00511 $server[<span class="stringliteral">&#39;port&#39;</span>],
  362. <a name="l00512"></a>00512 $server[<span class="stringliteral">&#39;use-framed-transport&#39;</span>],
  363. <a name="l00513"></a>00513 $server[<span class="stringliteral">&#39;send-timeout-ms&#39;</span>],
  364. <a name="l00514"></a>00514 $server[<span class="stringliteral">&#39;receive-timeout-ms&#39;</span>]
  365. <a name="l00515"></a>00515 );
  366. <a name="l00516"></a>00516
  367. <a name="l00517"></a>00517 $this-&gt;connections[$randomServerIndex]-&gt;useKeyspace(
  368. <a name="l00518"></a>00518 $this-&gt;keyspace,
  369. <a name="l00519"></a>00519 $this-&gt;username,
  370. <a name="l00520"></a>00520 $this-&gt;password
  371. <a name="l00521"></a>00521 );
  372. <a name="l00522"></a>00522
  373. <a name="l00523"></a>00523 <span class="keywordflow">return</span> $this-&gt;connections[$randomServerIndex];
  374. <a name="l00524"></a>00524 } <span class="keywordflow">catch</span> (TException $e) {
  375. <a name="l00525"></a>00525 <span class="keywordflow">continue</span>;
  376. <a name="l00526"></a>00526 }
  377. <a name="l00527"></a>00527 }
  378. <a name="l00528"></a>00528 }
  379. <a name="l00529"></a>00529
  380. <a name="l00530"></a>00530 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraConnectionFailedException.html">CassandraConnectionFailedException</a>(
  381. <a name="l00531"></a>00531 <span class="stringliteral">&#39;Connecting to any of the &#39;</span>.$serverCount.<span class="stringliteral">&#39; nodes failed&#39;</span>
  382. <a name="l00532"></a>00532 );
  383. <a name="l00533"></a>00533 }
  384. <a name="l00534"></a>00534
  385. <a name="l00540"></a><a class="code" href="classCassandraCluster.html#afbff3180c5d4bb74c8b230436349d460">00540</a> <span class="keyword">public</span> function <a class="code" href="classCassandraCluster.html#afbff3180c5d4bb74c8b230436349d460">closeConnections</a>() {
  386. <a name="l00541"></a>00541 <span class="keywordflow">foreach</span> ($this-&gt;connections as $connection) {
  387. <a name="l00542"></a>00542 $connection-&gt;close();
  388. <a name="l00543"></a>00543 }
  389. <a name="l00544"></a>00544
  390. <a name="l00545"></a>00545 $this-&gt;connections = array();
  391. <a name="l00546"></a>00546
  392. <a name="l00547"></a>00547 <span class="keywordflow">return</span> $this;
  393. <a name="l00548"></a>00548 }
  394. <a name="l00549"></a>00549 }
  395. <a name="l00550"></a>00550
  396. <a name="l00555"></a><a class="code" href="classCassandra.html">00555</a> <span class="keyword">class </span><a class="code" href="classCassandra.html">Cassandra</a> {
  397. <a name="l00556"></a>00556
  398. <a name="l00562"></a>00562 <span class="keyword">protected</span> <span class="keyword">static</span> $instances = array();
  399. <a name="l00563"></a>00563
  400. <a name="l00570"></a>00570 <span class="keyword">protected</span> <span class="keyword">static</span> $keyspaceRequiredMethods;
  401. <a name="l00571"></a>00571
  402. <a name="l00577"></a>00577 <span class="keyword">protected</span> <span class="keyword">static</span> $requestKeyTokens = array(<span class="charliteral">&#39;.&#39;</span>, <span class="charliteral">&#39;:&#39;</span>, <span class="charliteral">&#39;,&#39;</span>, <span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;|&#39;</span>);
  403. <a name="l00578"></a>00578
  404. <a name="l00584"></a>00584 <span class="keyword">protected</span> $cluster;
  405. <a name="l00585"></a>00585
  406. <a name="l00593"></a>00593 <span class="keyword">protected</span> $maxCallRetries = 5;
  407. <a name="l00594"></a>00594
  408. <a name="l00600"></a>00600 <span class="keyword">protected</span> $defaultColumnCount = 100;
  409. <a name="l00601"></a>00601
  410. <a name="l00610"></a>00610 <span class="keyword">protected</span> $columnFamilies = array();
  411. <a name="l00611"></a>00611
  412. <a name="l00617"></a>00617 <span class="keyword">protected</span> $keyspaceAuthentication = array();
  413. <a name="l00618"></a>00618
  414. <a name="l00625"></a>00625 <span class="keyword">protected</span> $autopack = <span class="keyword">true</span>;
  415. <a name="l00626"></a>00626
  416. <a name="l00634"></a><a class="code" href="classCassandra.html#afd35e5b7419ce2915891c349a44b6f22">00634</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#afd35e5b7419ce2915891c349a44b6f22">CONSISTENCY_ONE</a> = cassandra_ConsistencyLevel::ONE;
  417. <a name="l00635"></a>00635
  418. <a name="l00644"></a><a class="code" href="classCassandra.html#a58c08b49c2434526a62f74248c8b959d">00644</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a58c08b49c2434526a62f74248c8b959d">CONSISTENCY_QUORUM</a> = cassandra_ConsistencyLevel::QUORUM;
  419. <a name="l00645"></a>00645
  420. <a name="l00657"></a><a class="code" href="classCassandra.html#a94fdd09de0798393d86a9965482cefa7">00657</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a94fdd09de0798393d86a9965482cefa7">CONSISTENCY_ANY</a> = cassandra_ConsistencyLevel::ANY;
  421. <a name="l00658"></a>00658
  422. <a name="l00667"></a><a class="code" href="classCassandra.html#ac7e4763d615ce200970153894d53219a">00667</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#ac7e4763d615ce200970153894d53219a">CONSISTENCY_ALL</a> = cassandra_ConsistencyLevel::ALL;
  423. <a name="l00668"></a>00668
  424. <a name="l00672"></a><a class="code" href="classCassandra.html#a5b7fd78b8f044623445d9e9a8f175790">00672</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a5b7fd78b8f044623445d9e9a8f175790">COLUMN_STANDARD</a> = <span class="stringliteral">&#39;Standard&#39;</span>;
  425. <a name="l00673"></a>00673
  426. <a name="l00677"></a><a class="code" href="classCassandra.html#abf8e49b590d1e1b83d3e13cc133cd672">00677</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#abf8e49b590d1e1b83d3e13cc133cd672">COLUMN_SUPER</a> = <span class="stringliteral">&#39;Super&#39;</span>;
  427. <a name="l00678"></a>00678
  428. <a name="l00682"></a><a class="code" href="classCassandra.html#acc917786b5bbbdd6eb4783856bd5580c">00682</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#acc917786b5bbbdd6eb4783856bd5580c">TYPE_ASCII</a> = <span class="stringliteral">&#39;AsciiType&#39;</span>;
  429. <a name="l00683"></a>00683
  430. <a name="l00687"></a><a class="code" href="classCassandra.html#ab75de9aa0588c7665f1c9d8cf8d4e8ff">00687</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#ab75de9aa0588c7665f1c9d8cf8d4e8ff">TYPE_BYTES</a> = <span class="stringliteral">&#39;BytesType&#39;</span>;
  431. <a name="l00688"></a>00688
  432. <a name="l00697"></a><a class="code" href="classCassandra.html#a2af16bdea44f4e16ba5c5baa5380b9f0">00697</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a2af16bdea44f4e16ba5c5baa5380b9f0">TYPE_LEXICAL_UUID</a> = <span class="stringliteral">&#39;LexicalUUIDType&#39;</span>;
  433. <a name="l00698"></a>00698
  434. <a name="l00706"></a><a class="code" href="classCassandra.html#a42861ad94788ba940228767a79f1c4c7">00706</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a42861ad94788ba940228767a79f1c4c7">TYPE_TIME_UUID</a> = <span class="stringliteral">&#39;TimeUUIDType&#39;</span>;
  435. <a name="l00707"></a>00707
  436. <a name="l00711"></a><a class="code" href="classCassandra.html#acf64f8105c4bfe0c95f868437299442f">00711</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#acf64f8105c4bfe0c95f868437299442f">TYPE_LONG</a> = <span class="stringliteral">&#39;LongType&#39;</span>;
  437. <a name="l00712"></a>00712
  438. <a name="l00716"></a><a class="code" href="classCassandra.html#a4160c654a18aead3a642fd1f3f2415e9">00716</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a4160c654a18aead3a642fd1f3f2415e9">TYPE_INTEGER</a> = <span class="stringliteral">&#39;IntegerType&#39;</span>;
  439. <a name="l00717"></a>00717
  440. <a name="l00721"></a><a class="code" href="classCassandra.html#ac03a89bd430178d9bce987eba8001b82">00721</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#ac03a89bd430178d9bce987eba8001b82">TYPE_UTF8</a> = <span class="stringliteral">&#39;UTF8Type&#39;</span>;
  441. <a name="l00722"></a>00722
  442. <a name="l00726"></a><a class="code" href="classCassandra.html#a33b81650dd46405f23e6d469eeb1bd5b">00726</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a33b81650dd46405f23e6d469eeb1bd5b">OP_EQ</a> = cassandra_IndexOperator::EQ;
  443. <a name="l00727"></a>00727
  444. <a name="l00731"></a><a class="code" href="classCassandra.html#acf59b31536a8a886422ef7335020f99d">00731</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#acf59b31536a8a886422ef7335020f99d">OP_LT</a> = cassandra_IndexOperator::LT;
  445. <a name="l00732"></a>00732
  446. <a name="l00736"></a><a class="code" href="classCassandra.html#a660ca00d7f33558017e15ccc1f8f5d29">00736</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a660ca00d7f33558017e15ccc1f8f5d29">OP_GT</a> = cassandra_IndexOperator::GT;
  447. <a name="l00737"></a>00737
  448. <a name="l00741"></a><a class="code" href="classCassandra.html#ab633158313b4f7f785910884d950f945">00741</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#ab633158313b4f7f785910884d950f945">OP_LTE</a> = cassandra_IndexOperator::LTE;
  449. <a name="l00742"></a>00742
  450. <a name="l00746"></a><a class="code" href="classCassandra.html#a60a245248555c96cadec6977014c27df">00746</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#a60a245248555c96cadec6977014c27df">OP_GTE</a> = cassandra_IndexOperator::GTE;
  451. <a name="l00747"></a>00747
  452. <a name="l00752"></a><a class="code" href="classCassandra.html#acae99f4717a1b6a2fb14343b9ca02806">00752</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#acae99f4717a1b6a2fb14343b9ca02806">PLACEMENT_SIMPLE</a> = <span class="stringliteral">&#39;org.apache.cassandra.locator.SimpleStrategy&#39;</span>;
  453. <a name="l00753"></a>00753
  454. <a name="l00757"></a>00757 <span class="keyword">const</span> <a class="code" href="classCassandra.html#a82e1fae7c469b0983ad1d38b309273fd">PLACEMENT_NETWORK</a>
  455. <a name="l00758"></a><a class="code" href="classCassandra.html#a82e1fae7c469b0983ad1d38b309273fd">00758</a> = <span class="stringliteral">&#39;org.apache.cassandra.locator.NetworkTopologyStrategy&#39;</span>;
  456. <a name="l00759"></a>00759
  457. <a name="l00763"></a>00763 <span class="keyword">const</span> <a class="code" href="classCassandra.html#a3ea159c9a7ead7fa56cac7f8ebe9bc74">PLACEMENT_OLD_NETWORK</a>
  458. <a name="l00764"></a><a class="code" href="classCassandra.html#a3ea159c9a7ead7fa56cac7f8ebe9bc74">00764</a> = <span class="stringliteral">&#39;org.apache.cassandra.locator.OldNetworkTopologyStrategy&#39;</span>;
  459. <a name="l00765"></a>00765
  460. <a name="l00769"></a><a class="code" href="classCassandra.html#aa3d7e3c4c9454133e7b21165bb7c3953">00769</a> <span class="keyword">const</span> <a class="code" href="classCassandra.html#aa3d7e3c4c9454133e7b21165bb7c3953">INDEX_KEYS</a> = 0;
  461. <a name="l00770"></a>00770
  462. <a name="l00779"></a><a class="code" href="classCassandra.html#a92574efcf6569a6e2e6f82b6101e83d2">00779</a> <span class="keyword">private</span> function <a class="code" href="classCassandra.html#a92574efcf6569a6e2e6f82b6101e83d2">__construct</a>(array $servers = array(), $autopack = <span class="keyword">true</span>) {
  463. <a name="l00780"></a>00780 $this-&gt;cluster = <span class="keyword">new</span> <a class="code" href="classCassandraCluster.html">CassandraCluster</a>($servers);
  464. <a name="l00781"></a>00781 $this-&gt;autopack = $autopack;
  465. <a name="l00782"></a>00782 }
  466. <a name="l00783"></a>00783
  467. <a name="l00787"></a><a class="code" href="classCassandra.html#abb13b5073e065e8f2a60b1c6f18c573e">00787</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#abb13b5073e065e8f2a60b1c6f18c573e">__clone</a>() {
  468. <a name="l00788"></a>00788 trigger_error(<span class="stringliteral">&#39;Clone is not allowed.&#39;</span>, E_USER_ERROR);
  469. <a name="l00789"></a>00789 }
  470. <a name="l00790"></a>00790
  471. <a name="l00801"></a><a class="code" href="classCassandra.html#a0eb2d8394ec9b98363eb2ea13c3390a6">00801</a> <span class="keyword">public</span> <span class="keyword">static</span> function <a class="code" href="classCassandra.html#a0eb2d8394ec9b98363eb2ea13c3390a6">createInstance</a>(array $servers, $name = <span class="stringliteral">&#39;main&#39;</span>) {
  472. <a name="l00802"></a>00802 self::$instances[$name] = <span class="keyword">new</span> <span class="keyword">self</span>($servers);
  473. <a name="l00803"></a>00803
  474. <a name="l00804"></a>00804 <span class="keywordflow">return</span> self::$instances[$name];
  475. <a name="l00805"></a>00805 }
  476. <a name="l00806"></a>00806
  477. <a name="l00817"></a><a class="code" href="classCassandra.html#accae5522cc54a2f679f7925752d14c01">00817</a> <span class="keyword">public</span> <span class="keyword">static</span> function <a class="code" href="classCassandra.html#accae5522cc54a2f679f7925752d14c01">getInstance</a>($name = <span class="stringliteral">&#39;main&#39;</span>) {
  478. <a name="l00818"></a>00818 <span class="keywordflow">if</span> (!isset(self::$instances[$name])) {
  479. <a name="l00819"></a>00819 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraInvalidRequestException.html">CassandraInvalidRequestException</a>(
  480. <a name="l00820"></a>00820 <span class="stringliteral">&#39;Instance called &quot;&#39;</span>.$name.<span class="stringliteral">&#39;&quot; does not exist&#39;</span>
  481. <a name="l00821"></a>00821 );
  482. <a name="l00822"></a>00822 }
  483. <a name="l00823"></a>00823
  484. <a name="l00824"></a>00824 <span class="keywordflow">return</span> self::$instances[$name];
  485. <a name="l00825"></a>00825 }
  486. <a name="l00826"></a>00826
  487. <a name="l00834"></a><a class="code" href="classCassandra.html#a22c9c1782896b9ee47117643c89f0052">00834</a> <span class="keyword">protected</span> function <a class="code" href="classCassandra.html#a22c9c1782896b9ee47117643c89f0052">registerKeyspace</a>(
  488. <a name="l00835"></a>00835 $keyspace,
  489. <a name="l00836"></a>00836 $username = null,
  490. <a name="l00837"></a>00837 $password = null
  491. <a name="l00838"></a>00838 ) {
  492. <a name="l00839"></a>00839 $this-&gt;keyspaceAuthentication[$keyspace] = array(
  493. <a name="l00840"></a>00840 <span class="stringliteral">&#39;username&#39;</span> =&gt; $username,
  494. <a name="l00841"></a>00841 <span class="stringliteral">&#39;password&#39;</span> =&gt; $password
  495. <a name="l00842"></a>00842 );
  496. <a name="l00843"></a>00843 }
  497. <a name="l00844"></a>00844
  498. <a name="l00858"></a><a class="code" href="classCassandra.html#a4502befdb4278113462bc7fcfbafa09f">00858</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#a4502befdb4278113462bc7fcfbafa09f">useKeyspace</a>($keyspace, $username = null, $password = null) {
  499. <a name="l00859"></a>00859 <span class="keywordflow">if</span> (!empty($username)) {
  500. <a name="l00860"></a>00860 $this-&gt;<a class="code" href="classCassandra.html#a22c9c1782896b9ee47117643c89f0052">registerKeyspace</a>($keyspace, $username, $password);
  501. <a name="l00861"></a>00861 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (isset($this-&gt;keyspaceAuthentication[$keyspace])) {
  502. <a name="l00862"></a>00862 $username = $this-&gt;keyspaceAuthentication[$keyspace][<span class="stringliteral">&#39;username&#39;</span>];
  503. <a name="l00863"></a>00863 $password = $this-&gt;keyspaceAuthentication[$keyspace][<span class="stringliteral">&#39;password&#39;</span>];
  504. <a name="l00864"></a>00864 }
  505. <a name="l00865"></a>00865
  506. <a name="l00866"></a>00866 $this-&gt;cluster-&gt;useKeyspace($keyspace, $username, $password);
  507. <a name="l00867"></a>00867
  508. <a name="l00868"></a>00868 <span class="keywordflow">return</span> $this;
  509. <a name="l00869"></a>00869 }
  510. <a name="l00870"></a>00870
  511. <a name="l00876"></a><a class="code" href="classCassandra.html#ad8fe43e1ceb9841cca92cf981fb566b3">00876</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#ad8fe43e1ceb9841cca92cf981fb566b3">getCluster</a>() {
  512. <a name="l00877"></a>00877 <span class="keywordflow">return</span> $this-&gt;cluster;
  513. <a name="l00878"></a>00878 }
  514. <a name="l00879"></a>00879
  515. <a name="l00885"></a><a class="code" href="classCassandra.html#ac300f4b8ed3a2d80388225e0ec990883">00885</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#ac300f4b8ed3a2d80388225e0ec990883">getConnection</a>() {
  516. <a name="l00886"></a>00886 <span class="keywordflow">return</span> $this-&gt;cluster-&gt;getConnection();
  517. <a name="l00887"></a>00887 }
  518. <a name="l00888"></a>00888
  519. <a name="l00894"></a><a class="code" href="classCassandra.html#a382ebe135b67bddef1e0a9fa21448cde">00894</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#a382ebe135b67bddef1e0a9fa21448cde">closeConnections</a>() {
  520. <a name="l00895"></a>00895 $this-&gt;cluster-&gt;closeConnections();
  521. <a name="l00896"></a>00896 }
  522. <a name="l00897"></a>00897
  523. <a name="l00903"></a><a class="code" href="classCassandra.html#a4eaaed3e996a26cc145057487036584b">00903</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#a4eaaed3e996a26cc145057487036584b">getClient</a>() {
  524. <a name="l00904"></a>00904 <span class="keywordflow">return</span> $this-&gt;cluster-&gt;getConnection()-&gt;getClient();
  525. <a name="l00905"></a>00905 }
  526. <a name="l00906"></a>00906
  527. <a name="l00914"></a><a class="code" href="classCassandra.html#aea614dd2c8170609c0ec9e81607983a0">00914</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#aea614dd2c8170609c0ec9e81607983a0">setMaxCallRetries</a>($retryCount) {
  528. <a name="l00915"></a>00915 $this-&gt;maxCallRetries = $retryCount;
  529. <a name="l00916"></a>00916
  530. <a name="l00917"></a>00917 <span class="keywordflow">return</span> $this;
  531. <a name="l00918"></a>00918 }
  532. <a name="l00919"></a>00919
  533. <a name="l00925"></a><a class="code" href="classCassandra.html#af62c6e8771c55cfe9a94e8a6551a5e1b">00925</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#af62c6e8771c55cfe9a94e8a6551a5e1b">setDefaultColumnCount</a>($columnCountLimit) {
  534. <a name="l00926"></a>00926 $this-&gt;defaultColumnCount = $columnCountLimit;
  535. <a name="l00927"></a>00927 }
  536. <a name="l00928"></a>00928
  537. <a name="l00943"></a><a class="code" href="classCassandra.html#a5a83ae74dca462d6d7527c2a682ae550">00943</a> <span class="keyword">public</span> function <a class="code" href="classCassandra.html#a5a83ae74dca462d6d7527c2a682ae550">call</a>(<span class="comment">/*$methodName, $arg1, $arg2 */</span>) {
  538. <a name="l00944"></a>00944 $args = func_get_args();
  539. <a name="l00945"></a>00945 $methodName = array_shift($args);
  540. <a name="l00946"></a>00946
  541. <a name="l00947"></a>00947 $tries = $this-&gt;maxCallRetries;
  542. <a name="l00948"></a>00948 $lastException = null;
  543. <a name="l00949"></a>00949
  544. <a name="l00950"></a>00950 $keyspaceRequiredMethods = <a class="code" href="classCassandra.html#ad051f9ef0cdc597c5838124c58e9f962">self::getKeyspaceRequiredMethods</a>();
  545. <a name="l00951"></a>00951
  546. <a name="l00952"></a>00952 <span class="keywordflow">if</span> (
  547. <a name="l00953"></a>00953 in_array($methodName, $keyspaceRequiredMethods)
  548. <a name="l00954"></a>00954 &amp;&amp; $this-&gt;cluster-&gt;getCurrentKeyspace() === null
  549. <a name="l00955"></a>00955 ) {
  550. <a name="l00956"></a>00956 <span class="keywordflow">throw</span> <span class="keyword">new</span> <a class="code" href="classCassandraInvalidRequestException.html">CassandraInvalidRequestException</a>(
  551. <a name="l00957"></a>00957 <span class="stringliteral">&#39;Unable to call &quot;&#39;</span>.$methodName.<span class="stringliteral">&#39;&quot;, no keyspace has been set&#39;</span>
  552. <a name="l00958"></a>00958 );
  553. <a name="l00959"></a>00959 }
  554. <a name="l00960"></a>00960
  555. <a name="l00961"></a>00961 $try = 0;
  556. <a name="l00962"></a>00962
  557. <a name="l00963"></a>00963 <span class="keywordflow">while</span>($tries-- &gt; 0) {
  558. <a name="l00964"></a>00964 $client = $this-&gt;<a class="code" href="classCassandra.html#a4eaaed3e996a26cc145057487036584b">getClient</a>();
  559. <a name="l00965"></a>00965 $try++;
  560. <a name="l00966"></a>00966
  561. <a name="l00967"></a>00967 <span class="keywordflow">try</span> {
  562. <a name="l00968"></a>00968 <span class="keywordflow">return</span> call_user_func_array(array($client, $methodName), $args);
  563. <a name="l00969"></a>00969 } <span class="keywordflow">catch</span> (Exception $e) {
  564. <a name="l00970"></a>00970 $lastException = $e;
  565. <a name="l00971"></a>00971
  566. <a name="l00972"></a>00972 usleep(0.1 * pow(2, $try) * 1000000);
  567. <a name="l00973"></a>00973 }
  568. <a name="l00974"></a>00974 }
  569. <a name="l00975"></a>00975
  570. <a name="l00976"></a>00976 <span class="keywordflow">throw</span> <sp

Large files files are truncated, but you can click here to view the full file