Exemple #1
0
        public static void Main(string[] args)
        {
            TupleSpace ts = new TupleSpace("localhost", 2525, new String[] {"TestSpace"});

            Tuple t;

            Console.WriteLine("Connected to TS " + ts);
            t = new Tuple(new Field[] { new Field("Hallo"), new Field("Welt") });
            ts.Write(t);
            Console.WriteLine("Written tuple " + t);

            //t = new Tuple(new Field[] {new Field("Hello"), new Field("World")});
            //ts.Write(t);
            //Console.WriteLine ("Written tuple " + t);

            //t = new Tuple(new Field[] {new Field("Czesc"), new Field("Swiat")});
            //ts.Write(t);
            //Console.WriteLine ("Written tuple " + t);

            Tuple template = new Tuple(new Field[] {new Field(typeof(String)), new Field(typeof(String))});

            //Take
            //t = ts.Take(template);
            //Console.WriteLine("Tuple Read: " + t);

            //Ler tudo
            //Tuple[] tups = ts.ReadAll(template);
            //foreach (Tuple tu in tups)
            //{
            //    Console.WriteLine("---> Tuple Read: " + tu);
            //}

            //Read
            t = ts.Read(template);
            Console.WriteLine("Tuple Read: " + t);

            int num = ts.Count(template);
            Console.WriteLine (num + " tuples found!");

            //bool deleted = ts.Delete(template);
            //Console.WriteLine ("Deleted one tuple? " + deleted);

            //num = ts.Count(template);
            //Console.WriteLine (num + " tuples found!");

            //int deletedSomething = ts.DeleteAll(template);
            //Console.WriteLine ("Deleted something? " + deletedSomething);

            Console.WriteLine ("BYE");
        }
Exemple #2
0
 public bool Delete(Tuple tuple, string[] spaces)
 {
     return Delete(tuple, spaces, true);
 }
Exemple #3
0
 public object Clone()
 {
     Field[] newFields = new Field[fields.Length];
     for (int i = 0; i < fields.Length; i++)
     {
         newFields[i] = (Field)fields[i].Clone();
     }
     Tuple t = new Tuple(newFields);
     t.Expiration = expiration;
     return t;
 }
Exemple #4
0
        public TupleID Write(Tuple tuple, String space)
        {
            int spaceid = int.MinValue;
            for (int i = 0; i < spaces.Length && spaceid == int.MinValue; i++)
            {
                if (spaces[i].Name.Equals(space))
                {
                    spaceid = spaces[i].Id;
                }
            }

            if (spaceid == int.MinValue)
            {
                throw new TupleSpaceException("not connected to space '" + space + "'");
            }

            TSResponse resp = SendReceive(new WriteCommand(tuple, spaceid));

            if (resp.Type.Equals(TSResponse.ResponseType.answer))
            {
                long idStr = (long)resp.GetTuple(0).GetField(0).Value;
                return new TupleID(idStr);
            }
            else
            {
                return null;
            }
        }
Exemple #5
0
 public Tuple WaitToTake(Tuple t, long timeout, string[] spaces)
 {
     int[] spaceIds = GetSpaceIds(spaces);
     TSResponse resp = SendReceive(new QueryCommand(t, false, true, true, timeout, spaceIds));
     if (resp.Type.Equals(TSResponse.ResponseType.answer) && resp.NumberOfTuples != 0)
     {
         return resp.GetTuple(0);
     }
     else
     {
         return null;
     }
 }
Exemple #6
0
 public Tuple WaitToRead(Tuple t, string[] spaces)
 {
     return WaitToRead(t, 0, spaces);
 }
Exemple #7
0
 public bool Update(TupleID tupleId, Tuple tuple)
 {
     TSResponse resp = SendReceive(new UpdateCommand(tupleId, tuple));
     return resp.Type.Equals(TSResponse.ResponseType.ok);
 }
Exemple #8
0
 public Tuple[] TakeAll(Tuple t, string[] spaces)
 {
     int[] spaceIds = GetSpaceIds(spaces);
     TSResponse resp = SendReceive(new QueryCommand(t, true, true, false, 0, spaceIds));
     if (resp.Type.Equals(TSResponse.ResponseType.answer))
     {
         return resp.Tuples;
     }
     else
     {
         return null;
     }
 }
Exemple #9
0
 public Tuple Read(Tuple t)
 {
     return Read(t, GetSpaceNames(), true);
 }
Exemple #10
0
 public int EventRegister(Callback.Command command, Tuple template, int major, int minor, int version, String user, Callback cback, bool newThread)
 {
     TSResponse resp =
         SendReceive(
             new CallbackCommand(command, template, null, major, minor, version, user, int.MinValue, CallbackCommand.CallbackType.event_register));
     if (resp.Type.Equals(TSResponse.ResponseType.answer))
     {
         int seq = (int) resp.GetTuple(0).GetField(0).Value;
         responseThread.addCallback(cback, seq, newThread);
         return seq;
     }
     else
     {
         return int.MinValue;
     }
 }
Exemple #11
0
 public int EventRegister(Callback.Command command, Tuple template, Callback cback, bool newThread)
 {
     if (spaces.Length == 1)
     {
         return EventRegister(command, template, spaces[0].Version.Major, spaces[0].Version.Minor, null, cback, newThread);
     }
     else
     {
         throw new TupleSpaceException("no space given (connected to multiple spaces)");
     }
 }
Exemple #12
0
 public int EventRegister(Callback.Command command, Tuple template, int major, int minor, String user, Callback cback, bool newThread)
 {
     return EventRegister(command, template, spaces[0].Version.Major, spaces[0].Version.Minor, int.MinValue, null, cback, newThread);
 }
Exemple #13
0
 public int DeleteAll(Tuple tuple, string[] spaces)
 {
     int[] spaceIds = GetSpaceIds(spaces);
     TSResponse resp = SendReceive(new QueryCommand(tuple, true, true, false, 0, spaceIds, false, false));
     if (resp.Type.Equals(TSResponse.ResponseType.answer) && resp.NumberOfTuples != 0)
     {
         Tuple r = resp.GetTuple(0);
         if (r != null && r.GetField(0) != null && r.GetField(0).Value.GetType().Equals(typeof (int)))
         {
             return (int) r.GetField(0).Value;
         }
         return int.MinValue;
     }
     else
     {
         return int.MinValue;
     }
 }
Exemple #14
0
 public int DeleteAll(Tuple tuple)
 {
     return DeleteAll(tuple, GetSpaceNames());
 }
Exemple #15
0
 public bool Delete(Tuple tuple, bool randomize)
 {
     return Delete(tuple, GetSpaceNames(), randomize);
 }
Exemple #16
0
 public Tuple Take(Tuple t, string[] spaces, bool randomize)
 {
     int[] spaceIds = GetSpaceIds(spaces);
     TSResponse resp = SendReceive(new QueryCommand(t, false, true, false, 0, spaceIds, randomize, true));
     if (resp.Type.Equals(TSResponse.ResponseType.answer) && resp.NumberOfTuples != 0)
     {
         Tuple r = resp.GetTuple(0);
         return r;
     }
     else
     {
         return null;
     }
 }
Exemple #17
0
 public Tuple[] TakeAll(Tuple t)
 {
     return TakeAll(t, GetSpaceNames());
 }
Exemple #18
0
 public Tuple Read(Tuple t, bool randomize)
 {
     return Read(t, GetSpaceNames(), randomize);
 }
Exemple #19
0
 public Tuple TakeTupleById(TupleID id)
 {
     Tuple t = new Tuple(new Field[] {});
     t.TupleID = id;
     return Take(t);
 }
Exemple #20
0
 public Tuple Read(Tuple t, string[] spaces)
 {
     return Read(t, spaces, true);
 }
Exemple #21
0
 public Tuple WaitToRead(Tuple t)
 {
     return WaitToRead(t, 0, GetSpaceNames());
 }
Exemple #22
0
 public Tuple[] ReadAll(Tuple t)
 {
     return ReadAll(t, GetSpaceNames());
 }
Exemple #23
0
 public Tuple WaitToTake(Tuple t)
 {
     return WaitToTake(t, 0, GetSpaceNames());
 }
Exemple #24
0
 public Tuple ReadTupleById(TupleID id)
 {
     Tuple t = new Tuple(new Field[] {});
     t.TupleID = id;
     return Read(t);
 }
Exemple #25
0
 public TupleID Write(Tuple tuple)
 {
     if (spaces.Length == 1)
     {
         return Write(tuple, spaces[0].Name);
     }
     else
     {
         throw new TupleSpaceException("no space given to write into (connected to multiple spaces)");
     }
 }
Exemple #26
0
 public Tuple Take(Tuple t)
 {
     return Take(t, true);
 }
Exemple #27
0
 public Tuple Take(Tuple t, bool randomize)
 {
     return Take(t, GetSpaceNames(), randomize);
 }
Exemple #28
0
 public Tuple Take(Tuple t, string[] spaces)
 {
     return Take(t, spaces, true);
 }
Exemple #29
0
 public bool Matches(Tuple t)
 {
     if (fields.Length == 0 || t.NumerOfFields == 0)
     {
         // nulltuple always matches
         return true;
     }
     if (fields.Length != t.NumerOfFields)
     {
         return false;
     }
     else
     {
         for (int i = 0; i < fields.Length; i++)
         {
             if (!fields[i].Matches(t.GetField(i)))
             {
                 return false;
             }
         }
     }
     return true;
 }
Exemple #30
0
 public bool Delete(Tuple tuple)
 {
     return Delete(tuple, true);
 }