2 * Copyright 2013, 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 var registry = require("./registry");
17 var credentials = require("./credentials");
18 var flows = require("./flows");
19 var Node = require("./Node");
22 * Registers a node constructor
23 * @param type - the string type name
24 * @param constructor - the constructor function for this node type
25 * @param opts - optional additional options for the node
27 function registerType(type,constructor,opts) {
28 if (opts && opts.credentials) {
29 credentials.register(type,opts.credentials);
31 registry.registerType(type,constructor);
35 * Called from a Node's constructor function, invokes the super-class
36 * constructor and attaches any credentials to the node.
37 * @param node the node object being created
38 * @param def the instance definition for the node
40 function createNode(node,def) {
42 var creds = credentials.get(node.id);
44 node.credentials = creds;
48 function init(_settings,storage) {
49 credentials.init(storage);
51 registry.init(_settings);
54 function checkTypeInUse(id) {
55 var nodeInfo = registry.getNodeInfo(id);
57 throw new Error("Unrecognised id: "+info);
60 flows.each(function(n) {
61 inUse[n.type] = (inUse[n.type]||0)+1;
64 nodeInfo.types.forEach(function(t) {
69 if (nodesInUse.length > 0) {
70 var msg = nodesInUse.join(", ");
71 throw new Error("Type in use: "+msg);
75 function removeNode(id) {
77 return registry.removeNode(id);
80 function removeModule(module) {
81 var info = registry.getNodeModuleInfo(module);
82 for (var i=0;i<info.nodes.length;i++) {
83 checkTypeInUse(info.nodes[i]);
85 return registry.removeModule(module);
89 function disableNode(id) {
91 return registry.disableNode(id);
100 createNode: createNode,
103 addNode: registry.addNode,
104 removeNode: removeNode,
106 addModule: registry.addModule,
107 removeModule: removeModule,
109 enableNode: registry.enableNode,
110 disableNode: disableNode,
112 // Node type registry
113 registerType: registerType,
114 getType: registry.get,
115 getNodeInfo: registry.getNodeInfo,
116 getNodeModuleInfo: registry.getNodeModuleInfo,
117 getNodeList: registry.getNodeList,
118 getNodeConfigs: registry.getNodeConfigs,
119 getNodeConfig: registry.getNodeConfig,
120 clearRegistry: registry.clear,
121 cleanNodeList: registry.cleanNodeList,
124 loadFlows: flows.load,
125 stopFlows: flows.stopFlows,
126 setFlows: flows.setFlows,
127 getFlows: flows.getFlows,
130 addCredentials: credentials.add,
131 getCredentials: credentials.get,
132 deleteCredentials: credentials.delete