Class: Asherah::SessionFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/asherah/session_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(pointer) ⇒ SessionFactory

Returns a new instance of SessionFactory.



8
9
10
11
12
# File 'lib/asherah/session_factory.rb', line 8

def initialize(pointer)
  raise Asherah::Error::BadConfig, Native.last_error if pointer.null?
  @pointer = pointer
  @close_mu = Mutex.new
end

Instance Method Details

#closeObject



21
22
23
24
25
26
27
28
29
# File 'lib/asherah/session_factory.rb', line 21

def close
  ptr = @close_mu.synchronize do
    return if @pointer.null?
    p = @pointer
    @pointer = FFI::Pointer::NULL
    p
  end
  Native.asherah_factory_free(ptr)
end

#closed?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/asherah/session_factory.rb', line 31

def closed?
  @pointer.null?
end

#get_session(partition_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/asherah/session_factory.rb', line 14

def get_session(partition_id)
  raise Asherah::Error::NotInitialized, "factory closed" if @pointer.null?
  id = String(partition_id)
  raise ArgumentError, "partition_id cannot be empty" if id.empty?
  Session.new(Native.asherah_factory_get_session(@pointer, id))
end