long conversations in rich client applications - orchestra

I was looking through some projects and came upon orchestra from apache as part of teh myfaces project. It provides a generic mechanism for conversations. It is geared towards web applications but the framework appears to be quite general, depending on spring scopes, and potentially can be used in rich client applications. I'll investigate and post back here to this blog.

I can report back that it all works for rich client applications. Even though it uses spring scopes (where one could just use annotations or conversation names), the framework works. For rich clients, you need a different configuration approach than listed in the myfaces documentation that composes the umbrella project of which orchestra is a subproject.

You need to do this once somewhere:


FrameworkAdapter.setCurrentInstance((FrameworkAdapter)getBean("orchestraFramework"));

Here, I have a method in the same class that has getBean() obtain a bean from the toplevel application context. In that toplevel context I have the following bean definitions:

<bean id="conversationLogger" class="org.apache.myfaces.orchestra.conversation.basic.LogConversationMessager"/>
<bean id="orchestraFramework" class="org.apache.myfaces.orchestra.frameworkAdapter.local.LocalFrameworkAdapter"
p:conversationMessager-ref="conversationLogger" />

and I also include the following in my imported orchestra scopes xml configuration

<import resource="classpath*:/META-INF/spring-orchestra-init.xml" />
<bean
class="org.springframework.beans.factory.config.CustomScopeConfigurer">
<property name="scopes">
<map>
<entry key="conversation.manual"><bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope"></bean>

<bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope"><property name="advices">


<entry key="conversation.anotherScopeRelatedToAView">
<bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope"><property name="advices"><list></list></property> </entry>

<entry key="conversation.misc">
<bean class="org.apache.myfaces.orchestra.conversation.spring.SpringConversationScope">
</bean></entry></entry></entry>
</map>
</property>

<bean id="persistentContextConversationInterceptor"
class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">

</bean>


<bean id="persistentContextFactory"
class="org.apache.myfaces.orchestra.hibernate.HibernatePersistenceContextFactory">
<property name="entityManagerFactory" ref="defaultSessionFactory"></property></property>

That's about it. Now when you use an object whose bean definition has the scope defined as one of the scopes above, your object will have the same session object available on the thread for any method call in that class. Note that you need to watch your transaction boundaries so that the thread bound session has the correct transactional behavior you desire.

I know the formatting is completely messed up on the above configuration files. Hopefully, you can figure it out from what is posted here.

Comments

Popular posts from this blog

quick note on scala.js, react hooks, monix, auth

zio environment and modules pattern: zio, scala.js, react, query management

user experience, scala.js, cats-effect, IO