Class: Dizby::BasicServer

Inherits:
AbstractServer show all
Extended by:
ClassicAttributeAccess
Defined in:
lib/dizby/server/basic.rb

Direct Known Subclasses

TCProtocol::Server, UnixProtocol::Server

Instance Attribute Summary collapse

Attributes inherited from AbstractServer

#log

Instance Method Summary collapse

Methods included from ClassicAttributeAccess

attr_accessor, attr_reader, attr_writer

Methods inherited from AbstractServer

#connect_to, #make_distributed, #spawn_on

Methods included from Configurable

#config_accessor, #config_reader, #config_writer

Constructor Details

#initialize(uri, front, stream, config) ⇒ BasicServer

Returns a new instance of BasicServer.


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dizby/server/basic.rb', line 15

def initialize(uri, front, stream, config)
  super(config) { |msg| "#{uri} : #{msg}" }

  @uri = uri
  @front = front
  @stream = stream

  @exported_uri = Dizby.monitor([@uri])

  @shutdown_pipe = SelfPipe.new(*IO.pipe)
end

Instance Attribute Details

#exported_uri (readonly, private)

Returns the value of attribute exported_uri


91
92
93
# File 'lib/dizby/server/basic.rb', line 91

def exported_uri
  @exported_uri
end

#front (readonly, private)

Returns the value of attribute front


91
92
93
# File 'lib/dizby/server/basic.rb', line 91

def front
  @front
end

#shutdown_pipe (private)

Returns the value of attribute shutdown_pipe


92
93
94
# File 'lib/dizby/server/basic.rb', line 92

def shutdown_pipe
  @shutdown_pipe
end

#stream (private)

Returns the value of attribute stream


92
93
94
# File 'lib/dizby/server/basic.rb', line 92

def stream
  @stream
end

#uri (readonly)

Returns the value of attribute uri


73
74
75
# File 'lib/dizby/server/basic.rb', line 73

def uri
  @uri
end

Instance Method Details

#accept


42
43
44
45
46
47
# File 'lib/dizby/server/basic.rb', line 42

def accept
  readables, = IO.select([stream, shutdown_pipe.read])
  fail LocalServerShutdown if readables.include? shutdown_pipe.read
  log.debug('Accepting connection')
  stream.accept
end

#add_uri_alias(uri)


76
77
78
79
80
81
82
# File 'lib/dizby/server/basic.rb', line 76

def add_uri_alias(uri)
  log.debug("Adding uri alias: #{uri}")

  exported_uri.synchronize do
    exported_uri << uri unless exported_uri.include?(uri)
  end
end

#alive?Boolean

Returns:

  • (Boolean)

49
50
51
52
53
54
55
# File 'lib/dizby/server/basic.rb', line 49

def alive?
  return false unless stream
  return true if stream.ready?

  shutdown
  false
end

#close


27
28
29
30
31
32
33
34
35
# File 'lib/dizby/server/basic.rb', line 27

def close
  log.debug('Closing')
  if stream
    stream.close
    self.stream = nil
  end

  close_shutdown_pipe
end

#close_shutdown_pipe (private)


94
95
96
97
98
99
100
101
# File 'lib/dizby/server/basic.rb', line 94

def close_shutdown_pipe
  return nil unless shutdown_pipe

  log.debug('Closing shutdown pipe')
  shutdown_pipe.close_read
  shutdown_pipe.close_write
  self.shutdown_pipe = nil
end

#here?(uri) ⇒ Boolean

Returns:

  • (Boolean)

84
85
86
# File 'lib/dizby/server/basic.rb', line 84

def here?(uri)
  exported_uri.synchronize { exported_uri.include?(uri) }
end

#shutdown


37
38
39
40
# File 'lib/dizby/server/basic.rb', line 37

def shutdown
  log.debug('Shutting down')
  shutdown_pipe.close_write if shutdown_pipe
end

#to_id(obj)


68
69
70
71
# File 'lib/dizby/server/basic.rb', line 68

def to_id(obj)
  return nil if obj.__id__ == front.__id__
  idconv.to_id(obj)
end

#to_obj(ref)


57
58
59
60
61
62
63
64
65
66
# File 'lib/dizby/server/basic.rb', line 57

def to_obj(ref)
  case ref
  when nil
    front
  when QueryRef
    front[ref.to_s]
  else
    idconv.to_obj(ref)
  end
end