Files
sharp-coin/lib/sharp-coin/server.rb
Nick Thomas 00ce004ae5 Skeletor of integrating em-bitcoin with sharpcoin.
The server process actually runs now(!) - although it does nothing
useful.
2011-06-21 22:53:57 +01:00

55 lines
1.3 KiB
Ruby

require 'eventmachine'
require 'thin'
require 'sharp-coin/logging'
require 'sharp-coin/config'
require 'sharp-coin/db'
require 'sharp-coin/interface'
module SharpCoin
# Beating heart of the SharpCoin application. Sets up all the components
# according to the config, handles all the events as needed.
# @author Nick Thomas <nick@lupine.me.uk>
class Server
include Logging
# Create a new server instance. This instance coordinates the various bits
# of SharpCoin to produce a working application.
# @param[
def initialize
DB::setup!(logger)
end
# Start the various services off. This should generally be called inside an
# EM::run { ... } block
def run
@running = true
@http_server = Thin::Server.start(Interface::Web, *(Config::http_bind))
@telnet_server = EM::start_server(
Config::telnet_host,
Config::telnet_port,
Interface::Telnet
)
@bitcoin_node = Interface::Bitcoin.run(EM, Config)
end
# @return[Boolean] Is this server instance currently running?
def running?
@running == true
end
# Stop the various services.
def stop
@bitcoin_node.stop
EM::stop_server(@http_server)
EM::stop_server(@telnet_server)
@running = false
EM::stop
end
end
end