-
-
rpc Invoke
Parameters:
Name |
Type |
Description |
serId |
String
|
Server'sID |
msg |
Object
|
message object
Properties
Name |
Type |
Description |
namespace |
string
|
'user'|'sys' |
serverType |
string
|
|
service |
string
|
|
method |
string
|
|
args |
Array
|
|
|
cb |
function
|
callback |
Example
app.rpcInvoke( serId,
{ namespace:'user',
serverType:serType,
service:'gameRemote',
method:'leaveGame',
args: args
},function( err, result){
console.log('-----RPCNotify: err: ',err," result: ", result);
});
-
-
Add crons from current application at runtime.
Parameters:
Name |
Type |
Description |
crons |
Array
|
new crons would be added in application |
-
-
Add new server info to current application in runtime.
Parameters:
Name |
Type |
Description |
servers |
Array
|
new server info list |
-
-
Add after filter.
Parameters:
Name |
Type |
Description |
af |
Object
|
function
|
after filter, `af(err, msg, session, resp, next)` |
-
-
Lifecycle callback for after start.
Parameters:
Name |
Type |
Description |
cb |
function
|
callback function |
Returns:
Void
-
-
Add before filter.
Parameters:
Name |
Type |
Description |
bf |
Object
|
function
|
before filter, bf(msg, session, next) |
-
-
Set before stop function. It would perform before servers stop.
Parameters:
Name |
Type |
Description |
fun |
function
|
before close function |
Returns:
Void
-
-
Configure callback for the specified env and server type.
When no env is specified that callback will
be invoked for all environments and when no type is specified
that callback will be invoked for all server types.
Examples:
app.configure(function(){
// executed for all envs and server types
});
app.configure('development', function(){
// executed development env
});
app.configure('development', 'connector', function(){
// executed for development env and connector server type
});
app.configure('development', '!connector|gate', function(){
// executed for development env and not connector,not gate server type
});
Parameters:
Name |
Type |
Description |
env |
String
|
application environment |
fn |
function
|
callback function |
type |
String
|
server type, If the string starts with ! At first, this configuration is used by all servers except type |
-
-
Configure logger with {$base}/config/log4js.json
Parameters:
Name |
Type |
Description |
logger |
Object
|
sex-pomelo-logger instance without configuration |
-
-
Disable `setting`.
Parameters:
Name |
Type |
Description |
setting |
String
|
application setting |
Returns:
app
- for chaining
-
-
Check if `setting` is disabled.
Parameters:
Name |
Type |
Description |
setting |
String
|
application setting |
Returns:
Boolean
-
-
Enable `setting`.
Parameters:
Name |
Type |
Description |
setting |
String
|
application setting |
Returns:
app
- for chaining
-
-
Check if `setting` is enabled.
Parameters:
Name |
Type |
Description |
setting |
String
|
application setting |
Returns:
Boolean
-
-
add a filter to before and after filter
Parameters:
Name |
Type |
Description |
filter |
Object
|
provide before and after filter method.
A filter should have two methods: before and after. |
-
-
Get property from setting
Parameters:
Name |
Type |
Description |
setting |
string
|
application setting
- 'channelService' return @see ChannelService
- 'sessionService' return @see SessionService
- 'backendSessionService' return @see BackendSessionService
- '__routes__' return Object |
-
-
Get BackendSessionService
-
-
Get application base path
Returns:
String
- application base path
Example
cwd: /home/game/
pomelo start
app.getBase() -> /home/game
-
-
Get application config path
Parameters:
Name |
Type |
Attributes |
Description |
cfgFile |
String
|
<nullable>
|
config file name |
Returns:
String
- application base path
Example
cwd: /home/game/
pomelo start
app.getCfgPath() -> /home/game/config/[env]
-
getCfgSync(cfgFilenullable, parseJsonnullable) → {String}
-
Get application config file content
Parameters:
Name |
Type |
Attributes |
Default |
Description |
cfgFile |
String
|
<nullable>
|
|
config file name |
parseJson |
boolean
|
<nullable>
|
false
|
weather parse as JSON, default false |
Returns:
String
- cfg file content
Example
cwd: /home/game/
pomelo start
app.getCfgSync() -> /home/game/config/[env]
-
-
Get ChannelService
-
-
Get current server info.
Returns:
ServerInfo
- current server info, {id, serverType, host, port}
-
-
Get master server info.
Returns:
Object
- master server info, {id, host, port}
-
-
Get Routes
Returns:
object
-
-
Get server info by server id from current server cluster.
Parameters:
Name |
Type |
Description |
serverId |
String
|
server id |
Returns:
Object
- server info or undefined
-
-
Get server info by server id from servers.json.
Parameters:
Name |
Type |
Description |
serverId |
String
|
server id |
Returns:
Object
- server info or undefined
-
-
Get current server id.
Returns:
String
|
Number
- current server id from servers.json
-
-
Get all the current server infos.
Returns:
Object
- server info map, key: server id, value: server info
-
-
Get server infos by server type.
Parameters:
Name |
Type |
Description |
serverType |
String
|
server type |
Returns:
Array
- server info list
-
-
Get all server infos from servers.json.
Returns:
Object
- server info map, key: server id, value: server info
-
-
Get current server type.
Returns:
String
|
Number
- current server type from servers.json
-
-
Get all the server type.
Returns:
Array
- server type list
-
-
Get SessionService
-
-
Add global after filter.
Parameters:
Name |
Type |
Description |
af |
Object
|
function
|
after filter, `af(err, msg, session, resp, next)` |
-
-
Add global before filter.
Parameters:
Name |
Type |
Description |
bf |
Object
|
function
|
before filter, bf(msg, session, next) |
-
-
add a global filter to before and after global filter
Parameters:
Name |
Type |
Description |
filter |
Object
|
provide before and after filter method.
A filter should have two methods: before and after. |
-
-
Initialize the server.
- setup default configuration
-
-
Check the server whether is a backend server
Parameters:
Name |
Type |
Description |
server |
server
|
server info. it would check current server
if server not specified |
Returns:
Boolean
-
-
Check the server whether is a frontend server
Parameters:
Name |
Type |
Description |
server |
server
|
server info. it would check current server
if server not specified |
Returns:
Boolean
-
-
Check whether current server is a master server
Returns:
Boolean
-
-
Load component
Parameters:
Name |
Type |
Attributes |
Description |
name |
String
|
<optional>
|
(optional) name of the component |
component |
Object
|
|
component instance or factory function of the component |
opts |
Object
|
<optional>
|
(optional) construct parameters for the factory function |
Returns:
Object
- app instance for chain invoke
-
-
Load Configure json file to settings.
Parameters:
Name |
Type |
Description |
key |
String
|
environment key |
val |
String
|
object
|
environment value |
Returns:
Server
|
Mixed
- for chaining, or the setting value
-
-
Load Configure json file to settings.(support different environment directory & compatible for old path)
Parameters:
Name |
Type |
Description |
key |
String
|
environment key |
val |
String
|
environment value |
reload |
Boolean
|
whether reload after change default false |
Returns:
Server
|
Mixed
- for chaining, or the setting value
-
-
Register admin modules. Admin modules is the extends point of the monitor system.
Parameters:
Name |
Type |
Description |
module |
String
|
(optional) module id or provoided by module.moduleId |
module |
Object
|
module object or factory function for module |
opts |
Object
|
construct parameter for module |
-
-
Remove crons from current application at runtime.
Parameters:
Name |
Type |
Description |
crons |
Array
|
old crons would be removed in application |
-
-
Remove server info from current application at runtime.
Parameters:
Name |
Type |
Description |
ids |
Array
|
server id list |
-
-
Replace server info from current application at runtime.
Parameters:
Name |
Type |
Description |
server |
Object
|
id map |
-
-
Override require method in application
Parameters:
Name |
Type |
Description |
relative |
String
|
path of file |
-
-
Set the route function for the specified server type.
Examples:
app.route('area', routeFunc);
let routeFunc = function(session, msg, app, cb) {
// all request to area would be route to the first area server
let areas = app.getServersByType('area');
cb(null, areas[0].id);
};
Parameters:
Name |
Type |
Description |
serverType |
String
|
server type string |
routeFunc |
function
|
route function. routeFunc(session, msg, app, cb) |
Returns:
Object
- current application instance for chain invoking
-
-
Add rpc after filter.
Parameters:
Name |
Type |
Description |
af |
Object
|
function
|
after filter, `af(serverId, msg, opts, next)` |
-
-
Add rpc before filter.
Parameters:
Name |
Type |
Description |
bf |
Object
|
function
|
before fileter, bf(serverId, msg, opts, next) |
-
-
add a rpc filter to before and after rpc filter
Parameters:
Name |
Type |
Description |
filter |
Object
|
provide before and after filter method.
A filter should have two methods: before and after. |
-
-
Assign `setting` to `val`, or return `setting`'s value.
Example:
app.set('key1', 'value1');
app.get('key1'); // 'value1'
app.key1; // undefined
app.set('key2', 'value2', true);
app.get('key2'); // 'value2'
app.key2; // 'value2'
Parameters:
Name |
Type |
Description |
setting |
String
|
the setting of application |
val |
String
|
the setting's value |
attach |
Boolean
|
whether attach the settings to application |
Returns:
Server
|
Mixed
- for chaining, or the setting value
-
-
Start application. It would load the default components and start all the loaded components.
Parameters:
Name |
Type |
Description |
cb |
function
|
callback function |
-
-
Stop components.
Parameters:
Name |
Type |
Description |
force |
Boolean
|
whether stop the app immediately |
-
-
tr by default lang
Parameters:
Name |
Type |
Attributes |
Description |
msg |
string
|
|
|
paras |
any
|
<repeatable>
|
|
Returns:
string
-
-
tr by lang
Parameters:
Name |
Type |
Attributes |
Description |
locale |
string
|
|
the locale |
msg |
string
|
|
|
paras |
any
|
<repeatable>
|
|
Returns:
string
-
-
Application transaction. Transaction includes conditions and handlers, if conditions are satisfied, handlers would be executed.
And you can set retry times to execute handlers. The transaction log is in file logs/transaction.log.
Parameters:
Name |
Type |
Description |
name |
String
|
transaction name |
conditions |
Object
|
functions which are called before transaction |
handlers |
Object
|
functions which are called during transaction |
retry |
Number
|
retry times to execute handlers if conditions are successfully executed |
-
-
Use plugin.
Parameters:
Name |
Type |
Attributes |
Description |
plugin |
Object
|
|
plugin instance |
opts |
Object
|
<optional>
|
(optional) construct parameters for the factory function |