| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // Copyright 2015 MemDB.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- // implied. See the License for the specific language governing
- // permissions and limitations under the License. See the AUTHORS file
- // for names of contributors.
- 'use strict';
- /*
- * quick pomelo template project
- *
- * start memdb first by:
- * memdbcluster start -c ./config/memdb.conf.js
- */
- var util = require('util');
- var pomelo = require('pomelo');
- var quick = require('quick-pomelo');
- var pomeloConstants = require('pomelo/lib/util/constants');
- var P = quick.Promise;
- var logger = quick.logger.getLogger('pomelo', __filename);
- var pomeloLogger = require('pomelo/node_modules/pomelo-logger');
- var app = pomelo.createApp();
- app.set('name', 'fhmj');
- // Configure for global
- app.configure('all', function () {
- app.enable('systemMonitor');
- app.set('proxyConfig', {
- bufferMsg: true,
- interval: 30,
- lazyConnection: true,
- timeout: 15 * 1000,
- failMode: 'failfast'
- });
- app.set('remoteConfig', {
- bufferMsg: true,
- interval: 30
- });
- // Configure memdb
- app.loadConfigBaseApp('memdbConfig', 'memdb.json');
- // Load components
- app.load(quick.components.memdb);
- app.load(quick.components.controllers);
- app.load(quick.components.routes);
- app.load(quick.components.timer);
- // Configure logger
- var loggerConfig = app.getBase() + '/config/log4js.json';
- var loggerOpts = {
- serverId: app.getServerId(),
- base: app.getBase()
- };
- quick.logger.configure(loggerConfig, loggerOpts);
- // Configure filter
- if (app.getServerType() != 'gate') app.filter(quick.filters.transaction(app));
- app.globalFilter(require('./globalFilter')(app));
- // Add beforeStop hook
- app.lifecycleCbs[pomeloConstants.LIFECYCLE.BEFORE_SHUTDOWN] = function (app, shutdown, cancelShutDownTimer) {
- cancelShutDownTimer();
- if (app.getServerType() === 'master') {
- // Wait for all server stop
- var tryShutdown = function () {
- if (Object.keys(app.getServers()).length === 0) {
- quick.logger.shutdown(shutdown);
- }
- else {
- setTimeout(tryShutdown, 200);
- }
- };
- tryShutdown();
- return;
- }
- quick.logger.shutdown(shutdown);
- };
- app.set('errorHandler', function (err, msg, resp, session, cb) {
- resp = {
- code: 500,
- stack: err.stack,
- message: err.message
- };
- cb(err, resp);
- });
- });
- // Gate settings
- app.configure('all', 'gate', function () {
- app.set('connectorConfig', {
- connector: pomelo.connectors.hybridconnector
- });
- app.set('sessionConfig', {
- singleSession: true
- });
- });
- //Connector settings
- app.configure('all', 'connector', function () {
- app.set('connectorConfig', {
- connector: pomelo.connectors.hybridconnector,
- heartbeat: 30,
- disconnectOnTimeout: true
- });
- app.set('sessionConfig', {
- singleSession: true
- });
- });
- // Http servers
- app.configure('all', 'http', function () {
- var script = app.getCurServer().script;
- app.load(require('./http/' + script));
- });
- // Game route
- app.configure('production|development', function () {
- app.route('game', require('./gameRoute').gameRoute);
- });
- app.configure('development', function () {
- require('heapdump');
- quick.Promise.longStackTraces();
- quick.logger.setGlobalLogLevel(quick.logger.levels.WARN);
- pomeloLogger.setGlobalLogLevel(pomeloLogger.levels.WARN);
- });
- app.configure('production', function () {
- quick.logger.setGlobalLogLevel(quick.logger.levels.WARN);
- pomeloLogger.setGlobalLogLevel(pomeloLogger.levels.WARN);
- });
- process.on('uncaughtException', function (err) {
- logger.error('Uncaught exception: %s', err.stack);
- });
- app.start();
|