sfs2x.client.core
Class SFSEvent

java.lang.Object
  extended by sfs2x.client.core.BaseEvent
      extended by sfs2x.client.core.SFSEvent

public class SFSEvent
extends BaseEvent

SFSEvent is the class representing most of the events dispatched by the SmartFoxServer 2X ActionScript 3 API.

The SFSEvent parent class provides a public property called params which contains specific parameters depending on the event type.

Example
The following example shows a generic usage of a SFSEvent; please refer to the specific event types for the params object content:

package sfsTest;

import com.smartfoxserver.v2.exceptions.SFSException; import sfs2x.client.SmartFox; import sfs2x.client.core.BaseEvent; import sfs2x.client.core.IEventListener; import sfs2x.client.core.SFSEvent;

import java.util.Map;

public class MyTest { private SmartFox sfs;

public MyTest() { // Create a SmartFox instance sfs = new SmartFox();

// Add event handler for connection sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // Retrieve event parameters Map params = evt.getArguments();

if ((Boolean)params.get("success")) System.out.println("Connection established"); else System.out.println("Connection failed"); } });

// Connect to server sfs.connect("127.0.0.1", 9933); } }

See Also:
SFSBuddyEvent

Field Summary
static java.lang.String ADMIN_MESSAGE
          The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.
static java.lang.String CONFIG_LOAD_FAILURE
          The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.
static java.lang.String CONFIG_LOAD_SUCCESS
          The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.
static java.lang.String CONNECTION
          The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.
static java.lang.String CONNECTION_ATTEMPT_HTTP
          The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.
static java.lang.String CONNECTION_LOST
          The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.
static java.lang.String CONNECTION_RESUME
          The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.
static java.lang.String CONNECTION_RETRY
          The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.
static java.lang.String EXTENSION_RESPONSE
          The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.
static java.lang.String HANDSHAKE
          *Private*
static java.lang.String INVITATION
          The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.
static java.lang.String INVITATION_REPLY
          The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.
static java.lang.String INVITATION_REPLY_ERROR
          The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.
static java.lang.String LOGIN
          The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.
static java.lang.String LOGIN_ERROR
          The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.
static java.lang.String LOGOUT
          The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.
static java.lang.String MODERATOR_MESSAGE
          The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.
static java.lang.String OBJECT_MESSAGE
          The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.
static java.lang.String PING_PONG
          The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.
static java.lang.String PLAYER_TO_SPECTATOR
          The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.
static java.lang.String PLAYER_TO_SPECTATOR_ERROR
          The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.
static java.lang.String PRIVATE_MESSAGE
          The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.
static java.lang.String PUBLIC_MESSAGE
          The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.
static java.lang.String ROOM_ADD
          The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.
static java.lang.String ROOM_CAPACITY_CHANGE
          The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.
static java.lang.String ROOM_CAPACITY_CHANGE_ERROR
          The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.
static java.lang.String ROOM_CREATION_ERROR
          The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.
static java.lang.String ROOM_FIND_RESULT
          The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.
static java.lang.String ROOM_GROUP_SUBSCRIBE
          The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.
static java.lang.String ROOM_GROUP_SUBSCRIBE_ERROR
          The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.
static java.lang.String ROOM_GROUP_UNSUBSCRIBE
          The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.
static java.lang.String ROOM_GROUP_UNSUBSCRIBE_ERROR
          The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.
static java.lang.String ROOM_JOIN
          The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.
static java.lang.String ROOM_JOIN_ERROR
          The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.
static java.lang.String ROOM_NAME_CHANGE
          The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.
static java.lang.String ROOM_NAME_CHANGE_ERROR
          The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.
static java.lang.String ROOM_PASSWORD_STATE_CHANGE
          The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.
static java.lang.String ROOM_PASSWORD_STATE_CHANGE_ERROR
          The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.
static java.lang.String ROOM_REMOVE
          The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.
static java.lang.String ROOM_VARIABLES_UPDATE
          The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.
static java.lang.String SOCKET_ERROR
          The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.
static java.lang.String SPECTATOR_TO_PLAYER
          The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.
static java.lang.String SPECTATOR_TO_PLAYER_ERROR
          The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.
static java.lang.String UDP_INIT
          The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.
static java.lang.String USER_COUNT_CHANGE
          The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.
static java.lang.String USER_ENTER_ROOM
          The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.
static java.lang.String USER_EXIT_ROOM
          The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.
static java.lang.String USER_FIND_RESULT
          The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.
static java.lang.String USER_VARIABLES_UPDATE
          The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.
 
Constructor Summary
SFSEvent(java.lang.String type)
           
SFSEvent(java.lang.String type, java.util.Map<java.lang.String,java.lang.Object> args)
          Creates a new SFSEvent instance.
 
Method Summary
 
Methods inherited from class sfs2x.client.core.BaseEvent
clone, getArguments, getTarget, getType, setArguments, setTarget, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HANDSHAKE

public static final java.lang.String HANDSHAKE
*Private*

See Also:
Constant Field Values

UDP_INIT

public static final java.lang.String UDP_INIT
The SFSEvent.UDP_INIT constant defines the value of the type property of the event object for a udpInit event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
successBooleanThe connection result: true if a connection was established, false otherwise.

Example
The following example initializes the UDP communication and sends a custom UDP request to an Extension:

private void someMethod() { sfs.addEventListener(SFSEvent.UDP_INIT, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { if ((Boolean)evt.getArguments().get("success")) { // Connection successful: execute an Extension call via UDP sfs.send( new ExtensionRequest("udpTest", new SFSObject(), null, true) ); } else { System.out.println("UDP initialization failed!"); } } });

sfs.initUdp(); }

See Also:
Constant Field Values

CONNECTION

public static final java.lang.String CONNECTION
The SFSEvent.CONNECTION constant defines the value of the type property of the event object for a connection event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
successBooleanThe connection result: true if a connection was established, false otherwise.

Example
The following example starts a connection:

private void someMethod() { sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { if ((Boolean)evt.getArguments().get("success")) { // Connection successful: execute an Extension call via UDP System.out.println("Connection established"); } else { System.out.println("Connection failed"); } } });

sfs.connect(); }

See Also:
CONNECTION_RETRY, CONNECTION_RESUME, CONNECTION_LOST, Constant Field Values

PING_PONG

public static final java.lang.String PING_PONG
The SFSEvent.PING_PONG constant defines the value of the type property of the event object for a pingPong event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
lagValueintThe average of the last ten measured lag values, expressed in milliseconds.

See Also:
Constant Field Values

SOCKET_ERROR

public static final java.lang.String SOCKET_ERROR
The SFSEvent.SOCKET_ERROR constant defines the value of the type property of the event object for a socketError event.

The event is fired when an unexpected socket error occurs, typically a data error.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringthe description of the problem

See Also:
Constant Field Values

CONNECTION_LOST

public static final java.lang.String CONNECTION_LOST
The SFSEvent.CONNECTION_LOST constant defines the value of the type property of the event object for a connectionLost event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
reasonStringThe reason of the disconnection, among those available in the ClientDisconnectionReason class.

Example
The following example handles a disconnection event:

private void someMethod() { sfs.addEventListener(SFSEvent.CONNECTION_LOST, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { String reason = (String)evt.getArguments().get("reason");

if (!reason.equals(ClientDisconnectionReason.MANUAL)) { if (reason.equals(ClientDisconnectionReason.IDLE)) System.out.println("A disconnection occurred due to inactivity"); else if (reason.equals(ClientDisconnectionReason.KICK)) System.out.println("You have been kicked by the moderator"); else if (reason.equals(ClientDisconnectionReason.BAN)) System.out.println("You have been banned by the moderator"); else System.out.println("A disconnection occurred due to unknown reason; please check the server log"); } else { // Manual disconnection is usually ignored } } }); }

See Also:
ClientDisconnectionReason, CONNECTION, CONNECTION_RETRY, Constant Field Values

CONNECTION_RETRY

public static final java.lang.String CONNECTION_RETRY
The SFSEvent.CONNECTION_RETRY constant defines the value of the type property of the event object for a connectionRetry event.

No parameters are available for this event object.

Example
The following example handles a temporary disconnection event and the following connection resuming:

private void someMethod() { sfs.addEventListener(SFSEvent.CONNECTION_RETRY, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // Freeze the GUI and provide some feedback to the player ... } }); sfs.addEventListener(SFSEvent.CONNECTION_RESUME, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // Unfreeze the GUI and let the player continue with the game ... } }); sfs.addEventListener(SFSEvent.CONNECTION_LOST, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Ouch, connection was lost. Reason: " + (String)evt.getArguments().get("reason")); } }); }

See Also:
CONNECTION_RESUME, CONNECTION_LOST, Constant Field Values

CONNECTION_RESUME

public static final java.lang.String CONNECTION_RESUME
The SFSEvent.CONNECTION_RESUME constant defines the value of the type property of the event object for a connectionResume event.

No parameters are available for this event object.

Example
See the example provided in the CONNECTION_RETRY constant description.

See Also:
CONNECTION_RETRY, CONNECTION_LOST, Constant Field Values

CONNECTION_ATTEMPT_HTTP

public static final java.lang.String CONNECTION_ATTEMPT_HTTP
The SFSEvent.CONNECTION_ATTEMPT_HTTP constant defines the value of the type property of the event object for a connectionAttemptHttp event.

No parameters are available for this event object.

Example
See the example provided in the CONNECTION_ATTEMPT_HTTP constant description.

See Also:
CONNECTION, CONNECTION_LOST, Constant Field Values

CONFIG_LOAD_SUCCESS

public static final java.lang.String CONFIG_LOAD_SUCCESS
The SFSEvent.CONFIG_LOAD_SUCCESS constant defines the value of the type property of the event object for a configLoadSuccess event.

No parameters are available for this event object.

Example
The following example loads an external configuration file:

private void someMethod() { sfs.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // Configuration loaded successfully, now connect sfs.connect(); } }); sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Failed loading configuration file"); } });

sfs.loadConfig("testConfig.xml", false); }

See Also:
CONFIG_LOAD_FAILURE, Constant Field Values

CONFIG_LOAD_FAILURE

public static final java.lang.String CONFIG_LOAD_FAILURE
The SFSEvent.CONFIG_LOAD_FAILURE constant defines the value of the type property of the event object for a configLoadFailure event.

No parameters are available for this event object.

Example
See the example provided in the CONFIG_LOAD_SUCCESS constant description.

See Also:
CONFIG_LOAD_SUCCESS, Constant Field Values

LOGIN

public static final java.lang.String LOGIN
The SFSEvent.LOGIN constant defines the value of the type property of the event object for a login event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
userUserAn object representing the user who performed the login.
dataISFSObjectAn object containing custom parameters returned by a custom login system, if any.

Example
The following example performs a login in the "SimpleChat" Zone:

private void someMethod() { sfs.addEventListener(SFSEvent.LOGIN, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Login successful!"); } }); sfs.addEventListener(SFSEvent.LOGIN_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Login failure: " + evt.getArguments().get("errorMessage")); } });

// Login sfs.send(new LoginRequest("FozzieTheBear", "", "SimpleChat")); }

See Also:
LOGIN_ERROR, LOGOUT, Constant Field Values

LOGIN_ERROR

public static final java.lang.String LOGIN_ERROR
The SFSEvent.LOGIN_ERROR constant defines the value of the type property of the event object for a loginError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the LOGIN constant description.

See Also:
LOGIN, Constant Field Values

LOGOUT

public static final java.lang.String LOGOUT
The SFSEvent.LOGOUT constant defines the value of the type property of the event object for a logout event.

No parameters are available for this event object.

Example
The following example performs a logout from the current Zone:

private void someMethod() { sfs.addEventListener(SFSEvent.LOGOUT, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Logout executed!"); } });

// Logout sfs.send(new LogoutRequest()); }

See Also:
LOGIN, Constant Field Values

ROOM_ADD

public static final java.lang.String ROOM_ADD
The SFSEvent.ROOM_ADD constant defines the value of the type property of the event object for a roomAdd event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room that was created.

Example
The following example creates a new chat Room:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_ADD, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room created: " + (Room)evt.getArguments().get("room")); } }); sfs.addEventListener(SFSEvent.ROOM_CREATION_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room creation failure: " + evt.getArguments().get("errorMessage")); } });

// Define the settings of a new chat Room RoomSettings settings = new RoomSettings("My Chat Room"); settings.setMaxUsers(40); settings.setGroupId("chats");

// Create the Room sfs.send(new CreateRoomRequest(settings)); }

See Also:
ROOM_REMOVE, ROOM_CREATION_ERROR, Constant Field Values

ROOM_REMOVE

public static final java.lang.String ROOM_REMOVE
The SFSEvent.ROOM_REMOVE constant defines the value of the type property of the event object for a roomRemove event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room that was removed.

Example
The following example shows how to handle this event type:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_REMOVE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("The following Room was removed: " + (Room)evt.getArguments().get("room")); } }); }

See Also:
ROOM_ADD, Constant Field Values

ROOM_CREATION_ERROR

public static final java.lang.String ROOM_CREATION_ERROR
The SFSEvent.ROOM_CREATION_ERROR constant defines the value of the type property of the event object for a roomCreationError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_ADD constant description.

See Also:
ROOM_ADD, Constant Field Values

ROOM_JOIN

public static final java.lang.String ROOM_JOIN
The SFSEvent.ROOM_JOIN constant defines the value of the type property of the event object for a roomJoin event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room that was joined.

Example
The following example makes the user join an existing Room:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room joined successfully: " + (Room)evt.getArguments().get("room")); } }); sfs.addEventListener(SFSEvent.ROOM_JOIN, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room joining failed: " + evt.getArguments().get("errorMessage")); } });

// Join a Room called "Lobby" sfs.send(new JoinRoomRequest("Lobby")); }

See Also:
ROOM_JOIN_ERROR, Constant Field Values

ROOM_JOIN_ERROR

public static final java.lang.String ROOM_JOIN_ERROR
The SFSEvent.ROOM_JOIN_ERROR constant defines the value of the type property of the event object for a roomJoinError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_JOIN constant description.

See Also:
ROOM_JOIN, Constant Field Values

USER_ENTER_ROOM

public static final java.lang.String USER_ENTER_ROOM
The SFSEvent.USER_ENTER_ROOM constant defines the value of the type property of the event object for a userEnterRoom event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
userUserAn object representing the user who joined the Room.
roomRoomAn object representing the Room that was joined by a user.

Example
The following example shows how to handle this event type:

private void someMethod() { sfs.addEventListener(SFSEvent.USER_ENTER_ROOM, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { Room room = (Room) evt.getArguments().get("room"); User user = (User) evt.getArguments().get("user");

System.out.println("User " + user.getName() + " just joined Room " + room.getName()); } }); }

See Also:
USER_EXIT_ROOM, USER_COUNT_CHANGE, Constant Field Values

USER_EXIT_ROOM

public static final java.lang.String USER_EXIT_ROOM
The SFSEvent.USER_EXIT_ROOM constant defines the value of the type property of the event object for a userExitRoom event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
userUserAn object representing the user who left the Room.
roomRoomAn object representing the Room that was left by a user.

Example
The following example shows how to handle this event type:

private void someMethod() { sfs.addEventListener(SFSEvent.USER_EXIT_ROOM, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { Room room = (Room) evt.getArguments().get("room"); User user = (User) evt.getArguments().get("user");

System.out.println("User " + user.getName() + " just left Room " + room.getName()); } }); }

See Also:
USER_ENTER_ROOM, USER_COUNT_CHANGE, Constant Field Values

USER_COUNT_CHANGE

public static final java.lang.String USER_COUNT_CHANGE
The SFSEvent.USER_COUNT_CHANGE constant defines the value of the type property of the event object for a userCountChange event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room in which the users count changed.
uCountintThe new users count (players in case of Game Room).
sCountintThe new spectators count (Game Room only).

Example
The following example shows how to handle this event type:

private void someMethod() { sfs.addEventListener(SFSEvent.USER_COUNT_CHANGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { Room room = (Room) evt.getArguments().get("room"); int uCount = (Integer)evt.getArguments().get("uCount"); int sCount = (Integer)evt.getArguments().get("sCount");

System.out.println("Room: " + room.getName() + " now contains " + uCount + " users and " + sCount + " spectators"); } }); }

See Also:
USER_ENTER_ROOM, USER_EXIT_ROOM, Constant Field Values

PUBLIC_MESSAGE

public static final java.lang.String PUBLIC_MESSAGE
The SFSEvent.PUBLIC_MESSAGE constant defines the value of the type property of the event object for a publicMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room at which the message is targeted.
senderUserAn object representing the user who sent the message.
messageStringThe message sent by the user.
dataISFSObjectAn object containing custom parameters which might accompany the message.

Example
The following example sends a public message and handles the respective event:

private void someMethod() { sfs.addEventListener(SFSEvent.PUBLIC_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // As messages are forwarded to the sender too, // I have to check if I am the sender

User sender = (User)evt.getArguments().get("sender"); if (sender == sfs.getMySelf()) System.out.println("I said:" + evt.getArguments().get("message")); else System.out.println("User " + sender.getName() + " said: " + evt.getArguments().get("message")); } });

// Send a public message sfs.send(new PublicMessageRequest("Hello everyone!")); }

See Also:
PRIVATE_MESSAGE, Constant Field Values

PRIVATE_MESSAGE

public static final java.lang.String PRIVATE_MESSAGE
The SFSEvent.PRIVATE_MESSAGE constant defines the value of the type property of the event object for a privateMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
senderUserAn object representing the user who sent the message.
messageStringThe message sent by the user.
dataISFSObjectAn object containing custom parameters which might accompany the message.

Example
The following example sends a private message and handles the respective event:

private void someMethod() { sfs.addEventListener(SFSEvent.PRIVATE_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // As messages are forwarded to the sender too, // I have to check if I am the sender

User sender = (User)evt.getArguments().get("sender"); if (sender != sfs.getMySelf()) System.out.println("User " + sender.getName() + " sent me this PM: " + evt.getArguments().get("message")); } });

// Send a private message to Jack User user = sfs.getUserManager().getUserByName("Jack"); sfs.send(new PrivateMessageRequest("Hello everyone!", user.getId())); }

See Also:
PUBLIC_MESSAGE, Constant Field Values

MODERATOR_MESSAGE

public static final java.lang.String MODERATOR_MESSAGE
The SFSEvent.OBJECT_MESSAGE constant defines the value of the type property of the event object for a objectMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
senderUserAn object representing the user who sent the message.
messageSFSObjectThe content of the message: an object containing the custom parameters sent by the sender.

Example
The following example sends the player's character movement coordinates and handles the respective event (note: the myCharacter instance is supposed to be the user sprite on the stage, while the getUserCharacter method retrieves the sprite of other users' characters):

private void someMethod() { sfs.addEventListener(SFSEvent.OBJECT_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { ISFSObject dataObj = (SFSObject)evt.getArguments().get("message");

User sender = evt.getArguments().get("sender"); UserCharacter character = getUserCharacter(sender.getId());

character.x = dataObj.getInt("x"); character.y = dataObj.getInt("y");

} }); // Send my movement to all players ISFSObject dataObj = new SFSObject(); dataObj.putInt("x", myCharacter.x); dataObj.putInt("y", myCharacter.y);

sfs.send(new ObjectMessageRequest(dataObj)); }

See Also:
Constant Field Values

ADMIN_MESSAGE

public static final java.lang.String ADMIN_MESSAGE
The SFSEvent.MODERATOR_MESSAGE constant defines the value of the type property of the event object for a moderatorMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
senderUserAn object representing the moderator user who sent the message.
messageStringThe message sent by the moderator.
dataISFSObjectAn object containing custom parameters which might accompany the message.

Example
The following example sends a moderator message to all the users in the last joned Room; it also shows how to handle the related event:

private void someMethod() { sfs.addEventListener(SFSEvent.MODERATOR_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("The moderator sent the following message: " + evt.getArguments().get("message")); } }); // Set the message recipients: all users in the current Room MessageRecipientMode recipMode = new MessageRecipientMode(MessageRecipientMode.TO_ROOM, sfs.getLastJoinedRoom());

// Send the moderator message sfs.send(new ModeratorMessageRequest("Hello everybody, I'm the Moderator!", recipMode)); }

See Also:
ADMIN_MESSAGE, Constant Field Values

OBJECT_MESSAGE

public static final java.lang.String OBJECT_MESSAGE
The SFSEvent.ADMIN_MESSAGE constant defines the value of the type property of the event object for a adminMessage event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
senderUserAn object representing the administrator user who sent the message.
messageStringThe message sent by the administrator.
dataISFSObjectAn object containing custom parameters which might accompany the message.

Example
The following example sends an administration message to all the users in the Zone; it also shows how to handle the related event:

private void someMethod() { sfs.addEventListener(SFSEvent.ADMIN_MESSAGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("The administrator sent the following message: " + evt.getArguments().get("message")); } });

// Set the message recipients: all users in the Zone MessageRecipientMode recipMode = new MessageRecipientMode(MessageRecipientMode.TO_ZONE, null);

// Send the administrator message sfs.send(new AdminMessageRequest("Hello to everybody from the Administrator!", recipMode)); }

See Also:
MODERATOR_MESSAGE, Constant Field Values

EXTENSION_RESPONSE

public static final java.lang.String EXTENSION_RESPONSE
The SFSEvent.EXTENSION_RESPONSE constant defines the value of the type property of the event object for a extensionResponse event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
cmdStringThe name of the command which identifies an action that should be executed by the client. If this event is fired in response to a request sent by the client, it is a common practice to use the same command name passed to the request also in the response.
paramsISFSObjectAn object containing custom data sent by the Extension.
sourceRoomNumberThe id of the room where the server extension is attached to.
packetIdNumberThe id of the packet when the UDP protocol is used. As this is an auto-increment value generated by the server, it can be useful to detect UDP packets received in the wrong order.

Example
The following example sends a command to the Zone Extension; it also handles responses coming from the Extension by implementing the extensionResponse listener (the same command name is used in both the request and the response):

private void someMethod() { sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { if (evt.getArguments().get("cmd") == "add") { ISFSObject responseParams = (SFSObject)evt.getArguments().get("params");

// We expect an int parameter called "sum" System.out.println("The sum is: " + responseParams.getInt("sum")); } } });

// Send two integers to the Zone extension and get their sum in return ISFSObject params = new SFSObject(); params.putInt("n1", 26); params.putInt("n2", 16);

sfs.send(new ExtensionRequest("add", params)); }

See Also:
Constant Field Values

ROOM_VARIABLES_UPDATE

public static final java.lang.String ROOM_VARIABLES_UPDATE
The SFSEvent.ROOM_VARIABLES_UPDATE constant defines the value of the type property of the event object for a roomVariablesUpdate event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room where the Room Variable update occurred.
changedVarsArrayThe list of names of the Room Variables that were changed (or created for the first time).

Example
The following example sets a number of Room Variables and handles the respective update event:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { List changedVars = (List)evt.getArguments().get("changedVars"); Room room = (Room)evt.getArguments().get("room");

// Check if the "gameStarted" variable was changed if (changedVars.indexOf("gameStarted") != -1) { if (room.getVariable("gameStarted").getBoolValue() == true) System.out.println("Game started"); else System.out.println("Game stopped"); }

} }); // Create some Room Variables List roomVars = new ArrayList(); roomVars.add(new SFSRoomVariable("gameStarted", false)); roomVars.add(new SFSRoomVariable("gameType", "Snooker")); roomVars.add(new SFSRoomVariable("minRank", 10));

sfs.send(new SetRoomVariablesRequest(roomVars)); }

See Also:
Constant Field Values

USER_VARIABLES_UPDATE

public static final java.lang.String USER_VARIABLES_UPDATE
The SFSEvent.USER_VARIABLES_UPDATE constant defines the value of the type property of the event object for a userVariablesUpdate event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
userUserAn object representing the User who updated his own User Variables.
changedVarsArrayThe list of names of the User Variables that were changed (or created for the first time).

Example
The following example sets a number of User Variables and handles the respective update event:

private void someMethod() { sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { List changedVars = (List)evt.getArguments().get("changedVars"); User user = (User)evt.getArguments().get("user");

// Check if the user changed his x and y user variables if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1) { // Move the user avatar to a new position ... } } }); // Create some User Variables List userVars = new ArrayList(); userVars.add(new SFSUserVariable("avatarType", "SwedishCook")); userVars.add(new SFSUserVariable("country", "Sweden")); userVars.add(new SFSUserVariable("x", 10)); userVars.add(new SFSUserVariable("y", 5));

sfs.send(new SetUserVariablesRequest(userVars)); }

See Also:
Constant Field Values

ROOM_GROUP_SUBSCRIBE

public static final java.lang.String ROOM_GROUP_SUBSCRIBE
The SFSEvent.ROOM_GROUP_SUBSCRIBE constant defines the value of the type property of the event object for a roomGroupSubscribe event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
groupIdStringThe name of the Group that was subscribed.
newRoomsArrayA list of Room objects representing the Rooms belonging to the subscribed Group.

Example
The following example makes the current user subscribe a Group:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Group subscribed. The following rooms are now accessible: " + evt.getArguments().get("newRooms")); } }); sfs.addEventListener(SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Group subscription failed: " + evt.getArguments().get("errorMessage")); } }); // Subscribe the "cardGames" group sfs.send(new SubscribeRoomGroupRequest("cardGames")); }

See Also:
ROOM_GROUP_SUBSCRIBE_ERROR, ROOM_GROUP_UNSUBSCRIBE, Constant Field Values

ROOM_GROUP_UNSUBSCRIBE

public static final java.lang.String ROOM_GROUP_UNSUBSCRIBE
The SFSEvent.ROOM_GROUP_UNSUBSCRIBE constant defines the value of the type property of the event object for a roomGroupUnsubscribe event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
groupIdStringThe name of the Group that was unsubscribed.

Example
The following example makes the current user unsubscribe a Group:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Group unsubscribed: " + evt.getArguments().get("groupId")); } }); sfs.addEventListener(SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Group unsubscribing failed: " + evt.getArguments().get("errorMessage")); } }); // Unsubscribe the "cardGames" group sfs.send(new UnsubscribeRoomGroupRequest("cardGames")); }

See Also:
ROOM_GROUP_UNSUBSCRIBE_ERROR, ROOM_GROUP_SUBSCRIBE, Constant Field Values

ROOM_GROUP_SUBSCRIBE_ERROR

public static final java.lang.String ROOM_GROUP_SUBSCRIBE_ERROR
The SFSEvent.ROOM_GROUP_SUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupSubscribeError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_GROUP_SUBSCRIBE constant description.

See Also:
ROOM_GROUP_SUBSCRIBE, Constant Field Values

ROOM_GROUP_UNSUBSCRIBE_ERROR

public static final java.lang.String ROOM_GROUP_UNSUBSCRIBE_ERROR
The SFSEvent.ROOM_GROUP_UNSUBSCRIBE_ERROR constant defines the value of the type property of the event object for a roomGroupUnsubscribeError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_GROUP_UNSUBSCRIBE constant description.

See Also:
ROOM_GROUP_UNSUBSCRIBE, Constant Field Values

SPECTATOR_TO_PLAYER

public static final java.lang.String SPECTATOR_TO_PLAYER
The SFSEvent.SPECTATOR_TO_PLAYER constant defines the value of the type property of the event object for a spectatorToPlayer event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room in which the spectator is turned to player.
userUserAn object representing the spectator who was turned to player.
playerIdintThe player id of the user.

Example
The following example turns the current user from spectator to player in the last joined Game Room:

private void someMethod() { sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Spectator " + (User)evt.getArguments().get("user") + " is now a player"); } }); sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Unable to become a player due to the following error: " + evt.getArguments().get("errorMessage")); } }); // Switch spectator to player sfs.send(new SpectatorToPlayerRequest()); }

See Also:
SPECTATOR_TO_PLAYER_ERROR, PLAYER_TO_SPECTATOR, Constant Field Values

PLAYER_TO_SPECTATOR

public static final java.lang.String PLAYER_TO_SPECTATOR
The SFSEvent.PLAYER_TO_SPECTATOR constant defines the value of the type property of the event object for a playerToSpectator event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room in which the player is turned to spectator.
userUserAn object representing the player who was turned to spectator.

Example
The following example turns the current user from player to spectator in the last joined Game Room:

private void someMethod() { sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Spectator " + (User)evt.getArguments().get("user") + " is now a player"); } }); sfs.addEventListener(SFSEvent.SPECTATOR_TO_PLAYER_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Unable to become a player due to the following error: " + evt.getArguments().get("errorMessage")); } }); // Switch spectator to player sfs.send(new SpectatorToPlayerRequest()); }

See Also:
PLAYER_TO_SPECTATOR_ERROR, SPECTATOR_TO_PLAYER, Constant Field Values

SPECTATOR_TO_PLAYER_ERROR

public static final java.lang.String SPECTATOR_TO_PLAYER_ERROR
The SFSEvent.SPECTATOR_TO_PLAYER_ERROR constant defines the value of the type property of the event object for a spectatorToPlayerError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the SPECTATOR_TO_PLAYER constant description.

See Also:
SPECTATOR_TO_PLAYER, Constant Field Values

PLAYER_TO_SPECTATOR_ERROR

public static final java.lang.String PLAYER_TO_SPECTATOR_ERROR
The SFSEvent.PLAYER_TO_SPECTATOR_ERROR constant defines the value of the type property of the event object for a playerToSpectatorError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the PLAYER_TO_SPECTATOR constant description.

See Also:
PLAYER_TO_SPECTATOR, Constant Field Values

ROOM_NAME_CHANGE

public static final java.lang.String ROOM_NAME_CHANGE
The SFSEvent.ROOM_NAME_CHANGE constant defines the value of the type property of the event object for a roomNameChange event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room which was renamed.
oldNameStringThe previous name of the Room.

Example
The following example makes renames an existing Room:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room " + evt.getArguments().get("oldName") + " was successfully renamed to " + ((Room)evt.getArguments().get("room")).getName()); } });

sfs.addEventListener(SFSEvent.ROOM_NAME_CHANGE_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room name change failed: " + evt.getArguments().get("errorMessage")); } });

Room theRoom = sfs.getRoomByName("Gonzo's Room");

// Resize the Room so that it allows a maximum of 100 users and zero spectators sfs.send(new ChangeRoomNameRequest(theRoom, "Gonzo The Great's Room")); }

See Also:
ROOM_NAME_CHANGE_ERROR, Constant Field Values

ROOM_NAME_CHANGE_ERROR

public static final java.lang.String ROOM_NAME_CHANGE_ERROR
The SFSEvent.ROOM_NAME_CHANGE_ERROR constant defines the value of the type property of the event object for a roomNameChangeError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_NAME_CHANGE constant description.

See Also:
ROOM_NAME_CHANGE, Constant Field Values

ROOM_PASSWORD_STATE_CHANGE

public static final java.lang.String ROOM_PASSWORD_STATE_CHANGE
The SFSEvent.ROOM_PASSWORD_STATE_CHANGE constant defines the value of the type property of the event object for a roomPasswordStateChange event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room whose password was changed.

Example
The following example changes the password of an existing Room:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("The password of Room " + ((Room)evt.getArguments().get("room")).getName() + " was changed successfully"); } });

sfs.addEventListener(SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room password change failed: " + evt.getArguments().get("errorMessage")); } });

Room theRoom = sfs.getRoomByName("Gonzo's Room");

// Resize the Room so that it allows a maximum of 100 users and zero spectators sfs.send(new ChangeRoomPasswordStateRequest(theRoom, "mammamia")); }

See Also:
ROOM_PASSWORD_STATE_CHANGE_ERROR, Constant Field Values

ROOM_PASSWORD_STATE_CHANGE_ERROR

public static final java.lang.String ROOM_PASSWORD_STATE_CHANGE_ERROR
The SFSEvent.ROOM_PASSWORD_STATE_CHANGE_ERROR constant defines the value of the type property of the event object for a roomPasswordStateChangeError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_PASSWORD_STATE_CHANGE constant description.

See Also:
ROOM_PASSWORD_STATE_CHANGE, Constant Field Values

ROOM_CAPACITY_CHANGE

public static final java.lang.String ROOM_CAPACITY_CHANGE
The SFSEvent.ROOM_CAPACITY_CHANGE constant defines the value of the type property of the event object for a roomCapacityChange event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomRoomAn object representing the Room whose capacity was changed.

Example
The following example changes the capacity of an existing Room:

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("The capacity of Room " + ((Room)evt.getArguments().get("room")).getName() + " was changed successfully"); } });

sfs.addEventListener(SFSEvent.ROOM_CAPACITY_CHANGE_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Room capacity change failed: " + evt.getArguments().get("errorMessage")); } });

Room theRoom = sfs.getRoomByName("Gonzo's Room");

// Resize the Room so that it allows a maximum of 100 users and zero spectators sfs.send(new ChangeRoomCapacityRequest(theRoom, 100, 0)); }

See Also:
ROOM_CAPACITY_CHANGE_ERROR, Constant Field Values

ROOM_CAPACITY_CHANGE_ERROR

public static final java.lang.String ROOM_CAPACITY_CHANGE_ERROR
The SFSEvent.ROOM_CAPACITY_CHANGE_ERROR constant defines the value of the type property of the event object for a roomCapacityChangeError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the ROOM_CAPACITY_CHANGE constant description.

See Also:
ROOM_CAPACITY_CHANGE, Constant Field Values

ROOM_FIND_RESULT

public static final java.lang.String ROOM_FIND_RESULT
The SFSEvent.ROOM_FIND_RESULT constant defines the value of the type property of the event object for a roomFindResult event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
roomsArrayA list of Room objects representing the Rooms matching the search criteria. If no Room is found, the list is empty

Example
The following example looks for all the server Rooms whose "country" Room Variable is set to "Sweden":

private void someMethod() { sfs.addEventListener(SFSEvent.ROOM_FIND_RESULT, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException {

System.out.println("Rooms found: " + evt.getArguments().get("rooms")); } });

// Create a matching expression to find Rooms with a "country" variable equal to "Sweden" MatchExpression exp = new MatchExpression("country", StringMatch.EQUALS, "Sweden");

// Find the Rooms sfs.send(new FindRoomsRequest(exp)); }

See Also:
Constant Field Values

USER_FIND_RESULT

public static final java.lang.String USER_FIND_RESULT
The SFSEvent.USER_FIND_RESULT constant defines the value of the type property of the event object for a userFindResult event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
usersArrayA list of User objects representing the users matching the search criteria. If no user is found, the list is empty

Example
The following example looks for all the users whose "age" User Variable is greater than 29:

private void someMethod() { sfs.addEventListener(SFSEvent.USER_FIND_RESULT, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException {

System.out.println("Users found: " + evt.getArguments().get("users")); } });

// Create a matching expression to find users with an "age" variable greater than 29: MatchExpression exp = new MatchExpression("age", NumberMatch.GREATER_THAN, 29);

// Find the users sfs.send(new FindUsersRequest(exp)); }

See Also:
Constant Field Values

INVITATION

public static final java.lang.String INVITATION
The SFSEvent.INVITATION constant defines the value of the type property of the event object for a invitation event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
invitationInvitationAn object representing the invitation received by the current user.

Example
The following example receives an invitation and accepts it automatically; in a real case scenario, the application interface usually allows the user choosing to accept or refuse the invitation, or even ignore it:

private void someMethod() { sfs.addEventListener(SFSEvent.INVITATION, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { // Let's accept this invitation sfs.send(new InvitationReplyRequest((Invitation) evt.getArguments().get("invitation"), InvitationReply.ACCEPT)); } });

sfs.addEventListener(SFSEvent.INVITATION_REPLY_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Failed to reply to invitation due to the following problem: " + evt.getArguments().get("errorMessage")); } }); }

See Also:
INVITATION_REPLY, Constant Field Values

INVITATION_REPLY

public static final java.lang.String INVITATION_REPLY
The SFSEvent.INVITATION_REPLY constant defines the value of the type property of the event object for a invitationReply event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
inviteeUserAn object representing the user who replied to the invitation.
replyintThe answer to the invitation among those available as constants in the InvitationReply class.
dataISFSObjectAn object containing custom parameters, for example a message describing the reason of refusal.

Example
See the example provided in the INVITATION constant description.

See Also:
InvitationReply, INVITATION, INVITATION_REPLY_ERROR, Constant Field Values

INVITATION_REPLY_ERROR

public static final java.lang.String INVITATION_REPLY_ERROR
The SFSEvent.INVITATION_REPLY_ERROR constant defines the value of the type property of the event object for a invitationReplyError event.

The properties of the params object contained in the event object have the following values:

PropertyTypeDescription
errorMessageStringA message containing the description of the error.
errorCodeshortThe error code.

Example
See the example provided in the INVITATION constant description.

See Also:
INVITATION_REPLY, INVITATION, Constant Field Values
Constructor Detail

SFSEvent

public SFSEvent(java.lang.String type,
                java.util.Map<java.lang.String,java.lang.Object> args)
Creates a new SFSEvent instance.

Parameters:
type - The type of event.
args - An object containing the parameters of the event.

SFSEvent

public SFSEvent(java.lang.String type)