How to use initialize method of Monitor Package

Best Test-prof_ruby code snippet using Monitor.initialize

AccumulatingProgressMonitor.rb

Source:AccumulatingProgressMonitor.rb Github

copy

Full Screen

...92 # Create a new collector.93 # @param subTask94 # @param work95 # @param monitor96 def initialize(sub_task, work, monitor)97 @sub_task = nil98 @worked = 0.099 @monitor = nil100 @sub_task = sub_task101 @worked = work102 @monitor = monitor103 end104 105 typesig { [::Java::Double] }106 # Add worked to the work.107 # @param workedIncrement108 def worked(worked_increment)109 @worked = @worked + worked_increment110 end111 112 typesig { [String] }113 # Set the subTask name.114 # @param subTaskName115 def sub_task(sub_task_name)116 @sub_task = sub_task_name117 end118 119 typesig { [] }120 # Run the collector.121 def run122 clear_collector(self)123 if (!(@sub_task).nil?)124 @monitor.sub_task(@sub_task)125 end126 if (@worked > 0)127 @monitor.internal_worked(@worked)128 end129 end130 131 private132 alias_method :initialize__collector, :initialize133 end }134 }135 136 typesig { [IProgressMonitor, Display] }137 # Creates an accumulating progress monitor wrapping the given one138 # that uses the given display.139 # 140 # @param monitor the actual progress monitor to be wrapped141 # @param display the SWT display used to forward the calls142 # to the wrapped progress monitor143 def initialize(monitor, display)144 @display = nil145 @collector = nil146 @current_task = nil147 super(monitor)148 @current_task = ""149 Assert.is_not_null(display)150 @display = display151 end152 153 typesig { [String, ::Java::Int] }154 # (non-Javadoc)155 # Method declared on IProgressMonitor.156 def begin_task(name, total_work)157 synchronized((self)) do158 @collector = nil159 end160 @display.async_exec(Class.new(Runnable.class == Class ? Runnable : Object) do161 local_class_in AccumulatingProgressMonitor162 include_class_members AccumulatingProgressMonitor163 include Runnable if Runnable.class == Module164 165 typesig { [] }166 define_method :run do167 self.attr_current_task = name168 get_wrapped_progress_monitor.begin_task(name, total_work)169 end170 171 typesig { [Vararg.new(Object)] }172 define_method :initialize do |*args|173 super(*args)174 end175 176 private177 alias_method :initialize_anonymous, :initialize178 end.new_local(self))179 end180 181 typesig { [Collector] }182 # Clears the collector object used to accumulate work and subtask calls183 # if it matches the given one.184 # @param collectorToClear185 def clear_collector(collector_to_clear)186 synchronized(self) do187 # Check if the accumulator is still using the given collector.188 # If not, don't clear it.189 if ((@collector).equal?(collector_to_clear))190 @collector = nil191 end192 end193 end194 195 typesig { [String, ::Java::Double] }196 # Creates a collector object to accumulate work and subtask calls.197 # @param subTask198 # @param work199 def create_collector(sub_task, work)200 @collector = Collector.new_local(self, sub_task, work, get_wrapped_progress_monitor)201 @display.async_exec(@collector)202 end203 204 typesig { [] }205 # (non-Javadoc)206 # Method declared on IProgressMonitor.207 def done208 synchronized((self)) do209 @collector = nil210 end211 @display.async_exec(Class.new(Runnable.class == Class ? Runnable : Object) do212 local_class_in AccumulatingProgressMonitor213 include_class_members AccumulatingProgressMonitor214 include Runnable if Runnable.class == Module215 216 typesig { [] }217 define_method :run do218 get_wrapped_progress_monitor.done219 end220 221 typesig { [Vararg.new(Object)] }222 define_method :initialize do |*args|223 super(*args)224 end225 226 private227 alias_method :initialize_anonymous, :initialize228 end.new_local(self))229 end230 231 typesig { [::Java::Double] }232 # (non-Javadoc)233 # Method declared on IProgressMonitor.234 def internal_worked(work)235 synchronized(self) do236 if ((@collector).nil?)237 create_collector(nil, work)238 else239 @collector.worked(work)240 end241 end242 end243 244 typesig { [String] }245 # (non-Javadoc)246 # Method declared on IProgressMonitor.247 def set_task_name(name)248 synchronized((self)) do249 @collector = nil250 end251 @display.async_exec(Class.new(Runnable.class == Class ? Runnable : Object) do252 local_class_in AccumulatingProgressMonitor253 include_class_members AccumulatingProgressMonitor254 include Runnable if Runnable.class == Module255 256 typesig { [] }257 define_method :run do258 self.attr_current_task = name259 get_wrapped_progress_monitor.set_task_name(name)260 end261 262 typesig { [Vararg.new(Object)] }263 define_method :initialize do |*args|264 super(*args)265 end266 267 private268 alias_method :initialize_anonymous, :initialize269 end.new_local(self))270 end271 272 typesig { [String] }273 # (non-Javadoc)274 # Method declared on IProgressMonitor.275 def sub_task(name)276 synchronized(self) do277 if ((@collector).nil?)278 create_collector(name, 0)279 else280 @collector.sub_task(name)281 end282 end283 end284 285 typesig { [::Java::Int] }286 # (non-Javadoc)287 # Method declared on IProgressMonitor.288 def worked(work)289 synchronized(self) do290 internal_worked(work)291 end292 end293 294 typesig { [] }295 # (non-Javadoc)296 # @see org.eclipse.core.runtime.ProgressMonitorWrapper#clearBlocked()297 def clear_blocked298 # If this is a monitor that can report blocking do so.299 # Don't bother with a collector as this should only ever300 # happen once and prevent any more progress.301 pm = get_wrapped_progress_monitor302 if (!(pm.is_a?(IProgressMonitorWithBlocking)))303 return304 end305 @display.async_exec(Class.new(Runnable.class == Class ? Runnable : Object) do306 local_class_in AccumulatingProgressMonitor307 include_class_members AccumulatingProgressMonitor308 include Runnable if Runnable.class == Module309 310 typesig { [] }311 # (non-Javadoc)312 # @see java.lang.Runnable#run()313 define_method :run do314 (pm).clear_blocked315 Dialog.get_blocked_handler.clear_blocked316 end317 318 typesig { [Vararg.new(Object)] }319 define_method :initialize do |*args|320 super(*args)321 end322 323 private324 alias_method :initialize_anonymous, :initialize325 end.new_local(self))326 end327 328 typesig { [IStatus] }329 # (non-Javadoc)330 # @see org.eclipse.core.runtime.ProgressMonitorWrapper#setBlocked(org.eclipse.core.runtime.IStatus)331 def set_blocked(reason)332 # If this is a monitor that can report blocking do so.333 # Don't bother with a collector as this should only ever334 # happen once and prevent any more progress.335 pm = get_wrapped_progress_monitor336 if (!(pm.is_a?(IProgressMonitorWithBlocking)))337 return338 end339 @display.async_exec(Class.new(Runnable.class == Class ? Runnable : Object) do340 local_class_in AccumulatingProgressMonitor341 include_class_members AccumulatingProgressMonitor342 include Runnable if Runnable.class == Module343 344 typesig { [] }345 # (non-Javadoc)346 # @see java.lang.Runnable#run()347 define_method :run do348 (pm).set_blocked(reason)349 # Do not give a shell as we want it to block until it opens.350 Dialog.get_blocked_handler.show_blocked(pm, reason, self.attr_current_task)351 end352 353 typesig { [Vararg.new(Object)] }354 define_method :initialize do |*args|355 super(*args)356 end357 358 private359 alias_method :initialize_anonymous, :initialize360 end.new_local(self))361 end362 363 private364 alias_method :initialize__accumulating_progress_monitor, :initialize365 end366 367end...

Full Screen

Full Screen

data_structures.rb

Source:data_structures.rb Github

copy

Full Screen

...11 module ThreadSafe12 module Util13 def self.make_synchronized_on_cruby(klass)14 klass.class_eval do15 def initialize(*args, &block)16 @_monitor = Monitor.new17 super18 end19 def initialize_copy(other)20 # make sure a copy is not sharing a monitor with the original object!21 @_monitor = Monitor.new22 super23 end24 end25 klass.superclass.instance_methods(false).each do |method|26 klass.class_eval <<-RUBY, __FILE__, __LINE__ + 127 def #{method}(*args)28 monitor = @_monitor29 monitor or raise("BUG: Internal monitor was not properly initialized. Please report this to the concurrent-ruby developers.")30 monitor.synchronize { super }31 end32 RUBY33 end34 end35 def self.make_synchronized_on_rbx(klass)36 klass.class_eval do37 private38 def _mon_initialize39 @_monitor ||= Monitor.new # avoid double initialisation40 end41 def self.new(*args)42 obj = super(*args)43 obj.send(:_mon_initialize)44 obj45 end46 end47 klass.superclass.instance_methods(false).each do |method|48 case method49 when :new_range, :new_reserved50 klass.class_eval <<-RUBY, __FILE__, __LINE__ + 151 def #{method}(*args)52 obj = super53 obj.send(:_mon_initialize)54 obj55 end56 RUBY57 else58 klass.class_eval <<-RUBY, __FILE__, __LINE__ + 159 def #{method}(*args)60 monitor = @_monitor61 monitor or raise("BUG: Internal monitor was not properly initialized. Please report this to the concurrent-ruby developers.")62 monitor.synchronize { super }63 end64 RUBY65 end66 end67 end68 def self.make_synchronized_on_truffleruby(klass)69 klass.superclass.instance_methods(false).each do |method|70 klass.class_eval <<-RUBY, __FILE__, __LINE__ + 171 def #{method}(*args, &block) 72 TruffleRuby.synchronized(self) { super(*args, &block) }73 end74 RUBY75 end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Test-prof_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful