Regular hashMap is enough, as long as there is exactly one map per RPC.  If 
there are multiple RPCs, you will need to synchronize.  (Stated 
differently: each request StreamObserver and map pair should be 1-1 and 
onto, e.g a bijection). 


More detail:   each RPC has an associated SerializingExecutor that handles 
the callbacks for that RPC.   The SerializingExecutor is executed inside of 
the executor you provided to the ServerBuilder at construction.  The SE 
ensures that no callback for the given RPC overlaps with any other callback 
for the same RPC.  Thus, you can be sure that you don't get onCancelled in 
the middle of onMessage.   The events may happen on different threads, 
which is up to the executor you provided to the server.  This is okay, 
because there is a "Happens Before" relationship between the callbacks.  
The necessary synchronization barriers are present  to ensure you don't 
need to add your own.  

On Wednesday, June 19, 2019 at 12:50:56 AM UTC-7, Alexander Furer wrote:
>
> Thanks Carl, but I'll rephrase  the question.
> On the server side,my implementation of 'onNext'  aggregates the streaming 
> messages in to some in-memory storage, say Map. No one else is accessing it 
> till I get OnCompleted from client. 
> Does this map should be ConcurrentMap (in java language)  or regular 
> HashMap is enough ?
> I'm asking if  each 'onNext' waits completion of previous one before being 
> executed or they can be invoked in parallel ?
>  
>
>
> On Wednesday, June 12, 2019 at 7:41:00 PM UTC+3, Carl Mastrangelo wrote:
>>
>> What that means is that the messages will never be reordered.  You MUST 
>> synchronize access to the RPC, either by ensuring only one thread ever 
>> accesses it, or adding your own synchronization.  
>>
>> The comment you see is more in regards to other network stuff (like UDP), 
>> where packets can be reordered.  
>>
>> On Wednesday, June 12, 2019 at 1:38:15 AM UTC-7, Alexander Furer wrote:
>>>
>>> From the grpc guide "gRPC guarantees message ordering within an 
>>> individual RPC call."
>>>
>>> Given the service definition  
>>>
>>> rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse) {}
>>>
>>> does it mean that implementation of  onNext(HelloRequest request)  does 
>>> NOT need to be synchronized ? 
>>> In the other words, the onNext(HelloRequest request) is invoked  
>>> sequentially one after another ?
>>> Thanks
>>>
>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/28384952-e945-4f85-b1de-84b1455d8715%40googlegroups.com.

Reply via email to