vis.js is a dynamic, browser-based visualization library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB

10 years ago
  1. 'use strict';
  2. if (typeof window === 'undefined') {
  3. var eve = require('evejs');
  4. }
  5. function GenericAgent(id, type) {
  6. // execute super constructor
  7. eve.Agent.call(this, id);
  8. this.id = id;
  9. this.rpc = this.loadModule('rpc', this.rpcFunctions);
  10. this.connect(eve.system.transports.getAll());
  11. this.type = type;
  12. this.jobs = new JobManager(this);
  13. this.timelineDataset = timelineItems;
  14. timelineGroups.add({id:id, content:type + ": " + id, className: 'timelineGroup ' + type});
  15. this.availableSubgroups = [0,1,2,3,4,5,6,7,8,9,10];
  16. this.freeSubgroups = {};
  17. for (var i = 0; i < this.availableSubgroups.length; i++) {
  18. this.freeSubgroups[this.availableSubgroups[i]] = true;
  19. }
  20. this.usedSubgroups = {};
  21. }
  22. // extend the eve.Agent prototype
  23. GenericAgent.prototype = Object.create(eve.Agent.prototype);
  24. GenericAgent.prototype.constructor = GenericAgent;
  25. // define RPC functions, preferably in a separated object to clearly distinct
  26. // exposed functions from local functions.
  27. GenericAgent.prototype.rpcFunctions = {};
  28. GenericAgent.prototype.allocateSubgroup = function(type) {
  29. for (var i = 0; i < this.availableSubgroups.length; i++) {
  30. if (this.freeSubgroups[this.availableSubgroups[i]] == true) {
  31. this.usedSubgroups[type] = i;
  32. this.freeSubgroups[this.availableSubgroups[i]] = false;
  33. break;
  34. }
  35. }
  36. };
  37. GenericAgent.prototype.freeSubgroup = function(type) {
  38. this.freeSubgroups[this.usedSubgroups[type]] = true;
  39. delete this.usedSubgroups[type];
  40. };
  41. GenericAgent.prototype.newAssignment = function(id, type, time, prerequisites) {
  42. this.allocateSubgroup(type);
  43. this.jobs.add(id, type, time, prerequisites);
  44. };
  45. /**
  46. * @param id
  47. * @param time
  48. * @param type
  49. */
  50. GenericAgent.prototype.finishAssignment = function(id, type, time) {
  51. this.jobs.finish(id, type, time);
  52. };
  53. GenericAgent.prototype.updateAssignment = function(id, type, time, operation) {
  54. this.jobs.update(id, type, time, operation);
  55. };
  56. GenericAgent.prototype.rpcFunctions.newEvent = function(params) {
  57. // handle events
  58. if (params.operation == 'start') {
  59. this.newAssignment(params.jobId, params.assignment, params.time, params.prerequisites)
  60. }
  61. else if (params.operation == 'finish') {
  62. this.finishAssignment(params.jobId, params.assignment, params.time);
  63. }
  64. else if (params.operation == 'pause' || params.operation == 'resume') {
  65. this.updateAssignment(params.jobId,params.assignment,params.time, params.operation);
  66. }
  67. };
  68. if (typeof window === 'undefined') {
  69. module.exports = GenericAgent;
  70. }