| 6 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
| 7 |
* @name DesignPattern::RemoteProxy |
* @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.10 2003/03/28 03:05:54 joko |
| 22 |
|
* more fancy debugging-output |
| 23 |
|
* |
| 24 |
|
* Revision 1.9 2003/03/10 23:05:25 joko |
| 25 |
|
* + fixed metadata for phpDocumentor |
| 26 |
|
* |
| 27 |
|
* Revision 1.8 2003/03/10 22:31:56 joko |
| 28 |
|
* + fixed metadata for phpDocumentor |
| 29 |
|
* |
| 30 |
|
* Revision 1.7 2003/03/09 15:51:44 joko |
| 31 |
|
* + additional metadata for Autodia |
| 32 |
|
* |
| 33 |
|
* Revision 1.6 2003/03/05 17:28:43 joko |
| 34 |
|
* updated docu (phpDocumentor testing....) |
| 35 |
|
* |
| 36 |
|
* Revision 1.5 2003/03/05 17:02:22 joko |
| 37 |
|
* updated docu (phpDocumentor testing....) |
| 38 |
|
* |
| 39 |
|
* Revision 1.4 2003/03/05 16:32:19 joko |
| 40 |
|
* updated docu (phpDocumentor testing....) |
| 41 |
|
* |
| 42 |
* Revision 1.3 2003/03/05 16:10:17 joko |
* Revision 1.3 2003/03/05 16:10:17 joko |
| 43 |
* updated docu (phpDocumentor testing....) |
* updated docu (phpDocumentor testing....) |
| 44 |
* |
* |
| 133 |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
| 134 |
* + new |
* + new |
| 135 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
| 136 |
|
* </pre> |
| 137 |
|
* |
| 138 |
|
*/ |
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
/** |
| 144 |
|
* Load required modules: |
| 145 |
|
* |
| 146 |
*/ |
*/ |
| 147 |
|
loadModule('DesignPattern::Proxy'); |
| 148 |
|
|
| 149 |
|
|
| 150 |
/** |
/** |
| 151 |
* Data::Driver::Proxy -- Multiple stage data fetching and caching |
* DesignPattern::RemoteProxy -- Multiple stage data fetching and caching |
| 152 |
* |
* |
| 153 |
* |
* |
| 154 |
* This class (Data::Driver::Proxy) provides an abstract framework |
* This class (DesignPattern::RemoteProxy) provides an abstract framework |
| 155 |
* for loading/saving arbitrary data from/to data storages interfaced |
* for loading/saving arbitrary data from/to data storages interfaced |
| 156 |
* by storage *proxy*-drivers. |
* by storage *proxy*-drivers. |
| 157 |
* Don't mix these up with the concrete storage *handle*-drivers |
* Don't mix these up with the concrete storage *handle*-drivers |
| 160 |
* providing a more highlevel, consistent API making |
* providing a more highlevel, consistent API making |
| 161 |
* it easier for Data::Driver::Proxy to do its main work: |
* it easier for Data::Driver::Proxy to do its main work: |
| 162 |
* |
* |
| 163 |
|
* quote from: http://home.earthlink.net/~huston2/dp/proxy.html |
| 164 |
|
* "A remote proxy provides a local representative for an |
| 165 |
|
* object that resides in a different address space. This is |
| 166 |
|
* what the "stub" code in RPC and CORBA provides." |
| 167 |
|
* |
| 168 |
|
* |
| 169 |
* Multiple stage data fetching and caching: |
* Multiple stage data fetching and caching: |
| 170 |
* |
* |
| 171 |
|
* <pre> |
| 172 |
|
* |
| 173 |
* DATA, ... |
* DATA, ... |
| 174 |
* ... also refered to as data, should be handled as |
* ... also refered to as data, should be handled as |
| 175 |
* something called data. |
* something called data. |
| 212 |
* o Data::Driver::PEAR::DB |
* o Data::Driver::PEAR::DB |
| 213 |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
| 214 |
* |
* |
| 215 |
*/ |
* </pre> |
| 216 |
|
* |
| 217 |
/** |
* |
| 218 |
* An attempt to implement some software design patterns... |
* An attempt to implement some software design patterns |
| 219 |
* --- RemoteProxyPattern |
* --- RemoteProxyPattern |
| 220 |
* |
* |
| 221 |
|
* @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm |
| 222 |
|
* @link http://home.earthlink.net/~huston2/dp/proxy.html |
| 223 |
|
* @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject |
| 224 |
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
* @link http://c2.com/cgi-bin/wiki?ProxyPattern |
| 225 |
|
* @link http://c2.com/cgi-bin/wiki?LazyProxies |
| 226 |
* |
* |
| 227 |
* @author Andreas Motl <andreas.motl@ilo.de> |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 228 |
* @link http://www.netfrag.org/~joko/ |
* @link http://www.netfrag.org/~joko/ |
| 232 |
* @link http://www.gnu.org/licenses/lgpl.txt |
* @link http://www.gnu.org/licenses/lgpl.txt |
| 233 |
* |
* |
| 234 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
| 235 |
|
* @subpackage DesignPattern |
| 236 |
* @name DesignPattern::RemoteProxy |
* @name DesignPattern::RemoteProxy |
| 237 |
* |
* |
|
*/ |
|
|
|
|
|
/** |
|
|
* @todo |
|
|
* <pre> |
|
|
* 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? |
|
|
* </pre> |
|
| 238 |
* |
* |
| 239 |
*/ |
* @todo extend options to en-/disable caching via a) session and/or b) database |
| 240 |
|
* make feature available via runtime setter-method to these options |
| 241 |
/** |
* @todo PEAR::Cache for caching purposes!!! |
| 242 |
* Load required modules: |
* @todo refactor database access: use PEAR for this! no more 'connectdb' here!!! |
| 243 |
|
* @todo make database connection more flexible to make possible |
| 244 |
|
* to have different (probably named) proxy databases (besides a "main database") |
| 245 |
|
* @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
| 246 |
|
* @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject) |
| 247 |
|
* @todo rename this to "DesignPattern::LazyRemoteProxy"??? |
| 248 |
* |
* |
| 249 |
*/ |
*/ |
|
loadModule('DesignPattern::Proxy'); |
|
|
|
|
| 250 |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
| 251 |
|
|
| 252 |
var $objectId; |
var $objectId; |
| 299 |
session_register_safe("proxy"); |
session_register_safe("proxy"); |
| 300 |
} |
} |
| 301 |
|
|
| 302 |
|
/** |
| 303 |
|
* <!-- Autodia --> |
| 304 |
|
* can do: (this is metadata supplied for Autodia, don't delete!) |
| 305 |
|
* $this->backend = new DataSource_Proxy_XMLRPC() |
| 306 |
|
* |
| 307 |
|
*/ |
| 308 |
|
|
| 309 |
if ($this->meta[remote]) { |
if ($this->meta[remote]) { |
| 310 |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
//$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]); |
| 311 |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
$this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]); |
| 479 |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING); |
| 480 |
return; |
return; |
| 481 |
} |
} |
| 482 |
|
logp(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG); |
| 483 |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
$args = array( guid => $this->objectId, classname => $this->meta[classname] ); |
| 484 |
$result = $this->backend->send('getObjectByGuid', $args ); |
$result = $this->backend->send('getObjectByGuid', $args ); |
| 485 |
|
|
| 488 |
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); |
| 489 |
return; |
return; |
| 490 |
} |
} |
| 491 |
|
logp(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG); |
| 492 |
$result = $this->backend->send('getObject', $this->objectId); |
$result = $this->backend->send('getObject', $this->objectId); |
| 493 |
|
|
| 494 |
} elseif ($this->meta[key]) { |
} elseif ($this->meta[key]) { |
| 502 |
return; |
return; |
| 503 |
} |
} |
| 504 |
*/ |
*/ |
| 505 |
|
//logp(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG); |
| 506 |
|
//print Dumper(array($this->meta[command], $this->meta[query])); |
| 507 |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
$result = $this->backend->send($this->meta[command], $this->meta[query]); |
| 508 |
|
|
| 509 |
} |
} |
| 510 |
|
|
| 511 |
|
//print "result: " . dumpVar($result) . "<br>"; |
| 512 |
|
|
| 513 |
|
$status = $this->backend->getStatus(); |
| 514 |
|
//print Dumper($status); |
| 515 |
|
|
| 516 |
|
$style = html_style("text/css", '.caption { color: yellow }'); |
| 517 |
|
|
| 518 |
if ($result) { |
$statusbox = html_div(); |
| 519 |
//print "result: " . dumpVar($result) . "<br>"; |
$statusbox->set_style('background: #558856; border: 2px black groove; width:640px; padding:10px; margin:40px;'); |
| 520 |
if (count($result) == 0) { return; } |
$statusbox->add( html_b("Connected:"), $status[connected], html_br() ); |
| 521 |
|
$statusbox->add( html_span('caption', "Connected:"), $status[connected], html_br() ); |
| 522 |
|
foreach ($status[errors] as $error) { |
| 523 |
|
$statusbox->add( html_span('caption', "Error[$error[code]]:"), $error[message], html_br() ); |
| 524 |
|
} |
| 525 |
|
|
| 526 |
|
if (is_array($result)) { |
| 527 |
|
$good = 1; |
| 528 |
|
} else { |
| 529 |
|
$message = get_class($this) . "->_loadRemote: Error while trying to talk to remote side. Please check wire, socket or api."; |
| 530 |
|
$statusbox->add( $message, html_br() ); |
| 531 |
|
logp($message, PEAR_LOG_CRIT); |
| 532 |
|
} |
| 533 |
|
|
| 534 |
|
if ($good && sizeof($result)) { |
| 535 |
|
|
| 536 |
// FIXME: this is dangerous! |
// FIXME: this is dangerous! |
| 537 |
if ($_GET[debug]) { |
if ($_GET[debug]) { |
| 544 |
$this->_saveProxy(); |
$this->_saveProxy(); |
| 545 |
//print "oid: $this->objectId<br>"; |
//print "oid: $this->objectId<br>"; |
| 546 |
$this->flushState(); |
$this->flushState(); |
| 547 |
|
|
| 548 |
} else { |
} else { |
| 549 |
//print "Error in _loadRemote!!!<br>"; |
print $style->render(); |
| 550 |
logp(get_class($this) . "->_loadRemote: error while trying to talk to remote side", PEAR_LOG_CRIT); |
print $statusbox->render(); |
| 551 |
|
|
| 552 |
} |
} |
| 553 |
|
|
| 554 |
} |
} |