Skip to content

Commit

Permalink
Merge pull request #12 from Vrolijkx/feature/11_performance
Browse files Browse the repository at this point in the history
Feature/11 performance
fixes #11
  • Loading branch information
Vrolijkx committed Feb 19, 2016
2 parents e41030a + dc3cbdf commit 5540e19
Show file tree
Hide file tree
Showing 19 changed files with 598 additions and 290 deletions.
23 changes: 23 additions & 0 deletions api/configurable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Indicates that the component can be configured.
*/
var Configurable = {
/**
* This options will be presented to the user
* in the help description
*
* @return the possible configuration options
*/
getConfigurationOptions: function () {
},

/**
* Called when configuration might have been changed
*
* @param the configuration to use from now on
*/
updateConfiguration: function (configuration) {
}
};

module.exports = Configurable;
131 changes: 0 additions & 131 deletions api/contracts.js

This file was deleted.

12 changes: 12 additions & 0 deletions api/file-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var FileManager = {

scanAndWatchFiles: function (dir, category) {
},
getFilePaths: function (categoryName) {
},
hasChangedFileForCategory: function (categoryName) {
}

};

module.exports = FileManager;
33 changes: 33 additions & 0 deletions api/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Represents a directory from which assets, translations, ...
* will be served
*/
var Project = {
/**
* @param uri
* @return the full path matching the given uri
*/
getAsset: function (uri) {
},

/**
* Merges in the translations found in getProjectDir
*
* @param translations the translations JSON object to be updated
*/
updateTranslations: function (translations) {
},

updateUiFiles: function (category, uifiles) {
},

/**
* @return the working directory of this project
*/
getProjectDir: function () {
},
hasChangedFileForCategory: function (categoryName) {
}
};

module.exports = Project;
40 changes: 40 additions & 0 deletions api/request-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* The router will use requestHandlers to serve requests.
* The request handler with the lowest priority number
* that canHandle the request will be asked to handle
* the request first. If successful other following
* requestHandlers are ignored
*/
var RequestHandler = {
/**
* Lower priority number gets precedence
*/
getPriority: function () {
},
/**
* Indicates whether this requestHandler
* can handle this request
*
* @param req The request to handle
*/
canHandle: function (req) {
},
/**
* Try to serve the request
*
* @param req The request to handle
* @param res The response to send
*
* @return true if request was served successfully,
* false otherwise
*/
handle: function (req, res) {
},
/**
* Unique identifier for the requestHandler
*/
getName: function () {
}
};

module.exports = RequestHandler;
20 changes: 20 additions & 0 deletions api/response-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var ResponseHandler = {

canProcess: function (req) {
},
preProcess: function (res, req) {
},

/**
* Lower priority number gets precedence
*/
getPriority: function () {
},
/**
* Unique identifier for the requestHandler
*/
getName: function () {
}
};

module.exports = ResponseHandler;
14 changes: 14 additions & 0 deletions api/routable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Indicates that the component can route requests
*/
var Routable = {
/**
* Called by the http-server when a request arrives
* @param request
* @param response
*/
onRequest: function (request, response) {
}
};

module.exports = Routable;
47 changes: 28 additions & 19 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ require('./external/hubu');

var _ = require('lodash');
var path = require('path');
var contracts = require('./api/contracts');

var configurable = require('./api/configurable');

//TODO dynamicly load and register components
var httpServer = require('./lib/components/http-server');
var router = require('./lib/components/router');
var fileManager = require('./lib/components/file-manager');
var proxyRequestHandler = require('./lib/components/proxy-request-handler');
var assetRequestHandler = require('./lib/components/asset-request-handler');
var translationsResponseHandler = require('./lib/components/translations-response-handler');
var uiFilesResponseHandler = require('./lib/components/uifiles-response-handler');
var Project = require('./lib/components/Project');
var Project = require('./lib/components/project');

var cli = require('cli');

var parseOptions = {};

var configurableServiceListener = {
contract: contracts.configurable,
contract: configurable,
listener: function (event) {
if (event.getType() === SOC.ServiceEvent.REGISTERED) {
getService(event.getReference(), addParseOptions);
Expand All @@ -28,8 +32,7 @@ var configurableServiceListener = {
};

function getService(serviceReference, fn) {
var service = hub.getService(this, serviceReference);
fn.call(null, service);
fn.call(null, hub.getService(this, serviceReference));
hub.ungetService(serviceReference);
}

Expand All @@ -39,17 +42,9 @@ function addParseOptions(configurable) {

hub.registerServiceListener(configurableServiceListener);

hub
.registerComponent(httpServer.component)
.registerComponent(router.component)
.registerComponent(proxyRequestHandler.component)
.registerComponent(assetRequestHandler.component)
.registerComponent(translationsResponseHandler.component)
.registerComponent(uiFilesResponseHandler.component)
.start();
loadComponents();

cli.parse(parseOptions);

cli.main(exec);

function exec(args, options) {
Expand All @@ -60,16 +55,30 @@ function exec(args, options) {
args.push('.');
}

_.forEach(args, function (projectDir) {
hub.registerComponent(hub.createInstance(Project, {projectDir: path.resolve(projectDir)}));
});
_.forEach(args, registerProjectForDir);

var serviceReferences = hub.getServiceReferences(contracts.configurable);
var serviceReferences = hub.getServiceReferences(configurable);
_.forEach(serviceReferences, function (serviceReference) {
getService(serviceReference, function (service) {
service.updateConfiguration(_.pick(options, _.keys(service.getConfigurationOptions())));
});
});

httpServer.component.listen();
hub.publish(this, '/framework/started', {});
}

function registerProjectForDir(projectDir) {
hub.registerComponent(hub.createInstance(Project, {projectDir: path.resolve(projectDir)}));
}

function loadComponents() {
hub
.registerComponent(httpServer.component)
.registerComponent(router.component)
.registerComponent(proxyRequestHandler.component)
.registerComponent(assetRequestHandler.component)
.registerComponent(translationsResponseHandler.component)
.registerComponent(uiFilesResponseHandler.component)
.registerComponent(fileManager.component)
.start();
}
20 changes: 20 additions & 0 deletions lib/Mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var _ = require('lodash');

function Mode(value, active) {
this.isActive = function (fallback) {
return _.isUndefined(active) ? fallback.call() : active;
};

this.getValue = function () {
return value;
}
}


module.exports = {
on: new Mode('on', true),
off: new Mode('off', false),
auto: new Mode('auto')
};
Loading

0 comments on commit 5540e19

Please sign in to comment.