Commit 979fca4a authored by Tristan Cavelier's avatar Tristan Cavelier

Jio can now restore older jio instance.

parent 3d2ae5e9
......@@ -15,12 +15,12 @@ module.exports = function(grunt) {
dist: {
src: ['<banner:meta.banner>',
// Wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.top.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/exceptions.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/storages/storageHandler.js>',
// Jio wrapper top
'<file_strip_banner:../../src/<%= pkg.name %>/jio.top.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jio.intro.js>',
// Jio Classes
'<file_strip_banner:../../src/<%= pkg.name %>/commands/command.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/commands/getDocumentList.js>',
......@@ -42,10 +42,10 @@ module.exports = function(grunt) {
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobManager.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jobs/jobRules.js>',
// Jio wrappor bottem
'<file_strip_banner:../../src/<%= pkg.name %>/jio.bottom.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jio.outro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/jioNamespace.js>',
// Wrapper bottom
'<file_strip_banner:../../src/<%= pkg.name %>/wrapper.bottom.js>'],
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js'
}
},
......@@ -87,10 +87,7 @@ module.exports = function(grunt) {
browser: true
},
globals: {
jQuery: true,
sjcl:true,
LocalOrCookieStorage: true,
Base64: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with requireJs
......@@ -112,6 +109,6 @@ module.exports = function(grunt) {
});
// Default task.
grunt.registerTask('default', 'concat min lint qunit');
grunt.registerTask('default', 'concat lint min qunit');
};
......@@ -14,7 +14,9 @@ module.exports = function(grunt) {
concat: {
dist: {
src: ['<banner:meta.banner>',
'<file_strip_banner:../../src/<%= pkg.name %>.js>'],
'<file_strip_banner:../../src/<%= pkg.name %>/intro.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/localStorage.js>',
'<file_strip_banner:../../src/<%= pkg.name %>/outro.js>'],
dest: '../../lib/jio/<%= pkg.name %>.js'
}
},
......@@ -28,7 +30,7 @@ module.exports = function(grunt) {
files: []
},
lint: {
files: ['grunt.js','../../src/<%= pkg.name %>.js']
files: ['grunt.js','../../lib/jio/<%= pkg.name %>.js']
},
watch: {
files: '<config:lint.files>',
......@@ -53,7 +55,7 @@ module.exports = function(grunt) {
sjcl: true,
LocalOrCookieStorage: true,
Base64: true,
JIO: true,
jio: true,
console: true,
unescape: true,
// Needed to avoid "not defined error" with requireJs
......@@ -75,6 +77,6 @@ module.exports = function(grunt) {
});
// Default task.
grunt.registerTask('default', 'lint concat min');
grunt.registerTask('default', 'concat lint min');
};
......@@ -2,11 +2,9 @@
for node in `ls -1` ; do
if [ -d "$node" ] ; then
cd "$node"
printf "\n\033[1m\033[36mgrunt --force -> %s\033[0m\n" "$node"
grunt --force
printf "\n\033[1m\033[36mmake -C %s\033[0m\n" "$node"
make -C "$node"
cd ..
fi
done
This diff is collapsed.
This diff is collapsed.
......@@ -10,9 +10,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 1 : all ok
var newDummyStorageAllOk = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
that.setType('dummyallok');
var that = Jio.storage( spec, my, 'base' );
that.saveDocument = function (command) {
// Tells us that the document is saved.
......@@ -74,7 +72,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 2 : all fail
newDummyStorageAllFail = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallfail');
......@@ -121,7 +119,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 3 : all not found
newDummyStorageAllNotFound = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my );
var that = Jio.storage( spec, my, 'base' );
that.setType('dummyallnotfound');
......@@ -167,7 +165,7 @@
////////////////////////////////////////////////////////////////////////////
// Dummy Storage 4 : all 3 tries
newDummyStorageAll3Tries = function ( spec, my ) {
var that = Jio.storage( {type:'base'}, my ), priv = {};
var that = Jio.storage( spec, my, 'base' ), priv = {};
that.setType('dummyall3tries');
......
auto: grunt
check-syntax: grunt
grunt:
make -C ../../grunt/*_gruntJIO
......@@ -35,4 +35,5 @@ var activityUpdater = (function(spec, my) {
}
};
return that;
}());
\ No newline at end of file
}());
......@@ -103,7 +103,6 @@ var command = function(spec, my) {
};
that.done = function(return_value) {
console.log ('done');
priv.done(return_value);
priv.respond({status:doneStatus(),value:return_value});
priv.end();
......@@ -113,7 +112,6 @@ var command = function(spec, my) {
if (priv.option.max_retry === 0 || priv.tried < priv.option.max_retry) {
priv.retry();
} else {
console.log ('fail');
priv.fail(return_error);
priv.respond({status:failStatus(),error:return_error});
priv.end();
......@@ -142,5 +140,9 @@ var command = function(spec, my) {
option:priv.option};
};
that.canBeRestored = function() {
return true;
};
return that;
};
......@@ -12,5 +12,9 @@ var getDocumentList = function(spec, my) {
storage.getDocumentList(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -12,5 +12,9 @@ var loadDocument = function(spec, my) {
storage.loadDocument(that);
};
that.canBeRestored = function() {
return false;
};
return that;
};
......@@ -3,14 +3,15 @@ var saveDocument = function(spec, my) {
spec = spec || {};
my = my || {};
// Attributes //
var content = spec.content;
var priv = {};
priv.content = spec.content;
// Methods //
that.getLabel = function() {
return 'saveDocument';
};
that.getContent = function() {
return content;
return priv.content;
};
/**
......@@ -19,7 +20,7 @@ var saveDocument = function(spec, my) {
*/
var super_validate = that.validate;
that.validate = function(handler) {
if (typeof content !== 'string') {
if (typeof priv.content !== 'string') {
throw invalidCommandState({command:that,message:'No data to save'});
}
super_validate(handler);
......@@ -29,5 +30,12 @@ var saveDocument = function(spec, my) {
storage.saveDocument(that);
};
var super_serialized = that.serialized;
that.serialized = function() {
var o = super_serialized();
o.content = priv.content;
return o;
};
return that;
};
......@@ -5,37 +5,43 @@
// Attributes //
var priv = {};
var jio_id_array_name = 'jio/id_array';
priv.id = 1;
priv.storage = jioNamespace.storage(spec, that);
priv.id = null;
priv.storage = jioNamespace.storage(spec);
// initialize //
(function () {
priv.init = function() {
// Initialize the jio id and add the new id to the list
var i,
jio_id_a = LocalOrCookieStorage.getItem (jio_id_array_name) || [];
for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1;
if (priv.id === null) {
var i, jio_id_a =
LocalOrCookieStorage.getItem (jio_id_array_name) || [];
priv.id = 1;
for (i = 0; i < jio_id_a.length; i+= 1) {
if (jio_id_a[i] >= priv.id) {
priv.id = jio_id_a[i] + 1;
}
}
jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
activityUpdater.setId(priv.id);
jobManager.setId(priv.id);
}
jio_id_a.push(priv.id);
LocalOrCookieStorage.setItem (jio_id_array_name,jio_id_a);
}());
(function (){
// Start Jio updater, and the jobManager
activityUpdater.setId(priv.id);
activityUpdater.start();
jobManager.setId(priv.id);
jobManager.start();
}());
};
// Methods //
that.start = function() {
priv.init();
activityUpdater.start();
jobManager.start();
};
that.stop = function() {
jobManager.stop();
};
that.close = function() {
activityUpdater.stop();
jobManager.stop();
priv.id = null;
};
that.start();
/**
* Returns the jio id.
......
......@@ -12,11 +12,12 @@ var jioNamespace = (function(spec, my) {
* @method storage
* @param {object} spec The specifications.
* @param {object} my The protected object.
* @param {string} forcetype Force storage type
* @return {object} The storage object.
*/
that.storage = function(spec, my) {
that.storage = function(spec, my, forcetype) {
spec = spec || {};
var type = spec.type || 'base';
var type = forcetype || spec.type || 'base';
if (!storage_type_o[type]) {
throw invalidStorageType({type:type,
message:'Storage does not exists.'});
......
......@@ -122,7 +122,6 @@ var job = function(spec, my) {
* @param {object} job The other job.
*/
that.update = function(job) {
console.log ('updating');
priv.command.setMaxRetry(-1);
priv.command.fail({status:0,statusText:'Replaced',
message:'Job has been replaced by another one.'});
......
......@@ -92,6 +92,7 @@ var jobManager = (function(spec, my) {
if (jio_date < Date.now() - 10000) {
priv.restoreOldJobFromJioId(id);
priv.removeOldJioId(id);
priv.removeJobArrayFromJioId(id);
}
};
......@@ -99,9 +100,12 @@ var jobManager = (function(spec, my) {
var i, jio_job_array;
jio_job_array = LocalOrCookieStorage.getItem('jio/job_array/'+id)||[];
for (i = 0; i < jio_job_array.length; i+= 1) {
that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i]),
command:command(jio_job_array[i].command)}));
var command_o = command(jio_job_array[i].command);
if (command_o.canBeRestored()) {
that.addJob ( job(
{storage:jioNamespace.storage(jio_job_array[i].storage),
command:command_o}));
}
}
};
......@@ -114,6 +118,11 @@ var jobManager = (function(spec, my) {
}
}
LocalOrCookieStorage.setItem('jio/id_array',new_a);
LocalOrCookieStorage.deleteItem('jio/id/'+id);
};
priv.removeJobArrayFromJioId = function(id) {
LocalOrCookieStorage.deleteItem('jio/job_array/'+id);
};
/**
......@@ -138,11 +147,9 @@ var jobManager = (function(spec, my) {
var i;
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() === id) {
console.log ('found');
return true;
}
}
console.log ('not found');
return false;
};
......@@ -174,11 +181,9 @@ var jobManager = (function(spec, my) {
return;
}
}
console.log ('managing '+JSON.stringify (result_a));
for (i = 0; i < result_a.length; i+= 1) {
switch (result_a[i].action) {
case 'eliminate':
console.log ('eliminating');
that.eliminate(result_a[i].job);
break;
case 'update':
......@@ -186,7 +191,6 @@ var jobManager = (function(spec, my) {
priv.copyJobArrayToLocal();
return;
case 'wait':
console.log ('wait');
job.waitForJob(result_a[i].job);
break;
default: break;
......@@ -201,7 +205,6 @@ var jobManager = (function(spec, my) {
for (i = 0; i < priv.job_a.length; i+= 1) {
if (priv.job_a[i].getId() !== job.getId()) {
tmp_a.push(priv.job_a[i]);
console.log ('add: '+priv.job_a[i].getId()+' -> it is not '+job.getId());
}
}
priv.job_a = tmp_a;
......
......@@ -138,30 +138,22 @@ var jobRules = (function(spec, my) {
j2label = job2.getCommand().getLabel();
j1status = (job1.getStatus().getLabel()==='on going'?
'on going':'not on going');
try {
console.log (j1label);
console.log (j2label);
console.log (j1status);
if (priv.action[j1label] &&
priv.action[j1label][j1status] &&
priv.action[j1label][j1status][j2label]) {
return priv.action[j1label][j1status][j2label](job1,job2);
} catch (e) {
if(e.name==='TypeError') {
return priv.default_action(job1,job2);
} else {
throw e;
}
} else {
return priv.default_action(job1,job2);
}
};
priv.canCompare = function(job1,job2) {
var job1label = job1.getCommand().getLabel(),
job2label = job2.getCommand().getLabel();
try {
if (priv.compare[job1label] &&
priv.compare[job2label]) {
return priv.compare[job1label][job2label](job1,job2);
} catch(e) {
if (e.name==='TypeError') {
return priv.default_compare(job1,job2);
} else {
throw e;
}
} else {
return priv.default_compare(job1,job2);
}
};
that.validateJobAccordingToJob = function(job1,job2) {
......
......@@ -49,7 +49,6 @@ var waitStatus = function(spec, my) {
that.canStart = function() {
priv.refreshJobIdArray();
console.log (priv.job_id_a);
return (priv.job_id_a.length === 0 && Date.now() >= priv.threshold);
};
that.canRestart = function() {
......
......@@ -21,6 +21,7 @@ var storage = function(spec, my) {
* @param {object} command The command
*/
that.execute = function(command) {
that.validate(command);
command.executeOn(that);
};
......@@ -34,6 +35,10 @@ var storage = function(spec, my) {
};
that.validate = function(command) {
var mess = that.validateState();
if (mess) {
throw invalidStorage({storage:that,message:mess});
}
command.validate(that);
};
......@@ -59,5 +64,9 @@ var storage = function(spec, my) {
that.saveDocument();
};
that.validateState = function() {
return '';
};
return that;
};
......@@ -12,24 +12,22 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method beforeExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.beforeExecute = function(command,option) {};
that.beforeExecute = function(command) {};
/**
* Execute the command according to this storage.
* @method execute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.execute = function(command,option) {
that.execute = function(command) {
var i;
that.validate(command);
that.beforeExecute(command,option);
that.beforeExecute(command);
for(i = 0; i < priv.storage_a.length; i++) {
priv.storage_a[i].execute(command);
}
that.afterExecute(command,option);
that.afterExecute(command);
};
/**
......@@ -37,10 +35,9 @@ var storageHandler = function(spec, my) {
* Override this function.
* @method afterExecute
* @param {object} command The command.
* @param {object} option Some options.
*/
that.afterExecute = function(command,option) {
that.done();
that.afterExecute = function(command) {
command.done();
};
/**
......
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