Hello,
To communicate between room extension I am using "handleInternalMessage" which requires me to package up my parameters and parse them on the other side.
I'm mostly using SFSObjects.
Sometimes I need to pass a reference to a user to another extension, along with other info. Currently I am sending the userId and finding the user on the other side, but I would much rather just send the User object and skip the extra steps. I know you can just pass the User as a generic object and then convert to User, but this doesn't work when passing multiple parameters along with the user.
Is there a way to put a user into a SFSObject?
-Carl
Put users into a SFSObject?
- Carl Lydon
- Posts: 298
- Joined: 12 Nov 2007, 16:15
- Location: NYC
- Contact:
Re: Put users into a SFSObject?
Hi,
a couple of comments.
I would not recommend to use SFSObject to pass data around between Extensions. SFSObject is pretty limited in the types that it supports and it is designed for network transport, not for local object passing.
Since handleInternalMessage requires a generic Object (the root of the type hierarchy) you are severely limiting your options with something like SFSObject.
A much better strategy is to setup your own "protocol" for each command you create for the handleInternalMessage method. Here's an example. Suppose we have these two commands:
1- changeName (takes 2 Strings)
2- storeUser(takes a User)
In command #1 we need two String params, so we can ahead and create and object for this:
Now we can use this object to pass the parameters of the "changeName" command, which will look like this:
Makes sense?
I've also added the implementation of the "storeUser" command, which takes only one parameter.
The whole idea is that you're totally free to plan which object will be used for each call between Extension. The only caveat is to pay attention to converting (casting) each object to the appropriate type.
Hope it helps
a couple of comments.
I would not recommend to use SFSObject to pass data around between Extensions. SFSObject is pretty limited in the types that it supports and it is designed for network transport, not for local object passing.
Since handleInternalMessage requires a generic Object (the root of the type hierarchy) you are severely limiting your options with something like SFSObject.
A much better strategy is to setup your own "protocol" for each command you create for the handleInternalMessage method. Here's an example. Suppose we have these two commands:
1- changeName (takes 2 Strings)
2- storeUser(takes a User)
In command #1 we need two String params, so we can ahead and create and object for this:
Code: Select all
class ChangeNameData
{
public ChangeNameData(String oldName, String newName);
{
...
}
}
Now we can use this object to pass the parameters of the "changeName" command, which will look like this:
Code: Select all
@Override
public Object handleInternalMessage(String cmdName, Object params)
{
if (cmdName.equals("changeName"))
{
ChangeNameData data = (ChangeNameData) params;
// Rest of the changeName logic here...
}
else if (cmdName.equals("storeUser"))
{
User user = (User) params;
// Rest of the logic here...
}
}
Makes sense?
I've also added the implementation of the "storeUser" command, which takes only one parameter.
The whole idea is that you're totally free to plan which object will be used for each call between Extension. The only caveat is to pay attention to converting (casting) each object to the appropriate type.
Hope it helps
- Carl Lydon
- Posts: 298
- Joined: 12 Nov 2007, 16:15
- Location: NYC
- Contact:
Re: Put users into a SFSObject?
Thanks. Your example helps a lot. So, if I want to pass a string along with a User, I just make a Java class that accepts those parameters, create a Java object and pass that.
Re: Put users into a SFSObject?
Yes, that's the essence of all OOP programming. Encapsulating data (and behavior)
Who is online
Users browsing this forum: Bing [Bot] and 136 guests