示例#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
}
示例#2
0
文件: ldb.go 项目: jmptrader/firempq
// 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()
}
示例#3
0
文件: ldb.go 项目: jmptrader/firempq
func makeSettingsKey(serviceId string) []byte {
	return common.UnsafeStringToBytes(serviceConfigPrefix + serviceId)
}
示例#4
0
文件: ldb.go 项目: jmptrader/firempq
// 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)
}
示例#5
0
文件: ldb.go 项目: jmptrader/firempq
// 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)
}