Class: Zyps::EnvironmentServer

Inherits:
Object
  • Object
show all
Defined in:
lib/zyps/remote.rb

Overview

An Environment proxy, served over DRb. As with all DRb services, it is recommended you set $SAFE to 1 or higher.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment = Environment.new, uri = nil) ⇒ EnvironmentServer

Returns a new instance of EnvironmentServer.



38
39
40
# File 'lib/zyps/remote.rb', line 38

def initialize(environment = Environment.new, uri = nil)
	@environment, @uri = environment, uri
end

Instance Attribute Details

#uriObject (readonly)

The URI on which the server is operating.



35
36
37
# File 'lib/zyps/remote.rb', line 35

def uri
  @uri
end

Instance Method Details

#startObject

Offer the given environment for remote connections.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zyps/remote.rb', line 44

def start

	#Ensure GameObject and EnvironmentalFactor lists stay on server side.
	@environment.objects.extend DRbUndumped
	@environment.environmental_factors.extend DRbUndumped
	
	#Ensure Environment stays on server side.
	class <<@environment
		include DRbUndumped
		alias old_objects= objects=
		def objects=(value)
			old_objects=(value)
			@objects.extend DRbUndumped
		end
		alias old_environmental_factors= environmental_factors=
		def environmental_factors=(value)
			old_environmental_factors=(value)
			@environmental_factors.extend DRbUndumped
		end
	end
	
	#Start a network service.
	@server = DRb::DRbServer.new(
		@uri,
		@environment
	)
	@uri ||= @server.uri
	
end

#stopObject

Stop the server.



82
83
84
# File 'lib/zyps/remote.rb', line 82

def stop
	@server.stop_service
end

#waitObject

Wait until the server is finished running.



76
77
78
# File 'lib/zyps/remote.rb', line 76

def wait
	@server.thread.join
end