Hi, Folks:

I asked about this in February and have managed to move ahead without a proper solution. However, I am seeing glitches that point to synchronizing problems, so I would greatly appreciate any help that you could offer me. To recap: how do I synchronize the operation of a thread external to mina so that it plays nicely with mina? In particular, I have no idea what to synchronize *with*. My first thought was that synchronizing with IoSession would be the thing to do, but an inspection of the mina source code does not support this notion.

BTW, mina 2 has been a treat thus far. It is much slicker than mina 1, and is working very well for us. Thank you all for such a super piece of work.

Best regards,
Yigal


Yigal Rachman wrote: Hi, Mark:

Thank you for your rapid response - I really appreciate it.

Here is a distilled example of the kind of thing I have to do (there are a host of other similar examples). The Mina application is a network client that communicates with a scientific instrument. The client must periodically poll the instrument for its data. I am using a repeating timer to do this. Whenever the timer expires, it invokes a callback which writes a command to the instrument via Mina; this is where the synchronization is required. Below is a simplified snippet of code that demonstrates the problem. I have not sent the actual code because it is wrapped in my own layer of stuff, which just serves to confuse the issue. Also, I am not showing any synchronization here, although clearly some is needed (the topic of this post).


// notes:
// this thing manages just one session (the code that enforces this is omitted) // there is a TextLineCodec installed to convert between strings and raw ascii

public class DriverProtocolHandler extends IoHandlerAdapter {

   // the Timer thread on which all poll timers run
private static final Timer thePollTimerThread = new Timer("thePollTimerThread", true);

   // the timer callback task that operates in this instance
   private final PollTimerTask pollTimerTask = new PollTimerTask();

   // the session for this instance
   private IoSession session = null;

  // when the session opens
   public void sessionOpened(IoSession session) throws Exception {
       this.session = session;

// schedule a repeating timer on the given thread (this will repeat until canceled)
       long delayMsec = 0;         // start immediately
       long periodMsec = 1000;  // each tick is 1000 milliseconds
pollTimerTask.scheduleAtFixedRate(thePollTimerThread, delayMsec, periodMsec);
   }

   // when the session closes
   public void sessionClosed(IoSession session) throws Exception {
             // turn out the lights
             pollTimerTask.cancel();
             this.session = null;
   }


  // the timer inner class
// [ DurableTimerTask is simply a robust wrapper around java.util.TimerTask ]
  //
   private class PollTimerTask extends DurableTimerTask {

       // this is called once for each tick of the timer
       protected void run() throws Exception {
           if (session != null) {
               // poll the instrument
               session.write("\n");
           }
       }
   }



Please let me know if you need more information.

Thanks again,
Yigal




Mark Webb wrote:
I think I understand your problem, but maybe a sample program would
make things clearer...


On Mon, Feb 25, 2008 at 6:51 PM, Yigal Rachman <[EMAIL PROTECTED]> wrote:
Hi, Folks:

 I am thinking that the synchronizing bug is almost certainly in my
 application code.  Said application uses the Timer class to invoke some
 asynchronous processing.  The methods are all synchronized, but probably
 on the wrong instance!  So my follow-up question is: If I need to ensure
 that another thread does not conflict with a Mina thread, how do I
 synchronize it?

 Yigal Rachman


---------- Forwarded message ----------
From: Yigal Rachman <[EMAIL PROTECTED]>
To: dev@mina.apache.org
Date: Mon, 25 Feb 2008 14:51:57 -0800
Subject: Mina 2 problem - InvalidMarkException in java.nio.Buffer
Hi, Folks:

 I am biting the bullet and porting to Mina 2.0.0-M1.  Thus far, I seem
 to have resolved all the changes without much pain.  I love the look of
 the revised Mina - elegant and even simpler to use - wow!

 I have, however, run into a problem which appears to come from the
 bowels of Mina.  Here is the exception I am seeing:

 java.nio.InvalidMarkException
    at java.nio.Buffer.reset(Unknown Source)
    at
 org.apache.mina.common.AbstractIoBuffer.reset(AbstractIoBuffer.java:321)
    at
 
org.apache.mina.common.AbstractPollingIoProcessor.writeBuffer(AbstractPollingIoProcessor.java:577)
    at
 
org.apache.mina.common.AbstractPollingIoProcessor.flushNow(AbstractPollingIoProcessor.java:528)
    at
 
org.apache.mina.common.AbstractPollingIoProcessor.flush(AbstractPollingIoProcessor.java:469)
    at
 
org.apache.mina.common.AbstractPollingIoProcessor.access$500(AbstractPollingIoProcessor.java:43)
    at
 
org.apache.mina.common.AbstractPollingIoProcessor$Worker.run(AbstractPollingIoProcessor.java:681)
    at
 org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
 Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

 The message is clear enough: no mark has been set on the buffer, so a
 reset is not possible.  But it does look fishy.. perhaps a thread that
 is not properly synchronized?  Ideas, anyone?

 Thank you all for your continuing help.

 Yigal Rachman






Reply via email to