Class: PxnxJruby::ConnectionManager
- Inherits:
-
Object
- Object
- PxnxJruby::ConnectionManager
- Includes:
- Singleton
- Defined in:
- lib/pxnx_jruby/connection_manager.rb
Overview
This class managers the concurrency calls for pxGrid and Nexpose.
Instance Method Summary collapse
-
#initialize ⇒ ConnectionManager
constructor
A new instance of ConnectionManager.
-
#new_connection(ip) ⇒ Object
Adds a new IP to the list.
-
#setup(config_options = {}) ⇒ Object
TODO: This method ABC is too high (c2.com/cgi/wiki?AbcMetric).
Constructor Details
#initialize ⇒ ConnectionManager
Returns a new instance of ConnectionManager.
14 15 16 17 18 19 |
# File 'lib/pxnx_jruby/connection_manager.rb', line 14 def initialize @log = LoggerFactory.getLogger(ConnectionManager.become_java!) @join_list = ThreadSafe::Array.new @connection_pool = nil @scheduler = nil end |
Instance Method Details
#new_connection(ip) ⇒ Object
Adds a new IP to the list.
39 40 41 42 |
# File 'lib/pxnx_jruby/connection_manager.rb', line 39 def new_connection(ip) fail 'The IP address for a new connection cannot be empty!' if ip.nil? || ip.empty? @join_list << ip end |
#setup(config_options = {}) ⇒ Object
TODO: This method ABC is too high (c2.com/cgi/wiki?AbcMetric)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pxnx_jruby/connection_manager.rb', line 22 def setup( = {}) # We can only have a certain number of connections to Nexpose. Generate a pool of connections for realtime or batched scans. @connection_pool = Executors.newFixedThreadPool([:nexpose_connection_max]) # Schedule our "realtime" or batched tasks @scheduler = Rufus::Scheduler.new @scheduler.every [:batch_mode_delay] do begin @log.debug("Scheduler executed. Number of queued connections for scanning is <#{@join_list.size}>.") @connection_pool.submit(PxnxJruby::NexposeConnection.new(@join_list.clone, )) unless @join_list.empty? @join_list.clear rescue Exception => e @log.error("Error when executing the scheduler! The error was <#{e.}> and backtrace was <#{e.backtrace.join("\n")}>.") end end end |