Tue 27 Aug 00:14:56 CEST 2024
This commit is contained in:
		
							parent
							
								
									49b975bdf1
								
							
						
					
					
						commit
						bf52ebc1c5
					
				
							
								
								
									
										61
									
								
								test/test-forkA.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								test/test-forkA.js
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,61 @@
 | 
			
		|||
// Fork, migration, remote signalling
 | 
			
		||||
// Requires test-forkB, too.
 | 
			
		||||
 | 
			
		||||
Aios.Sig.options.debug.send=true;
 | 
			
		||||
 | 
			
		||||
port(DIR.IP('http://localhost:6666'))
 | 
			
		||||
start();
 | 
			
		||||
 | 
			
		||||
function ag (options) {
 | 
			
		||||
  this.child=null;
 | 
			
		||||
  this.master=null;
 | 
			
		||||
  
 | 
			
		||||
  this.act = {
 | 
			
		||||
    init : function () {
 | 
			
		||||
      this.master=true;
 | 
			
		||||
      log('Starting.');
 | 
			
		||||
      sleep(3000);
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    replicate : function () {
 | 
			
		||||
      log('Replicating...');
 | 
			
		||||
      this.child=fork();
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    migrate : function () {
 | 
			
		||||
      var nodes = link(DIR.IP('%'));
 | 
			
		||||
      log('Migrating to '+nodes[0]);
 | 
			
		||||
      if (nodes.length) moveto(DIR.NODE(nodes[0]));
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    killing : function () {
 | 
			
		||||
      log('Killing child...');
 | 
			
		||||
      kill(this.child);
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    wait : function () {
 | 
			
		||||
      log('Waiting ...');
 | 
			
		||||
      if (this.child) sleep(3000); else sleep(1000);
 | 
			
		||||
    },
 | 
			
		||||
    
 | 
			
		||||
    end : function () {
 | 
			
		||||
      log('Terminating.');
 | 
			
		||||
      kill();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  this.trans = {
 | 
			
		||||
    init      : replicate,
 | 
			
		||||
    replicate : function () { return this.child?wait:migrate },
 | 
			
		||||
    migrate   : wait,
 | 
			
		||||
    killing   : end,
 | 
			
		||||
    wait      : function () { return this.child?killing:wait },
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  this.next=init;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
compile(ag);
 | 
			
		||||
 | 
			
		||||
create('ag',{ },2);
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user