You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Kevin Kal <ke...@hotmail.com> on 2019/02/08 14:01:34 UTC

Loopback messages

Dear Sir/Madam,

I've been trying to find out how to send loopback messages on a IoSession, but I can't seem to figure this out.

My situation is as follows:
I am making a Game Server with NioSocketAcceptor. Each incoming connection is saved and every actually works fine. BUT, I need a way to execute something from one thread in a sessions thread. The easiest way I thought would be to use loopback messages, but there seems to be no way to do this. I've been looking at the source code and I don't think there is any way to execute something (asap) in a sessions thread.

Do you have any idea how I can implement this? I can't find anything on the internet about this. All I want is to schedule something on a sessions thread or just the ability to send loopback message.

Kind regards,
Kevin

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
On 08/02/2019 15:22, Jonathan Valliere wrote:
> You mean that you want to pass messages from one thread to another?


Or from one session to another one ?


>
> On Fri, Feb 8, 2019 at 9:02 AM Kevin Kal <ke...@hotmail.com> wrote:
>
>> Dear Sir/Madam,
>>
>> I've been trying to find out how to send loopback messages on a IoSession,
>> but I can't seem to figure this out.
>>
>> My situation is as follows:
>> I am making a Game Server with NioSocketAcceptor. Each incoming connection
>> is saved and every actually works fine. BUT, I need a way to execute
>> something from one thread in a sessions thread. The easiest way I thought
>> would be to use loopback messages, but there seems to be no way to do this.
>> I've been looking at the source code and I don't think there is any way to
>> execute something (asap) in a sessions thread.
>>
>> Do you have any idea how I can implement this? I can't find anything on
>> the internet about this. All I want is to schedule something on a sessions
>> thread or just the ability to send loopback message.
>>
>> Kind regards,
>> Kevin
>>

Re: Loopback messages

Posted by Jonathan Valliere <jo...@emoten.com>.
Is all of this conversation just to avoid using a lock?

The simplest thing to synchronize the non io processor with an external
thread would to use a lock.

On Thu, Feb 14, 2019 at 1:07 PM Emmanuel Lécharny <el...@gmail.com>
wrote:

>
> On 14/02/2019 17:28, kevintjuh93 wrote:
> > Yes, I am aware that's what happens. And in these cases I can make it
> execute
> > at the end of a messageReceived. But my case is that I do something from
> a
> > non io-processor thread, but what it does needs to be synced with the
> > io-processor.
>
> Ok, now that makes sense to me.
>
> The thing is that a session is really tied to a socket, so there is no
> obvious way to send an event to this session. The IoProcessor thread is
> really used only when a SelectorKey is receiving an event, and we can't
> create such an event.
>
> There is something you can do though: there is an idling mechanism that
> can be used to send an event to the IoHandler every second (this is not
> configurable), and you can probably leverage that. When the sessionIdle
> event is processed, you can check if there is something to due in a
> queue that your external thread has filled in.
>
> This is kind of a hack though...
>
> Another possibility would be to get the list of managed sessions from
> your service with the IoService.getManagedSessions() method, but there
> is a limited set of actions you can do on a session: write or set an
> attribute.
>
-- 

CONFIDENTIALITY NOTICE: The contents of this email message and any
attachments are intended solely for the addressee(s) and may contain
confidential and/or privileged information and may be legally protected
from disclosure.

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
On 14/02/2019 17:28, kevintjuh93 wrote:
> Yes, I am aware that's what happens. And in these cases I can make it execute
> at the end of a messageReceived. But my case is that I do something from a
> non io-processor thread, but what it does needs to be synced with the
> io-processor.

Ok, now that makes sense to me.

The thing is that a session is really tied to a socket, so there is no 
obvious way to send an event to this session. The IoProcessor thread is 
really used only when a SelectorKey is receiving an event, and we can't 
create such an event.

There is something you can do though: there is an idling mechanism that 
can be used to send an event to the IoHandler every second (this is not 
configurable), and you can probably leverage that. When the sessionIdle 
event is processed, you can check if there is something to due in a 
queue that your external thread has filled in.

This is kind of a hack though...

Another possibility would be to get the list of managed sessions from 
your service with the IoService.getManagedSessions() method, but there 
is a limited set of actions you can do on a session: write or set an 
attribute.

Re: Loopback messages

Posted by kevintjuh93 <ke...@hotmail.com>.
Yes, I am aware that's what happens. And in these cases I can make it execute
at the end of a messageReceived. But my case is that I do something from a
non io-processor thread, but what it does needs to be synced with the
io-processor.


Emmanuel Lécharny wrote
> Let's be clear:
> 
> - reads will result in a messageReceived event and you will be able to 
> process it and do whatever you want to do in your IoHandler, as soon as 
> the message is complete (ie, if the message is read in chunks, you will 
> only receive a messageReceived event once the message is complete)
> 
> - writes is a bit different: you do write, and you either decide to do 
> something *after* the write has been executed, but without any guarantee 
> that the message has been fully sent to the remote host, *or* you 
> execute your action when you receive the messageSent event - which means 
> you have written a message, *and* it has been fully sent to the remote
> peer.
> 
> In any case, you are still in the IoProcessor thread, so you can do 
> whatever you want (except that if you decide to do what you want to do 
> when receiving the messageSent, it will be executed later on, only if 
> the message has been fully sent.
> 
> 
> On 14/02/2019 16:56, kevintjuh93 wrote:
>> It's for a game server where actions need to be synchronized with
>> read/write
>> in order to make sure everything is done in order. Not everything is
>> executed from read/write methods, so I cannot ensure a message is being
>> received/sent and look at some queue for this.
>>
>> That's why I want to execute something on the same thread a read/write
>> event
>> is done for a specific session.
>>
>>
>> Jonathan Valliere-3 wrote
>>> I just read the last email Kevin wrote.
>>>
>>> Kevin, if you could execute something on the IO processor thread; you
>>> understand that It would be a deferred action that could only happen
>>> after
>>> the IO processor is done?  Maybe you could explain the reason why you
>>> want
>>> to do this?
>>>
>>> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
>>> elecharny@
>>> &gt;
>>> wrote:
>>>
>>>> I still don't get it.
>>>>
>>>> Your IoHandler will be called everytime an event occurs (message
>>>> received, message written, session created/closed/idling, exception).
>>>> You have the opportunity to execute some action at this moment.
>>>>
>>>>
>>>> Beside that, I don't see a use case. I'm probably missing something...
>>>> Unless what you want to do is to have another session to be called
>>>> while
>>>> processing an event, using the thread you are in ?
>>>>
>>>>
>>>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>>>>> There are some examples in the unit tests which accomplish this by
>>>> creating
>>>>> a Client and Server connection.  I don't believe there is a true
>>>> loopback
>>>>> implementation in Mina without going through the OS networking.
>>>>>
>>>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
>>> kevin_kal@
>>> &gt;
>>>> wrote:
>>>>>> Hi guys,
>>>>>>
>>>>>> What I mean is that I want a way to execute something for an
>>>>>> IoSession
>>>> in
>>>>>> the same thread the I/O events run. I figured a good way would be to
>>>> 'fake'
>>>>>> an incoming message, called a loopback packet. Like write a message
>>>>>> to
>>>>>> 'yourself'.
>>>>>>
>>>>>> I rather like to avoid using an ExecutorFilter or a lock.
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Sent from:
>>>>>>
>>>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>>
>>
>>
>>
>> --
>> Sent from:
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html





--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
On 14/02/2019 17:42, Jonathan Valliere wrote:
> On a side note, this is the developers mailing list.  We're filling the
> inboxes of other developers that probably don't want to be a part of this
> conversation.  We should move it to the users@mina.apache.org mailing list.

True.


Although I suggest we keep going, just to avoid splitting the thread.



Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
On a side note, this is the developers mailing list.  We're filling the
inboxes of other developers that probably don't want to be a part of this
conversation.  We should move it to the users@mina.apache.org mailing list.

On Thu, Feb 14, 2019 at 11:36 AM Jonathan Valliere <jo...@apache.org>
wrote:

> so I cannot ensure a message is being received/sent and look at some queue
>> for this.
>
>
> Why do you need to ensure the message is sent?  Once you call write(), it
> will be sent eventually.  The only guarantee that it was actually sent and
> received would to require the Client to reply to the message.  This could
> be done by using some kind of Queue attached to the IoSession which
> contains pending sent requests.
>
> *Note: messageSent* just means it was written to the OS socket, no
> guarantee that it made it anywhere.
>
> On Thu, Feb 14, 2019 at 11:22 AM Emmanuel Lécharny <el...@gmail.com>
> wrote:
>
>> Let's be clear:
>>
>> - reads will result in a messageReceived event and you will be able to
>> process it and do whatever you want to do in your IoHandler, as soon as
>> the message is complete (ie, if the message is read in chunks, you will
>> only receive a messageReceived event once the message is complete)
>>
>> - writes is a bit different: you do write, and you either decide to do
>> something *after* the write has been executed, but without any guarantee
>> that the message has been fully sent to the remote host, *or* you
>> execute your action when you receive the messageSent event - which means
>> you have written a message, *and* it has been fully sent to the remote
>> peer.
>>
>> In any case, you are still in the IoProcessor thread, so you can do
>> whatever you want (except that if you decide to do what you want to do
>> when receiving the messageSent, it will be executed later on, only if
>> the message has been fully sent.
>>
>>
>> On 14/02/2019 16:56, kevintjuh93 wrote:
>> > It's for a game server where actions need to be synchronized with
>> read/write
>> > in order to make sure everything is done in order. Not everything is
>> > executed from read/write methods, so I cannot ensure a message is being
>> > received/sent and look at some queue for this.
>> >
>> > That's why I want to execute something on the same thread a read/write
>> event
>> > is done for a specific session.
>> >
>> >
>> > Jonathan Valliere-3 wrote
>> >> I just read the last email Kevin wrote.
>> >>
>> >> Kevin, if you could execute something on the IO processor thread; you
>> >> understand that It would be a deferred action that could only happen
>> after
>> >> the IO processor is done?  Maybe you could explain the reason why you
>> want
>> >> to do this?
>> >>
>> >> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
>> >> elecharny@
>> >> &gt;
>> >> wrote:
>> >>
>> >>> I still don't get it.
>> >>>
>> >>> Your IoHandler will be called everytime an event occurs (message
>> >>> received, message written, session created/closed/idling, exception).
>> >>> You have the opportunity to execute some action at this moment.
>> >>>
>> >>>
>> >>> Beside that, I don't see a use case. I'm probably missing something...
>> >>> Unless what you want to do is to have another session to be called
>> while
>> >>> processing an event, using the thread you are in ?
>> >>>
>> >>>
>> >>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>> >>>> There are some examples in the unit tests which accomplish this by
>> >>> creating
>> >>>> a Client and Server connection.  I don't believe there is a true
>> >>> loopback
>> >>>> implementation in Mina without going through the OS networking.
>> >>>>
>> >>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
>> >> kevin_kal@
>> >> &gt;
>> >>> wrote:
>> >>>>> Hi guys,
>> >>>>>
>> >>>>> What I mean is that I want a way to execute something for an
>> IoSession
>> >>> in
>> >>>>> the same thread the I/O events run. I figured a good way would be to
>> >>> 'fake'
>> >>>>> an incoming message, called a loopback packet. Like write a message
>> to
>> >>>>> 'yourself'.
>> >>>>>
>> >>>>> I rather like to avoid using an ExecutorFilter or a lock.
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Sent from:
>> >>>>>
>> >>>
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>> >
>> >
>> >
>> >
>> > --
>> > Sent from:
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>>
>

Re: Loopback messages

Posted by kevintjuh93 <ke...@hotmail.com>.
If there is a way I can write a 'fake' message that isn't actually sent to
the client, that would work... 

Any way to do so?

Jonathan Valliere-3 wrote
>>
>> so I cannot ensure a message is being received/sent and look at some
>> queue
>> for this.
> 
> 
> Why do you need to ensure the message is sent?  Once you call write(), it
> will be sent eventually.  The only guarantee that it was actually sent and
> received would to require the Client to reply to the message.  This could
> be done by using some kind of Queue attached to the IoSession which
> contains pending sent requests.
> 
> *Note: messageSent* just means it was written to the OS socket, no
> guarantee that it made it anywhere.
> 
> On Thu, Feb 14, 2019 at 11:22 AM Emmanuel Lécharny &lt;

> elecharny@

> &gt;
> wrote:
> 
>> Let's be clear:
>>
>> - reads will result in a messageReceived event and you will be able to
>> process it and do whatever you want to do in your IoHandler, as soon as
>> the message is complete (ie, if the message is read in chunks, you will
>> only receive a messageReceived event once the message is complete)
>>
>> - writes is a bit different: you do write, and you either decide to do
>> something *after* the write has been executed, but without any guarantee
>> that the message has been fully sent to the remote host, *or* you
>> execute your action when you receive the messageSent event - which means
>> you have written a message, *and* it has been fully sent to the remote
>> peer.
>>
>> In any case, you are still in the IoProcessor thread, so you can do
>> whatever you want (except that if you decide to do what you want to do
>> when receiving the messageSent, it will be executed later on, only if
>> the message has been fully sent.
>>
>>
>> On 14/02/2019 16:56, kevintjuh93 wrote:
>> > It's for a game server where actions need to be synchronized with
>> read/write
>> > in order to make sure everything is done in order. Not everything is
>> > executed from read/write methods, so I cannot ensure a message is being
>> > received/sent and look at some queue for this.
>> >
>> > That's why I want to execute something on the same thread a read/write
>> event
>> > is done for a specific session.
>> >
>> >
>> > Jonathan Valliere-3 wrote
>> >> I just read the last email Kevin wrote.
>> >>
>> >> Kevin, if you could execute something on the IO processor thread; you
>> >> understand that It would be a deferred action that could only happen
>> after
>> >> the IO processor is done?  Maybe you could explain the reason why you
>> want
>> >> to do this?
>> >>
>> >> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
>> >> elecharny@
>> >> &gt;
>> >> wrote:
>> >>
>> >>> I still don't get it.
>> >>>
>> >>> Your IoHandler will be called everytime an event occurs (message
>> >>> received, message written, session created/closed/idling, exception).
>> >>> You have the opportunity to execute some action at this moment.
>> >>>
>> >>>
>> >>> Beside that, I don't see a use case. I'm probably missing
>> something...
>> >>> Unless what you want to do is to have another session to be called
>> while
>> >>> processing an event, using the thread you are in ?
>> >>>
>> >>>
>> >>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>> >>>> There are some examples in the unit tests which accomplish this by
>> >>> creating
>> >>>> a Client and Server connection.  I don't believe there is a true
>> >>> loopback
>> >>>> implementation in Mina without going through the OS networking.
>> >>>>
>> >>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
>> >> kevin_kal@
>> >> &gt;
>> >>> wrote:
>> >>>>> Hi guys,
>> >>>>>
>> >>>>> What I mean is that I want a way to execute something for an
>> IoSession
>> >>> in
>> >>>>> the same thread the I/O events run. I figured a good way would be
>> to
>> >>> 'fake'
>> >>>>> an incoming message, called a loopback packet. Like write a message
>> to
>> >>>>> 'yourself'.
>> >>>>>
>> >>>>> I rather like to avoid using an ExecutorFilter or a lock.
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Sent from:
>> >>>>>
>> >>>
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>> >
>> >
>> >
>> >
>> > --
>> > Sent from:
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>>





--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
On a side note, this is the developers mailing list.  We're filling the
inboxes of other developers that probably don't want to be a part of this
conversation.  We should move it to the users@mina.apache.org mailing list.

On Thu, Feb 14, 2019 at 11:36 AM Jonathan Valliere <jo...@apache.org>
wrote:

> so I cannot ensure a message is being received/sent and look at some queue
>> for this.
>
>
> Why do you need to ensure the message is sent?  Once you call write(), it
> will be sent eventually.  The only guarantee that it was actually sent and
> received would to require the Client to reply to the message.  This could
> be done by using some kind of Queue attached to the IoSession which
> contains pending sent requests.
>
> *Note: messageSent* just means it was written to the OS socket, no
> guarantee that it made it anywhere.
>
> On Thu, Feb 14, 2019 at 11:22 AM Emmanuel Lécharny <el...@gmail.com>
> wrote:
>
>> Let's be clear:
>>
>> - reads will result in a messageReceived event and you will be able to
>> process it and do whatever you want to do in your IoHandler, as soon as
>> the message is complete (ie, if the message is read in chunks, you will
>> only receive a messageReceived event once the message is complete)
>>
>> - writes is a bit different: you do write, and you either decide to do
>> something *after* the write has been executed, but without any guarantee
>> that the message has been fully sent to the remote host, *or* you
>> execute your action when you receive the messageSent event - which means
>> you have written a message, *and* it has been fully sent to the remote
>> peer.
>>
>> In any case, you are still in the IoProcessor thread, so you can do
>> whatever you want (except that if you decide to do what you want to do
>> when receiving the messageSent, it will be executed later on, only if
>> the message has been fully sent.
>>
>>
>> On 14/02/2019 16:56, kevintjuh93 wrote:
>> > It's for a game server where actions need to be synchronized with
>> read/write
>> > in order to make sure everything is done in order. Not everything is
>> > executed from read/write methods, so I cannot ensure a message is being
>> > received/sent and look at some queue for this.
>> >
>> > That's why I want to execute something on the same thread a read/write
>> event
>> > is done for a specific session.
>> >
>> >
>> > Jonathan Valliere-3 wrote
>> >> I just read the last email Kevin wrote.
>> >>
>> >> Kevin, if you could execute something on the IO processor thread; you
>> >> understand that It would be a deferred action that could only happen
>> after
>> >> the IO processor is done?  Maybe you could explain the reason why you
>> want
>> >> to do this?
>> >>
>> >> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
>> >> elecharny@
>> >> &gt;
>> >> wrote:
>> >>
>> >>> I still don't get it.
>> >>>
>> >>> Your IoHandler will be called everytime an event occurs (message
>> >>> received, message written, session created/closed/idling, exception).
>> >>> You have the opportunity to execute some action at this moment.
>> >>>
>> >>>
>> >>> Beside that, I don't see a use case. I'm probably missing something...
>> >>> Unless what you want to do is to have another session to be called
>> while
>> >>> processing an event, using the thread you are in ?
>> >>>
>> >>>
>> >>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>> >>>> There are some examples in the unit tests which accomplish this by
>> >>> creating
>> >>>> a Client and Server connection.  I don't believe there is a true
>> >>> loopback
>> >>>> implementation in Mina without going through the OS networking.
>> >>>>
>> >>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
>> >> kevin_kal@
>> >> &gt;
>> >>> wrote:
>> >>>>> Hi guys,
>> >>>>>
>> >>>>> What I mean is that I want a way to execute something for an
>> IoSession
>> >>> in
>> >>>>> the same thread the I/O events run. I figured a good way would be to
>> >>> 'fake'
>> >>>>> an incoming message, called a loopback packet. Like write a message
>> to
>> >>>>> 'yourself'.
>> >>>>>
>> >>>>> I rather like to avoid using an ExecutorFilter or a lock.
>> >>>>>
>> >>>>>
>> >>>>>
>> >>>>> --
>> >>>>> Sent from:
>> >>>>>
>> >>>
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>> >
>> >
>> >
>> >
>> > --
>> > Sent from:
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>>
>

Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
>
> so I cannot ensure a message is being received/sent and look at some queue
> for this.


Why do you need to ensure the message is sent?  Once you call write(), it
will be sent eventually.  The only guarantee that it was actually sent and
received would to require the Client to reply to the message.  This could
be done by using some kind of Queue attached to the IoSession which
contains pending sent requests.

*Note: messageSent* just means it was written to the OS socket, no
guarantee that it made it anywhere.

On Thu, Feb 14, 2019 at 11:22 AM Emmanuel Lécharny <el...@gmail.com>
wrote:

> Let's be clear:
>
> - reads will result in a messageReceived event and you will be able to
> process it and do whatever you want to do in your IoHandler, as soon as
> the message is complete (ie, if the message is read in chunks, you will
> only receive a messageReceived event once the message is complete)
>
> - writes is a bit different: you do write, and you either decide to do
> something *after* the write has been executed, but without any guarantee
> that the message has been fully sent to the remote host, *or* you
> execute your action when you receive the messageSent event - which means
> you have written a message, *and* it has been fully sent to the remote
> peer.
>
> In any case, you are still in the IoProcessor thread, so you can do
> whatever you want (except that if you decide to do what you want to do
> when receiving the messageSent, it will be executed later on, only if
> the message has been fully sent.
>
>
> On 14/02/2019 16:56, kevintjuh93 wrote:
> > It's for a game server where actions need to be synchronized with
> read/write
> > in order to make sure everything is done in order. Not everything is
> > executed from read/write methods, so I cannot ensure a message is being
> > received/sent and look at some queue for this.
> >
> > That's why I want to execute something on the same thread a read/write
> event
> > is done for a specific session.
> >
> >
> > Jonathan Valliere-3 wrote
> >> I just read the last email Kevin wrote.
> >>
> >> Kevin, if you could execute something on the IO processor thread; you
> >> understand that It would be a deferred action that could only happen
> after
> >> the IO processor is done?  Maybe you could explain the reason why you
> want
> >> to do this?
> >>
> >> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
> >> elecharny@
> >> &gt;
> >> wrote:
> >>
> >>> I still don't get it.
> >>>
> >>> Your IoHandler will be called everytime an event occurs (message
> >>> received, message written, session created/closed/idling, exception).
> >>> You have the opportunity to execute some action at this moment.
> >>>
> >>>
> >>> Beside that, I don't see a use case. I'm probably missing something...
> >>> Unless what you want to do is to have another session to be called
> while
> >>> processing an event, using the thread you are in ?
> >>>
> >>>
> >>> On 14/02/2019 16:21, Jonathan Valliere wrote:
> >>>> There are some examples in the unit tests which accomplish this by
> >>> creating
> >>>> a Client and Server connection.  I don't believe there is a true
> >>> loopback
> >>>> implementation in Mina without going through the OS networking.
> >>>>
> >>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
> >> kevin_kal@
> >> &gt;
> >>> wrote:
> >>>>> Hi guys,
> >>>>>
> >>>>> What I mean is that I want a way to execute something for an
> IoSession
> >>> in
> >>>>> the same thread the I/O events run. I figured a good way would be to
> >>> 'fake'
> >>>>> an incoming message, called a loopback packet. Like write a message
> to
> >>>>> 'yourself'.
> >>>>>
> >>>>> I rather like to avoid using an ExecutorFilter or a lock.
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Sent from:
> >>>>>
> >>>
> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
> >
> >
> >
> >
> > --
> > Sent from:
> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
Let's be clear:

- reads will result in a messageReceived event and you will be able to 
process it and do whatever you want to do in your IoHandler, as soon as 
the message is complete (ie, if the message is read in chunks, you will 
only receive a messageReceived event once the message is complete)

- writes is a bit different: you do write, and you either decide to do 
something *after* the write has been executed, but without any guarantee 
that the message has been fully sent to the remote host, *or* you 
execute your action when you receive the messageSent event - which means 
you have written a message, *and* it has been fully sent to the remote peer.

In any case, you are still in the IoProcessor thread, so you can do 
whatever you want (except that if you decide to do what you want to do 
when receiving the messageSent, it will be executed later on, only if 
the message has been fully sent.


On 14/02/2019 16:56, kevintjuh93 wrote:
> It's for a game server where actions need to be synchronized with read/write
> in order to make sure everything is done in order. Not everything is
> executed from read/write methods, so I cannot ensure a message is being
> received/sent and look at some queue for this.
>
> That's why I want to execute something on the same thread a read/write event
> is done for a specific session.
>
>
> Jonathan Valliere-3 wrote
>> I just read the last email Kevin wrote.
>>
>> Kevin, if you could execute something on the IO processor thread; you
>> understand that It would be a deferred action that could only happen after
>> the IO processor is done?  Maybe you could explain the reason why you want
>> to do this?
>>
>> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;
>> elecharny@
>> &gt;
>> wrote:
>>
>>> I still don't get it.
>>>
>>> Your IoHandler will be called everytime an event occurs (message
>>> received, message written, session created/closed/idling, exception).
>>> You have the opportunity to execute some action at this moment.
>>>
>>>
>>> Beside that, I don't see a use case. I'm probably missing something...
>>> Unless what you want to do is to have another session to be called while
>>> processing an event, using the thread you are in ?
>>>
>>>
>>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>>>> There are some examples in the unit tests which accomplish this by
>>> creating
>>>> a Client and Server connection.  I don't believe there is a true
>>> loopback
>>>> implementation in Mina without going through the OS networking.
>>>>
>>>> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;
>> kevin_kal@
>> &gt;
>>> wrote:
>>>>> Hi guys,
>>>>>
>>>>> What I mean is that I want a way to execute something for an IoSession
>>> in
>>>>> the same thread the I/O events run. I figured a good way would be to
>>> 'fake'
>>>>> an incoming message, called a loopback packet. Like write a message to
>>>>> 'yourself'.
>>>>>
>>>>> I rather like to avoid using an ExecutorFilter or a lock.
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Sent from:
>>>>>
>>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>
>
>
>
> --
> Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by kevintjuh93 <ke...@hotmail.com>.
It's for a game server where actions need to be synchronized with read/write
in order to make sure everything is done in order. Not everything is
executed from read/write methods, so I cannot ensure a message is being
received/sent and look at some queue for this.

That's why I want to execute something on the same thread a read/write event
is done for a specific session.


Jonathan Valliere-3 wrote
> I just read the last email Kevin wrote.
> 
> Kevin, if you could execute something on the IO processor thread; you
> understand that It would be a deferred action that could only happen after
> the IO processor is done?  Maybe you could explain the reason why you want
> to do this?
> 
> On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny &lt;

> elecharny@

> &gt;
> wrote:
> 
>> I still don't get it.
>>
>> Your IoHandler will be called everytime an event occurs (message
>> received, message written, session created/closed/idling, exception).
>> You have the opportunity to execute some action at this moment.
>>
>>
>> Beside that, I don't see a use case. I'm probably missing something...
>> Unless what you want to do is to have another session to be called while
>> processing an event, using the thread you are in ?
>>
>>
>> On 14/02/2019 16:21, Jonathan Valliere wrote:
>> > There are some examples in the unit tests which accomplish this by
>> creating
>> > a Client and Server connection.  I don't believe there is a true
>> loopback
>> > implementation in Mina without going through the OS networking.
>> >
>> > On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 &lt;

> kevin_kal@

> &gt;
>> wrote:
>> >
>> >> Hi guys,
>> >>
>> >> What I mean is that I want a way to execute something for an IoSession
>> in
>> >> the same thread the I/O events run. I figured a good way would be to
>> 'fake'
>> >> an incoming message, called a loopback packet. Like write a message to
>> >> 'yourself'.
>> >>
>> >> I rather like to avoid using an ExecutorFilter or a lock.
>> >>
>> >>
>> >>
>> >> --
>> >> Sent from:
>> >>
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>> >>
>>





--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
I just read the last email Kevin wrote.

Kevin, if you could execute something on the IO processor thread; you
understand that It would be a deferred action that could only happen after
the IO processor is done?  Maybe you could explain the reason why you want
to do this?

On Thu, Feb 14, 2019 at 10:40 AM Emmanuel Lécharny <el...@gmail.com>
wrote:

> I still don't get it.
>
> Your IoHandler will be called everytime an event occurs (message
> received, message written, session created/closed/idling, exception).
> You have the opportunity to execute some action at this moment.
>
>
> Beside that, I don't see a use case. I'm probably missing something...
> Unless what you want to do is to have another session to be called while
> processing an event, using the thread you are in ?
>
>
> On 14/02/2019 16:21, Jonathan Valliere wrote:
> > There are some examples in the unit tests which accomplish this by
> creating
> > a Client and Server connection.  I don't believe there is a true loopback
> > implementation in Mina without going through the OS networking.
> >
> > On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 <ke...@hotmail.com>
> wrote:
> >
> >> Hi guys,
> >>
> >> What I mean is that I want a way to execute something for an IoSession
> in
> >> the same thread the I/O events run. I figured a good way would be to
> 'fake'
> >> an incoming message, called a loopback packet. Like write a message to
> >> 'yourself'.
> >>
> >> I rather like to avoid using an ExecutorFilter or a lock.
> >>
> >>
> >>
> >> --
> >> Sent from:
> >>
> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
> >>
>

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
I still don't get it.

Your IoHandler will be called everytime an event occurs (message 
received, message written, session created/closed/idling, exception). 
You have the opportunity to execute some action at this moment.


Beside that, I don't see a use case. I'm probably missing something... 
Unless what you want to do is to have another session to be called while 
processing an event, using the thread you are in ?


On 14/02/2019 16:21, Jonathan Valliere wrote:
> There are some examples in the unit tests which accomplish this by creating
> a Client and Server connection.  I don't believe there is a true loopback
> implementation in Mina without going through the OS networking.
>
> On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 <ke...@hotmail.com> wrote:
>
>> Hi guys,
>>
>> What I mean is that I want a way to execute something for an IoSession in
>> the same thread the I/O events run. I figured a good way would be to 'fake'
>> an incoming message, called a loopback packet. Like write a message to
>> 'yourself'.
>>
>> I rather like to avoid using an ExecutorFilter or a lock.
>>
>>
>>
>> --
>> Sent from:
>> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>>

Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
There are some examples in the unit tests which accomplish this by creating
a Client and Server connection.  I don't believe there is a true loopback
implementation in Mina without going through the OS networking.

On Thu, Feb 14, 2019 at 10:16 AM kevintjuh93 <ke...@hotmail.com> wrote:

> Hi guys,
>
> What I mean is that I want a way to execute something for an IoSession in
> the same thread the I/O events run. I figured a good way would be to 'fake'
> an incoming message, called a loopback packet. Like write a message to
> 'yourself'.
>
> I rather like to avoid using an ExecutorFilter or a lock.
>
>
>
> --
> Sent from:
> http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html
>

Re: Loopback messages

Posted by kevintjuh93 <ke...@hotmail.com>.
Hi guys,

What I mean is that I want a way to execute something for an IoSession in
the same thread the I/O events run. I figured a good way would be to 'fake'
an incoming message, called a loopback packet. Like write a message to
'yourself'.

I rather like to avoid using an ExecutorFilter or a lock.



--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by kevintjuh93 <ke...@hotmail.com>.
What I mean is to send a loopback message. This means I want to write a
message to the session that's sending the message. But the reason I want to
do this, is because I need to execute something synchronized with the I/O
events (read/write).



--
Sent from: http://apache-mina.10907.n7.nabble.com/Apache-MINA-Developer-Forum-f6809.html

Re: Loopback messages

Posted by Emmanuel Lécharny <el...@gmail.com>.
On 08/02/2019 15:22, Jonathan Valliere wrote:
> You mean that you want to pass messages from one thread to another?

Or from one session to another one ?


>
> On Fri, Feb 8, 2019 at 9:02 AM Kevin Kal <ke...@hotmail.com> wrote:
>
>> Dear Sir/Madam,
>>
>> I've been trying to find out how to send loopback messages on a IoSession,
>> but I can't seem to figure this out.
>>
>> My situation is as follows:
>> I am making a Game Server with NioSocketAcceptor. Each incoming connection
>> is saved and every actually works fine. BUT, I need a way to execute
>> something from one thread in a sessions thread. The easiest way I thought
>> would be to use loopback messages, but there seems to be no way to do this.
>> I've been looking at the source code and I don't think there is any way to
>> execute something (asap) in a sessions thread.
>>
>> Do you have any idea how I can implement this? I can't find anything on
>> the internet about this. All I want is to schedule something on a sessions
>> thread or just the ability to send loopback message.
>>
>> Kind regards,
>> Kevin
>>

Re: Loopback messages

Posted by Jonathan Valliere <jo...@apache.org>.
You mean that you want to pass messages from one thread to another?

On Fri, Feb 8, 2019 at 9:02 AM Kevin Kal <ke...@hotmail.com> wrote:

> Dear Sir/Madam,
>
> I've been trying to find out how to send loopback messages on a IoSession,
> but I can't seem to figure this out.
>
> My situation is as follows:
> I am making a Game Server with NioSocketAcceptor. Each incoming connection
> is saved and every actually works fine. BUT, I need a way to execute
> something from one thread in a sessions thread. The easiest way I thought
> would be to use loopback messages, but there seems to be no way to do this.
> I've been looking at the source code and I don't think there is any way to
> execute something (asap) in a sessions thread.
>
> Do you have any idea how I can implement this? I can't find anything on
> the internet about this. All I want is to schedule something on a sessions
> thread or just the ability to send loopback message.
>
> Kind regards,
> Kevin
>