I understand there's no end. What I want to achieve is the following:
1. Say hello
2. Read all the persistent messages from inputstream
3. Send my insert/get requests
I mean I can handle the relevant messages from the node which is
specific to my requests but I don't know how to move from step 2 to step 3.
Thanks,
Michael
Matthew Toseland wrote:
> On Thursday 27 August 2009 17:42:56 Michael Yip wrote:
>
>> That's enough to read and terminate reading of one message. However, how
>> do I know when is the last message so I can stop reading from the stream?
>>
>> For example, a PersistentPut message came in..so I parse until
>> EndMesssage line. However, there could be yet more PersistentPut/Get
>> messages. Therefore, I'm just wondering how do I break out of the loop
>> after the last of these messages.
>>
>
> There is no end to messages! :) You can make any number of requests over a
> single connection, one after another or simultaneously.
>
> You submit a request or insert, with a specific Identifier. Then you wait for
> the terminal messages for that request or insert, which will include its
> Identifier. So for a request, that would typically be GetFailed or DataFound
> + AllData. For a persistent request (persistence != connection), you'll just
> get the DataFound and you have to do GetRequestStatus to get the data, and
> then RemoveRequest to delete the request. For a persistent insert, you're
> looking for PutSuccessful or PutFailed. In all cases IdentifierCollision is
> possible if there is already a request with the same Identifier, or
> ProtocolError if you have a bug, a file is not readable etc.
>
>> Matthew Toseland wrote:
>>
>>> On Thursday 27 August 2009 16:50:48 Michael Yip wrote:
>>>
>>>
>>>> Hi Matt,
>>>>
>>>> Problem is that (line = buffIns.readLine()) == null does not terminate
>>>> the loop. Since most messages ends with EndMessage, how do I know how
>>>> many more to read before I break the loop??
>>>>
>>>>
>>> A message ends with "EndMessage" or "Data", or something on a line with no
>>> = in it. All lines within a message include an "=". The first line, the
>>> message type, doesn't include an "=". That should be enough information to
>>> separate and parse messages, no?
>>>
>>>
>>>> Thanks,
>>>>
>>>> Michael
>>>>
>>>> Matthew Toseland wrote:
>>>>
>>>>
>>>>> On Thursday 27 August 2009 13:00:41 bbackde at googlemail.com wrote:
>>>>>
>>>>>
>>>>>
>>>>>> You should process the messages in a Thread. Put your code into a Thread
>>>>>> that calls handler methods when a specific message arrived.
>>>>>> The Thread runs forever and receives all messages and all data...
>>>>>>
>>>>>>
>>>>>>
>>>>> All you need to do is parse each message. The type of the message is the
>>>>> first line, it ends at the last line, unless it has trailing data. You
>>>>> can do this level of parsing without understanding the message. Then you
>>>>> can ignore it if you don't understand it, or you can handle it
>>>>> appropriately.
>>>>>
>>>>>
>>>>>
>>>>>> On Thu, Aug 27, 2009 at 03:22, Michael Yip<mhy831 at cs.bham.ac.uk>
>>>>>> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Hi guys,
>>>>>>>
>>>>>>> Does anyone know how to know when I've read all the PersistentPut and
>>>>>>> PersistentGet messages at the start? There's no way of knowing how many
>>>>>>> there are and I have no idea how to know when to stop reading? Below is
>>>>>>> the code I've written:
>>>>>>>
>>>>>>> String line;
>>>>>>> while((line = buffIns.readLine()) != null){
>>>>>>> System.out.println(line);
>>>>>>> _Logger.log(line);
>>>>>>> //Capture ConnectionIdentifer to be used as salt for file
>>>>>>> insertions
>>>>>>> if(line.contains("ConnectionIdentifier")){
>>>>>>> helloID = line.substring(line.indexOf('=') + 1,
>>>>>>> line.length());
>>>>>>> }
>>>>>>> if(line.equals("EndMessage")){
>>>>>>> //Read an extra line to see if there are more to read
>>>>>>> //Read all persistent puts and gets
>>>>>>> line = buffIns.readLine();
>>>>>>> if(line.contains("Get") || line.contains("Put") ||
>>>>>>> line.contains("URI") ||line.contains("Get") || line.contains("Data")
>>>>>>> ||line.contains("Started") || line.contains("Finished")||
>>>>>>> line.contains("Simple")){
>>>>>>> System.out.println(line);
>>>>>>> _Logger.log(line);
>>>>>>> }else{
>>>>>>> return true;
>>>>>>> }
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>> but obviously the reader doesn't know when to stop and so line is never
>>>>>>> null?
>>>>>>>
>>>>>>> Thanks,
>>>>>>>
>>>>>>> Michael
>>>>>>>
>>>>>>> ------------------------------------------------------------------------
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Devl mailing list
>>>>>>> Devl at freenetproject.org
>>>>>>> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl