예제 #1
0
파일: Main.cs 프로젝트: pepipe/ISEL
        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");
        }
예제 #2
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public bool Delete(Tuple tuple, string[] spaces)
 {
     return Delete(tuple, spaces, true);
 }
예제 #3
0
파일: Tuple.cs 프로젝트: pepipe/ISEL
 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;
 }
예제 #4
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
        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;
            }
        }
예제 #5
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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;
     }
 }
예제 #6
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple WaitToRead(Tuple t, string[] spaces)
 {
     return WaitToRead(t, 0, spaces);
 }
예제 #7
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public bool Update(TupleID tupleId, Tuple tuple)
 {
     TSResponse resp = SendReceive(new UpdateCommand(tupleId, tuple));
     return resp.Type.Equals(TSResponse.ResponseType.ok);
 }
예제 #8
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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;
     }
 }
예제 #9
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Read(Tuple t)
 {
     return Read(t, GetSpaceNames(), true);
 }
예제 #10
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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;
     }
 }
예제 #11
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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)");
     }
 }
예제 #12
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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);
 }
예제 #13
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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;
     }
 }
예제 #14
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public int DeleteAll(Tuple tuple)
 {
     return DeleteAll(tuple, GetSpaceNames());
 }
예제 #15
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public bool Delete(Tuple tuple, bool randomize)
 {
     return Delete(tuple, GetSpaceNames(), randomize);
 }
예제 #16
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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;
     }
 }
예제 #17
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple[] TakeAll(Tuple t)
 {
     return TakeAll(t, GetSpaceNames());
 }
예제 #18
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Read(Tuple t, bool randomize)
 {
     return Read(t, GetSpaceNames(), randomize);
 }
예제 #19
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple TakeTupleById(TupleID id)
 {
     Tuple t = new Tuple(new Field[] {});
     t.TupleID = id;
     return Take(t);
 }
예제 #20
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Read(Tuple t, string[] spaces)
 {
     return Read(t, spaces, true);
 }
예제 #21
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple WaitToRead(Tuple t)
 {
     return WaitToRead(t, 0, GetSpaceNames());
 }
예제 #22
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple[] ReadAll(Tuple t)
 {
     return ReadAll(t, GetSpaceNames());
 }
예제 #23
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple WaitToTake(Tuple t)
 {
     return WaitToTake(t, 0, GetSpaceNames());
 }
예제 #24
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple ReadTupleById(TupleID id)
 {
     Tuple t = new Tuple(new Field[] {});
     t.TupleID = id;
     return Read(t);
 }
예제 #25
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 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)");
     }
 }
예제 #26
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Take(Tuple t)
 {
     return Take(t, true);
 }
예제 #27
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Take(Tuple t, bool randomize)
 {
     return Take(t, GetSpaceNames(), randomize);
 }
예제 #28
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public Tuple Take(Tuple t, string[] spaces)
 {
     return Take(t, spaces, true);
 }
예제 #29
0
파일: Tuple.cs 프로젝트: pepipe/ISEL
 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;
 }
예제 #30
0
파일: TupleSpace.cs 프로젝트: pepipe/ISEL
 public bool Delete(Tuple tuple)
 {
     return Delete(tuple, true);
 }