Hello
I started trying to work with SFS2X. A lot of stuff is really cool and fancy to use.
But I wanted to ask if there is a best practice guideline to manage server side variables?
Is it better to use the UserVariable or the setProperty method of the User? Or even the setProperty method on the session? Or any other possibilities?
Are there any advantages?
For example I want to attach de users ID from the DB as a variable to the user. So that I can recognize him.
Thanks for response.
Best Practice on Server Side Variable Management
User Variables are meant to be shared among all the clients in a Room. So if this is what you need (for example you want to save the user's nickname and display it on all the clients) than you should use a User Variable.
For other cases (for example the one you mentioned, I think) you should use the user properties, which aren't transmitted to the clients.
For other cases (for example the one you mentioned, I think) you should use the user properties, which aren't transmitted to the clients.
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
-
- Posts: 17
- Joined: 05 Nov 2010, 15:31
-
- Posts: 17
- Joined: 05 Nov 2010, 15:31
Well, sorry. Maybe I just missed some basics...but...
Since I have a extension and I only get my code running when it's called by the whole SFS framework, all my logic is isolated on small classes and all my data is persisted on database....and I'm not sure it's the right thing to do.
Lets compare this to...like...JSP or PHP where I have the "application" space to store my data on memory...do I have something like that on SFS?
When my extension inits I'd like to put a string on the memory and I'd like to have that string read on another event later, when, lets say, a user logs in, or sends a message.
Did I miss something?
Since I have a extension and I only get my code running when it's called by the whole SFS framework, all my logic is isolated on small classes and all my data is persisted on database....and I'm not sure it's the right thing to do.
Lets compare this to...like...JSP or PHP where I have the "application" space to store my data on memory...do I have something like that on SFS?
When my extension inits I'd like to put a string on the memory and I'd like to have that string read on another event later, when, lets say, a user logs in, or sends a message.
Did I miss something?
According to the docs you have 2 ways for handling runtime objects for extension use....
1. not recommended - use singleton classes.... you can put all your desired logic / helpers in a separate jar / project and access the data you need by single ton classes ( you should read on hot to add .jar file to your projects)
2. the recommended way - inside your extension store what ever you want and you can access this data through the handlers supplied by SFS2x.
example:
later on you could access your custom object from the various handlers supplied by sfs2x, example:
1. not recommended - use singleton classes.... you can put all your desired logic / helpers in a separate jar / project and access the data you need by single ton classes ( you should read on hot to add .jar file to your projects)
2. the recommended way - inside your extension store what ever you want and you can access this data through the handlers supplied by SFS2x.
example:
Code: Select all
public class MyExtension extends com.smartfoxserver.v2.extensions.SFSExtension {
private Object objForRunTimeAccess;
public void init() {
objForRunTimeAccess = new Object();
}
public Object getObjForRunTimeAccess() {
return objForRunTimeAccess;
}
}
later on you could access your custom object from the various handlers supplied by sfs2x, example:
Code: Select all
public class LoginHandler extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException {
if(getParentExtension() instanceof MyExtension )
{
MyExtension te = (MyExtension )getParentExtension();
Object myCustomObject = te.getObjForRunTimeAccess();
}
}
}
-
- Posts: 17
- Joined: 05 Nov 2010, 15:31
Who is online
Users browsing this forum: No registered users and 55 guests