[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: question about capsule's lifetime



> Hi,tim
> 
> 	You have told me,the evaluate() method can execute arbitrary java
> code so it will wait as long as I want.But I encountered troubles.I want
> to poll a log file until the data I want. So I wrote the following lines
> in evaluate(),
> 
>   {
>     synchronized( this )
>     {
>     while( !file.isReady() )
>       {
> 		this.wait(1000); // Wait one second before testing again...
>       }
>     next=read(file)//get the next hop addr
> 	node.routeForNode(cap,next);
> 	
>     }
>   }
> But it cannot always work properly.If the file is ready within the first
> 11 loops,everything is ok.But if it cannot,the capsule wouldnot be sent
> out.And no error was prompt.
> 
> 
>     Later,you told me to use Node.EventHandler.So I write a class
> LogReader extending Node.EventHandler whose main work is polling and
> then reading the file.When arrives a node,the capsule inserts an
> instance of LogReader to the node cache.If LogReader find the
> information ,it calls the Node.routeForNode() method to forward the
> capusle according.
> 
> 	class MyCapsule 
> 		extends Capsule {
> 	...
>    
> 		class LogReader 
> 			extends Node.EventHandler {
> 			MyCapsule cap;

                        ^^^ Note that, since this is not a static inner
class it will already have an implicit reference to the enclosing
object.  You can access it with "MyCapsule.this"
>
> 			public int collected() {
> 				if (File.isReady()){
>  					next=read(logfile);
> 					Node.routeForNode(cap,next);
> 					return 0;
> 				}
> 				else
> 			    	return 1;
> 						
> 				 
> 			}
> 		 }
>  	
> 
> 	}
>   
> 	But I encountered the same problem.
> 
> 	So I want to know why this happened. The limitation on capsule's
> CPU consumption?

No, the thread should still execute, it will just take longer, it won't
just die if its using a lot of cpu.

> If it is,where can I find the code? How can I solve
> that problem?

I need more information to help, are you sure the file object is ready in
the scenario that takes > 10 seconds?  Are any exceptions/errors
thrown?  What does file.isReady() do?  Are you sure its not blocking in 
file.isReady() or read()?  Are you sure the next value read from the file
is a valid node address?  Are you sure there isn't some timeout happening
on the receiving end?

> 	thanks.
> 
> 
> woodhead.
> dcsdcs1@mail.jlu.edu.cn
> 2002-06-25

tim stack




[ Janos ] [ OSKit ] [ Network Testbed ] [ Flick ] [ Fluke ]
Flux Research Group / Department of Computer Science / University of Utah