In an earlier post we described a simple Topaz application that could be pushed to Cloud Foundry. It turns out that the example in that post did not handle multiple instances very well since each time the app started it would reinstall WebTools. Since the previous classes were removed as part of the subsequent install, this left the earlier instances looking for subclasses that no longer existed. In this example we obtain a lock on the user’s SymbolList to ensure that only one session attempts the install. Then we create an install script that only does the install if things are not yet present. Finally, we remove the lock before starting the web server.

run
[
  [
    System writeLock: System myUserProfile symbolList.
    true.
  ] on: Error do: [:ex | 
    ex return: false.
  ].
] whileFalse: [
  (Delay forSeconds: 1) wait.
  System abortTransaction.
].
true
%
run
| gsFile |
gsFile := GsFile openWriteOnServer: 'install.tpz'.
System myUserProfile symbolList last name == #'WebTools' ifFalse: [
  gsFile nextPutAll: 'input $GEMSTONE/examples/www/install.tpz'; lf.
].
gsFile close.
true
%
input install.tpz
run
System removeLock: System myUserProfile symbolList.
true.
%
run
| class port |
class := GsSession currentSession userProfile symbolList last at: #'Server'.
port := System gemEnvironmentVariable: 'VCAP_APP_PORT'.
class new 
  password: 'swordfish';
  startForegroundServerAtPort: port asNumber.
%
logout
exit

Once you have thing running if you have two instances you can try the following in a workspace and see what changes:

System myUserProfile userId. "This should not change"
System performOnServer: 'whoami; hostname; pwd'. "This might change"

We will discuss this example in a presentation Wednesday morning at STIC 2012.

About these ads