Commit c9ec180f authored by Tristan Cavelier's avatar Tristan Cavelier

Replicate storage and index storage completed.

parent d851fe95
......@@ -108,6 +108,6 @@ module.exports = function(grunt) {
});
// Default task.
grunt.registerTask('default', 'concat lint min qunit');
grunt.registerTask('default', 'concat lint min');
};
......@@ -18,6 +18,8 @@ module.exports = function(grunt) {
'<file_strip_banner:../../src/<%= pkg.name %>/localstorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/davstorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/replicatestorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/indexstorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/cryptstorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js'
}
......
/*! JIO - v0.1.0 - 2012-06-14
/*! JIO - v0.1.0 - 2012-06-15
* Copyright (c) 2012 Nexedi; Licensed */
var jio = (function () {
......@@ -150,8 +150,19 @@ var storageHandler = function(spec, my) {
my = my || {};
var that = storage( spec, my );
that.newCommand = function (method, spec) {
var o = spec || {};
o.label = method;
return command (o, my);
};
that.newStorage = function (spec) {
var o = spec || {};
return jioNamespace.storage (o, my);
};
that.addJob = function (storage,command) {
my.jobManager.addJob ( job({storage:storage, command:command}), my );
my.jobManager.addJob ( job({storage:storage, command:command}, my) );
};
return that;
......@@ -278,15 +289,27 @@ var command = function(spec, my) {
};
that.onResponseDo = function (fun) {
if (fun) {
priv.respond = fun;
} else {
return priv.respond;
}
};
that.onDoneDo = function (fun) {
if (fun) {
priv.done = fun;
} else {
return priv.done;
}
};
that.onFailDo = function (fun) {
if (fun) {
priv.fail = fun;
} else {
return priv.fail;
}
};
that.onEndDo = function (fun) {
......@@ -308,17 +331,40 @@ var command = function(spec, my) {
tried:priv.tried,
max_retry:priv.max_retry,
path:priv.path,
option:priv.option};
option:that.cloneOption()};
};
/**
* Is the command can be restored by another JIO : yes.
* @method canBeRestored
* @return {boolean} true
*/
that.canBeRestored = function() {
return true;
};
/**
* Clones the command and returns it.
* @method clone
* @return {object} The cloned command.
*/
that.clone = function () {
return command(that.serialized(), my);
};
/**
* Clones the command options and returns the clone version.
* @method cloneOption
* @return {object} The clone of the command options.
*/
that.cloneOption = function () {
var k, o = {};
for (k in priv.option) {
o[k] = priv.option[k];
}
return o;
};
return that;
};
......@@ -474,6 +520,10 @@ var jobStatus = function(spec, my) {
return false;
};
that.isDone = function() {
return false;
};
return that;
};
......@@ -493,6 +543,10 @@ var doneStatus = function(spec, my) {
that.canRestart = function() {
return false;
};
that.isDone = function() {
return true;
};
return that;
};
......@@ -998,7 +1052,7 @@ var jobManager = (function(spec, my) {
priv.job_a = [];
my.jobManager = that;
my.jobIdHandler = that;
my.jobIdHandler = jobIdHandler;
// Methods //
/**
......@@ -1471,7 +1525,6 @@ var jobRules = (function(spec, my) {
my.jobManager = jobManager;
my.jobIdHandler = jobIdHandler;
priv.storage = jioNamespace.storage(spec, my);
// initialize //
......@@ -1561,7 +1614,7 @@ var jobRules = (function(spec, my) {
jioNamespace.storage(specificstorage,my):
priv.storage),
command:saveDocument(
{path:path,content:content,option:option})},my));
{path:path,content:content,option:option},my)},my));
};
/**
......@@ -1590,7 +1643,7 @@ var jobRules = (function(spec, my) {
jioNamespace.storage(specificstorage,my):
priv.storage),
command:loadDocument(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
/**
......@@ -1616,7 +1669,7 @@ var jobRules = (function(spec, my) {
jioNamespace.storage(specificstorage,my):
priv.storage),
command:removeDocument(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
/**
......@@ -1645,7 +1698,7 @@ var jobRules = (function(spec, my) {
jioNamespace.storage(specificstorage,my):
priv.storage),
command:getDocumentList(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
return that;
......@@ -1673,6 +1726,7 @@ var jioNamespace = (function(spec, my) {
*/
that.storage = function(spec, my, forcetype) {
spec = spec || {};
my = my || {};
var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) {
throw invalidStorageType({type:type,
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
auto: grunt
check-syntax: grunt
grunt:
make -C ../../grunt/*_gruntJIOStorage > /dev/null 2>&1
This diff is collapsed.
......@@ -5,6 +5,21 @@ var newReplicateStorage = function ( spec, my ) {
priv.storagelist = spec.storagelist || [];
priv.nb_storage = priv.storagelist.length;
var super_serialized = that.serialized;
that.serialized = function () {
var o = super_serialized();
o.storagelist = priv.storagelist;
return o;
};
that.validateState = function () {
if (priv.storagelist.length === 0) {
return 'Need at least one parameter: "storagelist" '+
'containing at least one storage.';
}
return '';
};
priv.isTheLast = function () {
return (priv.return_value_array.length === priv.nb_storage);
};
......@@ -12,12 +27,10 @@ var newReplicateStorage = function ( spec, my ) {
priv.doJob = function (command,errormessage) {
var done = false, error_array = [], i,
onResponseDo = function (result) {
console.log ('respond');
priv.return_value_array.push(result);
},
onFailDo = function (result) {
if (!done) {
console.log ('fail');
error_array.push(result);
if (priv.isTheLast()) {
that.fail (
......@@ -30,7 +43,6 @@ var newReplicateStorage = function ( spec, my ) {
},
onDoneDo = function (result) {
if (!done) {
console.log ('done');
done = true;
that.done (result);
}
......@@ -38,7 +50,7 @@ var newReplicateStorage = function ( spec, my ) {
command.setMaxRetry (1);
for (i = 0; i < priv.nb_storage; i+= 1) {
var newcommand = command.clone();
var newstorage = Jio.storage(priv.storagelist[i], my);
var newstorage = that.newStorage(priv.storagelist[i]);
newcommand.onResponseDo (onResponseDo);
newcommand.onFailDo (onFailDo);
newcommand.onDoneDo (onDoneDo);
......
......@@ -4,4 +4,4 @@ auto: grunt
check-syntax: grunt
grunt:
make -C ../../grunt/*_gruntJIO
make -C ../../grunt/*_gruntJIO > /dev/null 2>&1
......@@ -119,15 +119,27 @@ var command = function(spec, my) {
};
that.onResponseDo = function (fun) {
if (fun) {
priv.respond = fun;
} else {
return priv.respond;
}
};
that.onDoneDo = function (fun) {
if (fun) {
priv.done = fun;
} else {
return priv.done;
}
};
that.onFailDo = function (fun) {
if (fun) {
priv.fail = fun;
} else {
return priv.fail;
}
};
that.onEndDo = function (fun) {
......@@ -149,16 +161,39 @@ var command = function(spec, my) {
tried:priv.tried,
max_retry:priv.max_retry,
path:priv.path,
option:priv.option};
option:that.cloneOption()};
};
/**
* Is the command can be restored by another JIO : yes.
* @method canBeRestored
* @return {boolean} true
*/
that.canBeRestored = function() {
return true;
};
/**
* Clones the command and returns it.
* @method clone
* @return {object} The cloned command.
*/
that.clone = function () {
return command(that.serialized(), my);
};
/**
* Clones the command options and returns the clone version.
* @method cloneOption
* @return {object} The clone of the command options.
*/
that.cloneOption = function () {
var k, o = {};
for (k in priv.option) {
o[k] = priv.option[k];
}
return o;
};
return that;
};
......@@ -9,7 +9,6 @@
my.jobManager = jobManager;
my.jobIdHandler = jobIdHandler;
priv.storage = jioNamespace.storage(spec, my);
// initialize //
......@@ -99,7 +98,7 @@
jioNamespace.storage(specificstorage,my):
priv.storage),
command:saveDocument(
{path:path,content:content,option:option})},my));
{path:path,content:content,option:option},my)},my));
};
/**
......@@ -128,7 +127,7 @@
jioNamespace.storage(specificstorage,my):
priv.storage),
command:loadDocument(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
/**
......@@ -154,7 +153,7 @@
jioNamespace.storage(specificstorage,my):
priv.storage),
command:removeDocument(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
/**
......@@ -183,7 +182,7 @@
jioNamespace.storage(specificstorage,my):
priv.storage),
command:getDocumentList(
{path:path,option:option})},my));
{path:path,option:option},my)},my));
};
return that;
......
......@@ -20,6 +20,7 @@ var jioNamespace = (function(spec, my) {
*/
that.storage = function(spec, my, forcetype) {
spec = spec || {};
my = my || {};
var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) {
throw invalidStorageType({type:type,
......
......@@ -11,7 +11,7 @@ var jobManager = (function(spec, my) {
priv.job_a = [];
my.jobManager = that;
my.jobIdHandler = that;
my.jobIdHandler = jobIdHandler;
// Methods //
/**
......
......@@ -14,5 +14,9 @@ var doneStatus = function(spec, my) {
that.canRestart = function() {
return false;
};
that.isDone = function() {
return true;
};
return that;
};
......@@ -19,5 +19,9 @@ var jobStatus = function(spec, my) {
return false;
};
that.isDone = function() {
return false;
};
return that;
};
......@@ -3,8 +3,19 @@ var storageHandler = function(spec, my) {
my = my || {};
var that = storage( spec, my );
that.newCommand = function (method, spec) {
var o = spec || {};
o.label = method;
return command (o, my);
};
that.newStorage = function (spec) {
var o = spec || {};
return jioNamespace.storage (o, my);
};
that.addJob = function (storage,command) {
my.jobManager.addJob ( job({storage:storage, command:command}), my );
my.jobManager.addJob ( job({storage:storage, command:command}, my) );
};
return that;
......
This diff is collapsed.
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