Class: Omnizip::Models::ParallelOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/models/parallel_options.rb

Overview

Model for parallel processing configuration

Stores settings for parallel compression and extraction operations including thread count, queue size, and load balancing strategy.

Examples:

Create parallel options

options = Omnizip::Models::ParallelOptions.new
options.threads = 8
options.queue_size = 100
options.strategy = :dynamic

Use with parallel compression

Omnizip::Parallel.compress_directory('files/', 'backup.zip', options)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParallelOptions

Initialize parallel options with default values



38
39
40
41
42
43
44
45
# File 'lib/omnizip/models/parallel_options.rb', line 38

def initialize
  @threads = detect_cpu_count
  @queue_size = 1000
  @chunk_size = 64 * 1024 * 1024 # 64MB default
  @strategy = :dynamic
  @verbose = false
  @batch_size = 10
end

Instance Attribute Details

#batch_sizeInteger

Returns Batch size for work queue polling.

Returns:

  • (Integer)

    Batch size for work queue polling



35
36
37
# File 'lib/omnizip/models/parallel_options.rb', line 35

def batch_size
  @batch_size
end

#chunk_sizeInteger

Returns Chunk size for chunked operations in bytes.

Returns:

  • (Integer)

    Chunk size for chunked operations in bytes



26
27
28
# File 'lib/omnizip/models/parallel_options.rb', line 26

def chunk_size
  @chunk_size
end

#queue_sizeInteger

Returns Maximum size of job queue (default: 1000).

Returns:

  • (Integer)

    Maximum size of job queue (default: 1000)



23
24
25
# File 'lib/omnizip/models/parallel_options.rb', line 23

def queue_size
  @queue_size
end

#strategySymbol

Returns Load balancing strategy (:dynamic or :static).

Returns:

  • (Symbol)

    Load balancing strategy (:dynamic or :static)



29
30
31
# File 'lib/omnizip/models/parallel_options.rb', line 29

def strategy
  @strategy
end

#threadsInteger

Returns Number of worker threads (default: auto-detect).

Returns:

  • (Integer)

    Number of worker threads (default: auto-detect)



20
21
22
# File 'lib/omnizip/models/parallel_options.rb', line 20

def threads
  @threads
end

#verboseBoolean

Returns Enable verbose progress output.

Returns:

  • (Boolean)

    Enable verbose progress output



32
33
34
# File 'lib/omnizip/models/parallel_options.rb', line 32

def verbose
  @verbose
end

Instance Method Details

#apply(attributes) ⇒ self

Apply a hash of attributes to this options object. Only keys that correspond to known writers (+threads=+, queue_size=, etc.) are applied; unknown keys are silently ignored.

Parameters:

  • attributes (Hash{Symbol=>Object})

    attributes to set

Returns:

  • (self)


69
70
71
72
73
74
75
76
# File 'lib/omnizip/models/parallel_options.rb', line 69

def apply(attributes)
  SETTERS.each do |key, setter|
    next unless attributes.key?(key)

    public_send(setter, attributes[key])
  end
  self
end

#dupParallelOptions

Create a copy of options

Returns:



91
92
93
94
95
96
97
98
99
100
# File 'lib/omnizip/models/parallel_options.rb', line 91

def dup
  copy = self.class.new
  copy.threads = threads
  copy.queue_size = queue_size
  copy.chunk_size = chunk_size
  copy.strategy = strategy
  copy.verbose = verbose
  copy.batch_size = batch_size
  copy
end

#to_hHash

Convert to hash

Returns:

  • (Hash)

    options as hash



105
106
107
108
109
110
111
112
113
114
# File 'lib/omnizip/models/parallel_options.rb', line 105

def to_h
  {
    threads: threads,
    queue_size: queue_size,
    chunk_size: chunk_size,
    strategy: strategy,
    verbose: verbose,
    batch_size: batch_size,
  }
end

#validate!Boolean

Validate options

Returns:

  • (Boolean)

    true if valid

Raises:

  • (ArgumentError)

    if options are invalid



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/omnizip/models/parallel_options.rb', line 51

def validate!
  raise ArgumentError, "threads must be > 0" if threads <= 0
  raise ArgumentError, "queue_size must be > 0" if queue_size <= 0
  raise ArgumentError, "chunk_size must be > 0" if chunk_size <= 0
  raise ArgumentError, "strategy must be :dynamic or :static" unless %i[
    dynamic static
  ].include?(strategy)
  raise ArgumentError, "batch_size must be > 0" if batch_size <= 0

  true
end