#!../../src/xotclsh
# $Id: s.Counter4.xotcl 1.7 01/03/23 22:00:32+01:00 neumann@somewhere.wu-wien.ac.at $
package require xotcl::awo::htmlPlace
package require xotcl::awo::webDocument

### Instantiate an Html place with the name receiver
HtmlPlace ::receiver -port 8094  -allowExit exit

### Define a class solely for counting
Class Counter -parameter {{count 1}}
Counter instproc increment {} {    ;### counter method
  ::incr [self]::count
}

### Definiere a Counter subclass for persistent counting
Class PersistentCounter -superclass Counter
PersistentCounter instproc init args { ;### Constructor
  next                             ;### call superclasses' init
  [self] mixinStrategy Persistent=Eager
  [self] persistenceMgr [Place getInstance]::agentPersistenceMgr
  [self] persistent count          ;### make count variable persistent
}

### Create two persistent counter instances with the names c1 and c2
PersistentCounter c1 
PersistentCounter c2


### Definiere a proxy class, that handles HTML decoration
### HtmlProxy forwards all unknown calls to "realSubject"
Class HtmlProxyCounter -superclass HtmlProxy
HtmlProxyCounter instproc init args {    ;### Constructor
  next
  [self] exportProcs increment     ;### export increment method
}
HtmlProxyCounter instproc default {} {
  [self] instvar realSubject
  $realSubject instvar count
  set objName [string trimleft [self] :]
  return "<HTML>The value in $realSubject is  $count.<p>
	<A HREF='$objName+increment'>Increment Counter</a><p>
	<HR>Last Update: [clock format [clock seconds]  -format %m/%d/%y-%H:%M]
]
	</HTML>\n"
}

### Create two proxy instances wc1 und wc2
HtmlProxyCounter wc1 -realSubject c1
HtmlProxyCounter wc2 -realSubject c2

### Start event loop and handle connections
receiver startEventLoop 
