Exemple #1
0
// Writes IResponse into connection.
func (s *SessionHandler) writeResponse(resp iface.IResponse) error {
	unsafeData := common.UnsafeStringToBytes(resp.GetResponse())
	if _, err := s.conn.Write(unsafeData); err != nil {
		return err
	}
	if _, err := s.conn.Write(EOM); err != nil {
		return err
	}
	return nil
}
Exemple #2
0
// FlushCache flushes all cache into database.
func (ds *DataStorage) FlushCache() {
	if ds.closed {
		return
	}
	ds.cacheLock.Lock()
	tmpItemCache := ds.itemCache
	ds.tmpPayloadCache = ds.payloadCache
	ds.itemCache = make(map[string][]byte)
	ds.payloadCache = make(map[string]string)
	ds.cacheLock.Unlock()

	wb := levigo.NewWriteBatch()
	for k, v := range tmpItemCache {
		key := common.UnsafeStringToBytes(k)
		if v == nil {
			wb.Delete(key)
		} else {
			wb.Put(key, v)
		}
	}

	for k, v := range ds.tmpPayloadCache {
		key := common.UnsafeStringToBytes(k)
		if v == "" {
			wb.Delete(key)
		} else {
			wb.Put(key, common.UnsafeStringToBytes(v))
		}
	}

	ds.db.Write(defaultWriteOptions, wb)

	ds.cacheLock.Lock()
	ds.tmpPayloadCache = make(map[string]string)
	ds.cacheLock.Unlock()
}
Exemple #3
0
func makeSettingsKey(serviceId string) []byte {
	return common.UnsafeStringToBytes(serviceConfigPrefix + serviceId)
}
Exemple #4
0
// SaveServiceMeta stores service metadata into database.
func (ds *DataStorage) SaveServiceMeta(serviceDescription *common.ServiceDescription) {
	key := serviceDescriptionPrefix + serviceDescription.GetName()
	data, _ := serviceDescription.Marshal()
	ds.db.Put(defaultWriteOptions, common.UnsafeStringToBytes(key), data)
}
Exemple #5
0
// IterServiceItems returns new over all service item metadata.
// Service name used as a prefix to file all service items.
func (ds *DataStorage) IterServiceItems(serviceId string) *ItemIterator {
	iter := ds.db.NewIterator(defaultReadOptions)
	prefix := common.UnsafeStringToBytes(makeItemID(serviceId, ""))
	return makeItemIterator(iter, prefix)
}