Exemplo n.º 1
0
func (sock *BusSocket) sendtopeers(m *message.Message) {
	/* sends messages to peers */
	handlePanic()
	for _, connection := range sock.listeners.list() {
		select {
		case (connection).channel <- m:
		default:
			var value []byte
			msg := <-(connection).channel
			key := msg.Key
			timestamp := msg.Timestamp
			value, err := json.Marshal(msg)
			if err == nil {
				action := SET
				var ttl int64
				ttl = 24 * 60 * 60 * 7
				Message := *message.NewMessage(action, key, string(value), ttl)
				Message.Timestamp = timestamp
				err, _ := (connection).cache.SetData(&Message, ttl)
				if err != nil {
					log.Printf("Stale data cannot be set in peer cache! Ignoring this message")
				}
				(connection).channel <- m
			}
		}
	}
}
Exemplo n.º 2
0
func (sock *BusSocket) SendMsg(action, key, value string, ttl_optional ...int64) {
	/* Sends messages specified by the user */
	handlePanic()
	var ttl int64
	ttl = 24 * 60 * 60
	if len(ttl_optional) > 0 {
		ttl = ttl_optional[0]
	}
	msg := message.NewMessage(action, key, value, ttl)
	sock.sender_chan <- msg
}