Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #39113 > unrolled thread

read messages that are both async & sync from one inputstream

Started bymike <mikaelpetterson@hotmail.com>
First post2019-08-20 08:35 -0700
Last post2019-08-20 11:04 -0700
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  read messages that are both async & sync from one inputstream mike <mikaelpetterson@hotmail.com> - 2019-08-20 08:35 -0700
    Re: read messages that are both async & sync from one inputstream Eric Douglas <e.d.programmer@gmail.com> - 2019-08-20 08:53 -0700
    Re: read messages that are both async & sync from one inputstream Eric Sosman <esosman@comcast-dot-net.invalid> - 2019-08-20 13:17 -0400
    Re: read messages that are both async & sync from one inputstream Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2019-08-20 19:58 +0200
    Re: read messages that are both async & sync from one inputstream Eric Douglas <e.d.programmer@gmail.com> - 2019-08-20 11:04 -0700

#39113 — read messages that are both async & sync from one inputstream

Frommike <mikaelpetterson@hotmail.com>
Date2019-08-20 08:35 -0700
Subjectread messages that are both async & sync from one inputstream
Message-ID<e601f9ed-292b-4494-b6b3-0f32d6269c79@googlegroups.com>
Hi,

I have an application that sends/receives output from a product using NETCONF protocol. We basically have 3 types of messages:

1. Configuration messages which is a write/read ( synchronous)
2. KeepAlive messages which is also a write/read ( synchronous ) Done every 10 seconds.
3. Notification messages from the product read-only ( asynchronous )

All of then are running in separate threads.

All output from product is read from an inputStream. The problem we are facing is that the notification messages are cut of for some reason. I can sometimes see that the KeepAlive read() gets the same message ( it checks the format of the message and decides it is not a KeepAlive response message but rather a notification. So looks like KeepAlive "eats" part of the message and then notification reader is reads what is left.

Any ideas of how to solve this without the mess of multiple thread sync?

//mike

[toc] | [next] | [standalone]


#39114

FromEric Douglas <e.d.programmer@gmail.com>
Date2019-08-20 08:53 -0700
Message-ID<463d9228-f2ca-46b4-bd31-76e031493339@googlegroups.com>
In reply to#39113
On Tuesday, August 20, 2019 at 11:35:55 AM UTC-4, mike wrote:
> Hi,
> 
> I have an application that sends/receives output from a product using NETCONF protocol. We basically have 3 types of messages:
> 
> 1. Configuration messages which is a write/read ( synchronous)
> 2. KeepAlive messages which is also a write/read ( synchronous ) Done every 10 seconds.
> 3. Notification messages from the product read-only ( asynchronous )
> 
> All of then are running in separate threads.
> 
> All output from product is read from an inputStream. The problem we are facing is that the notification messages are cut of for some reason. I can sometimes see that the KeepAlive read() gets the same message ( it checks the format of the message and decides it is not a KeepAlive response message but rather a notification. So looks like KeepAlive "eats" part of the message and then notification reader is reads what is left.
> 
> Any ideas of how to solve this without the mess of multiple thread sync?
> 
> //mike

code sample?

[toc] | [prev] | [next] | [standalone]


#39115

FromEric Sosman <esosman@comcast-dot-net.invalid>
Date2019-08-20 13:17 -0400
Message-ID<qjha03$ke7$1@dont-email.me>
In reply to#39113
On 8/20/2019 11:35 AM, mike wrote:
> Hi,
> 
> I have an application that sends/receives output from a product using NETCONF protocol. We basically have 3 types of messages:
> 
> 1. Configuration messages which is a write/read ( synchronous)
> 2. KeepAlive messages which is also a write/read ( synchronous ) Done every 10 seconds.
> 3. Notification messages from the product read-only ( asynchronous )
> 
> All of then are running in separate threads.
> 
> All output from product is read from an inputStream. The problem we are facing is that the notification messages are cut of for some reason. I can sometimes see that the KeepAlive read() gets the same message ( it checks the format of the message and decides it is not a KeepAlive response message but rather a notification. So looks like KeepAlive "eats" part of the message and then notification reader is reads what is left.
> 
> Any ideas of how to solve this without the mess of multiple thread sync?

     Could you please try to describe your problem more precisely?
Some points that are confusing (to me, at least):

     - What does "synchronous" mean?  Ordinarily it means that the
timing or occurrence of each event is "synchronized" with one or
more other events: A speaks while B listens, then B speaks while A
listens, that sort of thing.  But what does "synchronous" mean to you?

     - Similarly for "asynchronous," which usually means that an event's
occurrence or timing is not influenced by other (visible) events.  For
example, maybe C interrupts out of the blue while A and B are calmly
taking turns; C's message would be "asynchronous" to those of A and B.
But what do you mean by the term?

     - What is a "read/write message?"  I am not NETCONF-schooled, but
from the Wikipedia description it appears that each message carries a
complete XML document.  Do you modify the document and send it back to
its origin, or what?  And why is this "read/write" cycle any different
from any other "read/reply?"

     - What do you mean by "running in separate threads?"  I can easily
see that there could be many transmitting threads, but if there's more
than one receiver it's hard to imagine how confusion is avoidable.  (In
a traditionally-synchronous protocol it might be possible to "know"
which kind of message will be forthcoming next, but then you'd need some
way to "arm" the proper thread to receive it -- this sounds sort of like
the "mess" you want to avoid, and would be completely unable to handle
traditionally-asynchronous utterances.)

     Perhaps (only "perhaps!") what you need is a single receiver that
catches *all* incoming messages, decides what type they are, and stuffs
each onto a type-appropriate queue for the other threads to process.
Yes, this involves you in "multiple thread sync," but there's very
little "mess" to worry about.  If that's not helpful, please give more
detail.

-- 
esosman@comcast-dot-net.invalid
Five hundred nineteen days to go.

[toc] | [prev] | [next] | [standalone]


#39116

FromDaniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Date2019-08-20 19:58 +0200
Message-ID<qjhcbk$2d1$1@dont-email.me>
In reply to#39113
On 2019-08-20 17:35, mike wrote:
> Hi,
> 
> I have an application that sends/receives output from a product using NETCONF protocol. We basically have 3 types of messages:
> 
> 1. Configuration messages which is a write/read ( synchronous)
> 2. KeepAlive messages which is also a write/read ( synchronous ) Done every 10 seconds.
> 3. Notification messages from the product read-only ( asynchronous )
> 
> All of then are running in separate threads.
> 
> All output from product is read from an inputStream. The problem we are facing is that the notification messages are cut of for some reason. I can sometimes see that the KeepAlive read() gets the same message ( it checks the format of the message and decides it is not a KeepAlive response message but rather a notification. So looks like KeepAlive "eats" part of the message and then notification reader is reads what is left.
> 
> Any ideas of how to solve this without the mess of multiple thread sync?
> 
> //mike
> 

You can't read with multiple threads from the same InputStream.

And multiple thread sync is not a mess, it's art.

You need a single-threaded read + multi-threaded dispatch.

-- 
DF.

[toc] | [prev] | [next] | [standalone]


#39118

FromEric Douglas <e.d.programmer@gmail.com>
Date2019-08-20 11:04 -0700
Message-ID<e448e624-0947-4d5b-9889-1d57ba6a6597@googlegroups.com>
In reply to#39113
On Tuesday, August 20, 2019 at 11:35:55 AM UTC-4, mike wrote:
> Hi,
> 
> I have an application that sends/receives output from a product using NETCONF protocol. We basically have 3 types of messages:
> 
> 1. Configuration messages which is a write/read ( synchronous)
> 2. KeepAlive messages which is also a write/read ( synchronous ) Done every 10 seconds.
> 3. Notification messages from the product read-only ( asynchronous )
> 
> All of then are running in separate threads.
> 
> All output from product is read from an inputStream. The problem we are facing is that the notification messages are cut of for some reason. I can sometimes see that the KeepAlive read() gets the same message ( it checks the format of the message and decides it is not a KeepAlive response message but rather a notification. So looks like KeepAlive "eats" part of the message and then notification reader is reads what is left.
> 
> Any ideas of how to solve this without the mess of multiple thread sync?
> 
> //mike

If you have multiple threads client-side looking for different messages from one stream from the server/product, you should have one thread reading the stream which passes along each message to the appropriate thread.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web