/[cvs]/nfo/php/libs/org.netfrag.glib/DesignPattern/RemoteProxy.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.glib/DesignPattern/RemoteProxy.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4 by joko, Wed Mar 5 16:32:19 2003 UTC revision 1.17 by jonen, Mon Jul 14 10:05:23 2003 UTC
# Line 5  Line 5 
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>
# Line 15  Line 18 
18   *    $Id$   *    $Id$
19   * -------------------------------------------------------------------------   * -------------------------------------------------------------------------
20   *    $Log$   *    $Log$
21     *    Revision 1.17  2003/07/14 10:05:23  jonen
22     *    bugfix: added *needed* function 'getAttributes'
23     *
24     *    Revision 1.16  2003/07/02 13:51:38  jonen
25     *    removed debug dumper
26     *
27     *    Revision 1.15  2003/04/11 01:32:21  joko
28     *    renamed logging function
29     *
30     *    Revision 1.14  2003/04/09 02:06:45  joko
31     *    errormessage now shown preformatted
32     *
33     *    Revision 1.13  2003/04/04 17:38:03  joko
34     *    modifications regarding error-/exception-handling and -tracing
35     *
36     *    Revision 1.12  2003/03/29 08:01:21  joko
37     *    modified ErrorBoxing
38     *
39     *    Revision 1.11  2003/03/28 06:44:51  joko
40     *    VERBOSE mode
41     *
42     *    Revision 1.10  2003/03/28 03:05:54  joko
43     *    more fancy debugging-output
44     *
45     *    Revision 1.9  2003/03/10 23:05:25  joko
46     *    + fixed metadata for phpDocumentor
47     *
48     *    Revision 1.8  2003/03/10 22:31:56  joko
49     *    + fixed metadata for phpDocumentor
50     *
51     *    Revision 1.7  2003/03/09 15:51:44  joko
52     *    + additional metadata for Autodia
53     *
54     *    Revision 1.6  2003/03/05 17:28:43  joko
55     *    updated docu (phpDocumentor testing....)
56     *
57     *    Revision 1.5  2003/03/05 17:02:22  joko
58     *    updated docu (phpDocumentor testing....)
59     *
60   *    Revision 1.4  2003/03/05 16:32:19  joko   *    Revision 1.4  2003/03/05 16:32:19  joko
61   *    updated docu (phpDocumentor testing....)   *    updated docu (phpDocumentor testing....)
62   *   *
# Line 127  loadModule('DesignPattern::Proxy'); Line 169  loadModule('DesignPattern::Proxy');
169    
170    
171  /**  /**
172   * Data::Driver::Proxy  --  Multiple stage data fetching and caching   * DesignPattern::RemoteProxy  --  Multiple stage data fetching and caching
173   *   *
174   *   *
175   * This class (Data::Driver::Proxy) provides an abstract framework   * This class (DesignPattern::RemoteProxy) provides an abstract framework
176   * for loading/saving arbitrary data from/to data storages interfaced   * for loading/saving arbitrary data from/to data storages interfaced
177   * by storage *proxy*-drivers.   * by storage *proxy*-drivers.
178   * Don't mix these up with the concrete storage *handle*-drivers   * Don't mix these up with the concrete storage *handle*-drivers
# Line 139  loadModule('DesignPattern::Proxy'); Line 181  loadModule('DesignPattern::Proxy');
181   * providing a more highlevel, consistent API making   * providing a more highlevel, consistent API making
182   * it easier for Data::Driver::Proxy to do its main work:   * it easier for Data::Driver::Proxy to do its main work:
183   *   *
184     * quote from: http://home.earthlink.net/~huston2/dp/proxy.html
185     * "A remote proxy provides a local representative for an
186     * object that resides in a different address space. This is
187     * what the "stub" code in RPC and CORBA provides."
188     *
189     *
190   * Multiple stage data fetching and caching:   * Multiple stage data fetching and caching:
191   *   *
192   * <pre>   * <pre>
# Line 191  loadModule('DesignPattern::Proxy'); Line 239  loadModule('DesignPattern::Proxy');
239   * An attempt to implement some software design patterns   * An attempt to implement some software design patterns
240   * --- RemoteProxyPattern   * --- RemoteProxyPattern
241   *   *
242     * @link http://www.agcs.com/supportv2/techpapers/patterns/papers/tutnotes/sld017.htm
243     * @link http://home.earthlink.net/~huston2/dp/proxy.html
244     * @link http://wiki.cs.uiuc.edu/PatternStories/RemoteObject
245   * @link http://c2.com/cgi-bin/wiki?ProxyPattern   * @link http://c2.com/cgi-bin/wiki?ProxyPattern
246     * @link http://c2.com/cgi-bin/wiki?LazyProxies
247   *   *
248   * @author Andreas Motl <andreas.motl@ilo.de>   * @author Andreas Motl <andreas.motl@ilo.de>
249   * @link http://www.netfrag.org/~joko/   * @link http://www.netfrag.org/~joko/
# Line 201  loadModule('DesignPattern::Proxy'); Line 253  loadModule('DesignPattern::Proxy');
253   * @link http://www.gnu.org/licenses/lgpl.txt   * @link http://www.gnu.org/licenses/lgpl.txt
254   *   *
255   * @package org.netfrag.glib   * @package org.netfrag.glib
256     * @subpackage DesignPattern
257   * @name DesignPattern::RemoteProxy   * @name DesignPattern::RemoteProxy
258   *   *
259   *   *
260   * @todo   * @todo extend options to en-/disable caching via a) session and/or b) database
261   * <pre>   *           make feature available via runtime setter-method to these options
262   *  x extend options to en-/disable caching via a) session and/or b) database   * @todo PEAR::Cache for caching purposes!!!
263   *    o make feature available via runtime setter-method to these options   * @todo refactor database access: use PEAR for this! no more 'connectdb' here!!!
264   *  o use PEAR::Cache for caching purposes!!!   * @todo make database connection more flexible to make possible
265   *  o refactor database access: use PEAR for this! no more 'connectdb' here!!!   *           to have different (probably named) proxy databases (besides a "main database")
266   *  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?
267   *      to have different (probably named) proxy databases (besides a "main database")   * @todo refactor this to a "RemoteObject" class!!! (inheriting from DesignPattern::RemoteObject)
268   *  o rename this to Data::Proxy? or split into Data::Query, Data::Result and Data::Wrapper?   * @todo rename this to "DesignPattern::LazyRemoteProxy"???
  * </pre>  
269   *   *
270   */   */
271  class DesignPattern_RemoteProxy extends DesignPattern_Proxy {  class DesignPattern_RemoteProxy extends DesignPattern_Proxy {
# Line 226  class DesignPattern_RemoteProxy extends Line 278  class DesignPattern_RemoteProxy extends
278    var $backend;    var $backend;
279    
280    function DesignPattern_RemoteProxy($objectId = "", $options = array() ) {    function DesignPattern_RemoteProxy($objectId = "", $options = array() ) {
281      logp(get_class($this) . "->new()", PEAR_LOG_INFO);      php::log(get_class($this) . "->new()", PEAR_LOG_INFO);
282      global $proxy;      global $proxy;
283    
284      // 2003-03-05 - modified constructor      // 2003-03-05 - modified constructor
# Line 268  class DesignPattern_RemoteProxy extends Line 320  class DesignPattern_RemoteProxy extends
320        session_register_safe("proxy");        session_register_safe("proxy");
321      }        }  
322    
323        /**
324         * <!-- Autodia -->
325         * can do: (this is metadata supplied for Autodia, don't delete!)
326         *  $this->backend = new DataSource_Proxy_XMLRPC()
327         *
328         */
329    
330      if ($this->meta[remote]) {      if ($this->meta[remote]) {
331        //$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]);        //$this->backend = mkObject('Data::Driver::RPC::Remote', $this->meta[rpcinfo]);
332        $this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]);        $this->backend = php::mkComponent('DataSource::Proxy::XMLRPC', $this->meta[rpcinfo]);
# Line 283  class DesignPattern_RemoteProxy extends Line 342  class DesignPattern_RemoteProxy extends
342    
343    
344    function load() {    function load() {
345      logp(get_class($this) . "->load()", PEAR_LOG_INFO);      php::log(get_class($this) . "->load()", PEAR_LOG_INFO);
346      if (!$this->_loadState()) {      if (!$this->_loadState()) {
347        if (!$this->_loadProxy()) {        if (!$this->_loadProxy()) {
348    
# Line 340  class DesignPattern_RemoteProxy extends Line 399  class DesignPattern_RemoteProxy extends
399      $this->attributes = $data;      $this->attributes = $data;
400    }    }
401    
402      function getAttributes() {
403        return $this->attributes;
404      }
405    
406    function flushProxy() {    function flushProxy() {
407          connectdb();          connectdb();
408      $sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'";      $sql = "DELETE FROM f_proxy WHERE oid='$this->objectId'";
# Line 359  class DesignPattern_RemoteProxy extends Line 422  class DesignPattern_RemoteProxy extends
422        //print Dumper($this);        //print Dumper($this);
423    
424      // debug      // debug
425        logp(get_class($this) . "->_loadState()");        php::log(get_class($this) . "->_loadState()");
426                
427      if ($this->attributes = $proxy[$this->objectId]) {      if ($this->attributes = $proxy[$this->objectId]) {
428        //print "_loadState:" . dumpVar($this->attributes);        //print "_loadState:" . dumpVar($this->attributes);
# Line 371  class DesignPattern_RemoteProxy extends Line 434  class DesignPattern_RemoteProxy extends
434    
435    function _saveState() {    function _saveState() {
436      global $proxy;      global $proxy;
437      logp(get_class($this) . "->_saveState()");      php::log(get_class($this) . "->_saveState()");
438      $proxy[$this->objectId] = $this->attributes;      $proxy[$this->objectId] = $this->attributes;
439      //print "_saveState: " . dumpVar($this->attributes);      //print "_saveState: " . dumpVar($this->attributes);
440      // TODO: throw exception-message back to user if operation fails      // TODO: throw exception-message back to user if operation fails
# Line 384  class DesignPattern_RemoteProxy extends Line 447  class DesignPattern_RemoteProxy extends
447            
448      // trace & debug      // trace & debug
449        //print Dumper($this);        //print Dumper($this);
450        logp(get_class($this) . "->_loadProxy()");        php::log(get_class($this) . "->_loadProxy()");
451                
452      connectdb();      connectdb();
453      $sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'";      $sql = "SELECT payload FROM f_proxy WHERE oid='$this->objectId'";
# Line 404  class DesignPattern_RemoteProxy extends Line 467  class DesignPattern_RemoteProxy extends
467      // FIXME!      // FIXME!
468      if (!$this->meta[cache][db]) { return; }      if (!$this->meta[cache][db]) { return; }
469    
470      logp(get_class($this) . "->_saveProxy()");      php::log(get_class($this) . "->_saveProxy()");
471          connectdb();          connectdb();
472          if ($this->payload) {          if ($this->payload) {
473        //$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'";        //$sql = "INSERT INTO f_proxy SET payload='$this->payload' WHERE oid='$this->objectId'";
# Line 417  class DesignPattern_RemoteProxy extends Line 480  class DesignPattern_RemoteProxy extends
480    }    }
481        
482    function _loadRemote() {    function _loadRemote() {
483      logp(get_class($this) . "->_loadRemote()");      php::log(get_class($this) . "->_loadRemote()");
484            
485      // trace      // trace
486        //print Dumper($this->meta);        //print Dumper($this->meta);
# Line 426  class DesignPattern_RemoteProxy extends Line 489  class DesignPattern_RemoteProxy extends
489            
490      // 1. check backend-handle      // 1. check backend-handle
491      if (!$this->backend) {      if (!$this->backend) {
492        logp(get_class($this) . "->_loadRemote: no backend handle, please check argument 'rpcinfo'", PEAR_LOG_CRIT);        php::log(get_class($this) . "->_loadRemote: no backend handle, please check argument 'rpcinfo'", PEAR_LOG_CRIT);
493        return;        return;
494      }      }
495            
# Line 434  class DesignPattern_RemoteProxy extends Line 497  class DesignPattern_RemoteProxy extends
497        // check for guid or oid        // check for guid or oid
498        if ($this->meta[guid]) {        if ($this->meta[guid]) {
499          if (!$this->objectId) {          if (!$this->objectId) {
500            logp(get_class($this) . "->_loadRemote: argument 'guid' requires valid objectId", PEAR_LOG_WARNING);            php::log(get_class($this) . "->_loadRemote: argument 'guid' requires valid objectId", PEAR_LOG_WARNING);
501            return;            return;
502          }          }
503          if (!$this->meta[classname]) {          if (!$this->meta[classname]) {
504            logp(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING);            php::log(get_class($this) . "->_loadRemote: argument 'guid' requires 'classname'", PEAR_LOG_WARNING);
505            return;            return;
506          }          }
507            php::log(get_class($this) . "->_loadRemote: getObjectByGuid", PEAR_LOG_DEBUG);
508          $args = array( guid => $this->objectId, classname => $this->meta[classname] );          $args = array( guid => $this->objectId, classname => $this->meta[classname] );
509          $result = $this->backend->send('getObjectByGuid', $args );          $result = $this->backend->send('getObjectByGuid', $args );
510    
511        } elseif ($this->meta[oid]) {        } elseif ($this->meta[oid]) {
512          if (!$this->objectId) {          if (!$this->objectId) {
513            logp(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING);            php::log(get_class($this) . "->_loadRemote: argument 'oid' requires valid objectId", PEAR_LOG_WARNING);
514            return;            return;
515          }          }
516            php::log(get_class($this) . "->_loadRemote: getObject", PEAR_LOG_DEBUG);
517          $result = $this->backend->send('getObject', $this->objectId);          $result = $this->backend->send('getObject', $this->objectId);
518    
519        } elseif ($this->meta[key]) {        } elseif ($this->meta[key]) {
520          if (!$this->meta[command]) {          if (!$this->meta[command]) {
521            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING);            php::log(get_class($this) . "->_loadRemote: argument 'key' requires 'command'", PEAR_LOG_WARNING);
522            return;            return;
523          }          }
524          /*          /*
525          if (!$this->meta[query]) {          if (!$this->meta[query]) {
526            logp(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING);            php::log(get_class($this) . "->_loadRemote: argument 'key' requires 'query'", PEAR_LOG_WARNING);
527            return;            return;
528          }          }
529          */          */
530            //php::log(get_class($this) . "->_loadRemote: $this->meta[command](" . join(' ', $this->meta[query]) . ")", PEAR_LOG_DEBUG);
531            //print Dumper(array($this->meta[command], $this->meta[query]));
532          $result = $this->backend->send($this->meta[command], $this->meta[query]);          $result = $this->backend->send($this->meta[command], $this->meta[query]);
533                    
534        }        }
535    
536        //print "result: " . dumpVar($result) . "<br>";
537    
538        $status = $this->backend->status();
539        //print Dumper($status);
540            
541      if ($result) {      $good = is_array($result) && sizeof($result) && $status[connected];
542        //print "result: " . dumpVar($result) . "<br>";  
543        if (count($result) == 0) { return; }      if ($good) {
544                
545        // FIXME: this is dangerous!        // FIXME: this is dangerous!
546          /*
547        if ($_GET[debug]) {        if ($_GET[debug]) {
548          print Dumper($result);          print Dumper($result);
549        }        }
550          */
551                
552        $this->payload = serialize($result);        $this->payload = serialize($result);
553        // ----- move this to _encode some times        // ----- move this to _encode some times
# Line 483  class DesignPattern_RemoteProxy extends Line 555  class DesignPattern_RemoteProxy extends
555        $this->_saveProxy();        $this->_saveProxy();
556        //print "oid: $this->objectId<br>";        //print "oid: $this->objectId<br>";
557        $this->flushState();        $this->flushState();
558        
559      } else {      } else {
560        //print "Error in _loadRemote!!!<br>";        
561        logp(get_class($this) . "->_loadRemote: error while trying to talk to remote side", PEAR_LOG_CRIT);        if (constants::get('APP_MODE_DEBUG')) {
562            $this->draw_error_box($status);
563          } else {
564            php::maintenance('rpc', array( status => $status ) );
565          }
566        
567      }      }
568            
569    }    }
570    
571    function draw_error_box($status) {
572      $style = html_style("text/css", '.boxlabel_yellow { color: yellow; font-weight:bold; }');
573      $statusbox = html_div();
574      $statusbox->set_style('background: red; border: 2px black groove; width:640px; padding:10px; margin:40px;');
575      $statusbox->add( html_span('boxlabel_yellow', "Method:"), get_class($this) . "->_loadRemote", html_br() );
576      $statusbox->add( html_span('boxlabel_yellow', "Connected:"), $status[connected], html_br() );
577      $statusbox->add( html_span('boxlabel_yellow', "RPCSESSID:"), $status[RPCSESSID], html_br() );
578      foreach ($status[errors] as $error) {
579        $msg = html_pre($error[message]);
580        $statusbox->add( html_span('boxlabel_yellow', "Error($error[code]):"), $msg );
581      }
582        
583      $message = "Error while talking to remote side. Please check wire, socket or api.";
584      php::log($message, PEAR_LOG_CRIT);
585      $statusbox->add( html_span('boxlabel_yellow', "Critical:"), $message, html_br() );
586    
587      // V1
588      /*
589      if (constants::get('VERBOSE') || constants::get('ERRORS_ONLY')) {
590        print $style->render();
591        print $statusbox->render();
592      } else {
593        foreach ($status[errors] as $error) {
594          print Dumper($error);
595        }
596      }
597      */
598    
599      // V2
600      trace( container($style, $statusbox) );
601    
602    }  
603    
604    
605    function _saveBackend($result) {    function _saveBackend($result) {
606      logp(get_class($this) . "->_saveBackend()");      php::log(get_class($this) . "->_saveBackend()");
607    
608      //$encoder = new TextEncode($result);      //$encoder = new TextEncode($result);
609      //$encoder->toUTF8();      //$encoder->toUTF8();
# Line 522  class DesignPattern_RemoteProxy extends Line 634  class DesignPattern_RemoteProxy extends
634    
635  }  }
636    
 ?>  
637    ?>

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.17

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed