Class: Baykit::BayServer::Tours::Tour

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTour

Returns a new instance of Tour.



60
61
62
63
64
65
66
# File 'lib/baykit/bayserver/tours/tour.rb', line 60

def initialize()
  @obj_id = Tour.oid_counter.next
  @req = TourReq.new(self)
  @res = TourRes.new(self)
  @lock = Mutex.new
  reset()
end

Class Attribute Details

.oid_counterObject (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_counterObject (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

#cityObject

Returns the value of attribute city.



45
46
47
# File 'lib/baykit/bayserver/tours/tour.rb', line 45

def city
  @city
end

#clubObject

Returns the value of attribute club.



46
47
48
# File 'lib/baykit/bayserver/tours/tour.rb', line 46

def club
  @club
end

#errorObject

Returns the value of attribute error.



57
58
59
# File 'lib/baykit/bayserver/tours/tour.rb', line 57

def error
  @error
end

#error_handlingObject (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

#intervalObject

Returns the value of attribute interval.



53
54
55
# File 'lib/baykit/bayserver/tours/tour.rb', line 53

def interval
  @interval
end

#is_secureObject

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

#lockObject (readonly)

Returns the value of attribute lock.



51
52
53
# File 'lib/baykit/bayserver/tours/tour.rb', line 51

def lock
  @lock
end

#obj_idObject (readonly)

object id



40
41
42
# File 'lib/baykit/bayserver/tours/tour.rb', line 40

def obj_id
  @obj_id
end

#reqObject (readonly)

Returns the value of attribute req.



48
49
50
# File 'lib/baykit/bayserver/tours/tour.rb', line 48

def req
  @req
end

#resObject (readonly)

Returns the value of attribute res.



49
50
51
# File 'lib/baykit/bayserver/tours/tour.rb', line 49

def res
  @res
end

#shipObject (readonly)

Returns the value of attribute ship.



38
39
40
# File 'lib/baykit/bayserver/tours/tour.rb', line 38

def ship
  @ship
end

#ship_idObject (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

#stateObject

Returns the value of attribute state.



55
56
57
# File 'lib/baykit/bayserver/tours/tour.rb', line 55

def state
  @state
end

#tour_idObject (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

#townObject

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

Returns:

  • (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

Returns:

  • (Boolean)


163
164
165
# File 'lib/baykit/bayserver/tours/tour.rb', line 163

def ended?()
  return @state == TourState::ENDED
end

#goObject



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

#idObject



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

Returns:

  • (Boolean)


167
168
169
# File 'lib/baykit/bayserver/tours/tour.rb', line 167

def initialized?()
  return state != TourState::UNINITIALIZED
end

#inspectObject



183
184
185
# File 'lib/baykit/bayserver/tours/tour.rb', line 183

def inspect
  return to_s
end

#preparing?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/baykit/bayserver/tours/tour.rb', line 142

def preparing?()
  return @state == TourState::PREPARING
end

#reading?Boolean

Returns:

  • (Boolean)


146
147
148
# File 'lib/baykit/bayserver/tours/tour.rb', line 146

def reading?()
  return @state == TourState::READING
end

#resetObject

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

Returns:

  • (Boolean)


151
152
153
# File 'lib/baykit/bayserver/tours/tour.rb', line 151

def running?()
  return @state == TourState::RUNNING
end

#secure?Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/baykit/bayserver/tours/tour.rb', line 179

def secure?
  @is_secure
end

#to_sObject



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

#valid?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/baykit/bayserver/tours/tour.rb', line 138

def valid?()
  return @state == TourState::PREPARING || @state == TourState::READING || @state == TourState::RUNNING
end

#zombie?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/baykit/bayserver/tours/tour.rb', line 155

def zombie?()
  return @state == TourState::ZOMBIE
end