Apache Mina synchronous receive client message

Source: Internet
Author: User
Tags getmessage
Apache Mina synchronous receive client message Blog Categories:Mina Mina

We know that in MINA2, two separate worker threads are sent and accepted, but you can set a parameter to read the client's return synchronously after the server sends the message: Java code session.getconfig (). Setusereadoperation ( true);



Recently, using MINA2 (RC) Synchronous reading method, found that can not really synchronous read the client's return;
The scenario is: The server sends a message to the client, needs to synchronize a message receipt for the client, and then the server's program continues to execute;
  Java code    sendsession.getconfig (). Setusereadoperation (True);            writefuture future = sendsession.write (XmlMsgBean); //  send data            future.awaituninterruptibly (); //  Waiting to send data operation completed            if  (future.getexception ()  !=  null)  {               throw  new appexception (Future.getexception (). GetMessage ());            }           if  (Future.iswritten ())  {               //  Data has been sent successfully                logger.debug ("Data has been successfully sent");     &NBsp;          readfuture readfuture =  Sendsession.read ();                readfuture.awaituninterruptibly ();                if  (Readfuture.getexception ()  != null)  {                    throw new appexception ( Readfuture.getexception (). GetMessage ());                }                Sendsession.getconfig (). Setusereadoperation (false);                return  ((Xmlmsgbean)  readfuture.getmessage ()). Getstrerrmsg ();            } else {               //   Data send failure                logger.debug (" Data send Failed ");           }       





Later, Google search for a while, found in Mina's official online, the foreigner also asked an identical question, and raised a bug up, but the current state of the bug or open;
https://issues.apache.org/jira/browse/DIRMINA-777
  Java code    I ' m attempting to perform a synchronous write/read  in a demux-based client application with mina 2.0 rc1, but  it seems to get stuck. here is my code:       { code}    Public boolean login (final string username, final string  password)  {        // block inbound messages         session.getconfig (). Setusereadoperation (true);            // send the login request         final loginrequest loginrequest = new loginrequest (username,  Password);        final WriteFuture writeFuture =  Session.write (loginrequEST);        writefuture.awaituninterruptibly ();            if  (Writefuture.getexception ()  != null)  {            session.getconfig (). Setusereadoperation (False);             return false;         }           // retrieve the login  response        final ReadFuture readFuture =  Session.read ();        readfuture.awaituninterruptibly ();           if  (readfuture.getexception ()  != null)  {             session.getconfig (). Setusereadoperation (False);             return false;        }           // stop blocking inbound messages        session.getconfig (). Setusereadoperation (false);            // determine if the login info provided was valid         final LoginResponse loginResponse =  ( Loginresponse) readfuture.getmessage ();        return  Loginresponse.getsuccess ();   }    {code}       I can  see on the server side that the loginrequest object is  retrieved, and a LoginResponse message is sent. On the  Client side, the demuxingprotoColcodecfactory receives the response, but after throwing in some  logging, i can see that the client gets stuck on the  call to  ' readfuture.awaituninterruptibly ()   ' .       i can ' t  for the life of me figure out why it is stuck  here based upon my own code. i properly set the read  Operation to true on the session config, meaning that messages  should be blocked. however, it seems as if the message  no longer exists by time I try to read response  messages synchronously.  


  
key:dirmina-777  
type:  bug  
status:  Open  &NBSP
priority:  blocker  
assignee:unassigned  
Reporter:matt Huggins  &NBSP
votes:0  
watchers:0  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.