Class: Jettr::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/jettr/server.rb

Defined Under Namespace

Classes: HandlerCollectionProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



10
11
12
13
14
# File 'lib/jettr/server.rb', line 10

def initialize(options={})
  @server = Jetty::Server.new
  @handlers = HandlerCollectionProxy.for(@server)
  configure(options)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/jettr/server.rb', line 5

def config
  @config
end

#handlersObject (readonly)

Returns the value of attribute handlers.



5
6
7
# File 'lib/jettr/server.rb', line 5

def handlers
  @handlers
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/jettr/server.rb', line 5

def server
  @server
end

Instance Method Details

#configure(options_or_file, opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jettr/server.rb', line 16

def configure(options_or_file,opts={})
  @config ||= Configatron::Store.new
  @config.set_default(:name, "ObjectId:#{self.object_id}")
  @config.set_default(:port, 8080)
  @config.set_default(:acceptors, 5)
  @config.thread_pool.set_default(:max, 20)
  @config.thread_pool.set_default(:min, 1)
  @config.shutdown.set_default(:graceful, false)
  @config.shutdown.set_default(:graceful_timeout, 500)
  case options_or_file
  when String then @config.configure_from_yaml(options_or_file,opts)
  when Hash then @config.configure_from_hash(options_or_file)
  end
                                    
  configure_jetty
end

#destroyObject



64
65
66
67
68
# File 'lib/jettr/server.rb', line 64

def destroy
  @server.stop unless stopped?
  @server.destroy()
  @destroyed = true
end

#destroyed?Boolean

Returns:

  • (Boolean)


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

def destroyed?
  @destroyed ||=false
end

#failed?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/jettr/server.rb', line 78

def failed?
  @server.isFailed
end

#joinObject



86
87
88
89
# File 'lib/jettr/server.rb', line 86

def join
  logger.debug "Joining server thread..."
  @server.join
end

#restartObject



54
55
56
57
58
59
60
61
62
# File 'lib/jettr/server.rb', line 54

def restart
  logger.info "Restarting server..."
  stop
  until stopped?
    logger.debug "#restart: waiting for server to stop..."
    sleep 0.2
  end
  start
end

#running?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/jettr/server.rb', line 70

def running?
  @server.isRunning
end

#startObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jettr/server.rb', line 33

def start
  begin
    if stopped?
      logger.info "Starting server..."
      @server.start
    end
  rescue BindException => ex
    stop
    raise ex
  end
end

#stopObject



45
46
47
48
49
50
51
52
# File 'lib/jettr/server.rb', line 45

def stop
  if running? || failed?
    logger.info "Stopping server..."
    @server.stop
  else
    logger.debug "#stop: Server already stopped."
  end
end

#stopped?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/jettr/server.rb', line 74

def stopped?
  @server.isStopped
end