1 |
<?php |
<?php |
2 |
|
/** |
3 |
|
* This file contains the DesignPattern::RemoteProxy class |
4 |
|
* |
5 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
|
* @package org.netfrag.glib |
7 |
|
* @name DesignPattern::RemoteProxy |
8 |
|
* |
9 |
|
* |
10 |
|
*/ |
11 |
|
|
12 |
|
|
13 |
/** |
/** |
14 |
|
* <b>Cvs-Log:</b> |
15 |
|
* |
16 |
|
* <pre> |
17 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
18 |
* $Id$ |
* $Id$ |
19 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
20 |
* $Log$ |
* $Log$ |
21 |
|
* Revision 1.14 2003/04/09 02:06:45 joko |
22 |
|
* errormessage now shown preformatted |
23 |
|
* |
24 |
|
* Revision 1.13 2003/04/04 17:38:03 joko |
25 |
|
* modifications regarding error-/exception-handling and -tracing |
26 |
|
* |
27 |
|
* Revision 1.12 2003/03/29 08:01:21 joko |
28 |
|
* modified ErrorBoxing |
29 |
|
* |
30 |
|
* Revision 1.11 2003/03/28 06:44:51 joko |
31 |
|
* VERBOSE mode |
32 |
|
* |
33 |
|
* Revision 1.10 2003/03/28 03:05:54 joko |
34 |
|
* more fancy debugging-output |
35 |
|
* |
36 |
|
* Revision 1.9 2003/03/10 23:05:25 joko |
37 |
|
* + fixed metadata for phpDocumentor |
38 |
|
* |
39 |
|
* Revision 1.8 2003/03/10 22:31:56 joko |
40 |
|
* + fixed metadata for phpDocumentor |
41 |
|
* |
42 |
|
* Revision 1.7 2003/03/09 15:51:44 joko |
43 |
|
* + additional metadata for Autodia |
44 |
|
* |
45 |
|
* Revision 1.6 2003/03/05 17:28:43 joko |
46 |
|
* updated docu (phpDocumentor testing....) |
47 |
|
* |
48 |
|
* Revision 1.5 2003/03/05 17:02:22 joko |
49 |
|
* updated docu (phpDocumentor testing....) |
50 |
|
* |
51 |
|
* Revision 1.4 2003/03/05 16:32:19 joko |
52 |
|
* updated docu (phpDocumentor testing....) |
53 |
|
* |
54 |
|
* Revision 1.3 2003/03/05 16:10:17 joko |
55 |
|
* updated docu (phpDocumentor testing....) |
56 |
|
* |
57 |
* Revision 1.2 2003/03/05 12:14:02 joko |
* Revision 1.2 2003/03/05 12:14:02 joko |
58 |
* renamed method |
* renamed method |
59 |
* constructor argument expansion |
* constructor argument expansion |
145 |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
146 |
* + new |
* + new |
147 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
148 |
|
* </pre> |
149 |
|
* |
150 |
*/ |
*/ |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
/** |
/** |
156 |
|
* Load required modules: |
157 |
* |
* |
158 |
* Data::Driver::Proxy -- Multiple stage data fetching and caching |
*/ |
159 |
|
loadModule('DesignPattern::Proxy'); |
160 |
|
|
161 |
|
|
162 |
|
/** |
163 |
|
* DesignPattern::RemoteProxy -- Multiple stage data fetching and caching |
164 |
* |
* |
165 |
* |
* |
166 |
* This class (Data::Driver::Proxy) provides an abstract framework |
* This class (DesignPattern::RemoteProxy) provides an abstract framework |
167 |
* for loading/saving arbitrary data from/to data storages interfaced |
* for loading/saving arbitrary data from/to data storages interfaced |
168 |
* by storage *proxy*-drivers. |
* by storage *proxy*-drivers. |
169 |
* Don't mix these up with the concrete storage *handle*-drivers |
* Don't mix these up with the concrete storage *handle*-drivers |
172 |
* providing a more highlevel, consistent API making |
* providing a more highlevel, consistent API making |
173 |
* it easier for Data::Driver::Proxy to do its main work: |
* it easier for Data::Driver::Proxy to do its main work: |
174 |
* |
* |
175 |
|
* quote from: http://home.earthlink.net/~huston2/dp/proxy.html |
176 |
|
* "A remote proxy provides a local representative for an |
177 |
|
* object that resides in a different address space. This is |
178 |
|
* what the "stub" code in RPC and CORBA provides." |
179 |
|
* |
180 |
|
* |
181 |
* Multiple stage data fetching and caching: |
* Multiple stage data fetching and caching: |
182 |
* |
* |
183 |
|
* <pre> |
184 |
|
* |
185 |
* DATA, ... |
* DATA, ... |
186 |
* ... also refered to as data, should be handled as |
* ... also refered to as data, should be handled as |
187 |
* something called data. |
* something called data. |
224 |
* o Data::Driver::PEAR::DB |
* o Data::Driver::PEAR::DB |
225 |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
226 |
* |
* |
227 |
*/ |
* </pre> |
|
|
|
|
/** |
|
|
* Todo: |
|
|
* x extend options to en-/disable caching via a) session and/or b) database |
|
|
* o make feature available via runtime setter-method to these options |
|
|
* o use PEAR::Cache for caching purposes!!! |
|
|
* o refactor database access: use PEAR for this! no more 'connectdb' here!!! |
|
|
* o make database connection more flexible to make possible |
|
|
* to have different (probably named) proxy databases (besides a "main database") |
|
|
* o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
|
228 |
* |
* |
229 |
*/ |
* |
230 |
|
* An attempt to implement some software design patterns |
231 |
/** |
* --- RemoteProxyPattern |
232 |
* Load required modules: |
* |
233 |
|
* @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm |
234 |
|
* @link http://home.earthlink.net/~huston2/dp/proxy.html |
235 |
|
* @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject |
236 |
|
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
237 |
|
* @link http://c2.com/cgi-bin/wiki?LazyProxies |
238 |
|
* |
239 |
|
* @author Andreas Motl <andreas.motl@ilo.de> |
240 |
|
* @link http://www.netfrag.org/~joko/ |
241 |
|
* |
242 |
|
* @copyright (c) 2003 - All Rights reserved. |
243 |
|
* @license GNU LGPL (GNU Lesser General Public License) |
244 |
|
* @link http://www.gnu.org/licenses/lgpl.txt |
245 |
|
* |
246 |
|
* @package org.netfrag.glib |
247 |
|
* @subpackage DesignPattern |
248 |
|
* @name DesignPattern::RemoteProxy |
249 |
|
* |
250 |
|
* |
251 |
|
* @todo extend options to en-/disable caching via a) session and/or b) database |
252 |
|
* make feature available via runtime setter-method to these options |
253 |
|
* @todo PEAR::Cache for caching purposes!!! |
254 |
|
* @todo refactor database access: use PEAR for this! no more 'connectdb' here!!! |
255 |
|
* @todo make database connection more flexible to make possible |
256 |
|
* to have different (probably named) proxy databases (besides a "main database") |
257 |
|
* @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
258 |
|
* @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject) |
259 |
|
* @todo rename this to "DesignPattern::LazyRemoteProxy"??? |
260 |
* |
* |
261 |
*/ |
*/ |
|
loadModule('DesignPattern::Proxy'); |
|
|
|
|
262 |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
263 |
|
|
264 |
var $objectId; |
var $objectId; |
311 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
312 |
} |
} |
313 |
|
|
314 |
|
/** |
315 |
|
* <!-- Autodia --> |
316 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
317 |
|
* $this->backend = new DataSource_Proxy_XMLRPC() |
318 |
|
* |
319 |
|
*/ |
320 |
|
|
321 |
if ($this->meta[remote]) { |
if ($this->meta[remote]) { |
322 |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
323 |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
491 |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
492 |
return; |
return; |
493 |
} |
} |
494 |
|
logp(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG); |
495 |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
496 |
$result = $this->backend->send('getObjectByGuid', $args ); |
$result = $this->backend->send('getObjectByGuid', $args ); |
497 |
|
|
500 |
logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING); |
501 |
return; |
return; |
502 |
} |
} |
503 |
|
logp(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG); |
504 |
$result = $this->backend->send('getObject', $this->objectId); |
$result = $this->backend->send('getObject', $this->objectId); |
505 |
|
|
506 |
} elseif ($this->meta[key]) { |
} elseif ($this->meta[key]) { |
514 |
return; |
return; |
515 |
} |
} |
516 |
*/ |
*/ |
517 |
|
//logp(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG); |
518 |
|
//print Dumper(array($this->meta[command], $this->meta[query])); |
519 |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
520 |
|
|
521 |
} |
} |
522 |
|
|
523 |
|
//print "result: " . dumpVar($result) . "<br>"; |
524 |
|
|
525 |
|
$status = $this->backend->status(); |
526 |
|
//print Dumper($status); |
527 |
|
|
528 |
if ($result) { |
$good = is_array($result) && sizeof($result) && $status[connected]; |
529 |
//print "result: " . dumpVar($result) . "<br>"; |
|
530 |
if (count($result) == 0) { return; } |
if ($good) { |
531 |
|
|
532 |
// FIXME: this is dangerous! |
// FIXME: this is dangerous! |
533 |
|
/* |
534 |
if ($_GET[debug]) { |
if ($_GET[debug]) { |
535 |
print Dumper($result); |
print Dumper($result); |
536 |
} |
} |
537 |
|
*/ |
538 |
|
|
539 |
$this->payload = serialize($result); |
$this->payload = serialize($result); |
540 |
// ----- move this to _encode some times |
// ----- move this to _encode some times |
542 |
$this->_saveProxy(); |
$this->_saveProxy(); |
543 |
//print "oid: $this->objectId<br>"; |
//print "oid: $this->objectId<br>"; |
544 |
$this->flushState(); |
$this->flushState(); |
545 |
|
|
546 |
} else { |
} else { |
547 |
//print "Error in _loadRemote!!!<br>"; |
|
548 |
logp(get_class($this) . "->_loadRemote: error while trying to talk to remote side", PEAR_LOG_CRIT); |
if (constants::get('APP_MODE_DEBUG')) { |
549 |
|
$this->draw_error_box($status); |
550 |
|
} else { |
551 |
|
php::maintenance('rpc', array( status => $status ) ); |
552 |
|
} |
553 |
|
|
554 |
} |
} |
555 |
|
|
556 |
} |
} |
557 |
|
|
558 |
|
function draw_error_box($status) { |
559 |
|
$style = html_style("text/css", '.boxlabel_yellow { color: yellow; font-weight:bold; }'); |
560 |
|
$statusbox = html_div(); |
561 |
|
$statusbox->set_style('background: red; border: 2px black groove; width:640px; padding:10px; margin:40px;'); |
562 |
|
$statusbox->add( html_span('boxlabel_yellow', "Method:"), get_class($this) . "->_loadRemote", html_br() ); |
563 |
|
$statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() ); |
564 |
|
$statusbox->add( html_span('boxlabel_yellow', "RPCSESSID:"), $status[RPCSESSID], html_br() ); |
565 |
|
foreach ($status[errors] as $error) { |
566 |
|
$msg = html_pre($error[message]); |
567 |
|
$statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $msg ); |
568 |
|
} |
569 |
|
|
570 |
|
$message = "Error while talking to remote side. Please check wire, socket or api."; |
571 |
|
logp($message, PEAR_LOG_CRIT); |
572 |
|
$statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() ); |
573 |
|
|
574 |
|
// V1 |
575 |
|
/* |
576 |
|
if (constants::get('VERBOSE') || constants::get('ERRORS_ONLY')) { |
577 |
|
print $style->render(); |
578 |
|
print $statusbox->render(); |
579 |
|
} else { |
580 |
|
foreach ($status[errors] as $error) { |
581 |
|
print Dumper($error); |
582 |
|
} |
583 |
|
} |
584 |
|
*/ |
585 |
|
|
586 |
|
// V2 |
587 |
|
trace( container($style, $statusbox) ); |
588 |
|
|
589 |
|
} |
590 |
|
|
591 |
|
|
592 |
function _saveBackend($result) { |
function _saveBackend($result) { |
593 |
logp(get_class($this) . "->_saveBackend()"); |
logp(get_class($this) . "->_saveBackend()"); |
594 |
|
|