You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Coding Horse <zh...@hotmail.com> on 2007/04/08 15:40:39 UTC

a question when learning mina-sm

Hi, Community,

I'm trying to model my app logic with mina-sm framework and reading
StateMachineProxyFactoryTest as the start point, like what was suggested by
Niklas.

There are lines like this:

        @Handler( on = "eject",  in = "s4", next = "s1" )
        public void ejected()
        {
            messages.add( "Tape ejected" );
        }

I'm not sure I understand the above code correctly:
If current state is "s4" and event "eject" is received, the method ejected()
of the hander will be called and then the state will be changed to "s1".

Also, I can't figure out how to model this scenario:
conditioned state transition, like:
if(condition met){
  // next state is "stateA"
}else{
  // next state is "stateB"
}
It seems to me that the state transition is predefine in  
on = "eject",  in = "s4", next = "s1"

Anyone can shed light on this?  Thanks a lot!
-- 
View this message in context: http://www.nabble.com/a-question-when-learning-mina-sm-tf3543552.html#a9892328
Sent from the mina dev mailing list archive at Nabble.com.


Re: mina-sm: other options?

Posted by Trustin Lee <tr...@gmail.com>.
On 5/26/07, Niklas Therning <ni...@trillian.se> wrote:

<snip/>

> My main motivation for starting mina-sm was that I wanted to express my
> state machine in pure Java. It's by no means finished so any suggestions
> for improvements would be most welcome.
>
> If you want more info about mina-sm you could check out the tutorial I'm
> working on,
> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
> Please be aware that it's not finished yet.

It's an exciting tutorial for me. :)  Can't wait the IoHandler example!

Cheers,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: mina-sm: other options?

Posted by Julien Vermillard <jv...@archean.fr>.
Le vendredi 01 juin 2007 à 10:51 +0200, Niklas Therning a écrit :
> Julien Vermillard wrote:
> > Le samedi 26 mai 2007 à 09:44 +0200, Niklas Therning a écrit :
> >   
> >> My main motivation for starting mina-sm was that I wanted to express my
> >> state machine in pure Java. It's by no means finished so any suggestions
> >> for improvements would be most welcome.
> >>
> >> If you want more info about mina-sm you could check out the tutorial I'm
> >> working on,
> >> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
> >> Please be aware that it's not finished yet.
> >>
> >>     
> >
> > Nice tutorial, you sohuld add a like in the documentation page.
> >
> > I got a little suggestion : 
> > why not use Enum {} for defining the list of states in place of
> > Strings ?
> > in place of : 
> >
> > @State public static final String EMPTY   = "Empty";
> > @State public static final String LOADED  = "Loaded";
> > @State public static final String PLAYING = "Playing";
> > @State public static final String PAUSED  = "Paused";
> >
> > public enum State {EMPTY,LOADED,PLAYING,PAUSED};
> >   
> If that was possible it would have been so great! Unfortunately, to my
> knowledge, the enum has to be known at the time mina-sm is compiled.
> :-(  Can you think of a way to get around it?
> 
Damn , now I need to checkout this code ;)


Re: mina-sm: other options?

Posted by Julien Vermillard <jv...@archean.fr>.
Le vendredi 01 juin 2007 à 11:19 +0200, Julien Vermillard a écrit :
> Le vendredi 01 juin 2007 à 10:51 +0200, Niklas Therning a écrit :
> > Julien Vermillard wrote:
> > > Le samedi 26 mai 2007 à 09:44 +0200, Niklas Therning a écrit :
> > >   
> > >> My main motivation for starting mina-sm was that I wanted to express my
> > >> state machine in pure Java. It's by no means finished so any suggestions
> > >> for improvements would be most welcome.
> > >>
> > >> If you want more info about mina-sm you could check out the tutorial I'm
> > >> working on,
> > >> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
> > >> Please be aware that it's not finished yet.
> > >>
> > >>     
> > >
> > > Nice tutorial, you sohuld add a like in the documentation page.
> > >
> > > I got a little suggestion : 
> > > why not use Enum {} for defining the list of states in place of
> > > Strings ?
> > > in place of : 
> > >
> > > @State public static final String EMPTY   = "Empty";
> > > @State public static final String LOADED  = "Loaded";
> > > @State public static final String PLAYING = "Playing";
> > > @State public static final String PAUSED  = "Paused";
> > >
> > > public enum State {EMPTY,LOADED,PLAYING,PAUSED};
> > >   
> > If that was possible it would have been so great! Unfortunately, to my
> > knowledge, the enum has to be known at the time mina-sm is compiled.
> > :-(  Can you think of a way to get around it?
> > 
> 
> If you  call 
> Object.getClass.getClasses() 
> you get all the public classes defined in this class
> You can loop testing the .isEnum(); method and find the Enum called
> "State".
> 
> Could it be enought ?
> 

Replying to myself, apparently you can't @anotate a vaule of an Enum, so
you won't be able to parametrize your different state like you did with
static Strings :(

Julien


Re: mina-sm: other options?

Posted by Julien Vermillard <jv...@archean.fr>.
Le vendredi 01 juin 2007 à 10:51 +0200, Niklas Therning a écrit :
> Julien Vermillard wrote:
> > Le samedi 26 mai 2007 à 09:44 +0200, Niklas Therning a écrit :
> >   
> >> My main motivation for starting mina-sm was that I wanted to express my
> >> state machine in pure Java. It's by no means finished so any suggestions
> >> for improvements would be most welcome.
> >>
> >> If you want more info about mina-sm you could check out the tutorial I'm
> >> working on,
> >> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
> >> Please be aware that it's not finished yet.
> >>
> >>     
> >
> > Nice tutorial, you sohuld add a like in the documentation page.
> >
> > I got a little suggestion : 
> > why not use Enum {} for defining the list of states in place of
> > Strings ?
> > in place of : 
> >
> > @State public static final String EMPTY   = "Empty";
> > @State public static final String LOADED  = "Loaded";
> > @State public static final String PLAYING = "Playing";
> > @State public static final String PAUSED  = "Paused";
> >
> > public enum State {EMPTY,LOADED,PLAYING,PAUSED};
> >   
> If that was possible it would have been so great! Unfortunately, to my
> knowledge, the enum has to be known at the time mina-sm is compiled.
> :-(  Can you think of a way to get around it?
> 

If you  call 
Object.getClass.getClasses() 
you get all the public classes defined in this class
You can loop testing the .isEnum(); method and find the Enum called
"State".

Could it be enought ?


Re: mina-sm: other options?

Posted by Niklas Therning <ni...@trillian.se>.
Julien Vermillard wrote:
> Le samedi 26 mai 2007 à 09:44 +0200, Niklas Therning a écrit :
>   
>> My main motivation for starting mina-sm was that I wanted to express my
>> state machine in pure Java. It's by no means finished so any suggestions
>> for improvements would be most welcome.
>>
>> If you want more info about mina-sm you could check out the tutorial I'm
>> working on,
>> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
>> Please be aware that it's not finished yet.
>>
>>     
>
> Nice tutorial, you sohuld add a like in the documentation page.
>
> I got a little suggestion : 
> why not use Enum {} for defining the list of states in place of
> Strings ?
> in place of : 
>
> @State public static final String EMPTY   = "Empty";
> @State public static final String LOADED  = "Loaded";
> @State public static final String PLAYING = "Playing";
> @State public static final String PAUSED  = "Paused";
>
> public enum State {EMPTY,LOADED,PLAYING,PAUSED};
>   
If that was possible it would have been so great! Unfortunately, to my
knowledge, the enum has to be known at the time mina-sm is compiled.
:-(  Can you think of a way to get around it?

-- 
Niklas Therning
www.spamdrain.net



Re: mina-sm: other options?

Posted by Julien Vermillard <jv...@archean.fr>.
Le samedi 26 mai 2007 à 09:44 +0200, Niklas Therning a écrit :
> My main motivation for starting mina-sm was that I wanted to express my
> state machine in pure Java. It's by no means finished so any suggestions
> for improvements would be most welcome.
> 
> If you want more info about mina-sm you could check out the tutorial I'm
> working on,
> http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
> Please be aware that it's not finished yet.
> 

Nice tutorial, you sohuld add a like in the documentation page.

I got a little suggestion : 
why not use Enum {} for defining the list of states in place of
Strings ?
in place of : 

@State public static final String EMPTY   = "Empty";
@State public static final String LOADED  = "Loaded";
@State public static final String PLAYING = "Playing";
@State public static final String PAUSED  = "Paused";

public enum State {EMPTY,LOADED,PLAYING,PAUSED};


Julien


Re: mina-sm: other options?

Posted by Niklas Therning <ni...@trillian.se>.
Yigal Rachman wrote:
> Hi, Folks:
>
> Yesterday my first MINA-based code went into production.  As expected,
> it is working wonderfully well - really cool!  Thank you all for
> making MINA such a joy to use.
>
> As noted by others in this group, MINA is very well suited for use
> with state machines because all the operations are non-blocking.  I am
> planning to exploit this for the instrument drivers that I am
> developing with MINA, but am still researching the best tools for the
> job (no offense to mina-sm).  The most promising tool I have found is
> CHSM (Concurrent Hierarchical State Machine).  The home page is
> http://chsm.sourceforge.net/index.html  .  Written originally for C++,
> it now works for Java, too.
>
> If you have an interest in state machines in general, then the
> original thesis that spawned CHSM is a must-read: 
> http://homepage.mac.com/pauljlucas/resume/pjl-chsm-thesis.pdf  (there
> is a link to it from the home page, too).  It describes in detail the
> theory of hierarchical state machines (based on UML state charts -
> much more powerful than the "usual" state machines), the programming
> algorithms, and some great examples.  It is the best work on the
> subject that I have found thus far.
>
> CHSM is a pre-compiler, which may make it more awkward to use than
> direct java.  However, I suspect that there may be a way to rework it
> to use java directly, in the spirit of mina-sm.
>
> Comments, anyone?
>
There's also the State Machine Compiler (http://smc.sourceforge.net/).
If you haven't you might want to check it out too. It also uses a
special language with embedded Java code which needs to be compiled into
Java by a special compiler.

My main motivation for starting mina-sm was that I wanted to express my
state machine in pure Java. It's by no means finished so any suggestions
for improvements would be most welcome.

If you want more info about mina-sm you could check out the tutorial I'm
working on,
http://cwiki.apache.org/confluence/display/MINA/Introduction+to+mina-sm.
Please be aware that it's not finished yet.

-- 
Niklas Therning
www.spamdrain.net


mina-sm: other options?

Posted by Yigal Rachman <yi...@uvic.ca>.
Hi, Folks:

Yesterday my first MINA-based code went into production.  As expected, 
it is working wonderfully well - really cool!  Thank you all for making 
MINA such a joy to use.

As noted by others in this group, MINA is very well suited for use with 
state machines because all the operations are non-blocking.  I am 
planning to exploit this for the instrument drivers that I am developing 
with MINA, but am still researching the best tools for the job (no 
offense to mina-sm).  The most promising tool I have found is CHSM 
(Concurrent Hierarchical State Machine).  The home page is 
http://chsm.sourceforge.net/index.html  .  Written originally for C++, 
it now works for Java, too.

If you have an interest in state machines in general, then the original 
thesis that spawned CHSM is a must-read:  
http://homepage.mac.com/pauljlucas/resume/pjl-chsm-thesis.pdf  (there is 
a link to it from the home page, too).  It describes in detail the 
theory of hierarchical state machines (based on UML state charts - much 
more powerful than the "usual" state machines), the programming 
algorithms, and some great examples.  It is the best work on the subject 
that I have found thus far.

CHSM is a pre-compiler, which may make it more awkward to use than 
direct java.  However, I suspect that there may be a way to rework it to 
use java directly, in the spirit of mina-sm.

Comments, anyone?

Yigal Rachman
Instrument Data Acquisition Developer
NEPTUNE Canada
www.neptunecanada.ca


Re: a question when learning mina-sm

Posted by Niklas Therning <ni...@trillian.se>.
Trustin Lee wrote:
> On 4/10/07, Niklas Therning <ni...@trillian.se> wrote:
>> Coding Horse wrote:
>> > Hi, Community,
>> >
>> > I'm trying to model my app logic with mina-sm framework and reading
>> > StateMachineProxyFactoryTest as the start point, like what was
>> suggested by
>> > Niklas.
>> >
>> > There are lines like this:
>> >
>> >         @Handler( on = "eject",  in = "s4", next = "s1" )
>> >         public void ejected()
>> >         {
>> >             messages.add( "Tape ejected" );
>> >         }
>> >
>> > I'm not sure I understand the above code correctly:
>> > If current state is "s4" and event "eject" is received, the method
>> ejected()
>> > of the hander will be called and then the state will be changed to
>> "s1".
>> >
>>
>> Yes, you've understood correctly.
>>
>> > Also, I can't figure out how to model this scenario:
>> > conditioned state transition, like:
>> > if(condition met){
>> >   // next state is "stateA"
>> > }else{
>> >   // next state is "stateB"
>> > }
>> > It seems to me that the state transition is predefine in
>> > on = "eject",  in = "s4", next = "s1"
>> >
>>
>> Yes, the annotations doesn't handle this case. You can use the
>> StateControl class to achieve what you want:
>>
>> if (condition met) {
>>     StateControl.breakAndGotoNext("stateA");
>> } else {
>>     StateControl.breakAndGotoNext("stateB");
>> }
>>
>> If you use StateControl it will override the @Handler annotation. It
>> will cause an exception to be thrown and a state change will occur on
>> the next event.
>>
>> You can also use breakAndGotoNow(state). This will cause a state
>> transition and then the current event will be reexecuted by the state
>> machine starting from the specified state.
>>
>> breakAndContinue() will interrupt the current @Handler method as if it
>> never matched the event in the first place. Any transitions with higher
>> weights will be searched and the first which handles the current event
>> will be executed.
>>
>> Finally, you have breakAndCallNext(state) and breakAndCallNow(state)
>> which can be used to create sub-routine like sub state machines. The
>> current state will be pushed onto a stack and the state machine will
>> transition to the specified state (either on the next event or the
>> current event). Use breakAndReturnNext() or breakAndReturnNow() to
>> return to the previously pushed state.
>>
>> I must admit that things can become quite messy if you overuse
>> StateControl. However, in small doses it works quite well ;-)  . Just
>> let me know if you see any potential for improvements. I'd very much
>> appreciate to get some feedback on this piece of code.
>
> Would there any way to use this framework to implement a protocol
> decoder? :)
>
> Trustin
Yes indeed it would! The only limitation at the moment is that you can
only create a state machine proxy for a set of interfaces. Proxy
creation for classes isn't possible. Though it would be quite simple I
guess using CGLIB. Since ProtocolDecoder and ProtocolEncoder are
interfaces you could definitely create a state machine proxy which acts
as a decoder/encoder.

-- 
Niklas Therning
www.spamdrain.net


Re: a question when learning mina-sm

Posted by Trustin Lee <tr...@gmail.com>.
On 4/10/07, Niklas Therning <ni...@trillian.se> wrote:
> Coding Horse wrote:
> > Hi, Community,
> >
> > I'm trying to model my app logic with mina-sm framework and reading
> > StateMachineProxyFactoryTest as the start point, like what was suggested by
> > Niklas.
> >
> > There are lines like this:
> >
> >         @Handler( on = "eject",  in = "s4", next = "s1" )
> >         public void ejected()
> >         {
> >             messages.add( "Tape ejected" );
> >         }
> >
> > I'm not sure I understand the above code correctly:
> > If current state is "s4" and event "eject" is received, the method ejected()
> > of the hander will be called and then the state will be changed to "s1".
> >
>
> Yes, you've understood correctly.
>
> > Also, I can't figure out how to model this scenario:
> > conditioned state transition, like:
> > if(condition met){
> >   // next state is "stateA"
> > }else{
> >   // next state is "stateB"
> > }
> > It seems to me that the state transition is predefine in
> > on = "eject",  in = "s4", next = "s1"
> >
>
> Yes, the annotations doesn't handle this case. You can use the
> StateControl class to achieve what you want:
>
> if (condition met) {
>     StateControl.breakAndGotoNext("stateA");
> } else {
>     StateControl.breakAndGotoNext("stateB");
> }
>
> If you use StateControl it will override the @Handler annotation. It
> will cause an exception to be thrown and a state change will occur on
> the next event.
>
> You can also use breakAndGotoNow(state). This will cause a state
> transition and then the current event will be reexecuted by the state
> machine starting from the specified state.
>
> breakAndContinue() will interrupt the current @Handler method as if it
> never matched the event in the first place. Any transitions with higher
> weights will be searched and the first which handles the current event
> will be executed.
>
> Finally, you have breakAndCallNext(state) and breakAndCallNow(state)
> which can be used to create sub-routine like sub state machines. The
> current state will be pushed onto a stack and the state machine will
> transition to the specified state (either on the next event or the
> current event). Use breakAndReturnNext() or breakAndReturnNow() to
> return to the previously pushed state.
>
> I must admit that things can become quite messy if you overuse
> StateControl. However, in small doses it works quite well ;-)  . Just
> let me know if you see any potential for improvements. I'd very much
> appreciate to get some feedback on this piece of code.

Would there any way to use this framework to implement a protocol decoder? :)

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Question on SSL connections

Posted by Trustin Lee <tr...@gmail.com>.
Scott,

On 4/11/07, Scott Peters <sp...@visto.com> wrote:
> Here is a thread dump of when it is stuck.  It is the client side that
> is deadlocking on a write.
>
> I can reproduce it 100% of the time now.  By adding a print statement
> just before the session.write(...) it starts to work just fine, with out
> it and it locks up.  Also adding a 50ms delay does the trick till the
> server gets bogged down (after about 2250 connections are going).

I don't have any clue yet.  Can I download the source code so I can
test by myself?  I'd like to see how sessionOpened() and messageSend()
are implemented at least.

Removing .join() call might help, but it should work even with it.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

RE: Question on SSL connections

Posted by Scott Peters <sp...@visto.com>.
Here is a thread dump of when it is stuck.  It is the client side that
is deadlocking on a write.

 

I can reproduce it 100% of the time now.  By adding a print statement
just before the session.write(...) it starts to work just fine, with out
it and it locks up.  Also adding a 50ms delay does the trick till the
server gets bogged down (after about 2250 connections are going).

 

This is the one trying to write out that is blocked: Thread
[AnonymousIoService-2] (Suspended)

 

-Scott

 

 

org.eclipse.jdt.internal.junit.runner.RemoteTestRunner at localhost:1972
(Suspended)

      System Thread [Finalizer] (Suspended)

            Object.wait(long) line: not available [native method]

            ReferenceQueue<T>.remove(long) line: not available

            ReferenceQueue<T>.remove() line: not available

            Finalizer$FinalizerThread.run() line: not available

      System Thread [Reference Handler] (Suspended)

            Object.wait(long) line: not available [native method]

            Reference$Lock(Object).wait() line: not available

            Reference$ReferenceHandler.run() line: not available

      Thread [main] (Suspended)

            Thread.sleep(long) line: not available [native method]

            Utility.safe_sleep(long) line: 32

            ConnectorTest.setupManyConnection(int, int, boolean) line:
214

            ConnectorTest.test_ZZ__SSLManyConnectionData() line: 179

            NativeMethodAccessorImpl.invoke0(Method, Object, Object[])
line: not available [native method]

            NativeMethodAccessorImpl.invoke(Object, Object[]) line: not
available

            DelegatingMethodAccessorImpl.invoke(Object, Object[]) line:
not available

            Method.invoke(Object, Object...) line: not available

            ConnectorTest(TestCase).runTest() line: 164

            ConnectorTest(TestCase).runBare() line: 130

            TestResult$1.protect() line: 110

            TestResult.runProtected(Test, Protectable) line: 128

            TestResult.run(TestCase) line: 113

            ConnectorTest(TestCase).run(TestResult) line: 120

            TestSuite.runTest(Test, TestResult) line: 228

            TestSuite.run(TestResult) line: 223

            RemoteTestRunner.runTests(String[], String) line: 478

            RemoteTestRunner.run() line: 344

            RemoteTestRunner.main(String[]) line: 196

      System Thread [Signal Dispatcher] (Suspended)

      Thread [ReaderThread] (Suspended)

            SocketInputStream.socketRead0(FileDescriptor, byte[], int,
int, int) line: not available [native method]

            SocketInputStream.read(byte[], int, int) line: not available

            StreamDecoder$CharsetSD.readBytes() line: not available

            StreamDecoder$CharsetSD.implRead(char[], int, int) line: not
available

            StreamDecoder$CharsetSD(StreamDecoder).read(char[], int,
int) line: not available

            InputStreamReader.read(char[], int, int) line: not available

            BufferedReader.fill() line: not available

            BufferedReader.readLine(boolean) line: not available

            BufferedReader.readLine() line: not available

            RemoteTestRunner$ReaderThread.run() line: 149

      Thread [SocketAcceptor-0] (Suspended)

            WindowsSelectorImpl$SubSelector.poll0(long, int, int[],
int[], int[], long) line: not available [native method]

            WindowsSelectorImpl$SubSelector.poll() line: not available

 
WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelect
or) line: not available

            WindowsSelectorImpl.doSelect(long) line: not available

            WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long)
line: not available

            WindowsSelectorImpl(SelectorImpl).select(long) line: not
available

            WindowsSelectorImpl(SelectorImpl).select() line: not
available

            SocketAcceptor$Worker.run() line: 260

            NamePreservingRunnable.run() line: 43

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [pool-4-thread-1] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.parkNanos(long) line: not available

 
SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue$TransferSta
ck$SNode, boolean, long) line: 427

            SynchronousQueue$TransferStack.transfer(Object, boolean,
long) line: 326

            SynchronousQueue.poll(long, TimeUnit) line: 877

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [SocketConnectorIoProcessor-0.0] (Suspended)

            WindowsSelectorImpl$SubSelector.poll0(long, int, int[],
int[], int[], long) line: not available [native method]

            WindowsSelectorImpl$SubSelector.poll() line: not available

 
WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelect
or) line: not available

            WindowsSelectorImpl.doSelect(long) line: not available

            WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long)
line: not available

            WindowsSelectorImpl(SelectorImpl).select(long) line: not
available

            SocketIoProcessor$Worker.run() line: 557

            NamePreservingRunnable.run() line: 43

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [SocketAcceptorIoProcessor-0.0] (Suspended)

            WindowsSelectorImpl$SubSelector.poll0(long, int, int[],
int[], int[], long) line: not available [native method]

            WindowsSelectorImpl$SubSelector.poll() line: not available

 
WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelect
or) line: not available

            WindowsSelectorImpl.doSelect(long) line: not available

            WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long)
line: not available

            WindowsSelectorImpl(SelectorImpl).select(long) line: not
available

            SocketIoProcessor$Worker.run() line: 557

            NamePreservingRunnable.run() line: 43

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-1] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [PooledByteBufferExpirer-0] (Suspended)

            Thread.sleep(long) line: not available [native method]

            PooledByteBufferAllocator$Expirer.run() line: 277

      Thread [AnonymousIoService-2] (Suspended)

            Object.wait(long) line: not available [native method]

            DefaultWriteFuture(Object).wait() line: not available

            DefaultWriteFuture(DefaultIoFuture).join() line: 86

 
ClientEchoTestProtocolHandler(ClientProtocolHandler).messageSend(ByteBuf
fer) line: 275

            ClientEchoTestProtocolHandler.sessionOpened() line: 67

 
ClientEchoTestProtocolHandler(ClientProtocolHandler).sessionOpened(IoSes
sion) line: 75

            ClientEchoTestProtocolHandler.sessionOpened(IoSession) line:
114

 
AbstractIoFilterChain$TailFilter.sessionOpened(IoFilter$NextFilter,
IoSession) line: 659

 
SocketFilterChain(AbstractIoFilterChain).callNextSessionOpened(IoFilterC
hain$Entry, IoSession) line: 291

            AbstractIoFilterChain.access$800(AbstractIoFilterChain,
IoFilterChain$Entry, IoSession) line: 54

            AbstractIoFilterChain$EntryImpl$1.sessionOpened(IoSession)
line: 775

            ExecutorFilter.processEvent(IoFilter$NextFilter, IoSession,
ExecutorFilter$EventType, Object) line: 261

            ExecutorFilter$ProcessEventsRunnable.run() line: 305

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-4] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-3] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [SocketConnectorIoProcessor-0.2] (Suspended)

            WindowsSelectorImpl$SubSelector.poll0(long, int, int[],
int[], int[], long) line: not available [native method]

            WindowsSelectorImpl$SubSelector.poll() line: not available

 
WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelect
or) line: not available

            WindowsSelectorImpl.doSelect(long) line: not available

            WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long)
line: not available

            WindowsSelectorImpl(SelectorImpl).select(long) line: not
available

            SocketIoProcessor$Worker.run() line: 557

            NamePreservingRunnable.run() line: 43

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-5] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-6] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-7] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [SocketAcceptorIoProcessor-0.2] (Suspended)

            

      Thread [AnonymousIoService-8] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-10] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-9] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-11] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-12] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-13] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-14] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-15] (Suspended)

            Unsafe.park(boolean, long) line: not available [native
method]

            LockSupport.park() line: not available

            AbstractQueuedSynchronizer$ConditionObject.await() line: not
available

            ConditionObjectWrapper.await() line: 40

            LinkedBlockingQueue.take() line: 363

            ThreadPoolExecutor.getTask() line: 924

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 983

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [AnonymousIoService-16] (Suspended)

            Object.wait(long) line: not available [native method]

            DefaultWriteFuture(Object).wait() line: not available

            DefaultWriteFuture(DefaultIoFuture).join() line: 86

 
ClientEchoTestProtocolHandler(ClientProtocolHandler).messageSend(ByteBuf
fer) line: 275

            ClientEchoTestProtocolHandler.sessionOpened() line: 67

 
ClientEchoTestProtocolHandler(ClientProtocolHandler).sessionOpened(IoSes
sion) line: 75

            ClientEchoTestProtocolHandler.sessionOpened(IoSession) line:
114

 
AbstractIoFilterChain$TailFilter.sessionOpened(IoFilter$NextFilter,
IoSession) line: 659

 
SocketFilterChain(AbstractIoFilterChain).callNextSessionOpened(IoFilterC
hain$Entry, IoSession) line: 291

            AbstractIoFilterChain.access$800(AbstractIoFilterChain,
IoFilterChain$Entry, IoSession) line: 54

            AbstractIoFilterChain$EntryImpl$1.sessionOpened(IoSession)
line: 775

            ExecutorFilter.processEvent(IoFilter$NextFilter, IoSession,
ExecutorFilter$EventType, Object) line: 261

            ExecutorFilter$ProcessEventsRunnable.run() line: 305

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

      Thread [SocketAcceptor-1] (Suspended)

            WindowsSelectorImpl$SubSelector.poll0(long, int, int[],
int[], int[], long) line: not available [native method]

            WindowsSelectorImpl$SubSelector.poll() line: not available

 
WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl$SubSelect
or) line: not available

            WindowsSelectorImpl.doSelect(long) line: not available

            WindowsSelectorImpl(SelectorImpl).lockAndDoSelect(long)
line: not available

            WindowsSelectorImpl(SelectorImpl).select(long) line: not
available

            WindowsSelectorImpl(SelectorImpl).select() line: not
available

            SocketAcceptor$Worker.run() line: 260

            NamePreservingRunnable.run() line: 43

            ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker)
line: 990

            ThreadPoolExecutor$Worker.run() line: 531

            Thread.run() line: not available

 

-----Original Message-----
From: Trustin Lee [mailto:trustin@gmail.com] 
Sent: Tuesday, April 10, 2007 2:00 AM
To: dev@mina.apache.org
Subject: Re: Question on SSL connections

 

Scott,

 

On 4/10/07, Scott Peters <sp...@visto.com> wrote:

> I am seeing this with the 1.0.3 snapshot.  Before that with 1.0.1,
1.0.2

> or 1.1 I was not able to get even this amount of regularity in the SSL

> connnections, they locked up even more often due to that known

> deadlock.  I believe there is still a race condition still since the

> non-SSL work 100% of the time.  From what I can determine it is around

> the when a new ssl filter is added on an existing session.  I have yet
to

> spend much time digging into the MINA layer.  Adding a new SSLFilter

> object on an existing IoHandler object that had been previously

> connected during the sessionOpened(...) callback there is a chance
that

> it won't be seutp correctly.  As I'm more knowledable of the high
level

> MINA architecure now I will start to dig deeper into the guts to see
if i

> can determine where the problem is.  If you have any idea as to where
to

> look that would be great. Otherwise I'll just keep looking around and

> see what I can figure out.  I will keep you posted on what I find.

 

You could post your thread dump here so we can track down the problem

more easily?

 

Trustin

-- 

what we call human nature is actually human habit

--

http://gleamynode.net/

--

PGP Key ID: 0x0255ECA6


Re: Question on SSL connections

Posted by Trustin Lee <tr...@gmail.com>.
Scott,

On 4/10/07, Scott Peters <sp...@visto.com> wrote:
> I am seeing this with the 1.0.3 snapshot.  Before that with 1.0.1, 1.0.2
> or 1.1 I was not able to get even this amount of regularity in the SSL
> connnections, they locked up even more often due to that known
> deadlock.  I believe there is still a race condition still since the
> non-SSL work 100% of the time.  From what I can determine it is around
> the when a new ssl filter is added on an existing session.  I have yet to
> spend much time digging into the MINA layer.  Adding a new SSLFilter
> object on an existing IoHandler object that had been previously
> connected during the sessionOpened(...) callback there is a chance that
> it won't be seutp correctly.  As I'm more knowledable of the high level
> MINA architecure now I will start to dig deeper into the guts to see if i
> can determine where the problem is.  If you have any idea as to where to
> look that would be great. Otherwise I'll just keep looking around and
> see what I can figure out.  I will keep you posted on what I find.

You could post your thread dump here so we can track down the problem
more easily?

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

RE: Question on SSL connections

Posted by Scott Peters <sp...@visto.com>.
Trustin,
 
I am seeing this with the 1.0.3 snapshot.  Before that with 1.0.1, 1.0.2 or 1.1 I was not able to get even this amount of regularity in the SSL connnections, they locked up even more often due to that known deadlock.  I believe there is still a race condition still since the non-SSL work 100% of the time.  From what I can determine it is around the when a new ssl filter is added on an existing session.  I have yet to spend much time digging into the MINA layer.  Adding a new SSLFilter object on an existing IoHandler object that had been previously connected during the sessionOpened(...) callback there is a chance that it won't be seutp correctly.  As I'm more knowledable of the high level MINA architecure now I will start to dig deeper into the guts to see if i can determine where the problem is.  If you have any idea as to where to look that would be great. Otherwise I'll just keep looking around and see what I can figure out.  I will keep you posted on what I find.
 
Thanks again for all your work on MINA,
-Scott

________________________________

From: Trustin Lee [mailto:trustin@gmail.com]
Sent: Mon 4/9/2007 7:32 PM
To: dev@mina.apache.org
Subject: Re: Question on SSL connections



Hi Scott,

On 4/10/07, Scott Peters <sp...@visto.com> wrote:
> Hello all,
>
> I'm writing up a connector framework to use as the back end for our test
> tools.  I have been able to get non-SSL connections to work with up to
> 10k (20k server+client).  The problem is when I try to use SSL.

Glad to hear that you successfully implemented your network
application using MINA.

> I believe the problem is a race condition since it does not seem to
> reproduce itself the same every time and slight innocuous code changes
> can seem to effect if it works or not or even just running the same code
> multiple times produces different results.
>
> 1. When trying a disconnect/reconnect test. It locks up about 20% of the
> time upon the next attempt to send a message after a reconnect.
> 2. When writing out to the socket on both ends during sessionOpen(...)
> the connection just hangs and waiting on the write never returns.
> Debugging into the MINA layers show that the SSL handshake is taking
> place but then it just stops for some reason upon attempting to write to
> the session.

There's known deadlock problem with SSLFilter with MINA 1.0.2.  Could
you download 1.0.3-SNAPSHOT and try again?  FYI, 1.0.3 will be
released this week.

http://people.apache.org/repo/m2-snapshot-repository/org/apache/mina/

HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6



Re: Question on SSL connections

Posted by Trustin Lee <tr...@gmail.com>.
Hi Scott,

On 4/10/07, Scott Peters <sp...@visto.com> wrote:
> Hello all,
>
> I'm writing up a connector framework to use as the back end for our test
> tools.  I have been able to get non-SSL connections to work with up to
> 10k (20k server+client).  The problem is when I try to use SSL.

Glad to hear that you successfully implemented your network
application using MINA.

> I believe the problem is a race condition since it does not seem to
> reproduce itself the same every time and slight innocuous code changes
> can seem to effect if it works or not or even just running the same code
> multiple times produces different results.
>
> 1. When trying a disconnect/reconnect test. It locks up about 20% of the
> time upon the next attempt to send a message after a reconnect.
> 2. When writing out to the socket on both ends during sessionOpen(...)
> the connection just hangs and waiting on the write never returns.
> Debugging into the MINA layers show that the SSL handshake is taking
> place but then it just stops for some reason upon attempting to write to
> the session.

There's known deadlock problem with SSLFilter with MINA 1.0.2.  Could
you download 1.0.3-SNAPSHOT and try again?  FYI, 1.0.3 will be
released this week.

http://people.apache.org/repo/m2-snapshot-repository/org/apache/mina/

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Question on SSL connections

Posted by Scott Peters <sp...@visto.com>.
Hello all,

I'm writing up a connector framework to use as the back end for our test
tools.  I have been able to get non-SSL connections to work with up to
10k (20k server+client).  The problem is when I try to use SSL.

I believe the problem is a race condition since it does not seem to
reproduce itself the same every time and slight innocuous code changes
can seem to effect if it works or not or even just running the same code
multiple times produces different results.  

1. When trying a disconnect/reconnect test. It locks up about 20% of the
time upon the next attempt to send a message after a reconnect.
2. When writing out to the socket on both ends during sessionOpen(...)
the connection just hangs and waiting on the write never returns.
Debugging into the MINA layers show that the SSL handshake is taking
place but then it just stops for some reason upon attempting to write to
the session.

I am using the BogusSSL setup from the example echo server project for
the SSLFilter.

The client:
Set SSLFilter.USE_NOTIFICATION during sessionCreated(...)
Add the SSL filter to the chain during sessionOpen(...)
messageRecieved(...) returns for any message passed that is not a
ByteBuffer

<code>
				sslFilter = new SSLFilter(
BogusSSLContextFactory.getInstance( false ) );
				sslFilter.setUseClientMode( true );
...
chain.addFirst( ProtocolHandler.SSL_FILTER, setupSSLFilter() );
</code>


The server:
Set SSLFilter.USE_NOTIFICATION during sessionCreated(...)
SSL filter is added just before binding to the socket
messageRecieved(...) returns for any message passed that is not a
ByteBuffer

<code>
sslFilter = new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
...
chain.addLast( ProtocolHandler.SSL_FILTER, setupSSLFilter() );
</code>

Configuration 
---------------------------------
Windows XP
Java 1.5.0_11
Running out of Eclipse 3.1

__Libs__
backport-util-concurrent.jar [latest java 5 compiled]
junit-4.1.jar
mina-core-1.0.3-SNAPSHOT.jar  [svn 526942]
mina-filter-ssl-1.0.3-SNAPSHOT.jar  [svn 526942]
slf4j-api-1.1.0.jar
slf4j-simple-1.1.0.jar


Any help or thoughts on how to debug this would be apprenticed.

Thank you,
Scott

Re: a question when learning mina-sm

Posted by Niklas Therning <ni...@trillian.se>.
Coding Horse wrote:
> Hi, Community,
>
> I'm trying to model my app logic with mina-sm framework and reading
> StateMachineProxyFactoryTest as the start point, like what was suggested by
> Niklas.
>
> There are lines like this:
>
>         @Handler( on = "eject",  in = "s4", next = "s1" )
>         public void ejected()
>         {
>             messages.add( "Tape ejected" );
>         }
>
> I'm not sure I understand the above code correctly:
> If current state is "s4" and event "eject" is received, the method ejected()
> of the hander will be called and then the state will be changed to "s1".
>   

Yes, you've understood correctly.

> Also, I can't figure out how to model this scenario:
> conditioned state transition, like:
> if(condition met){
>   // next state is "stateA"
> }else{
>   // next state is "stateB"
> }
> It seems to me that the state transition is predefine in  
> on = "eject",  in = "s4", next = "s1"
>   

Yes, the annotations doesn't handle this case. You can use the
StateControl class to achieve what you want:

if (condition met) {
    StateControl.breakAndGotoNext("stateA");
} else {
    StateControl.breakAndGotoNext("stateB");
}

If you use StateControl it will override the @Handler annotation. It
will cause an exception to be thrown and a state change will occur on
the next event.

You can also use breakAndGotoNow(state). This will cause a state
transition and then the current event will be reexecuted by the state
machine starting from the specified state.

breakAndContinue() will interrupt the current @Handler method as if it
never matched the event in the first place. Any transitions with higher
weights will be searched and the first which handles the current event
will be executed.

Finally, you have breakAndCallNext(state) and breakAndCallNow(state)
which can be used to create sub-routine like sub state machines. The
current state will be pushed onto a stack and the state machine will
transition to the specified state (either on the next event or the
current event). Use breakAndReturnNext() or breakAndReturnNow() to
return to the previously pushed state.

I must admit that things can become quite messy if you overuse
StateControl. However, in small doses it works quite well ;-)  . Just
let me know if you see any potential for improvements. I'd very much
appreciate to get some feedback on this piece of code.

-- 
Niklas Therning
www.spamdrain.net