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