Commit af50a514 authored by project's avatar project

--no commit message

--no commit message
parent 5f915d6f
...@@ -88,9 +88,9 @@ BSSEngine.prototype.cmd_write = function(prm,cb) ...@@ -88,9 +88,9 @@ BSSEngine.prototype.cmd_write = function(prm,cb)
this.bss.write(data,{'meta':meta},function(err,obj){ this.bss.write(data,{'meta':meta},function(err,obj){
if(!err){ if(!err){
cb("write error");
}else {
cb(null); cb(null);
}else {
cb("write error");
} }
}); });
} }
...@@ -9,10 +9,43 @@ function BSSPool(prm) ...@@ -9,10 +9,43 @@ function BSSPool(prm)
BSSPool.prototype.get = function(name,cb) BSSPool.prototype.get = function(name,cb)
{ {
var self=this;
var filepath = this.repos_dir + '/' + name2path(name) + '.bss' var filepath = this.repos_dir + '/' + name2path(name) + '.bss'
var bssname = name; var bssname = name;
var bss = this.search(name);
if(bss){
process.nextTick(function() {
cb(null,bss.engine);
});
}else{
bss = BSSEngine.create(filepath);
bss.open(function(err){
if(!err){
self.pool.push({
'name' : name,
'engine':bss
});
}
cb(err,bss);
});
}
}
BSSPool.prototype.search = function(name)
{
var ret=null;
for(var i=0;i<this.pool.length;i++)
{
var bssI = this.pool[i]
if(bssI.name == name){
ret = bssI;
break;
}
}
return ret;
} }
function name2path(name){ function name2path(name){
......
var BSSPool = require('./bsspool'); var BSSPool = require('./bsspool');
module.exports.create = function(cfg){
return new Db(cfg);
}
function Db(cfg) function Db(cfg)
{ {
this.repos_dir = cfg.repos_dir; this.repos_dir = cfg.repos_dir;
...@@ -9,7 +13,7 @@ function Db(cfg) ...@@ -9,7 +13,7 @@ function Db(cfg)
Db.prototype.request = function(req,cb) Db.prototype.request = function(req,cb)
{ {
if(req.object_type!='storage_service_request'){ if(req.object_type!='storage_request'){
return cb(null,result_error('invalid request')); return cb(null,result_error('invalid request'));
} }
...@@ -32,8 +36,30 @@ Db.prototype.request = function(req,cb) ...@@ -32,8 +36,30 @@ Db.prototype.request = function(req,cb)
Db.prototype.bsscmd_w = function(cmd,cb) Db.prototype.bsscmd_w = function(cmd,cb)
{ {
var self = this;
var filepath = this.repos_dir + '/' + name2path(cmd.storage) + '.bss' var filepath = this.repos_dir + '/' + name2path(cmd.storage) + '.bss'
var bssname = cmd.storage; var bssname = cmd.storage;
var w_cmd = {
'command' : 'write',
'param' : {
'meta' : cmd.meta,
'data' : cmd.data
}
}
this.bsspool.get(bssname,function(err,bss){
if(!err){
bss.cmd(w_cmd,function(err){
if(!err){
cb(null,result_ok('success'));
}else{
cb(null,result_error('write error'));
}
});
}else{
cb(null,result_error('bss error'));
}
});
} }
......
...@@ -3,10 +3,11 @@ var async = require('async'); ...@@ -3,10 +3,11 @@ var async = require('async');
var BinStream = ctx.getLib('lib/bss/binarystream_v1_1'); var BinStream = ctx.getLib('lib/bss/binarystream_v1_1');
var FNAME = "D:/testfile/MyBss.bss"; var FNAME = "D:/testfile/gcs/file/test.bss";
BinStream.open(FNAME,function(err,bss){ BinStream.open(FNAME,function(err,bss){
var rd = bss.reader(); var rd = bss.reader();
var cont = true; var cont = true;
......
...@@ -22,9 +22,27 @@ const crypto = require("crypto"); ...@@ -22,9 +22,27 @@ const crypto = require("crypto");
// //
// console.log(id); // console.log(id);
var bss_handler = ctx.getLib('storage-service/lib/bss_engine'); // var bss_handler = ctx.getLib('storage-service/lib/bss_engine');
//
// var bss = bss_handler.create('d:/testfile/new/slash/hnd.bss');
// bss.open(function(err){
// console.log('open');
// });
var Db = ctx.getLib('storage-service/lib/db');
var database = Db.create({'repos_dir':'D:/testfile'});
var req = {
'object_type' : 'storage_request',
'command' : 'write',
'storage_name' : 'gcs.file.test',
'meta' : {'name':'gcs'},
'resource' : {
'value' : 'Kamron Aroonrua'
}
}
var bss = bss_handler.create('d:/testfile/new/slash/hnd.bss'); database.request(req,function(err,res){
bss.open(function(err){ console.log(res);
console.log('open');
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment