forked from steger/pr3-ws202627
baggage Handling
parent
40426f54d5
commit
d1d2753280
|
|
@ -1,9 +1,9 @@
|
||||||
package airport
|
package airport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitty.informatik.hs-mannheim.de/3010261/pr3-code/go/06-airport/airport"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type BaggageProcessor interface {
|
type BaggageProcessor interface {
|
||||||
|
|
@ -14,7 +14,14 @@ type BaggageHandlingSystem struct {
|
||||||
processingTime time.Duration
|
processingTime time.Duration
|
||||||
sinks map[FlightNumber]BaggageProcessor
|
sinks map[FlightNumber]BaggageProcessor
|
||||||
//TODO: extend
|
//TODO: extend
|
||||||
baggae airport.Baggage
|
queue chan baggageData
|
||||||
|
list []LostBaggage
|
||||||
|
mu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
type baggageData struct {
|
||||||
|
fn FlightNumber
|
||||||
|
b Baggage
|
||||||
}
|
}
|
||||||
|
|
||||||
type LostBaggage struct {
|
type LostBaggage struct {
|
||||||
|
|
@ -29,19 +36,42 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
|
||||||
return BaggageHandlingSystem{
|
return BaggageHandlingSystem{
|
||||||
processingTime: processingTime,
|
processingTime: processingTime,
|
||||||
sinks: sinks,
|
sinks: sinks,
|
||||||
|
queue: make(chan baggageData),
|
||||||
|
list: make([]LostBaggage, 0),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
|
_, ok := bhs.sinks[fn]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Keine Flugnummer passend gefunden")
|
||||||
|
}
|
||||||
|
bhs.queue <- baggageData{fn: fn, b: b}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
return nil
|
bhs.mu.Lock()
|
||||||
|
verloren := bhs.list
|
||||||
|
bhs.list = make([]LostBaggage, 0)
|
||||||
|
bhs.mu.Unlock()
|
||||||
|
return verloren
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) Start() {
|
func (bhs *BaggageHandlingSystem) Start() {
|
||||||
//TODO: implement
|
//TODO: implement
|
||||||
|
for element := range bhs.queue {
|
||||||
|
|
||||||
|
time.Sleep(bhs.processingTime)
|
||||||
|
sink := bhs.sinks[element.fn]
|
||||||
|
err := sink.ProcessBaggage(element.fn, element.b)
|
||||||
|
if err != nil {
|
||||||
|
bhs.mu.Lock()
|
||||||
|
bhs.list = append(bhs.list, LostBaggage{element.b, element.fn, err})
|
||||||
|
bhs.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue