palta 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/bin/palta.rb +36 -0
- data/examples/basic.rb +27 -0
- data/lib/palta/client.rb +17 -0
- data/lib/palta/core.rb +8 -0
- data/lib/palta/server.rb +56 -0
- data/lib/palta/version.rb +3 -0
- data/lib/palta.rb +7 -0
- data/palta.gemspec +23 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bafb31735c22c19de6c20ee038932f8f24c5b6e5
|
4
|
+
data.tar.gz: 7ed043730ebeaf39a2e532b772f6a8c94421b9e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9477cc46257912bd83d2e67daf893a6f8923d99812d42f049fbd4c02c136ec96491e69d4d2c395d6c08fe546da5ebd741f5eddf653c9d6b8d019ac373cc9e5da
|
7
|
+
data.tar.gz: f3178804358b52aba7ffb540879dd3d99d2c41079097f081352da8c24c9a63e9719feeeea43472b76935850a6332e1ba4a032b4f82c3451f9916c045f51f9e42
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ignacio Contreras Pinilla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Palta
|
2
|
+
|
3
|
+
Simple server for simple (remote) logging. Right now it's just an experimental work in progress.
|
4
|
+
|
5
|
+
It receives messages and triggers actions.
|
6
|
+
|
7
|
+
The criteria should be fully customizable and it should be able to work via TCP and UDP (HTTP too?).
|
8
|
+
|
9
|
+
## Planned Usage
|
10
|
+
|
11
|
+
It's *planned*, it means *not implemented*. ;\*
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require "palta"
|
15
|
+
|
16
|
+
server = Palta::Server.new
|
17
|
+
|
18
|
+
server.actions do
|
19
|
+
|
20
|
+
def on_info msg
|
21
|
+
puts "relax: #{msg}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_warning msg
|
25
|
+
puts "just saying: #{msg}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_error msg
|
29
|
+
puts "oops: #{msg}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
server.start
|
35
|
+
```
|
data/Rakefile
ADDED
data/bin/palta.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'palta'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: palta.rb [options]"
|
10
|
+
|
11
|
+
opts.on("-v", "--verbose", "Run verbosely") do |v|
|
12
|
+
options[:verbose] = v
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-h", "--host", "Set the address to bind. Defaults to 'localhost'") do |h|
|
16
|
+
options[:host] = h
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-p", "--port", Integer, "Set the port to run. Defaults to 8888") do |p|
|
20
|
+
options[:port] = p
|
21
|
+
end
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
server = Palta::Server.new options
|
25
|
+
server.start
|
26
|
+
puts "[palta.rb] Server started!"
|
27
|
+
|
28
|
+
begin
|
29
|
+
loop do
|
30
|
+
end
|
31
|
+
rescue Interrupt => e
|
32
|
+
puts "[palta.rb] stopping the server"
|
33
|
+
server.stop
|
34
|
+
puts "[palta.rb] main thread stopped"
|
35
|
+
|
36
|
+
end
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "./palta"
|
2
|
+
|
3
|
+
server = Palta::Server.new({
|
4
|
+
:debug => true,
|
5
|
+
:dir => "./.palta/data",
|
6
|
+
:host => "localhost",
|
7
|
+
:port => 8888,
|
8
|
+
:max_threads => 8
|
9
|
+
})
|
10
|
+
|
11
|
+
server.actions do
|
12
|
+
|
13
|
+
def on_error msg
|
14
|
+
puts "on_error: #{msg}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_warning msg
|
18
|
+
puts "on_warning: #{msg}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_info msg
|
22
|
+
puts "on_info: #{msg}"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
server.start
|
data/lib/palta/client.rb
ADDED
data/lib/palta/core.rb
ADDED
data/lib/palta/server.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "palta/core"
|
2
|
+
require "socket"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
module Palta
|
6
|
+
|
7
|
+
class Server
|
8
|
+
|
9
|
+
def initialize options = {}
|
10
|
+
@host = options[:host] || "localhost"
|
11
|
+
@port = options[:port] || 8888
|
12
|
+
@debug = options[:debug] || options[:verbose] || false
|
13
|
+
@dir = options[:dir] || "./.palta/data"
|
14
|
+
@max_threads = options[:max_threads] || 8
|
15
|
+
@threads = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def actions &block
|
19
|
+
instance_eval(&block) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def on_msg msg
|
23
|
+
on_any(msg)
|
24
|
+
send("on_#{msg[:type]}", msg)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_any msg
|
28
|
+
puts "on_any: #{msg}"
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
@server = TCPServer.new @host, @port
|
33
|
+
@max_threads.times do |i|
|
34
|
+
@threads << Thread.new do
|
35
|
+
loop do
|
36
|
+
client = @server.accept
|
37
|
+
data = client.recv(1024)
|
38
|
+
if @debug
|
39
|
+
puts "[Palta::Server] thread #{i} recv: #{data}"
|
40
|
+
end
|
41
|
+
msg = JSON.parse(data, :symbolize_names => true)
|
42
|
+
on_msg(msg)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def stop
|
49
|
+
@threads.each do |t|
|
50
|
+
Thread.kill(t)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
data/lib/palta.rb
ADDED
data/palta.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'palta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "palta"
|
8
|
+
spec.version = Palta::VERSION
|
9
|
+
spec.authors = ["Ignacio Contreras Pinilla"]
|
10
|
+
spec.email = ["ignacio@ignacio.cat"]
|
11
|
+
spec.description = %q{Simple server for simple (remote) logging}
|
12
|
+
spec.summary = %q{Simple Ruby server made for logging remote messages and triggering actions according to customizable criteria}
|
13
|
+
spec.homepage = "http://github.com/ignc/palta"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: palta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ignacio Contreras Pinilla
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Simple server for simple (remote) logging
|
42
|
+
email:
|
43
|
+
- ignacio@ignacio.cat
|
44
|
+
executables:
|
45
|
+
- palta.rb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/palta.rb
|
55
|
+
- examples/basic.rb
|
56
|
+
- lib/palta.rb
|
57
|
+
- lib/palta/client.rb
|
58
|
+
- lib/palta/core.rb
|
59
|
+
- lib/palta/server.rb
|
60
|
+
- lib/palta/version.rb
|
61
|
+
- palta.gemspec
|
62
|
+
homepage: http://github.com/ignc/palta
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.3
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Simple Ruby server made for logging remote messages and triggering actions
|
86
|
+
according to customizable criteria
|
87
|
+
test_files: []
|