tiq 0.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e436fceef44012df5924defa9947216cac33a6703f222a738a0abc56f48c21b
4
- data.tar.gz: b802bf48b8133fce415abc875069ee33eb2e3d362cc8e5043288c534d8caf856
3
+ metadata.gz: 18d6c9646c99ec4a20f1836345ae4d40d2cd2c2e4b13b357f354d41e2a1549d0
4
+ data.tar.gz: 7e9957b6a21ec8aec869b885b14e84b519a2276e070c2406b190f37338b2d287
5
5
  SHA512:
6
- metadata.gz: 6bf88679ecc201e7a814724d8efa5888d8944515325c8d3ec087d4da95d23d8eae66745b941731ea7a195ac94a010f7785687773749de13ba2691baac6757f91
7
- data.tar.gz: 80d673141cf5ea1d7cb213dc6ae0a4fa2c843f10fe4ec373ffa8ccf8c1e897c6d209520ee2ce23b7ad2f2ffad20edfcd8e20ab2455f88de434f4e316bb5eb38d
6
+ metadata.gz: 762d1f49e97bd77ffe029b6f7ebd2c5974b62a75462b2412f2cc930e08c83c58ad9284c774779f31635eeafc2f026de6a4facfb9dc0d6f89e5676f53b8a740c0
7
+ data.tar.gz: e8b7897d8a18d9d932986edc09ac160d744247e31672a3ffc879f2c742528473ca4e554675369bba3fbc0e5f75bda135ee531c34d66fe0b433fd5c3efd1cb874
data/README.md CHANGED
@@ -1,10 +1,6 @@
1
1
  # Tiq
2
2
 
3
3
  <table>
4
- <tr>
5
- <th>Version</th>
6
- <td>0.0.1</td>
7
- </tr>
8
4
  <tr>
9
5
  <th>Github page</th>
10
6
  <td><a href="http://github.com/qadron/tiq">http://github.com/qadron/tiq</a></td>
@@ -19,7 +15,7 @@
19
15
  </tr>
20
16
  <tr>
21
17
  <th>Copyright</th>
22
- <td>2025 <a href="https://ecsypno.com">Ecsypno</a></td>
18
+ <td><a href="mailto:tasos.laskos@gmail.com">Tasos Laskos</a></td>
23
19
  </tr>
24
20
  <tr>
25
21
  <th>License</th>
@@ -27,19 +23,28 @@
27
23
  </tr>
28
24
  </table>
29
25
 
26
+ ## Quadron Overall
27
+
28
+ * [Cuboid](https://github.com/qadron/cuboid) -- Cluster partitioning.
29
+ * -> **[Tiq](https://github.com/qadron/tiq)** -- Clustering solution.
30
+ * [Toq](https://github.com/qadron/toq) -- RPC handling.
31
+ * [Ratkr](https://github.com/qadron/raktr) -- Network connection handling.
32
+
33
+ Also be sure to check-out [dSel](https://github.com/qadron/dsel) for spiffy DSL generation.
34
+
30
35
  ## Synopsis
31
36
 
32
- Tiq is a simple and lightweight clustering solution protocol.
37
+ Tiq is a simple and lightweight clustering solution.
33
38
 
34
- This implementation is based on [Toq](https://github.com/qadron/toq) for Remote Procedure Call needs.
39
+ This implementation is based on [Toq](https://github.com/qadron/toq) to cover Remote Procedure Call needs.
35
40
 
36
41
  ## Concepts
37
42
 
38
- There are a few key concepts in `Tik`:
43
+ There are a few key concepts in `Tiq`:
39
44
 
40
45
  ### Node
41
46
 
42
- `Tik::Node` offers _Node_ representations, _server-side_ presences if you must.
47
+ `Tiq::Node` offers _Node_ representations, _server-side_ presences if you must.
43
48
 
44
49
  To start a _Node_, you need to create a class that inherits from `Tiq::Node`
45
50
  and instantiate it with a URL to bind to.
@@ -67,7 +72,7 @@ node_2 = MySecondNode.new( url: "localhost:9998", peer: 'localhost:9999' )
67
72
 
68
73
  ### Client
69
74
 
70
- `Tik::Client` offers a _Client_ to enable _Node_/User communications.
75
+ `Tiq::Client` offers a _Client_ to enable _Node_/User communications.
71
76
 
72
77
  ```ruby
73
78
  client = MyClient.new( "localhost:9999" )
@@ -123,9 +128,6 @@ every _Node_.
123
128
  class MyNode < Tiq::Node
124
129
  end
125
130
 
126
- class MyClient < Tiq::Client
127
- end
128
-
129
131
  # Set up initial Node.
130
132
  node_1 = MyNode.new( url: "localhost:9999" )
131
133
 
@@ -135,8 +137,7 @@ Tiq::Addon::Attach node_1, :poll do |arguments = nil|
135
137
  end
136
138
 
137
139
  # Interact with the service via a Client.
138
- client_1 = MyClient.new( "localhost:9999" )
139
- Tiq::Addon client_1, :poll, 'ping' do
140
+ Tiq::Addon "localhost:9999", :poll, 'ping' do
140
141
  puts "CLIENT: #{r}"
141
142
  end
142
143
  ```
data/lib/tiq/channel.rb CHANGED
@@ -2,17 +2,16 @@ require 'msgpack'
2
2
  require 'toq'
3
3
 
4
4
  module Tiq
5
- class Channel
5
+ class Channel < Toq::Client
6
6
 
7
7
  def initialize( url, options = {} )
8
8
  host, port = url.split( ':' )
9
- @client = Toq::Client.new( options.merge( host: host, port: port.to_i ) )
9
+ super( options.merge( host: host, port: port.to_i ) )
10
10
  end
11
11
 
12
12
  def method_missing( method, *args, &block )
13
- @client.call( "data.#{method}", *args, &block )
13
+ call( "data.#{method}", *args, &block )
14
14
  end
15
15
 
16
16
  end
17
-
18
17
  end
data/lib/tiq/client.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'msgpack'
2
+ require 'toq'
2
3
 
3
4
  module Tiq
4
5
  class Client < Toq::Client
@@ -1,7 +1,8 @@
1
1
  module Tiq
2
2
 
3
- def self.Addon( node, shortname, *args, &block )
4
- node.call_addon( shortname, *args, &block )
3
+ def self.Addon( client_or_url, shortname, *args, &block )
4
+ client = client_or_url.is_a?( Tiq::Client ) ? client_or_url : Tiq::Client.new( client_or_url )
5
+ client.call_addon( shortname, *args, &block )
5
6
  end
6
7
 
7
8
  module Addon
@@ -32,8 +33,8 @@ class Node
32
33
  @payload = payload
33
34
  end
34
35
 
35
- def call( *aguments, &block )
36
- @payload.call( *aguments, &block )
36
+ def call( *arguments, &block )
37
+ instance_eval { @payload.call *arguments, &block }
37
38
  end
38
39
 
39
40
  # @return [Server::node::Node]
data/lib/tiq/node.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'set'
2
2
  require_relative 'node/data'
3
+ require_relative 'node/addon'
3
4
  require_relative 'channel'
4
5
  require_relative 'client'
5
6
 
@@ -36,7 +37,7 @@ class Node
36
37
  options[:host] ||= host || 'localhost'
37
38
  options[:port] ||= port || 9999
38
39
 
39
- @server = Toq::Server.new( host: options[:host], port: options[:port] )
40
+ @server = Toq::Server.new( options.merge( host: options[:host], port: options[:port] ) )
40
41
  @reactor = @server.reactor
41
42
  @server.add_async_check do |method|
42
43
  # methods that expect a block are async
@@ -98,11 +99,18 @@ class Node
98
99
  end
99
100
 
100
101
  def attach_addon( name, service, options = {} )
101
- @addons[name.to_s] = Addon.new( self, service, options )
102
+ if @addons[name.to_s]
103
+ fail "Add-on already registered with name: #{name}"
104
+ end
105
+ @addons[name.to_s] = Node::Addon.new( self, service, options )
102
106
  nil
103
107
  end
104
108
 
105
109
  def call_addon( name, *arguments )
110
+ if !@addons[name.to_s]
111
+ fail "Add-on not attached with name: #{name}"
112
+ end
113
+
106
114
  @addons[name.to_s].call( *arguments )
107
115
  end
108
116
 
@@ -111,6 +119,10 @@ class Node
111
119
  end
112
120
 
113
121
  def dettach_addon( name )
122
+ if !@addons[name.to_s]
123
+ fail "Add-on not attached with name: #{name}"
124
+ end
125
+
114
126
  @addons.delete name
115
127
  end
116
128
 
data/lib/tiq.rb CHANGED
@@ -4,5 +4,5 @@ require_relative 'tiq/client'
4
4
  require_relative 'tiq/channel'
5
5
 
6
6
  module Tiq
7
- VERSION = '0.1'
7
+ VERSION = '0.2'
8
8
  end
@@ -1 +1,5 @@
1
1
  require 'spec_helper'
2
+
3
+ describe Tiq::Channel do
4
+
5
+ end
@@ -19,13 +19,60 @@ describe 'Tiq::Node::Addon' do
19
19
  end
20
20
 
21
21
  it 'attaches and calls an addon' do
22
- node.attach_addon( 'echo', 'Tiq::Service::Echo' )
22
+ node.attach_addon 'echo', proc { |arguments|
23
+ arguments
24
+ }
23
25
  result = node.call_addon( 'echo', 'hello' )
24
26
  expect( result ).to eq 'hello'
25
27
  end
26
28
 
27
29
  it 'lists addons' do
28
- node.attach_addon( 'echo', 'Tiq::Service::Echo' )
30
+ node.attach_addon 'echo', proc { |arguments|
31
+ arguments
32
+ }
29
33
  expect( node.addons ).to include 'echo'
30
34
  end
35
+
36
+ describe 'Tiq.Addon' do
37
+ it 'calls an Addon to handle the request' do
38
+ Tiq::Addon.Attach( node, 'echo' ) { |arguments|
39
+ arguments
40
+ }
41
+ result = Tiq::Addon( 'localhost:9999', 'echo', 'test' )
42
+ expect( result ).to eq 'test'
43
+ end
44
+ end
45
+
46
+ describe Tiq::Addon do
47
+ describe '.Attach' do
48
+ it 'attaches an Addon' do
49
+ Tiq::Addon.Attach( node, 'echo' ) { |arguments|
50
+ arguments
51
+ }
52
+ result = Tiq::Addon( 'localhost:9999', 'echo', 'test' )
53
+ expect( result ).to eq 'test'
54
+ end
55
+ end
56
+
57
+ describe '.Dettach' do
58
+ it 'dettaches an Addon' do
59
+ Tiq::Addon::Attach( node, 'echo' ) { |arguments|
60
+ arguments
61
+ }
62
+ result = Tiq::Addon( 'localhost:9999', 'echo', 'test' )
63
+ expect( result ).to eq 'test'
64
+
65
+ Tiq::Addon.Dettach( node, 'echo' )
66
+
67
+ result = nil
68
+ begin
69
+ Tiq::Addon( 'localhost:9999', 'echo', 'test' )
70
+ rescue => e
71
+ result = e
72
+ end
73
+
74
+ expect(result.class).to be Toq::Exceptions::RemoteException
75
+ end
76
+ end
77
+ end
31
78
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiq
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Laskos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-10 00:00:00.000000000 Z
11
+ date: 2025-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: msgpack