mina-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oscar <ro4...@gmail.com>
Subject Re: problem
Date Fri, 25 Jul 2008 16:54:02 GMT
Josic, you're right.
If we added code to feed data to client in *sessionOpened*, server-side
would get a read event, then it tried to *read* the data.

*        if (isReadable(session) && session.getTrafficMask().isReadable()) {
            read(session);
        }


            if (ret < 0) {
                scheduleRemove(session);
            }

*Then, the session was scheduled to be removed.

So far I have no idea about why server got a *read* event.
Anybody know it?

Thank you,
-Oscar

On Fri, Jul 25, 2008 at 11:41 PM, Zlatko Josic <zlatko.josic@gmail.com>
wrote:

> Hi,
>
> i think there is problem with sessionOpen method call. I put counter in
> that
> method and it was  not called as many times as it should be.
>
> When i put code from sessionOpen method into messageReceivde everythis
> works
> fine.
>
> On Fri, Jul 25, 2008 at 4:06 PM, Zlatko Josic <zlatko.josic@gmail.com>
> wrote:
>
> > Thanks for reply.
> >
> > That is right client is blocked...but i dont unterstand why client never
> > get data from server.
> > Server does not report any error.
> >
> > This is the scenario.
> >
> > 1.Client connect to server
> > 2. Server writes data to client (This is done in sessionOpen metnod,
> > initiali was in sessionCreated)
> > 3. Client sends request to server.
> > 4. Server response to client.
> >
> > Some clinet stuck in step 2.
> >
> >
> > On Fri, Jul 25, 2008 at 3:55 PM, Oscar <ro4tub@gmail.com> wrote:
> >
> >> Since your client uses the blocked socket,  it is blocked at
> >> 'br.readLine()'.
> >>
> >> That is, client doesn't end until server feeds data to it.
> >>
> >>
> >> On Fri, Jul 25, 2008 at 7:25 PM, Zlatko Josic <zlatko.josic@gmail.com>
> >> wrote:
> >>
> >> > does session that entered idle state can write and read mesasage
> later?
> >> >
> >> > On Fri, Jul 25, 2008 at 1:17 PM, Zlatko Josic <zlatko.josic@gmail.com
> >> > >wrote:
> >> >
> >> > > Hi,
> >> > >
> >> > > tnis is snippet code of client
> >> > >
> >> > >     for (int i = 0; i < stepNumber; i++) {
> >> > >             ClientRequest request = new ClientRequest();
> >> > >             request.setParameter("command", "addEVEronet");
> >> > >             request.setParameter("Amt", "10");
> >> > >             request.setParameter("phoneNumber", "0642361393");
> >> > >             request.setParameter("serN", "000001");
> >> > >             // slanje zahteva.
> >> > >
> >> > >             // kreiranje soketa.
> >> > >             Socket socket = null;
> >> > >             BufferedReader br = null;
> >> > >             PrintWriter pw = null;
> >> > >             Map<String, Object> result = null;
> >> > >             try {
> >> > >                 socket = new Socket(host, port);
> >> > >                 br = new BufferedReader(new
> >> > > InputStreamReader(socket.getInputStream()));
> >> > >                 pw = new PrintWriter(socket.getOutputStream());
> >> > >                 //citanje trenutnog vremena.
> >> > >                 result = readTransformator.transform(br.readLine());
> >> > >                 log.info(CollectionsUtil.formatMap(result));
> >> > >
> >> > >                 String currTime = (String)result.get("currT");
> >> > >                 //kriptovana vrednost.
> >> > >                 String crypt = Coder.decode(currTime);
> >> > >                 request.setParameter("orN", crypt);
> >> > >                 pw.println(writeTransformator
> >> > >                         .transform(request.getParameters()));
> >> > >                 pw.flush();
> >> > >                 result = readTransformator.transform(br.readLine());
> >> > >                 log.info(CollectionsUtil.formatMap(result));
> >> > >             } catch (UnknownHostException e) {
> >> > >                 throw new DestinationNotAvailableException(e);
> >> > >             } catch (IOException e) {
> >> > >                 throw new DestinationNotAvailableException(e);
> >> > >             } finally {
> >> > >                 //zatvaranje resursa.
> >> > >                 SocketUtil.close(socket);
> >> > >                 IOUtil.close(br);
> >> > >                 IOUtil.close(pw);
> >> > >
> >> > >             }
> >> > >
> >> > >             sleepQuetly(3*1000);
> >> > >         }// for
> >> > >
> >> > >
> >> > > and this is snippet of server code
> >> > >
> >> > > public void process(final MobileContext context) {
> >> > >         //uzimanje sesije.
> >> > >         IoSession session =
> >> (IoSession)context.getParameter("ioSession");
> >> > >         TransactionDirector transactionDirector =
> >> > > (TransactionDirector)context.getParameter("transactionDirector");
> >> > >         final DaoFactory daoFactory =
> >> > > (DaoFactory)context.getParameter("daoFactory");
> >> > >         final Transaction transaction =
> >> > > transactionDirector.getTransaction();
> >> > >         final Voucher voucher = transaction.getVoucher();
> >> > >
> >> > >
> >> > >         final WriteFuture future =
> >> > >
> >> >
> >>
> session.write(transformator.transform(context.getResponse().getParameters()));
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >         future.addListener(new IoFutureListener<IoFuture>(){
> >> > >
> >> > >             @Override
> >> > >             public void operationComplete(IoFuture ioFuture) {
> >> > >                 try{
> >> > >                 WriteFuture newfuture = (WriteFuture)future.await();
> >> > >                 //WriteFuture future = (WriteFuture)ioFuture;
> >> > >
> >> > >                 //provera da li je podatak upisan.
> >> > >                 if (newfuture.isWritten()){
> >> > >
> >> > >                     //provera da li j u pitanju offline dopuna.
> >> > >                     if (voucher!= null){
> >> > >                         VoucherDao dao = daoFactory.getVoucherDao();
> >> > >                         //oznacavanje da je voucher iskoriscen.
> >> > >                         try {
> >> > >                             dao.updateUsed(voucher);
> >> > >                         } catch (DaoException e) {
> >> > >                             log.error("Nije oznaceno u bazi da je
> >> vaucer
> >> > > iskoriscen "+voucher.getId(),e);
> >> > >                         }
> >> > >                     }
> >> > >                 }else{
> >> > >                     //ako odgovor nije poslat terminalu vraca se
> >> vaucer u
> >> > > red.
> >> > >                     if (voucher != null){
> >> > >                         Queue queue =
> >> > (Queue)context.getParameter("queue");
> >> > >                         queue.putVoucher(voucher);
> >> > >                     }else{
> >> > >                         //TODO register for autostorno.
> >> > >                     }
> >> > >                     TransactionDao dao =
> >> daoFactory.getTransactionDao();
> >> > >                     try {
> >> > >
> >> > > dao.updateDelivered(transaction.getTransactionId(),NOT_DELIVERED);
> >> > >                     } catch (DaoException e) {
> >> > >                         log.error("Nije oznaceno u bazi da poruka
> nije
> >> > > isporucena klijentu "+transaction.getTransactionId());
> >> > >                     }
> >> > >
> >> > >                     //provera da li je doslo do greske pri slanju
> >> > odgovora.
> >> > >                     Throwable t = future.getException();
> >> > >                     if (t != null){
> >> > >                         log.error("Greska pri slanju odgovara
> klijentu
> >> za
> >> > > transakciju "+transaction.getTransactionId(),t);
> >> > >                     }
> >> > >                 }
> >> > >
> >> > >
> >> > >             }catch(Throwable e){
> >> > >                 log.error("Ovde je problem",e);
> >> > >             }
> >> > >
> >> > >             }
> >> > >
> >> > >         }
> >> > >
> >> > >             );
> >> > >         session.closeOnFlush();
> >> > >
> >> > >
> >> > >
> >> >
> >>
> //System.out.println(""+context.getResponse().getParameter(TerminalKeys.ERR));
> >> > >         context.endProcessing();
> >> > >
> >> > >
> >> > >     }
> >> > >
> >> > > On Fri, Jul 25, 2008 at 4:50 AM, Wenrui Guo <
> wenrui.guo@ericsson.com
> >> > >wrote:
> >> > >
> >> > >> From my point of view, you had better post your code snippet from
> >> your
> >> > >> application. For example, the logic of client side.
> >> > >>
> >> > >> BR
> >> > >> anderson
> >> > >>
> >> > >> -----Original Message-----
> >> > >> From: Zlatko Josic [mailto:zlatko.josic@gmail.com]
> >> > >> Sent: Friday, July 25, 2008 3:36 AM
> >> > >> To: users@mina.apache.org
> >> > >> Subject: problem
> >> > >>
> >> > >> Hi,
> >> > >>
> >> > >> I have server based on mina framework adn stupid socket client.
> >> > >> Messages sent to server have "\n\r" for end of message  and
> messages
> >> > >> send to client have '\n' for end of message.
> >> > >>
> >> > >> When I start lot of clients some of clients never ends and server
> has
> >> > >> lotof sessionIdle method calls.
> >> > >>
> >> > >> what can be problem?
> >> > >>
> >> > >> Thanks for any help.
> >> > >>
> >> > >
> >> > >
> >> >
> >>
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message