it.gotoandplay.smartfoxserver.extensions
Class AbstractExtension

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.extensions.AbstractExtension
All Implemented Interfaces:
it.gotoandplay.smartfoxserver.events.IEventListener, it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
Direct Known Subclasses:
PixelGame, SchedulerExample, SimpleDbExtension, SimpleExtension

public abstract class AbstractExtension
extends java.lang.Object
implements it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension, it.gotoandplay.smartfoxserver.events.IEventListener

AbstractExtension is the parent class for all SmartFoxServer extensions.
In a nutshell an extension accomplishes four main tasks by implementing the following methods:

Since SmartFoxServer 1.6.0 there's an additional handleInternalRequest() method which is optional and can be used to invoke methods between extensions or other classes.

Author:
(c) 2004-2007 gotoAndPlay() -- www.gotoandplay.it

Field Summary
 it.gotoandplay.smartfoxserver.extensions.AdminExtension adminExtension
           
 
Constructor Summary
AbstractExtension()
           
 
Method Summary
 void destroy()
          This method should be overridden by the child class.
 java.lang.String getOwnerRoom()
          Get the name of the room where the extension is attached to (if any)
 java.lang.String getOwnerZone()
          Get the name of the zone where the extension is attached to
 java.lang.Object handleInternalRequest(java.lang.Object params)
          Allows to send requests from another extension / class / or servlet.
 void handleRequest(java.lang.String cmd, org.json.JSONObject jso, User u, int fromRoom)
          Basic implementation of interface method Needed to avoid breaking extensions of version 1.4.0 and previous which only handle XML or String requests.
 void init()
          This method should be overridden by the child class.
 boolean isActive()
          Returns true if the extension is active
 net.n3.nanoxml.IXMLElement loadConfig(java.lang.String xmlFile)
           
 void registerForEvents(java.lang.String zoneName, java.lang.String roomName)
           
 void sendResponse(ActionscriptObject ao, int fromRoom, User sender, java.util.LinkedList recipients)
          Send a response to one or more clients using XML format
 void sendResponse(org.json.JSONObject jso, int fromRoom, User sender, java.util.LinkedList recipients)
          Send a response to one or more clients using JSON format
 void sendResponse(net.sf.json.JSONObject jso, int fromRoom, User sender, java.util.LinkedList recipients)
          Send a response to one or more clients using JSON format
 void sendResponse(java.lang.String[] params, int fromRoom, User sender, java.util.LinkedList recipients)
          Send a response to one or more clients using String format
 void setActive(boolean b)
           
 void setOwner(java.lang.String zoneName, java.lang.String roomName)
           
 void trace(java.lang.String msg)
          Trace the message remotely to admin tool and to the console
 void unRegister()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
handleRequest, handleRequest
 
Methods inherited from interface it.gotoandplay.smartfoxserver.events.IEventListener
handleInternalEvent
 

Field Detail

adminExtension

public it.gotoandplay.smartfoxserver.extensions.AdminExtension adminExtension
Constructor Detail

AbstractExtension

public AbstractExtension()
Method Detail

setOwner

public void setOwner(java.lang.String zoneName,
                     java.lang.String roomName)
Specified by:
setOwner in interface it.gotoandplay.smartfoxserver.events.IEventListener

getOwnerZone

public java.lang.String getOwnerZone()
Get the name of the zone where the extension is attached to

Specified by:
getOwnerZone in interface it.gotoandplay.smartfoxserver.events.IEventListener
Returns:
the zone name of the extension

getOwnerRoom

public java.lang.String getOwnerRoom()
Get the name of the room where the extension is attached to (if any)

Specified by:
getOwnerRoom in interface it.gotoandplay.smartfoxserver.events.IEventListener
Returns:
the room name of the extension (can be null, if extension is at Zone level only)

init

public void init()
This method should be overridden by the child class.
Here you should run your extension initialization code. This method is executed once, when the extension is started.

Specified by:
init in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

destroy

public void destroy()
This method should be overridden by the child class.
This method is called when the extension is being stopped buy the server: here you should release the resources acquired by the extension (close files, db connections etc...)

Specified by:
destroy in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

isActive

public boolean isActive()
Returns true if the extension is active

Specified by:
isActive in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
Returns:
true if the extension is active

setActive

public void setActive(boolean b)
Specified by:
setActive in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

registerForEvents

public void registerForEvents(java.lang.String zoneName,
                              java.lang.String roomName)
Specified by:
registerForEvents in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

unRegister

public void unRegister()
Specified by:
unRegister in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

trace

public void trace(java.lang.String msg)
Trace the message remotely to admin tool and to the console

Parameters:
msg - the string message to trace

loadConfig

public net.n3.nanoxml.IXMLElement loadConfig(java.lang.String xmlFile)

handleRequest

public void handleRequest(java.lang.String cmd,
                          org.json.JSONObject jso,
                          User u,
                          int fromRoom)
Basic implementation of interface method Needed to avoid breaking extensions of version 1.4.0 and previous which only handle XML or String requests.

Specified by:
handleRequest in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension

handleInternalRequest

public java.lang.Object handleInternalRequest(java.lang.Object params)
Allows to send requests from another extension / class / or servlet.
It can be overridden with a custom implementation.

Parameters:
params - any number of objects
Returns:
an object
Since:
1.6.0

sendResponse

public void sendResponse(ActionscriptObject ao,
                         int fromRoom,
                         User sender,
                         java.util.LinkedList recipients)
Send a response to one or more clients using XML format

Specified by:
sendResponse in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
Parameters:
ao - the ActionscriptObject containing the data for the client
fromRoom - the roomId (-1 for none)
recipients - a list of SocketChannels
sender - the User object of the sender (if null, the sender is the Server)

sendResponse

public void sendResponse(java.lang.String[] params,
                         int fromRoom,
                         User sender,
                         java.util.LinkedList recipients)
Send a response to one or more clients using String format

Specified by:
sendResponse in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
Parameters:
params - an array of String params
fromRoom - the roomId (-1 for none)
recipients - a list of SocketChannels
sender - the User object of the sender (if null, the sender is the Server)

sendResponse

public void sendResponse(org.json.JSONObject jso,
                         int fromRoom,
                         User sender,
                         java.util.LinkedList recipients)
Send a response to one or more clients using JSON format

Specified by:
sendResponse in interface it.gotoandplay.smartfoxserver.extensions.ISmartFoxExtension
Parameters:
jso - a JSONObject
fromRoom - the roomId (-1 for none)
recipients - a list of SocketChannels
sender - the User object of the sender (if null, the sender is the Server)

sendResponse

public void sendResponse(net.sf.json.JSONObject jso,
                         int fromRoom,
                         User sender,
                         java.util.LinkedList recipients)
Send a response to one or more clients using JSON format

Parameters:
jso - a JSONObject
fromRoom - the roomId (-1 for none)
recipients - a list of SocketChannels
sender - the User object of the sender (if null, the sender is the Server)