User list empty

Post here all your questions related with SmartFoxServer Java API

Moderators: Bax, Lapo, rjgtav

User list empty

Postby rgfernan » 25 Mar 2010, 12:50

Does anyone know why could happend that at some point I get an empty user list in the current room, despite having a user logged in, and even the userCount being 1?
User avatar
rgfernan
 
Posts: 10
Joined: 20 Mar 2010, 00:25
Location: Buenos Aires, Argentina

Postby Lapo » 20 Apr 2010, 15:15

Can you provide an example of the problem? Code snippets etc...
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16133
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby rgfernan » 20 Apr 2010, 16:00

I will write a simplified version of the code where I detected the problem. It basically sends a join room message, waits until it receives a join room event, and then it attempts to set user variables.

(I put it with colors below, because it could be more readable)

Code: Select all
public void joinRoom(final String roomName) {
// this creates a result bound to 'onJoinRoom' event, that will be
// set in 'CLOSED' state when that event is received, if the matcher
// is satisfied; in this case, the matcher is allways satisfied,
// so any 'onJoinRoom' event will pass
OperationResult operationResult = getOperationResultFactory()
          .withMatcher(SFSEvent.onJoinRoom, new TautologyEventMatcher())
          .create();

getSmartFoxClient()
       .joinRoom(roomName, DEFAULT_ROOM_PASSWORD,
                       DEFAULT_IS_EXPECTATOR, DEFAULT_DONT_LEAVE,
                       getCurrentRoomId(getSmartFoxClient());

// blocks until a 'onJoinRoom' event is received;
// if success is not true, throws an exception
waitForEvent(operationResult);

// HERE is the problem, sometimes the user list in current room
// is empty, so I get a NullPointerException and as far as I am
// concerned, it should be automatically updated as the 'onJoinRoom'
// event has already been received
getSmartFoxClient().setUserVariables(
                       createParameters(getAvatarId(), getUserIdAsString()));   
}


public void joinRoom(final String roomName) {
// this creates a result bound to 'onJoinRoom' event, that will be
// set in 'CLOSED' state when that event is received, if the matcher
// is satisfied; in this case, the matcher is allways satisfied,
// so any 'onJoinRoom' event will pass
OperationResult operationResult = getOperationResultFactory()
.withMatcher(SFSEvent.onJoinRoom, new TautologyEventMatcher())
.create();

getSmartFoxClient()
.joinRoom(roomName, DEFAULT_ROOM_PASSWORD,
DEFAULT_IS_EXPECTATOR, DEFAULT_DONT_LEAVE,
getCurrentRoomId(getSmartFoxClient());

// blocks until a 'onJoinRoom' event is received;
// if success is not true, throws an exception

waitForEvent(operationResult);

// :!: HERE is the problem, sometimes the user list in current room
// is empty, so I get a NullPointerException and as far as I am
// concerned, it should be automatically updated as the 'onJoinRoom'
// event has already been received

getSmartFoxClient().setUserVariables(
createParameters(getAvatarId(), getUserIdAsString()));
}
User avatar
rgfernan
 
Posts: 10
Joined: 20 Mar 2010, 00:25
Location: Buenos Aires, Argentina

Postby Lapo » 21 Apr 2010, 16:23

The way you are handling the event is a little "obscure" to me... I am not the Java API expert here, so I might be wrong, but the thread that calls the joinRoom is unlikely to be the same that will fire the event back so I am a little confused at how your code should block and wait for the server response.

Also in general it would be better to create a separate handler and allow your code flow to continue. Anyways this is not a critique to your coding but simply an observation and I am wondering if this could be part of the problem.
Especially since you alluded to the fact that the problem is erratic.

Have you tried with a "normal" approach where you register the event handler and execute the code there?
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
 
Posts: 16133
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby rgfernan » 21 Apr 2010, 18:08

Operation result has a CountDownLatch, which is decremented by the handler when the corresponding event is received. If the event is not received, waitForEvent() will throw a timeout exception, so the code below wouldn't execute.

What seems odd to me, is that the object representing the current room in smartfox client gets to inconstistent state, having an empty user list and userCount = 1.
User avatar
rgfernan
 
Posts: 10
Joined: 20 Mar 2010, 00:25
Location: Buenos Aires, Argentina


Return to Java2SE / Android Client API

Who is online

Users browsing this forum: No registered users and 1 guest