Class: Control::Deferred

Inherits:
EventMachine::Connection
  • Object
show all
Defined in:
lib/automate-em/interfaces/OLD CODE/deferred.rb

Direct Known Subclasses

TelnetServer

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Deferred

Returns a new instance of Deferred.



9
10
11
12
13
14
15
# File 'lib/automate-em/interfaces/OLD CODE/deferred.rb', line 9

def initialize(*args)
	super

	@selected = nil
	@receive_queue = Queue.new
	@command_lock = Mutex.new
end

Instance Method Details

#connection_completedObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/automate-em/interfaces/OLD CODE/deferred.rb', line 30

def connection_completed
	if self.respond_to?(:connected)
		EM.defer do
			begin
				self.connected
			rescue => e
				if !@system.nil?
					@system.logger.error "-- in defferred.rb, connection_completed : bad user code in #{self.class}.connected --"
					@system.logger.error e.message
					@system.logger.error e.backtrace
				end
			end
		end
	end
end

#post_initObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/automate-em/interfaces/OLD CODE/deferred.rb', line 17

def post_init
	return unless self.respond_to?(:initiate_session)
	begin
		self.initiate_session
	rescue => e
		if !@system.nil?
			@system.logger.error "-- in defferred.rb, post_init : bad user code in #{self.class}.initiate_session --"
			@system.logger.error e.message
			@system.logger.error e.backtrace
		end
	end
end

#receive_data(data) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/automate-em/interfaces/OLD CODE/deferred.rb', line 50

def receive_data(data)
	@receive_queue.push(data)
	EM.defer do
		begin
			@command_lock.synchronize {
				self.received
			}
		rescue => e
			if !@system.nil?
				@system.logger.error "-- in defferred.rb, receive_data : bad user code in #{self.class}.received --"
				@system.logger.error e.message
				@system.logger.error e.backtrace
			end
		end
	end
end

#unbindObject



46
47
48
# File 'lib/automate-em/interfaces/OLD CODE/deferred.rb', line 46

def unbind
	@selected.disconnected(self) unless @selected.nil?
end