Quantcast
Channel: Joachim Jaeckel's blog
Viewing all articles
Browse latest Browse all 10

Iliad (subclassing Sessions)

$
0
0

Hi again,

it took me some time today with big support from Nicolas, to figure out how to using an own version of a session.

And before you run into the same mistake than me, I would like to decribe the really simple steps to use an own Session for your Iliad-Applications.

I made some errors in reasoning, which was my problem at the end. But here's how a session could be subclassed and used.

Make a subclass of Iliad.Session e.g. something like the following, which I use to store a datbase connection for every session.

Iliad.Session subclass: MySession [
    | userLoggedIn dbConnection |

    isUserLoggedIn [ ^self userLoggedIn]
    userLoggedIn [ ^userLoggedIn  ifNil: [userLoggedIn := false]]
    userLoggedIn: aBoolean [ userLoggedIn := aBoolean ]

    dbConnection [ ^dbConnection ]
    dbConnection: aDbConnection [ dbConnection := aDbConnection ]

    expire [
        super expire.
        self dbConnection ifNotNil: [self dbConnection close].
    ]

]

Then, you have to set MySession as the default type of Session for Iliad. You should/could doit directly after you start the Swazoo server like:

echo "Starting server ..."
/opt/bin/gst-remote -I my.im --server &
sleep 3

echo "Restarting Swazoo! startOn: 7777..."
/opt/bin/gst-remote --eval 'Iliad.SwazooIliad startOn: 7777'
echo done!
echo "Set Session to: MySession!"
#/opt/bin/gst-remote --eval 'Iliad.SessionManager current sessionClass: MySession.'

The important thing is, as I learned from Nicolas, that it should be done outside of your Application class

If you are not sure, if already some Sessions exists, you could execute the following command after you set the new session type:

Iliad.SessionManager current removeAllSessions

After this, if your Application is running, you have your new type of Session available and it could be used with e.g.:

...
    self session userLoggedIn: true.
...
...
    self session userLoggedIn: false.
...
...
(self session isUserLoggedIn)
    ifTrue: ['User is logged in!' printNl]
    ifFalse: ['User is not logged in!' printNl].

That's all for today.

Happy coding!

Joachim.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images