forked from steger/pr3-sose2026
baggage handling system implementation
parent
89e3c3eab9
commit
5c1338301b
|
|
@ -1,6 +1,7 @@
|
||||||
package airport
|
package airport
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -11,7 +12,7 @@ type BaggageProcessor interface {
|
||||||
type BaggageHandlingSystem struct {
|
type BaggageHandlingSystem struct {
|
||||||
processingTime time.Duration
|
processingTime time.Duration
|
||||||
sinks map[FlightNumber]BaggageProcessor
|
sinks map[FlightNumber]BaggageProcessor
|
||||||
//TODO: extend
|
lostBaggage chan LostBaggage
|
||||||
}
|
}
|
||||||
|
|
||||||
type LostBaggage struct {
|
type LostBaggage struct {
|
||||||
|
|
@ -26,19 +27,39 @@ func NewBaggageHandlingSystem(processingTime time.Duration, sinks map[FlightNumb
|
||||||
return BaggageHandlingSystem{
|
return BaggageHandlingSystem{
|
||||||
processingTime: processingTime,
|
processingTime: processingTime,
|
||||||
sinks: sinks,
|
sinks: sinks,
|
||||||
|
lostBaggage: make(chan LostBaggage),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
func (bhs *BaggageHandlingSystem) ProcessBaggage(fn FlightNumber, b Baggage) error {
|
||||||
//TODO: implement
|
sink, ok := bhs.sinks[fn]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("invalid flight %v", fn)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(bhs.processingTime)
|
||||||
|
if err := sink.ProcessBaggage(fn, b); err != nil {
|
||||||
|
bhs.lostBaggage <- LostBaggage{b, fn, err}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
func (bhs *BaggageHandlingSystem) CollectLostBaggage() []LostBaggage {
|
||||||
//TODO: implement
|
lostBaggage := []LostBaggage{}
|
||||||
return nil
|
for {
|
||||||
|
select {
|
||||||
|
case lb := <-bhs.lostBaggage:
|
||||||
|
lostBaggage = append(lostBaggage, lb)
|
||||||
|
default:
|
||||||
|
return lostBaggage
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bhs *BaggageHandlingSystem) Start() {
|
func (bhs *BaggageHandlingSystem) Start() {
|
||||||
//TODO: implement
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue