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.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 |
40 |
|
* updated docu (phpDocumentor testing....) |
41 |
|
* |
42 |
|
* Revision 1.5 2003/03/05 17:02:22 joko |
43 |
|
* updated docu (phpDocumentor testing....) |
44 |
|
* |
45 |
|
* Revision 1.4 2003/03/05 16:32:19 joko |
46 |
|
* updated docu (phpDocumentor testing....) |
47 |
|
* |
48 |
* Revision 1.3 2003/03/05 16:10:17 joko |
* Revision 1.3 2003/03/05 16:10:17 joko |
49 |
* updated docu (phpDocumentor testing....) |
* updated docu (phpDocumentor testing....) |
50 |
* |
* |
139 |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
* Revision 1.1 2002/10/09 00:51:39 cvsjoko |
140 |
* + new |
* + new |
141 |
* ------------------------------------------------------------------------- |
* ------------------------------------------------------------------------- |
142 |
|
* </pre> |
143 |
|
* |
144 |
*/ |
*/ |
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
/** |
/** |
150 |
* Data::Driver::Proxy -- Multiple stage data fetching and caching |
* Load required modules: |
151 |
* |
* |
152 |
|
*/ |
153 |
|
loadModule('DesignPattern::Proxy'); |
154 |
|
|
155 |
|
|
156 |
|
/** |
157 |
|
* DesignPattern::RemoteProxy -- Multiple stage data fetching and caching |
158 |
* |
* |
159 |
* This class (Data::Driver::Proxy) provides an abstract framework |
* |
160 |
|
* 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> |
178 |
|
* |
179 |
* DATA, ... |
* DATA, ... |
180 |
* ... also refered to as data, should be handled as |
* ... also refered to as data, should be handled as |
181 |
* something called data. |
* something called data. |
218 |
* o Data::Driver::PEAR::DB |
* o Data::Driver::PEAR::DB |
219 |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
* x Data::Driver::PEAR::Tree (via Data::Lift) |
220 |
* |
* |
221 |
*/ |
* </pre> |
222 |
|
* |
223 |
/** |
* |
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/ |
238 |
* @link http://www.gnu.org/licenses/lgpl.txt |
* @link http://www.gnu.org/licenses/lgpl.txt |
239 |
* |
* |
240 |
* @package org.netfrag.glib |
* @package org.netfrag.glib |
241 |
|
* @subpackage DesignPattern |
242 |
* @name DesignPattern::RemoteProxy |
* @name DesignPattern::RemoteProxy |
243 |
* |
* |
|
*/ |
|
|
|
|
|
/** |
|
|
* @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> |
|
244 |
* |
* |
245 |
*/ |
* @todo extend options to en-/disable caching via a) session and/or b) database |
246 |
|
* make feature available via runtime setter-method to these options |
247 |
/** |
* @todo PEAR::Cache for caching purposes!!! |
248 |
* Load required modules: |
* @todo refactor database access: use PEAR for this! no more 'connectdb' here!!! |
249 |
|
* @todo make database connection more flexible to make possible |
250 |
|
* to have different (probably named) proxy databases (besides a "main database") |
251 |
|
* @todo rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper? |
252 |
|
* @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject) |
253 |
|
* @todo rename this to "DesignPattern::LazyRemoteProxy"??? |
254 |
* |
* |
255 |
*/ |
*/ |
|
loadModule('DesignPattern::Proxy'); |
|
|
|
|
256 |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
class DesignPattern_RemoteProxy extends DesignPattern_Proxy { |
257 |
|
|
258 |
var $objectId; |
var $objectId; |
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 |
|
$style = html_style("text/css", '.boxlabel_yellow { color: yellow; font-weight:bold; }'); |
523 |
|
$statusbox = html_div(); |
524 |
|
$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 ($result) { |
if (is_array($result)) { |
531 |
//print "result: " . dumpVar($result) . "<br>"; |
$good = 1; |
532 |
if (count($result) == 0) { return; } |
} 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 |
} |
} |