1#!../../src/xotclsh
2# $Id: Counter4.xotcl,v 1.2 2004/07/27 21:39:46 neumann Exp $
3array set opts {-pkgdir .}; array set opts $argv
4lappend auto_path $opts(-pkgdir)
5
6package require XOTcl 1; namespace import -force xotcl::*
7package require xotcl::actiweb::htmlPlace
8package require xotcl::actiweb::webDocument
9
10### Instantiate an Html place with the name receiver
11HtmlPlace ::receiver -port 8094  -allowExit exit
12
13### Define a class solely for counting
14Class Counter -parameter {{count 1}}
15Counter instproc increment {} {        ;### counter method
16  my incr count
17}
18
19### Define a Counter subclass for persistent counting
20Class PersistentCounter -superclass Counter
21PersistentCounter instproc init args { ;### Constructor
22  next                                 ;### call superclasses' init
23  my mixinStrategy Persistent=Eager
24  my persistenceMgr [Place getInstance]::agentPersistenceMgr
25  my persistent count          ;### make count variable persistent
26}
27
28### Create two persistent counter instances with the names c1 and c2
29PersistentCounter c1 
30PersistentCounter c2
31
32
33### Define a proxy class, that handles HTML decoration
34### HtmlProxy forwards all unknown calls to "realSubject"
35Class HtmlProxyCounter -superclass HtmlProxy
36HtmlProxyCounter instproc init args {    ;### Constructor
37  next
38  my exportProcs increment               ;### export increment method
39}
40HtmlProxyCounter instproc default {} {
41  my instvar realSubject
42  $realSubject instvar count
43  set objName [string trimleft [self] :]
44  return "<HTML>The value in $realSubject is  $count.<p>
45	<A HREF='[my selfAction increment]'>Increment Counter</a><p>
46	<HR>Last Update: [clock format [clock seconds]  -format %m/%d/%y-%H:%M]
47]
48	</HTML>\n"
49}
50
51### Create two proxy instances wc1 und wc2
52HtmlProxyCounter wc1 -realSubject c1
53HtmlProxyCounter wc2 -realSubject c2
54
55### Start event loop and handle connections
56receiver startEventLoop 
57