-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: writing custom servers is difficult
Basically, it requires duplicating a lot of code that is currently in pumpkindb_server (with respect to mio and putting all the necessary engine elements together) Writing such servers is very useful when one needs to add new built-in functionality to PumpkinDB yet retain its standard communication protocol. Solution: extract pumpkindb_mio_server crate that focuses primarily on the mio part) and let pumpkindb_server handle the rest. Note that this is still requiring one to at least look at pumpkindb_server to implement their own custom server, but this is far better than before. Also, the separation is not very clean, but this will start the ball rolling.
- Loading branch information
Showing
9 changed files
with
102 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "pumpkindb_mio_server" | ||
version = "0.2.0" | ||
license = "MPL-2.0" | ||
repository = "https://github.com/PumpkinDB/PumpkinDB" | ||
homepage = "http://pumpkindb.org" | ||
keywords = [ "pumpkindb", "database" ] | ||
categories = [ "database" ] | ||
|
||
authors = ["Yurii Rashkovskii <yrashk@gmail.com>"] | ||
|
||
[dependencies] | ||
mio = "0.6.4" | ||
byteorder = "1.0.0" | ||
memmap = "0.5.2" | ||
slab = "0.3.0" | ||
num-bigint = "0.1.35" | ||
num-traits = "0.1.36" | ||
rand = "0.3.15" | ||
log = "0.3.6" | ||
log4rs = { version = "0.6.1", features = ["toml_format"] } | ||
lmdb-zero = "0.4.0" | ||
uuid = { version = "0.4", features = ["v4"] } | ||
|
||
pumpkindb_engine = { version = "0.2", path = "../pumpkindb_engine" } |
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2017, All Contributors (see CONTRIBUTORS file) | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
#![feature(slice_patterns, advanced_slice_patterns)] | ||
|
||
extern crate mio; | ||
extern crate memmap; | ||
extern crate byteorder; | ||
extern crate rand; | ||
#[macro_use] | ||
extern crate log; | ||
extern crate log4rs; | ||
extern crate slab; | ||
extern crate num_bigint; | ||
extern crate num_traits; | ||
extern crate lmdb_zero as lmdb; | ||
extern crate uuid; | ||
|
||
extern crate pumpkindb_engine; | ||
|
||
mod connection; | ||
mod server; | ||
|
||
use mio::Poll; | ||
use mio::tcp::TcpListener; | ||
|
||
use mio::channel as mio_chan; | ||
|
||
use pumpkindb_engine::script; | ||
|
||
pub fn run(port: i64, | ||
senders: Vec<script::Sender<script::RequestMessage>>, | ||
relay_sender: mio_chan::Sender<server::RelayedPublishedMessage>, | ||
relay_receiver: mio_chan::Receiver<server::RelayedPublishedMessage>) { | ||
let addr = format!("0.0.0.0:{}", port).parse().unwrap(); | ||
|
||
info!("Listening on {}", addr); | ||
|
||
let sock = TcpListener::bind(&addr).expect("Failed to bind address"); | ||
|
||
let mut poll = Poll::new().expect("Failed to initialize polling"); | ||
|
||
let mut server = server::Server::new(sock, relay_sender, relay_receiver, senders); | ||
server.run(&mut poll).expect("Failed to run server"); | ||
|
||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters