// Implement comm.ServerMessageHandler Interface -> DiscoverTopology()
func (this *ExampleServerMessageHandler) DiscoverTopology(serverMsg *proto.MediationServerMessage) {
	glog.V(2).Infof("Now discovering toplogy of target %s.", this.TurboMetadata.NameOrAddress)

	// 1. Get message ID.
	msgID := serverMsg.GetMessageID()
	// 2. Stop being timed out. Send back KeepAlive message every 10s.
	stopCh := make(chan struct{})
	defer close(stopCh)
	go func() {
		for {
			select {
			case <-stopCh:
				return
			default:
			}

			this.keepDiscoveryAlive(msgID)

			t := time.NewTimer(time.Second * 10)
			select {
			case <-stopCh:
				return
			case <-t.C:
			}
		}

	}()
	// 3. Create probe and use probe to discover target topology.
	exampleProbe := probe.NewExampleProbe(this.TopoAccessor)
	discoveryResults, err := exampleProbe.Discover()
	// 4. Build discovery response.
	// If there is error during discovery, return an ErrorDTO.
	var discoveryResponse *proto.DiscoveryResponse
	if err != nil {
		// If there is error during discovery, return an ErrorDTO.
		serverity := proto.ErrorDTO_CRITICAL
		description := fmt.Sprintf("%v", err)
		errorDTO := &proto.ErrorDTO{
			Severity:    &serverity,
			Description: &description,
		}
		discoveryResponse = &proto.DiscoveryResponse{
			ErrorDTO: []*proto.ErrorDTO{errorDTO},
		}
	} else {
		// No error. Return the result entityDTOs.
		discoveryResponse = &proto.DiscoveryResponse{
			EntityDTO: discoveryResults,
		}
	}
	// 5. Build client message.
	clientMsg := comm.NewClientMessageBuilder(msgID).SetDiscoveryResponse(discoveryResponse).Create()
	// 6. Send to client msg channel.
	this.clientMsgChan <- clientMsg

}
// Implement comm.ServerMessageHandler Interface -> Validate()
func (this *ExampleServerMessageHandler) Validate(serverMsg *proto.MediationServerMessage) {
	glog.V(2).Infof("Now validating target %s", this.TurboMetadata.NameOrAddress)
	// NOTE: Here we validate regardless of what info sent along with Validation request from server.
	// 1. Retreive message ID from server message.
	msgID := serverMsg.GetMessageID()
	// 2. Build validation response.
	validationResponse := new(proto.ValidationResponse)
	// 3. Create client message.
	clientMsg := comm.NewClientMessageBuilder(msgID).SetValidationResponse(validationResponse).Create()
	//4. Send it to client msg channel.
	this.clientMsgChan <- clientMsg
}
// Handle server message according to serverMessage type
func (wsc *WebSocketCommunicator) handleServerMessage(serverMsg *proto.MediationServerMessage) {
	if wsc.ServerMsgHandler == nil {
		// Log the error
		glog.V(4).Infof("Server Message Handler is nil")
		return
	}
	glog.V(3).Infof("Receive message from server. Unmarshalled to: %+v", serverMsg)

	// if serverMsg.GetAck() != nil && clientMsg.GetContainerInfo() != nil {
	// 	glog.V(3).Infof("VMTurbo server acknowledged, connection established and adding target.")
	// 	// Add current Kuberenetes target.
	// 	wsc.ServerMsgHandler.AddTarget()

	// } else
	if serverMsg.GetValidationRequest() != nil {
		wsc.ServerMsgHandler.Validate(serverMsg)
	} else if serverMsg.GetDiscoveryRequest() != nil {
		wsc.ServerMsgHandler.DiscoverTopology(serverMsg)
	} else if serverMsg.GetActionRequest() != nil {
		wsc.ServerMsgHandler.HandleAction(serverMsg)
	}
}