Could it be that the players are stuck because the User Logout handler somehow throws an exception?
Also, could this be happening because I keep the user object (http://docs2x.smartfoxserver.com/api-do ... /User.html) in another object? (Maybe it can't collect garbage?)
Example:
Code: Select all
package com.arcade.entity;
import com.smartfoxserver.v2.entities.User;
public final class ArcadePlayer
{
private final User user;
private int turnIndex;
public ArcadePlayer(User user)
{
this.user = user;
}
public ArcadePlayer(boolean online)
{
this.user = null;
}
public int getTurnIndex()
{
return turnIndex;
}
public void setTurnIndex(int value)
{
turnIndex = value;
}
public User getUser()
{
return this.user;
}
public boolean isOnline()
{
if(this.user == null)
return false;
//if user is not online, skip turn of user.
return this.user.isConnected();
}
}
If the problem is about keeping the user object in another object, I think keeping the user object using weak reference will solve the problem.
Weak Reference Example:
Code: Select all
package com.arcade.entity;
import com.smartfoxserver.v2.entities.User;
import java.lang.ref.WeakReference;
import javax.annotation.Nullable;
public final class ArcadePlayer
{
private final WeakReference<User> user;
private int turnIndex;
public ArcadePlayer(User user)
{
this.user = new WeakReference<User>(user);
}
public ArcadePlayer()
{
this.user = null;
}
public int getTurnIndex()
{
return turnIndex;
}
public void setTurnIndex(int value)
{
turnIndex = value;
}
public @Nullable User user()
{
if(this.user == null)
return null;
return this.user.get();
}
public boolean isOnline()
{
User user = this.user();
if(user == null)
return false;
return user.isConnected();
}
}