2015-01-21 02:16:06 -05:00
|
|
|
/*
|
|
|
|
* Mini Object Storage, (C) 2014 Minio, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2015-01-18 16:31:22 -05:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/minio-io/minio/pkg/httpserver"
|
2015-01-18 19:10:48 -05:00
|
|
|
storageModule "github.com/minio-io/minio/pkg/storage"
|
2015-01-19 14:51:45 -05:00
|
|
|
"github.com/minio-io/minio/pkg/webapi/minioapi"
|
2015-01-18 16:31:22 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func Start() {
|
2015-01-20 17:07:39 -05:00
|
|
|
var ctrlChans []chan<- string
|
|
|
|
var statusChans []<-chan error
|
2015-01-18 16:31:22 -05:00
|
|
|
|
2015-01-19 14:51:45 -05:00
|
|
|
ctrlChan, statusChan, storage := storageModule.Start()
|
2015-01-18 16:31:22 -05:00
|
|
|
ctrlChans = append(ctrlChans, ctrlChan)
|
|
|
|
statusChans = append(statusChans, statusChan)
|
|
|
|
|
2015-01-20 19:08:14 -05:00
|
|
|
ctrlChan, statusChan = httpserver.Start(minioapi.HttpHandler(storage), ":8080")
|
2015-01-18 16:31:22 -05:00
|
|
|
ctrlChans = append(ctrlChans, ctrlChan)
|
|
|
|
statusChans = append(statusChans, statusChan)
|
|
|
|
|
|
|
|
cases := createSelectCases(statusChans)
|
|
|
|
|
2015-01-18 19:59:23 -05:00
|
|
|
for len(cases) > 0 {
|
2015-01-18 16:31:22 -05:00
|
|
|
chosen, value, recvOk := reflect.Select(cases)
|
|
|
|
if recvOk == true {
|
|
|
|
// Status Message Received
|
|
|
|
log.Println(chosen, value.Interface(), recvOk)
|
|
|
|
} else {
|
|
|
|
// Channel closed, remove from list
|
2015-01-20 17:07:39 -05:00
|
|
|
var aliveStatusChans []<-chan error
|
2015-01-18 16:31:22 -05:00
|
|
|
for i, ch := range statusChans {
|
|
|
|
if i != chosen {
|
|
|
|
aliveStatusChans = append(aliveStatusChans, ch)
|
|
|
|
}
|
|
|
|
}
|
2015-01-18 18:50:53 -05:00
|
|
|
// create new select cases without defunct channel
|
2015-01-18 16:31:22 -05:00
|
|
|
statusChans = aliveStatusChans
|
|
|
|
cases = createSelectCases(statusChans)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func createSelectCases(channels []<-chan error) []reflect.SelectCase {
|
|
|
|
cases := make([]reflect.SelectCase, len(channels))
|
|
|
|
for i, ch := range channels {
|
|
|
|
cases[i] = reflect.SelectCase{
|
|
|
|
Dir: reflect.SelectRecv,
|
|
|
|
Chan: reflect.ValueOf(ch),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cases
|
|
|
|
}
|