📄 statemachineproxyfactorytest.html
字号:
<a name="95" href="#95">95</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> testTapeDeckStateMachineAnnotations() <strong class="jxr_keyword">throws</strong> Exception {<a name="96" href="#96">96</a> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">TapeDeckStateMachineHandler</a> handler = <strong class="jxr_keyword">new</strong> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">TapeDeckStateMachineHandler</a>();<a name="97" href="#97">97</a> <a name="98" href="#98">98</a> StateMachine sm = StateMachineFactory.getInstance(Transition.<strong class="jxr_keyword">class</strong>).create(TapeDeckStateMachineHandler.S1, handler);<a name="99" href="#99">99</a> <a name="100" href="#100">100</a> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">TapeDeck</a> player = StateMachineProxyFactory.create(TapeDeck.<strong class="jxr_keyword">class</strong>, sm);<a name="101" href="#101">101</a> player.insert(<span class="jxr_string">"Kings of convenience - Riot on an empty street"</span>);<a name="102" href="#102">102</a> player.start();<a name="103" href="#103">103</a> player.pause();<a name="104" href="#104">104</a> player.pause();<a name="105" href="#105">105</a> player.eject();<a name="106" href="#106">106</a> player.stop();<a name="107" href="#107">107</a> player.eject();<a name="108" href="#108">108</a> <a name="109" href="#109">109</a> LinkedList<String> messages = handler.messages;<a name="110" href="#110">110</a> assertEquals(<span class="jxr_string">"Tape 'Kings of convenience - Riot on an empty street' inserted"</span>, messages.removeFirst());<a name="111" href="#111">111</a> assertEquals(<span class="jxr_string">"Playing"</span>, messages.removeFirst());<a name="112" href="#112">112</a> assertEquals(<span class="jxr_string">"Paused"</span>, messages.removeFirst());<a name="113" href="#113">113</a> assertEquals(<span class="jxr_string">"Playing"</span>, messages.removeFirst());<a name="114" href="#114">114</a> assertEquals(<span class="jxr_string">"Error: Cannot eject at this time"</span>, messages.removeFirst());<a name="115" href="#115">115</a> assertEquals(<span class="jxr_string">"Stopped"</span>, messages.removeFirst());<a name="116" href="#116">116</a> assertEquals(<span class="jxr_string">"Tape ejected"</span>, messages.removeFirst());<a name="117" href="#117">117</a> assertTrue(messages.isEmpty());<a name="118" href="#118">118</a> }<a name="119" href="#119">119</a> <a name="120" href="#120">120</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">interface</strong> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> {<a name="121" href="#121">121</a> <strong class="jxr_keyword">void</strong> call1(<a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy);<a name="122" href="#122">122</a> <strong class="jxr_keyword">void</strong> call2(<a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy);<a name="123" href="#123">123</a> <strong class="jxr_keyword">void</strong> call3(<a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy);<a name="124" href="#124">124</a> }<a name="125" href="#125">125</a> <a name="126" href="#126">126</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">ReentrantStateMachineHandler</a> {<a name="127" href="#127">127</a> <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> finished = false;<a name="128" href="#128">128</a> <a name="129" href="#129">129</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> call1(<a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy) {<a name="130" href="#130">130</a> proxy.call2(proxy);<a name="131" href="#131">131</a> }<a name="132" href="#132">132</a> <a name="133" href="#133">133</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> call2(<a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy) {<a name="134" href="#134">134</a> proxy.call3(proxy);<a name="135" href="#135">135</a> }<a name="136" href="#136">136</a> <a name="137" href="#137">137</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> call3(<a name="138" href="#138">138</a> @SuppressWarnings(<span class="jxr_string">"unused"</span>) <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">Reentrant</a> proxy) {<a name="139" href="#139">139</a> finished = <strong class="jxr_keyword">true</strong>;<a name="140" href="#140">140</a> }<a name="141" href="#141">141</a> }<a name="142" href="#142">142</a> <a name="143" href="#143">143</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">interface</strong> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">TapeDeck</a> {<a name="144" href="#144">144</a> <strong class="jxr_keyword">void</strong> insert(String name);<a name="145" href="#145">145</a> <strong class="jxr_keyword">void</strong> eject();<a name="146" href="#146">146</a> <strong class="jxr_keyword">void</strong> start();<a name="147" href="#147">147</a> <strong class="jxr_keyword">void</strong> pause();<a name="148" href="#148">148</a> <strong class="jxr_keyword">void</strong> stop();<a name="149" href="#149">149</a> }<a name="150" href="#150">150</a> <a name="151" href="#151">151</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">class</strong> <a href="../../../../org/apache/mina/statemachine/StateMachineProxyFactoryTest.html">TapeDeckStateMachineHandler</a> {<a name="152" href="#152">152</a> @org.apache.mina.statemachine.annotation.State <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String PARENT = <span class="jxr_string">"parent"</span>;<a name="153" href="#153">153</a> @org.apache.mina.statemachine.annotation.State(PARENT) <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String S1 = <span class="jxr_string">"s1"</span>;<a name="154" href="#154">154</a> @org.apache.mina.statemachine.annotation.State(PARENT) <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String S2 = <span class="jxr_string">"s2"</span>;<a name="155" href="#155">155</a> @org.apache.mina.statemachine.annotation.State(PARENT) <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String S3 = <span class="jxr_string">"s3"</span>;<a name="156" href="#156">156</a> @org.apache.mina.statemachine.annotation.State(PARENT) <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String S4 = <span class="jxr_string">"s4"</span>;<a name="157" href="#157">157</a> @org.apache.mina.statemachine.annotation.State(PARENT) <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">static</strong> <strong class="jxr_keyword">final</strong> String S5 = <span class="jxr_string">"s5"</span>;<a name="158" href="#158">158</a> <a name="159" href="#159">159</a> <strong class="jxr_keyword">private</strong> LinkedList<String> messages = <strong class="jxr_keyword">new</strong> LinkedList<String>();<a name="160" href="#160">160</a> <a name="161" href="#161">161</a> @Transition(on = <span class="jxr_string">"insert"</span>, in = <span class="jxr_string">"s1"</span>, next = <span class="jxr_string">"s2"</span>)<a name="162" href="#162">162</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> inserted(String name) {<a name="163" href="#163">163</a> messages.add(<span class="jxr_string">"Tape '"</span> + name + <span class="jxr_string">"' inserted"</span>);<a name="164" href="#164">164</a> }<a name="165" href="#165">165</a> <a name="166" href="#166">166</a> @Transition(on = <span class="jxr_string">"eject"</span>, in = <span class="jxr_string">"s4"</span>, next = <span class="jxr_string">"s1"</span>)<a name="167" href="#167">167</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> ejected() {<a name="168" href="#168">168</a> messages.add(<span class="jxr_string">"Tape ejected"</span>);<a name="169" href="#169">169</a> }<a name="170" href="#170">170</a> <a name="171" href="#171">171</a> @Transitions({@Transition( on = <span class="jxr_string">"start"</span>, in = <span class="jxr_string">"s2"</span>, next = <span class="jxr_string">"s3"</span> ),<a name="172" href="#172">172</a> @Transition( on = <span class="jxr_string">"pause"</span>, in = <span class="jxr_string">"s5"</span>, next = <span class="jxr_string">"s3"</span> )})<a name="173" href="#173">173</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> playing() {<a name="174" href="#174">174</a> messages.add(<span class="jxr_string">"Playing"</span>);<a name="175" href="#175">175</a> }<a name="176" href="#176">176</a> <a name="177" href="#177">177</a> @Transition(on = <span class="jxr_string">"pause"</span>, in = <span class="jxr_string">"s3"</span>, next = <span class="jxr_string">"s5"</span>)<a name="178" href="#178">178</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> paused() {<a name="179" href="#179">179</a> messages.add(<span class="jxr_string">"Paused"</span>);<a name="180" href="#180">180</a> }<a name="181" href="#181">181</a> <a name="182" href="#182">182</a> @Transition(on = <span class="jxr_string">"stop"</span>, in = <span class="jxr_string">"s3"</span>, next = <span class="jxr_string">"s4"</span>)<a name="183" href="#183">183</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> stopped() {<a name="184" href="#184">184</a> messages.add(<span class="jxr_string">"Stopped"</span>);<a name="185" href="#185">185</a> }<a name="186" href="#186">186</a> <a name="187" href="#187">187</a> @Transition(on = <span class="jxr_string">"*"</span>, in = <span class="jxr_string">"parent"</span>)<a name="188" href="#188">188</a> <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">void</strong> error(Event event) {<a name="189" href="#189">189</a> messages.add(<span class="jxr_string">"Error: Cannot "</span> + event.getId() + <span class="jxr_string">" at this time"</span>);<a name="190" href="#190">190</a> }<a name="191" href="#191">191</a> }; <a name="192" href="#192">192</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -