func (t *TupleSpaceClient) read(match *tuplespace.TupleMatcher, timeout time.Duration, actions int, out interface{}) error { method := "GET" if actions&tuplespace.ActionTake != 0 { method = "DELETE" } req := &tuplespace.ReadRequest{ Match: match.String(), Timeout: timeout, } req.All = actions&tuplespace.ActionOne == 0 log.Fine("TupleSpaceClient.read(%+v)", req) return t.do(method, req, out) }
func (m *MemoryStore) Match(match *tuplespace.TupleMatcher, limit int) ([]*tuplespace.TupleEntry, []*tuplespace.TupleEntry, error) { now := time.Now() matches := make([]*tuplespace.TupleEntry, 0, 32) deletes := make([]*tuplespace.TupleEntry, 0, 32) log.Fine("Matching %s against %d tuples limit %d", match, len(m.tuples), limit) for _, entry := range m.tuples { if entry.IsExpired(now) { deletes = append(deletes, entry) continue } if match.Match(entry.Tuple) { matches = append(matches, entry) if len(matches) == limit { break } } } if len(deletes) > 0 { m.Delete(deletes) } return matches, nil, nil }