| 5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
| 7 |
* @name DesignPattern::RemoteProxy |
* @name DesignPattern::RemoteProxy |
|
* @filesource |
|
| 8 |
* |
* |
| 9 |
* |
* |
| 10 |
|
*/ |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
/** |
| 14 |
* <b>Cvs-Log:</b> |
* <b>Cvs-Log:</b> |
| 15 |
* |
* |
| 16 |
* <pre> |
* <pre> |
| 18 |
* $Id$ |
* $Id$ |
| 19 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
| 20 |
* $Log$ |
* $Log$ |
| 21 |
|
* Revision 1.12 2003/03/29 08:01:21 joko |
| 22 |
|
* modified ErrorBoxing |
| 23 |
|
* |
| 24 |
|
* Revision 1.11 2003/03/28 06:44:51 joko |
| 25 |
|
* VERBOSE mode |
| 26 |
|
* |
| 27 |
|
* Revision 1.10 2003/03/28 03:05:54 joko |
| 28 |
|
* more fancy debugging-output |
| 29 |
|
* |
| 30 |
|
* Revision 1.9 2003/03/10 23:05:25 joko |
| 31 |
|
* + fixed metadata for phpDocumentor |
| 32 |
|
* |
| 33 |
|
* Revision 1.8 2003/03/10 22:31:56 joko |
| 34 |
|
* + fixed metadata for phpDocumentor |
| 35 |
|
* |
| 36 |
|
* Revision 1.7 2003/03/09 15:51:44 joko |
| 37 |
|
* + additional metadata for Autodia |
| 38 |
|
* |
| 39 |
* Revision 1.6 2003/03/05 17:28:43 joko |
* Revision 1.6 2003/03/05 17:28:43 joko |
| 40 |
* updated docu (phpDocumentor testing....) |
* updated docu (phpDocumentor testing....) |
| 41 |
* |
* |
| 154 |
|
|
| 155 |
|
|
| 156 |
/** |
/** |
| 157 |
* Data::Driver::Proxy -- Multiple stage data fetching and caching |
* DesignPattern::RemoteProxy -- Multiple stage data fetching and caching |
| 158 |
* |
* |
| 159 |
* |
* |
| 160 |
* This class (Data::Driver::Proxy) provides an abstract framework |
* This class (DesignPattern::RemoteProxy) provides an abstract framework |
| 161 |
* for loading/saving arbitrary data from/to data storages interfaced |
* for loading/saving arbitrary data from/to data storages interfaced |
| 162 |
* by storage *proxy*-drivers. |
* by storage *proxy*-drivers. |
| 163 |
* Don't mix these up with the concrete storage *handle*-drivers |
* Don't mix these up with the concrete storage *handle*-drivers |
| 166 |
* providing a more highlevel, consistent API making |
* providing a more highlevel, consistent API making |
| 167 |
* it easier for Data::Driver::Proxy to do its main work: |
* it easier for Data::Driver::Proxy to do its main work: |
| 168 |
* |
* |
| 169 |
|
* quote from: http://home.earthlink.net/~huston2/dp/proxy.html |
| 170 |
|
* "A remote proxy provides a local representative for an |
| 171 |
|
* object that resides in a different address space. This is |
| 172 |
|
* what the "stub" code in RPC and CORBA provides." |
| 173 |
|
* |
| 174 |
|
* |
| 175 |
* Multiple stage data fetching and caching: |
* Multiple stage data fetching and caching: |
| 176 |
* |
* |
| 177 |
* <pre> |
* <pre> |
| 224 |
* An attempt to implement some software design patterns |
* An attempt to implement some software design patterns |
| 225 |
* --- RemoteProxyPattern |
* --- RemoteProxyPattern |
| 226 |
* |
* |
| 227 |
|
* @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm |
| 228 |
|
* @link http://home.earthlink.net/~huston2/dp/proxy.html |
| 229 |
|
* @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject |
| 230 |
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
| 231 |
|
* @link http://c2.com/cgi-bin/wiki?LazyProxies |
| 232 |
* |
* |
| 233 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 234 |
* @link http://www.netfrag.org/~joko/ |
* @link http://www.netfrag.org/~joko/ |
| 242 |
* @name DesignPattern::RemoteProxy |
* @name DesignPattern::RemoteProxy |
| 243 |
* |
* |
| 244 |
* |
* |
| 245 |
* @todo |
* @todo extend options to en-/disable caching via a) session and/or b) database |
| 246 |
* <pre> |
* make feature available via runtime setter-method to these options |
| 247 |
* x extend options to en-/disable caching via a) session and/or b) database |
* @todo PEAR::Cache for caching purposes!!! |
| 248 |
* o make feature available via runtime setter-method to these options |
* @todo refactor database access: use PEAR for this! no more 'connectdb' here!!! |
| 249 |
* o use PEAR::Cache for caching purposes!!! |
* @todo make database connection more flexible to make possible |
| 250 |
* o refactor database access: use PEAR for this! no more 'connectdb' here!!! |
* to have different (probably named) proxy databases (besides a "main database") |
| 251 |
* o make database connection more flexible to make possible |
* @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
| 252 |
* to have different (probably named) proxy databases (besides a "main database") |
* @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject) |
| 253 |
* o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
* @todo rename this to "DesignPattern::LazyRemoteProxy"??? |
|
* </pre> |
|
| 254 |
* |
* |
| 255 |
*/ |
*/ |
| 256 |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
| 305 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
| 306 |
} |
} |
| 307 |
|
|
| 308 |
|
/** |
| 309 |
|
* <!-- Autodia --> |
| 310 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
| 311 |
|
* $this->backend = new DataSource_Proxy_XMLRPC() |
| 312 |
|
* |
| 313 |
|
*/ |
| 314 |
|
|
| 315 |
if ($this->meta[remote]) { |
if ($this->meta[remote]) { |
| 316 |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
| 317 |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
| 485 |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
| 486 |
return; |
return; |
| 487 |
} |
} |
| 488 |
|
logp(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG); |
| 489 |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
| 490 |
$result = $this->backend->send('getObjectByGuid', $args ); |
$result = $this->backend->send('getObjectByGuid', $args ); |
| 491 |
|
|
| 494 |
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); |
| 495 |
return; |
return; |
| 496 |
} |
} |
| 497 |
|
logp(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG); |
| 498 |
$result = $this->backend->send('getObject', $this->objectId); |
$result = $this->backend->send('getObject', $this->objectId); |
| 499 |
|
|
| 500 |
} elseif ($this->meta[key]) { |
} elseif ($this->meta[key]) { |
| 508 |
return; |
return; |
| 509 |
} |
} |
| 510 |
*/ |
*/ |
| 511 |
|
//logp(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG); |
| 512 |
|
//print Dumper(array($this->meta[command], $this->meta[query])); |
| 513 |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
| 514 |
|
|
| 515 |
} |
} |
| 516 |
|
|
| 517 |
|
//print "result: " . dumpVar($result) . "<br>"; |
| 518 |
|
|
| 519 |
|
$status = $this->backend->getStatus(); |
| 520 |
|
//print Dumper($status); |
| 521 |
|
|
| 522 |
if ($result) { |
$style = html_style("text/css", '.boxlabel_yellow { color: yellow; font-weight:bold; }'); |
| 523 |
//print "result: " . dumpVar($result) . "<br>"; |
$statusbox = html_div(); |
| 524 |
if (count($result) == 0) { return; } |
$statusbox->set_style('background: red; border: 2px black groove; width:640px; padding:10px; margin:40px;'); |
| 525 |
|
$statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() ); |
| 526 |
|
foreach ($status[errors] as $error) { |
| 527 |
|
$statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $error[message], html_br() ); |
| 528 |
|
} |
| 529 |
|
|
| 530 |
|
if (is_array($result)) { |
| 531 |
|
$good = 1; |
| 532 |
|
} else { |
| 533 |
|
$message = get_class($this) . "->_loadRemote: Error while trying to talk to remote side. Please check wire, socket or api."; |
| 534 |
|
logp($message, PEAR_LOG_CRIT); |
| 535 |
|
$statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() ); |
| 536 |
|
} |
| 537 |
|
|
| 538 |
|
if ($good && sizeof($result)) { |
| 539 |
|
|
| 540 |
// FIXME: this is dangerous! |
// FIXME: this is dangerous! |
| 541 |
if ($_GET[debug]) { |
if ($_GET[debug]) { |
| 548 |
$this->_saveProxy(); |
$this->_saveProxy(); |
| 549 |
//print "oid: $this->objectId<br>"; |
//print "oid: $this->objectId<br>"; |
| 550 |
$this->flushState(); |
$this->flushState(); |
| 551 |
|
|
| 552 |
} else { |
} else { |
| 553 |
//print "Error in _loadRemote!!!<br>"; |
if (constants::get('VERBOSE') || constants::get('ERRORS_ONLY')) { |
| 554 |
logp(get_class($this) . "->_loadRemote: error while trying to talk to remote side", PEAR_LOG_CRIT); |
print $style->render(); |
| 555 |
|
print $statusbox->render(); |
| 556 |
|
} else { |
| 557 |
|
foreach ($status[errors] as $error) { |
| 558 |
|
print Dumper($error); |
| 559 |
|
} |
| 560 |
|
} |
| 561 |
|
|
| 562 |
} |
} |
| 563 |
|
|
| 564 |
} |
} |