5 $DEBUG = true # This is a Global Variable Useful for Debugging
7 ###########################################################################
9 ###########################################################################
11 Thread.abort_on_exception = true
12 attr_accessor :permits
14 def initialize ( permits )
20 raise "Interrupted Thread " if (!Thread.current.alive?)
26 @permits = @permits - 1
39 ########################################################################
41 ########################################################################
42 class RbProcess < Thread
45 attr_accessor :bind, :id, :properties, :name,
46 :pargs, :schedBegin, :schedEnd, :mutex, :cv
48 # Initialize : Used from ApplicationHandler to fill it in
53 if argc == 0 # Default initializer
62 puts "Init Default Initializer...Nothing to do...Bye"
66 # 2 arguments: (HostName,Name) Or (Host , Name)
70 if ( type.to_s == "String")
71 host = Host.getByName(args[0])
72 elsif ( type.to_s == "MSG::Host")
75 raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
80 raise "Process name cannot be null" if args[1].empty?
85 @pargs = Array.new() # No Args[] Passed in Arguments
90 createProcess(self,host)
92 puts "Initilize with 2 args"
96 # 3 arguments: (hostName,Name,args[]) or (Host,Name,args[])
100 if ( type.to_s == "String")
101 host = Host.getByName(args[0])
102 elsif ( type.to_s == "MSG::Host")
105 raise "first argument of type "+args[0].type().to_s+", but expecting either String or MSG::Host"
111 raise "Process name cannot be null" if args[1].empty?
113 type = args[2].type()
114 raise "Third argument should be an Array" if type != "Array"
117 @id = @@nextProcessId
119 createProcess(self,host)
122 puts "Initilize with 3 args"
125 # sleep #keep the thread running
128 raise "Bad number of argument: Expecting either 1, 2 or 3, but got "+argc
132 # Init_var Called By Initialize
134 @proprieties = Hash.new()
136 @cv = ConditionVariable.new
137 # Process Synchronization Tools
138 @schedBegin = Semaphore.new(0)
139 @schedEnd = Semaphore.new(0)
144 # To Be Implemented within The Process...
145 # The Main Code of The Process to be Executed ...
148 # Start : To keep the Process Alive and waitin' via semaphore
150 @schedBegin.acquire(@mutex,@cv)
151 #execute The Main Code of The Process ( Example Master ; Slave ...)
153 processExit(self) #Exite the Native Process
154 @schedEnd.release(@mutex,@cv)
160 return @@nextProcessId
166 Thread.list.each {|t| p t}
181 def processID(process)
191 def processName(process)
207 @schedEnd.release(@mutex,@cv)
208 # info("@schedEnd.release(@mutex,@cv)")
209 @schedBegin.acquire(@mutex,@cv)
210 # info("@schedBegin.acquire(@mutex,@cv)")
215 @schedBegin.release(@mutex,@cv)
216 @schedEnd.acquire(@mutex,@cv)
219 #C Simualateur Process Equivalent Management
220 # After Binding Ruby Process to C Process
234 processIsSuspended(self)
242 # The Rest of Methods !!! To be Continued ...
245 ########################################################################
246 # Class ProcessFactory
247 ########################################################################
252 attr_accessor :args, :proprieties, :hostName, :function
257 @proprieties = Hash.new
264 def setProcessIdentity(hostName,function)
272 if !proprieties.empty?
279 def registerProcessArg(arg)
288 process = rubyNewInstance(@function) # process = rubyNewInstanceArgs(@function,@args) #
291 process.pargs.push(@args[i])
293 process.name = @function
294 process.id = process.nextId() # This increment Automaticaly The Static ProcessNextId for The Class RbProces
295 host = RbHost.getByName(@hostName)
296 processCreate(process,host)
297 process.properties = @properties
298 @proprieties = Hash.new
303 def setProperty(id,value)
304 @proprieties[id] = value
308 #########################################################################
309 # Class ApplicationHandler
310 #########################################################################
311 class ApplicationHandler
319 def onStartDocument()
321 @processFactory = ProcessFactory.new
323 puts "onStartDocument"
329 def onBeginProcess(hostName,function)
331 @processFactory.setProcessIdentity(hostName,function)
334 puts "onBeginProcess"
340 def onProperty(id,value)
342 @processFactory.setProperty(id,value)
351 def onProcessArg(arg)
353 @processFactory.registerProcessArg(arg)
364 @processFactory.createProcess()
374 # Erm... Actually nothing to do !!
384 #########################
386 #########################
390 attr_accessor :bind, :data
401 #########################
403 #########################
407 def initialize(name,comp_size,comm_size)
408 super(name,comp_size,comm_size)
413 #########################
415 #########################