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


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

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


89
90
91
# File 'lib/dizby/server/basic.rb', line 89

def exported_uri
  @exported_uri
end

#front (readonly, private)

Returns the value of attribute front


89
90
91
# File 'lib/dizby/server/basic.rb', line 89

def front
  @front
end

#shutdown_pipe (private)

Returns the value of attribute shutdown_pipe


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

def shutdown_pipe
  @shutdown_pipe
end

#stream (private)

Returns the value of attribute stream


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

def stream
  @stream
end

#uri (readonly)

Returns the value of attribute uri


71
72
73
# File 'lib/dizby/server/basic.rb', line 71

def uri
  @uri
end

Instance Method Details

#accept


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

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)


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

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


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

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

  shutdown
  false
end

#close


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

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

  close_shutdown_pipe
end

#close_shutdown_pipe (private)


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

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


82
83
84
# File 'lib/dizby/server/basic.rb', line 82

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

#shutdown


35
36
37
38
# File 'lib/dizby/server/basic.rb', line 35

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

#to_id(obj)


66
67
68
69
# File 'lib/dizby/server/basic.rb', line 66

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

#to_obj(ref)


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

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