hi, everyone.
I profiled my application, and found that this way indeed got bad
perfermance..
Can you give me some advice, thanks.
On 11/3/06, sishen <[EMAIL PROTECTED]> wrote:
On 11/3/06, Hieu Phan Thanh <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> You could not check by the code:
> while(!IoSession.containsAttribute("result"));
> Because the IoSession instances are different between Server side and
> Client side (2 different processes).
No. you misunderstand my meaning.
I use this way because there are the same IoSession.
More details. I hope now i explain my idea more clearly, :)
Client:
public class ResultMessageHandler implements MessageHandler {
public void messageReceived(IoSession session, Object message) throws
Exception {
// TODO Auto-generated method stub
ResultMessage result = (ResultMessage)message;
session.setAttribute("result", result);
}
}
ResultMessage is decoded by the class ResultMessageDecoder, which is
implemented in another class of mine.
public class ClientSessionHandler extends DemuxingIoHandler {
public ClientSessionHandler() {
super.addMessageHandler(ResultMessage.class , new
ResultMessageHandler());
super.addMessageHandler(ErrorMessage.class, new
ErrorMessageHandler());
}
}
public class Client {
IoSession session;
ConnectFuture future = connector.connect(new
InetSocketAddress(host, port), handler, cfg);
future.join();
session = future.getSession();
while (!session.containsAttribute("result")
;
}
I can ensure that i can read the attribute from the same IoSession.
But i don't prefer the way i use in the class "ResultMessageHandler". I
want a more flexible way than setAttribute().
Because using containsAttribute to judge whether i have received
ResultMessage may block the whole application
unexpectedly, i'm afraid.
You should modify the protocol: server will send the acknowledge (ACK)
> back to client whenever the message is received completely via the
> messageReceived() of MINA framework. How do you think?
>
> I have been working around this protocol for month in my current
> project.
>
> Thanks & best regards,
> Hieu Phan.
>
> > -----Original Message-----
> > From: sishen [mailto:[EMAIL PROTECTED]
> > Sent: Thursday, November 02, 2006 3:05 PM
> > To: [email protected]
> > Subject: Re: How to get the received message object?
> >
> > On 11/1/06, Hieu Phan Thanh < [EMAIL PROTECTED]> wrote:
> > >
> > > Hi,
> > >
> > > > But i don't know when the result message is done. I use
> > > I don't know what you meant when saying "when the result message is
> > > done"? MINA just helps us to transfer the message. And you have to
> > > customize and handle the processing logic of the system yourself.
> > > Please give me more detail or something related. Hope I could help
> you
> > > guy.
> >
> >
> > That's when the message is received by client totally.
> > for (::) {
> > try {
> > ConnectFuture future = connector.connect(new
> InetSocketAddress(host,
> > port), handler, cfg);
> > future.join();
> > session = future.getSession();
> > break;
> > } catch ... {
> > }
> > }
> >
> > When i connect to the server, i send a query message. And
> furture.join()
> > is
> > return just when the connection is established.
> >
> > I want to ensure that i have received the request message which is
> sent by
> > the server. My question is how can i do this?
> >
> > Now i use
> >
> > when received message,
> > I set an attribute in the IoSession. IoSession.setAttribute("result",
> > object);
> >
> > and in the client's process flow, i use while statement to ensure the
>
> > message is received totally.
> >
> > while ( !IoSession.containsAttribute("result") )
> > ;
> >
> > I'm seeking a better way. Thx for advice, :)
> >
> > > Thanks & best regards,
> > > Hieu Phan.
> > >
> > > > -----Original Message-----
> > > > From: sishen [mailto:[EMAIL PROTECTED]
> > > > Sent: Wednesday, November 01, 2006 4:26 PM
> > > > To: [email protected]
> > > > Subject: How to get the received message object?
> > > >
> > > > public class ResultMessageHandler implements MessageHandler {
> > > > public void messageReceived(IoSession session, Object message)
> > > throws
> > > > Exception {
> > > > ResultMessage result = (ResultMessage)message;
> > > > System.out.println("Message Received: ResultMessage");
> > > > }
> > > > }
> > > >
> > > > when i received the ResultMessage, i need to save it.
> > > >
> > > > Now i use
> > > > session.setAttribute("result", result);
> > > > And in the client,
> > > > ResultMessage result =
> (ResultMessage)session.getAttribute("result");
> > > >
> > > > But i don't know when the result message is done. I use
> > > > while (!session.containsAttribute("result"))
> > > > ;
> > > > ResultMessage result =
> (ResultMessage)session.getAttribute("result");
> > > >
> > > > But this has an problem, which is that when the server met an
> mistake,
> > > it
> > > > will block forever. I do not prefer this way.
> > > >
> > > >
> > > > I want to know whether there is a way to solve this problem. I
> want
> > > to
> > > > return the message the server sent to me.
> > > >
> > > > thx~
> > >
> > >
>
>