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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.13

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