Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: AlexKVal/D2DDB
base: f1cb26fcc4
...
head fork: AlexKVal/D2DDB
compare: 498d4f4b7d
  • 2 commits
  • 13 files changed
  • 0 commit comments
  • 1 contributor
View
1  Version
@@ -0,0 +1 @@
+0.0.1
View
51 central_run_me.rb
@@ -5,55 +5,8 @@
module Central
- FRONT_OBJECT=TimeServer.new
- DRb.start_service(LISTEN_URI, FRONT_OBJECT)
+ DRb.start_service(LISTEN_URI, Dispatcher.new)
+ puts "Now listening: #{DRb.uri}"
DRb.thread.join
-
-
-
-
-
- applier = Applier.new
- while true # here must be server, who will dispatch incoming connections
- # then it will save incoming data into #{filial_code}_prepared_data
- # and then run Applier (in same Thread was receiving data)
-
- # =========================================================
- # here is hackery-emulation receiving data from Filial
- # move data from client PreparedQueue to
- # =========================================================
- puts "incoming connection, receiving."
- received_data = []
- client_data_queue = Filial::PreparedDataQueue.new
-
- client_data_queue.data.each do |pdr|
- received_data << [pdr.id, pdr.tblname, pdr.rowid, pdr.action, pdr.data]
- end
-
- 5.times{print '.'; sleep(1)}
-
- puts "\nreceived_data:"
- rdq = ReceivedDataQueue.new
- saved_ids = rdq.save(received_data)
- client_data_queue.remove_acknowledged_data!(saved_ids)
- p saved_ids
- # =========================================================
- # acknowledged_ids = @remote_object.process_filial_data(@filial_id, data_to_transmit)
-
- # now applier has to insert received data onto central dbase
- puts "\ngot incoming data for _filial_code_"
- puts "#{'='*60}"
- applier.run
- puts "#{'='*60}"
- sleep(3)
-
- # here should be the code preparing and sending data from Central to Filial db
- # puts "\prepare_tracked_data"
- # puts "#{'='*60}"
- # applier.prepare_tracked_data
- # #client.send_tracked_data
- # puts "#{'='*60}"
- # sleep(6)
- end
end
View
6 client_run_me.rb
@@ -1,10 +1,10 @@
SIDE = 'filial'
-require_relative 'lib/client'
+require_relative 'lib/client/client'
module Filial
- client = Client.new(FILIAL_ID)
+ client = Client.new(FILIAL_ID, FILIAL_ALIAS)
client.setup_remote_object(SERVER_URI)
while true
puts "\nget_trackings!"
@@ -21,7 +21,7 @@ module Filial
puts "\nsend_tracked_data"
puts "#{'='*60}"
- client.seconds_wait = SECONDS_WAIT
+ client.seconds_wait = SECONDS_WAIT_SERVER
client.send_tracked_data
puts "#{'='*60}"
sleep 6
View
5 config.rb
@@ -1,10 +1,13 @@
# Filial-side
FILIAL_ID = 'Chab' # used for distinguish connections on server-side
SERVER_URI = 'druby://localhost:8083'
-SECONDS_WAIT = 2
+SECONDS_WAIT_SERVER = 2
+FILIAL_ALIAS = "D2Main.NET"
# Central-side
CENTRAL_ALIAS = "CentrChab.NET" # alias for filial db on central server
CENTRAL_PREFIX = 'chab' # prefix for tables
LISTEN_URI = 'druby://:8083'
+
+# DRb
$SAFE = 1 # disable eval() and friends
View
7 lib/central/applier.rb
@@ -4,13 +4,14 @@
module Central
class Applier
- def initialize(rdq = ReceivedDataQueue.new, stdout = $stdout)
- @received_data_queue = rdq
+ def initialize(pvsw_alias, stdout = $stdout)
+ @received_data_queue = ReceivedDataQueue.new
+ Pvsw.odbc_alias = @pvsw_alias = pvsw_alias
@stdout = stdout
end
def run
- ODBC::connect(CENTRAL_ALIAS) do |dbc|
+ ODBC::connect(@pvsw_alias) do |dbc|
pvsw = Pvsw.new(dbc)
received_rows = @received_data_queue.data
View
29 lib/central/dispatcher.rb
@@ -3,24 +3,33 @@
module Central
# Front object for DRb on server side
class Dispatcher
- def initialize(rdq = ReceivedDataQueue.new, appl = Applier.new, stdout = $stdout)
+ def initialize(rdq = ReceivedDataQueue.new,
+ appl = Applier.new(CENTRAL_ALIAS),
+ stdout = $stdout)
@received_data_queue = rdq
@applier = appl
@stdout = stdout
end
def process_filial_data(filial_id, incoming_data)
- @stdout.puts "\nReceived data: #{incoming_data.size} for filial: #{filial_id}"
- @stdout.puts "#{'='*60}"
- saved_ids = @received_data_queue.save(incoming_data)
- @stdout.puts "#{'='*60}"
+ unless incoming_data.size == 0
+ @stdout.puts "\nIncoming data: #{incoming_data.size} for filial: #{filial_id}"
+ @stdout.puts "#{'='*60}"
+ saved_ids = @received_data_queue.save(incoming_data)
+ @stdout.puts "#{'='*60}"
- @stdout.puts "\nProcessing data for filial: #{filial_id}"
- @stdout.puts "#{'='*60}"
- @applier.run
- @stdout.puts "#{'='*60}"
+ @stdout.puts "\nProcessing data for filial: #{filial_id}"
+ @stdout.puts "#{'='*60}"
+ @applier.run
+ @stdout.puts "#{'='*60}"
- saved_ids
+ return saved_ids
+ else
+ @stdout.puts "\nEmpty incoming data from filial: #{filial_id}"
+ @stdout.puts "#{'='*60}"
+
+ return []
+ end
end
end
end
View
1  lib/central/received_data_queue.rb
@@ -5,6 +5,7 @@ class ReceivedDataQueue
def initialize(stdout = $stdout)
@stdout = stdout
end
+
def data
ReceivedDataRow.all
end
View
12 lib/client.rb → lib/client/client.rb
@@ -1,7 +1,7 @@
-require_relative "configuration"
-require_relative "client/table_tracking"
-require_relative "client/trackings_queue"
-require_relative "client/prepared_data_queue"
+require_relative "../configuration"
+require_relative "table_tracking"
+require_relative "trackings_queue"
+require_relative "prepared_data_queue"
require 'drb'
module Filial
@@ -15,7 +15,7 @@ def setup_remote_object(server_uri)
@remote_object = DRbObject.new_with_uri server_uri
end
- def initialize(fil_id,
+ def initialize(fil_id, pvsw_alias,
tbl_tracking = TableTracking.new,
tr_queue = TrackingsQueue.new,
prep_data_q = PreparedDataQueue.new,
@@ -26,6 +26,8 @@ def initialize(fil_id,
@prepared_data_queue = prep_data_q
@stdout = stdout
+ Pvsw.odbc_alias = pvsw_alias
+
@infinite = true
@seconds_wait = 10
end
View
6 lib/client/prepared_data_queue.rb
@@ -3,6 +3,10 @@
module Filial
class PreparedDataQueue
+ def initialize(stdout = $stdout)
+ @stdout = stdout
+ end
+
def data
PreparedDataRow.all
end
@@ -47,7 +51,7 @@ def get_data_for(trackings)
def saves_data_as_prepared_data_rows(data_to_queue)
data_to_queue.each do |pdr|
- puts "saving data as prepared for: #{pdr[0]} #{pdr[1]} #{pdr[2]}"
+ @stdout.puts "saving data as prepared for: #{pdr[0]} #{pdr[1]} #{pdr[2]}"
PreparedDataRow.create!(
tblname: pdr[0],
rowid: pdr[1],
View
6 spec/applier_spec.rb → spec/central/applier_spec.rb
@@ -2,8 +2,8 @@
module Central
describe Applier do
- let(:stdout) { StringIO.new }
- let(:applier) {Applier.new(stdout)}
+ let(:stdout) { StringIO.new }
+ let(:applier) { Applier.new(TESTDB_ALIAS, stdout) }
describe "#names_values_for_insert_from" do
it "doesn't quotes column names" do
@@ -101,7 +101,7 @@ module Central
def pvsw_table_two_size
Pvsw.do_sql_single_result("SELECT COUNT(*) FROM tableTwo")
end
-
+
def string_prm_of_table_two(id)
Pvsw.do_sql_single_result("SELECT string_prm FROM tableTwo WHERE ID = #{id}")
end
View
2  spec/client_spec.rb → spec/client/client_spec.rb
@@ -7,7 +7,7 @@ module Filial
let(:prepared_data_queue) { double("PreparedDataQueue") }
let(:remote_double) { double('proxy').as_null_object }
let(:stdout) { StringIO.new }
- let(:client) { Client.new('filial', table_tracking, trackings_queue, prepared_data_queue, stdout) }
+ let(:client) { Client.new('filial', TESTDB_ALIAS, table_tracking, trackings_queue, prepared_data_queue, stdout) }
describe "#get_trackings!" do
describe "when there are no trackings" do
View
3  spec/client/prepared_data_queue_spec.rb
@@ -4,7 +4,8 @@ module Filial
Track = Struct.new(:tblname, :rowid, :action)
describe PreparedDataQueue do
- let(:pdq) {PreparedDataQueue.new}
+ let(:stdout) { StringIO.new }
+ let(:pdq) {PreparedDataQueue.new(stdout)}
describe "#remove_acknowledged_data!" do
after(:each) {PreparedDataRow.clear!}
View
4 spec/spec_helper.rb
@@ -18,10 +18,10 @@ def self.each_run
Spork.prefork do
ENV['TEST'] = 'True'
- require "client"
+ require "client/client"
require "central/applier"
- Pvsw.odbc_alias = CENTRAL_ALIAS = "TestDB.NET"
+ Pvsw.odbc_alias = TESTDB_ALIAS = "TestDB.NET"
Dir['./spec/support/**/*.rb'].map {|f| require f}

No commit comments for this range

Something went wrong with that request. Please try again.