Class: Dcmgr::NodeModules::CustomEventHandler

Inherits:
Trema::EventHandler
  • Object
show all
Includes:
Logger
Defined in:
lib/dcmgr/node_modules/service_openflow.rb

Constant Summary collapse

@@fd_set =
[]

Instance Method Summary collapse

Methods included from Logger

create, default_logdev, included

Instance Method Details

#add_periodic_event_callback(interval, timer) ⇒ Object



706
707
708
709
710
711
712
713
714
715
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 706

def add_periodic_event_callback interval, timer
  logger.debug "Called CustomEventHandler: timer:#{timer.inspect} interval:#{interval}."

  timer.handle.cancel if not timer.handle.nil?

  timer.handle = EventMachine::PeriodicTimer.new(interval) do
    # logger.debug "Calling periodic timer event: timer:#{timer.inspect} interval:#{interval}."
    timer.call
  end
end

#add_timer_event_callback(timer) ⇒ Object



694
695
696
697
698
699
700
701
702
703
704
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 694

def add_timer_event_callback timer
  logger.debug "Called CustomEventHandler: first:#{timer.inspect} interval:#{timer.interval} expiration:#{timer.expiration}."

  timer.handle.cancel if not timer.handle.nil?

  # timer.handle = EventMachine::Timer.new(timer.interval) do
  timer.handle = EventMachine::Timer.new(timer.expiration) do
    logger.debug "Calling timer event: first:#{timer.inspect} interval:#{timer.interval} expiration:#{timer.expiration}."
    timer.call
  end
end

#delete_fd_handler(fd) ⇒ Object



647
648
649
650
651
652
653
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 647

def delete_fd_handler fd
  logger.debug "Called CustomEventHandler delete_fd_handler, #{fd}."
  connection = @@fd_set[ fd ]
  @@fd_set[ fd ] = nil

  connection.detach
end

#delete_timer_event(timer) ⇒ Object



717
718
719
720
721
722
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 717

def delete_timer_event timer
  logger.debug "Called CustomEventHandler: timer:#{timer.inspect}."

  timer.handle.cancel if not timer.handle.nil?
  timer.handle = nil
end

#execute_timer_eventsObject



724
725
726
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 724

def execute_timer_events
  logger.debug "Called CustomEventHandler execute_timer_events."
end

#finalize_event_handlerObject



627
628
629
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 627

def finalize_event_handler
  logger.debug "Called CustomEventHandler finalize_event_handler."
end

#finalize_timerObject



690
691
692
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 690

def finalize_timer
  logger.debug "Called CustomEventHandler finalize_timer."
end

#init_event_handlerObject



623
624
625
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 623

def init_event_handler
  logger.debug "Called CustomEventHandler init_event_handler."
end

#init_timerObject

Timer event handlers:



686
687
688
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 686

def init_timer
  logger.debug "Called CustomEventHandler init_timer."
end

#readable(fd) ⇒ Object



677
678
679
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 677

def readable fd
  logger.debug "Called CustomEventHandler readable, #{fd}."
end

#run_event_handler_onceObject



636
637
638
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 636

def run_event_handler_once
  logger.debug "Called CustomEventHandler run_event_handler_once."
end

#set_fd_handler(fd, connection) ⇒ Object



640
641
642
643
644
645
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 640

def set_fd_handler fd, connection
  logger.debug "Called CustomEventHandler immediate set_fd_handler, #{fd}."
  raise "CustomEventHandler event handler already registered." if not @@fd_set[ fd ].nil?

  @@fd_set[ fd ] = EM.watch fd, EventFdConnection, connection
end

#set_readable(fd, state) ⇒ Object



655
656
657
658
659
660
661
662
663
664
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 655

def set_readable fd, state
  # logger.debug "Called CustomEventHandler set_readable, #{fd}."

  if fd < 0
    logger.error "Called set_readable with negative fd: #{fd}, #{state}."
    return
  end

  @@fd_set[ fd ].notify_readable = state
end

#set_writable(fd, state) ⇒ Object



666
667
668
669
670
671
672
673
674
675
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 666

def set_writable fd, state
  # logger.debug "Called CustomEventHandler set_writable, #{fd}."

  if fd < 0
    logger.error "Called set_writable with negative fd: #{fd}, #{state}."
    return
  end

  @@fd_set[ fd ].notify_writable = state
end

#stop_event_handlerObject



631
632
633
634
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 631

def stop_event_handler
  logger.debug "Called CustomEventHandler stop_event_handler."
  EM.stop
end

#writable(fd) ⇒ Object



681
682
683
# File 'lib/dcmgr/node_modules/service_openflow.rb', line 681

def writable fd
  logger.debug "Called CustomEventHandler writable, #{fd}."
end