Class: Baykit::BayServer::Tours::Tour
- Inherits:
-
Object
- Object
- Baykit::BayServer::Tours::Tour
- Includes:
- Baykit::BayServer, Ships, Util, Util::Reusable
- Defined in:
- lib/baykit/bayserver/tours/tour.rb
Defined Under Namespace
Classes: TourState
Constant Summary collapse
- TOUR_ID_NOCHECK =
-1
- INVALID_TOUR_ID =
0
Class Attribute Summary collapse
-
.oid_counter ⇒ Object
readonly
Returns the value of attribute oid_counter.
-
.tour_id_counter ⇒ Object
readonly
Returns the value of attribute tour_id_counter.
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#club ⇒ Object
Returns the value of attribute club.
-
#error ⇒ Object
Returns the value of attribute error.
-
#error_handling ⇒ Object
readonly
Returns the value of attribute error_handling.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#is_secure ⇒ Object
Returns the value of attribute is_secure.
-
#lock ⇒ Object
readonly
Returns the value of attribute lock.
-
#obj_id ⇒ Object
readonly
object id.
-
#req ⇒ Object
readonly
Returns the value of attribute req.
-
#res ⇒ Object
readonly
Returns the value of attribute res.
-
#ship ⇒ Object
readonly
Returns the value of attribute ship.
-
#ship_id ⇒ Object
readonly
Returns the value of attribute ship_id.
-
#state ⇒ Object
Returns the value of attribute state.
-
#tour_id ⇒ Object
readonly
Returns the value of attribute tour_id.
-
#town ⇒ Object
Returns the value of attribute town.
Instance Method Summary collapse
- #aborted? ⇒ Boolean
- #change_state(chk_id, new_state) ⇒ Object
- #check_tour_id(chk_id) ⇒ Object
- #ended? ⇒ Boolean
- #go ⇒ Object
- #id ⇒ Object
- #init(key, sip) ⇒ Object
-
#initialize ⇒ Tour
constructor
A new instance of Tour.
- #initialized? ⇒ Boolean
- #inspect ⇒ Object
- #preparing? ⇒ Boolean
- #reading? ⇒ Boolean
-
#reset ⇒ Object
implements Reusable.
- #running? ⇒ Boolean
- #secure? ⇒ Boolean
- #to_s ⇒ Object
- #valid? ⇒ Boolean
- #zombie? ⇒ Boolean
Constructor Details
Class Attribute Details
.oid_counter ⇒ Object (readonly)
Returns the value of attribute oid_counter.
29 30 31 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 29 def oid_counter @oid_counter end |
.tour_id_counter ⇒ Object (readonly)
Returns the value of attribute tour_id_counter.
30 31 32 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 30 def tour_id_counter @tour_id_counter end |
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
45 46 47 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 45 def city @city end |
#club ⇒ Object
Returns the value of attribute club.
46 47 48 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 46 def club @club end |
#error ⇒ Object
Returns the value of attribute error.
57 58 59 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 57 def error @error end |
#error_handling ⇒ Object (readonly)
Returns the value of attribute error_handling.
43 44 45 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 43 def error_handling @error_handling end |
#interval ⇒ Object
Returns the value of attribute interval.
53 54 55 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 53 def interval @interval end |
#is_secure ⇒ Object
Returns the value of attribute is_secure.
54 55 56 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 54 def is_secure @is_secure end |
#lock ⇒ Object (readonly)
Returns the value of attribute lock.
51 52 53 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 51 def lock @lock end |
#obj_id ⇒ Object (readonly)
object id
40 41 42 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 40 def obj_id @obj_id end |
#req ⇒ Object (readonly)
Returns the value of attribute req.
48 49 50 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 48 def req @req end |
#res ⇒ Object (readonly)
Returns the value of attribute res.
49 50 51 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 49 def res @res end |
#ship ⇒ Object (readonly)
Returns the value of attribute ship.
38 39 40 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 38 def ship @ship end |
#ship_id ⇒ Object (readonly)
Returns the value of attribute ship_id.
39 40 41 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 39 def ship_id @ship_id end |
#state ⇒ Object
Returns the value of attribute state.
55 56 57 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 55 def state @state end |
#tour_id ⇒ Object (readonly)
Returns the value of attribute tour_id.
42 43 44 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 42 def tour_id @tour_id end |
#town ⇒ Object
Returns the value of attribute town.
44 45 46 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 44 def town @town end |
Instance Method Details
#aborted? ⇒ Boolean
159 160 161 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 159 def aborted?() return @state == TourState::ABORTED end |
#change_state(chk_id, new_state) ⇒ Object
171 172 173 174 175 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 171 def change_state(chk_id, new_state) BayLog.debug("%s change state: %s", self, new_state) check_tour_id(chk_id) @state = new_state end |
#check_tour_id(chk_id) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 187 def check_tour_id(chk_id) if chk_id == TOUR_ID_NOCHECK return end if !initialized? raise Sink.new("%s Tour not initialized", self) end if chk_id != @tour_id raise Sink.new("%s Invalid tours id: %s", self, chk_id== nil ? "" : chk_id) end end |
#ended? ⇒ Boolean
163 164 165 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 163 def ended?() return @state == TourState::ENDED end |
#go ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 113 def go if(req.headers.content_length > 0) change_state(TOUR_ID_NOCHECK, TourState::READING) else change_state(TOUR_ID_NOCHECK, TourState::RUNNING) end city = @ship.port_docker.find_city(@req.req_host) if city == nil city = BayServer.find_city(@req.req_host) end BayLog.debug("%s GO TOUR! ...( ^_^)/: city=%s url=%s", self, @req.req_host, @req.uri); if city == nil raise HttpException.new HttpStatus::NOT_FOUND, @req.uri else begin city.enter(self) rescue HttpException => e change_state(TOUR_ID_NOCHECK, TourState::ABORTED) raise e end end end |
#id ⇒ Object
91 92 93 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 91 def id() @tour_id end |
#init(key, sip) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 95 def init(key, sip) if initialized? raise Sink.new("#{@ship} Tour already initialized: #{self}") end @ship = sip @ship_id = sip.ship_id if @ship_id == Ship::INVALID_SHIP_ID raise Sink.new() end @tour_id = Tour.tour_id_counter.next change_state(TOUR_ID_NOCHECK, TourState::PREPARING) @req.init(key) @res.init() BayLog.debug("%s initialized", self) end |
#initialized? ⇒ Boolean
167 168 169 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 167 def initialized?() return state != TourState::UNINITIALIZED end |
#inspect ⇒ Object
183 184 185 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 183 def inspect return to_s end |
#preparing? ⇒ Boolean
142 143 144 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 142 def preparing?() return @state == TourState::PREPARING end |
#reading? ⇒ Boolean
146 147 148 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 146 def reading?() return @state == TourState::READING end |
#reset ⇒ Object
implements Reusable
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 75 def reset() @city = nil @town = nil @club = nil @error_handling = false @tour_id = INVALID_TOUR_ID @interval = 0 @is_secure = false change_state(TOUR_ID_NOCHECK, TourState::UNINITIALIZED) @error = nil @req.reset() @res.reset() end |
#running? ⇒ Boolean
151 152 153 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 151 def running?() return @state == TourState::RUNNING end |
#secure? ⇒ Boolean
179 180 181 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 179 def secure? @is_secure end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/baykit/bayserver/tours/tour.rb', line 68 def to_s() return "#{@ship} tur##{@tour_id}/#{@obj_id}[key=#{@req.key}]" end |