Permalink
Browse files

added object component and first approach to ObjectResolver/Registry

  • Loading branch information...
biamontidv committed Jun 3, 2011
1 parent 27c9518 commit 6eef27327f9992e39748958e48f59157705c8858
View
@@ -0,0 +1,17 @@
+var util = require(process.binding('natives').util ? 'util' : 'sys');
+var Processor = require('../lib/node-donkey/processors/Processor');
+
+var myObj = module.exports = function myObj(options){
+ Processor.call(this);
+};
+util.inherits(myObj, Processor);
+
+myObj.prototype.process = function(exchange){
+ exchange.in.p = exchange.in.messageId;
+ this.emit('exchangeOut',exchange);
+};
+
+myObj.prototype.myMethod = function(exchange){
+ exchange.in.p = 'myMethod';
+ this.emit('exchangeOut',exchange);
+};
View
@@ -9,6 +9,9 @@ var rb = new RouteBuilder();
var route;
+var obj = require('./myObj');
+require('../lib/node-donkey/components/obj/ObjectResolver').register('myObj',new obj());
+
rb.configureRoute(filename);
rb.on('routes',function(routes){
routes[0].on('started',function(){
@@ -20,7 +23,6 @@ rb.on('routes',function(routes){
var msg = new Message({'body':"messageIn-"+c.toString()});
if(c%3 == 0){msg.foo = 'heya'};
var ex = new Exchange({'in':msg});
- console.log(ex)
begin.process(ex);
c = c+1;
View
@@ -1,10 +1,5 @@
<route>
<from uri="direct://initialorders"/>
- <filter>
- <expression>exchange.in.foo</expression>
- </filter>
- <multicast>
- <to uri="file:test1?fileName=what.txt&&fileExist=Override"/>
- <to uri="log://myLOG?level=log"/>
- </multicast>
+ <to uri='obj://myObj?method=myMethod'/>
+ <to uri="log://myLOG?level=log"/>
</route>
@@ -0,0 +1,15 @@
+var util = require(process.binding('natives').util ? 'util' : 'sys');
+var Component = require('../Component');
+var ObjectEndpoint = require('./ObjectEndpoint');
+
+var ObjectComponent = module.exports = function ObjectComponent(options){
+ Component.call(this,options);
+ this.endpoint;
+}
+
+util.inherits(ObjectComponent,Component);
+
+ObjectComponent.prototype.createEndpoint = function(options){
+ var endp = new ObjectEndpoint({'uri':options.uri,'objId':options.path,'param':options.param});
+ return endp;
+}
@@ -0,0 +1,16 @@
+var util = require(process.binding('natives').util ? 'util' : 'sys');
+var Endpoint = require('../Endpoint');
+var ObjectProducer = require('./ObjectProducer');
+var ObjectResolver = require('./ObjectResolver');
+
+
+var ObjectEndpoint = module.exports = function ObjectEndpoint(options){
+ Endpoint.call(this,options);
+ this.producer = this.createProducer();
+ this.consumer = this.producer;
+};
+util.inherits(ObjectEndpoint, Endpoint);
+
+ObjectEndpoint.prototype.createProducer = function(){
+ return new ObjectProducer({'endpoint':this,'processor':ObjectResolver.resolve(this.objId)});
+};
@@ -0,0 +1,16 @@
+var util = require(process.binding('natives').util ? 'util' : 'sys');
+var Producer = require('../Producer');
+
+
+var ObjectProducer = module.exports = function ObjectProducer(options){
+ Producer.call(this,options);
+ this.emit('ready');
+ var self = this;
+ var onExchangeOut = function(exchange){self.emit('exchangeOut',exchange);};
+ this.processor.on('exchangeOut',onExchangeOut);
+};
+util.inherits(ObjectProducer, Producer);
+
+ObjectProducer.prototype.process = function(exchange){
+ this.processor[this.endpoint.param.method](exchange);
+}
@@ -0,0 +1,30 @@
+
+
+
+var ObjectResolver = module.exports = (function ObjectProducer(options){
+
+ var registry = {};
+
+ function lookup(objId){
+ console.log('current dir: '+__dirname);
+ var obj = require(objId);
+ return obj;
+ };
+
+ function resolve(objId){
+ console.log(registry);
+ var obj = registry[objId];
+ if(obj === undefined){
+ console.log('Object '+objId+' not in registry');
+ obj = lookup(objId);
+ registry[objId] = obj;
+ };
+ return obj;
+ };
+
+
+ return { 'resolve': resolve,
+ 'register': function(name,obj){
+ registry[name] = obj;
+ }};
+})();
@@ -0,0 +1,2 @@
+{ "name" : "donkey-obj",
+ "main" : "./ObjectComponent.js"}

0 comments on commit 6eef273

Please sign in to comment.