Is there a transition evaluation order in Spring Statemachine? - spring-statemachine

I'm using Spring Statemachine to model the behaviour of a project. Is there a transition evaluation order, particularly in what concerns internal, local and external transitions? Something like internal transitions are evaluated first/last or something like that.
I've looked at the documentation and also searched Stack Overflow, but I can't find any information regarding that.

Related

Is Spring more suitable for business-logic-focused apps?

After reading the official doc of Spring, I got this impression:
"Spring, specifically its IoC container, suits better for apps that requires only one instance of most classes".
For example we have an online shopping app. Its business logic is divided into
Order process
Payment process
and encapsulating these two parts into classes is for better code organisation rather than for implementing any functionalities, and Spring makes it easier to inject the same instance to whichever object needs it, to avoid frequent and redundant new.
However, in a Mario-like game, we might have a class Coin that requires hundreds of individual instances, and hence Spring can't be applied in this case ('cause I think #qualifier makes more mess than the good part brought by IoC).
Is the above correct?
You're correct in thinking that you wouldn't inject an object that only applies in a narrow scope.
I could see objects with Request scope that are not Singleton. Spring has supported that from the beginning.
Method scope variables should not be under Spring's control. There's nothing wrong with calling new.
You should understand Spring better before you make judgements about its efficacy.

Converting Java DSL to Spring XML equivalent

So this may be a more general question, but I feel it needs to be asked.
Time and time again I come across examples on Camel's documentation pages where I say "that's exactly what I want!... but it's in Java not Spring. How the heck do I convert it properly?"
So my question is: What is the rule of thumb for converting things?
Is there some conversion guide out there?
For example, I wanted to append a \n to the end of each line as the data comes through a socket into a file using the Netty4 component.
I see an example such as .transform().body(append("\n"))
How would I interpret that as Spring, to put in my Spring-based route?
Maybe this is just a thing that a person new to Camel struggles with and once you get the hang of it you can see the obvious answer. But I feel like I can't be the only one who's thinking this about the examples out there.
It seems like a lot of Java -> Spring conversion can be done in a 1 to 1 ratio, but that's not all the time.
Well, the mapping isn't straightforward and there isn't a 1-to-1 mapping available - generally, a Java DSL method invocation will in most cases translate to a tag in Spring XML DSL but the position of that tag is not always the same - in some cases Java DSL method invocation chains translate to tags being placed on the same level, sometimes (e.g. idempotent consumer) the chain translates to child tags of the first invocation.
I guess that the mapping was done this way because XML and Java are two very different languages and making the mapping 1-1 would have crippled the expressiveness of at least one, if not both, DSLs.
My advice would be to always import the XML schema and rely on your IDE's auto-completion and the documentations from the schema itself and Camel's online documentation.
You can run your camel context via mvn camel:run goal and then use a JMX client to connect to that process. There is an mbean in camel which provides a method called dumpRoutesAsXML or similar. Invoking that one will give u the xml equivalent of your context. But keep in mind that it only prints the routes and all stuff out of routes is discarded.
Hope that helps,
Lars

Multiple Controllers appropriate with one entity in spring framework

I'm starting to develop website that use the spring framework.I have three controller.There are newCustomerController,editCustomerController and deleteCustomerController.These controllers are mapped with view that use for create update and delete, but I create only customer.
So, I would like to know.Is it appropriate to declare the controllers like this.
Thank
The answer to this question is subjective and maybe more a topic for https://softwareengineering.stackexchange.com/. However, there is something very spring related about it that I would like to comment.
There are a few principles that attempt at guiding developers of how to strike a good balance when thinking about designing the classes. One of those is the Single responsibility principle.
In object-oriented programming, the single responsibility principle
states that every class should have a single responsibility, and that
responsibility should be entirely encapsulated by the class. All its
services should be narrowly aligned with that responsibility
A catchier explanation is
A class or module should have one, and only one, reason to change.
However, its still often hard to reason about it properly.
Nevertheless, Spring gives you means for it (think of this statement as a poetic freedom of interpretation). Embrace constructor based dependency injection. There are quite a few reasons why you should consider constructor based dependency injection, but the part relevent to your question is adressed in the quote from the blog
An often faced argument I get is: “Constructors just get too verbose
if I have 6 or 7 dependencies. With fields only, this is fine”.
Awesome, you’ve effectively worked around a clear indicator that the
code you write is doing way too much. An increase in the number of
dependencies a type has should hurt, as it makes you think about
whether you should split up the component into multiple ones.
In other words, if you stick to constructor based injection, and your constructor turns a bit ugly, the class is most likely doing too much and you should consider redesigning.
The same works the other way around, if your operations are a part of the logical whole (like CRUD operations), and they use the same dependencies (now "measurable" by the count and the type of the injected deps) with no clear ideas of what can cause the operations to evolve independently of each other, than no reason to split to separate classes/components.
It should be better if you define one controller for Customer class and in that class you should have all methods related to customer operations (edit,delete,create and read).

DDD Events and abstract base classes

I am currently working on implementing multiple events which share common properties and are basically the same: Templates. Our event provider applies several events like SomeTemplateAddedEvent and SomeOtherTemplateAddedEvent. There could possibly come more variations later, so I was thinking about implementing a base class for each TemplateAddedEvent since they all share common properties. But I am doubtful if this is the right way to go, since some people prefer events to be simple classes containing every property instead of having to dig deeper to find out what the event can provide.
I hope someone can shed some light on this subject.
Inheritance is normally used for two orthogonal reasons - to reuse functionality and to declare an "is-a" relationship between classes. It seems that you're using it for the first reason. This reason is a weaker argument because reuse can also be attained with composition. The question to ask then is whether there exists an "is-a" relationship between the events. Sometimes inheritance among events is desirable, such as when it makes sense to provide a handler for all events deriving from the base class.
Overall, I'd caution against inheritance if it is only applied to attain code reuse. If it is an appropriate statement about the domain, then it can make sense.

Aspect to trap Controller creation in Roo project - how to?

I would like my first Aspect in a Roo project to run the advice when a web controller starts up. But I cant get the pointcut to match.
The controllers have a class name starting Cfx. I have tried with the following form:
pointcut setBrand() : initialization(Cfx*.new (..));
before() : setBrand()
{
log.info("xxxxxxxxxxxx setting brand");
}
As well as "initialization" I have tried (from the book AspectJ Cookbook) call(Signature) with new keyword, preinitialization, staticinitialization. What is the formula?
Maybe this is related - the Roo aspects do not have this form - no pointcut for example. How are they working? Where is this documented?
Thanks
PS apologies, this is a re-post. I posted this to the Spring Roo forum but got no response. http://forum.springsource.org/showthread.php?129374-Aspect-to-trap-Controller-creation-how-to
I know next to nothing about Roo or Spring, but some AspectJ, so I am going to answer your question from an AspectJ perspective only, assuming that you are an AOP newbie (sorry if my assumption is incorrect):
If you want to do something when a class is loaded, use a staticinitialization(TypePat) pointcut.
If you want to do something when an object (instance) is created, use something like execution(ConstructorPat). The initialization is for special purposes and preinitialization is needed even more rarely. I am assuming that the first one will do for you, not knowing your exact purpose.
Further assuming that something like execution(Cfx*.new (..)) is basically the thing you want, I suggest you look at possible errors or warnings like "advice defined in ... has not been applied [Xlint:adviceDidNotMatch]", because it might just be a pointcut matching issue. Please note that the type pattern you use assumes the matched constructors are in the same package as the aspect and that they have standard visibility (not public or anything else). So unless there is a class-loading issue, maybe you just want to specify more exactly (or more generally) what you want to match. Examples:
com.bigboxco.my_app.Cfx*.new(..)
com.bigboxco..Cfx*.new(..)
public com.bigboxco..Cfx*.new(..)
!private com.bigboxco..Cfx*.new(..)
* com.bigboxco..Cfx*.new(..)
A good strategy could be trying to match one of your constructors by replicating its exact signature and using its fully qualified class name, then working on from that point to make it more general.
Update: I know you can do a web search by yourself, but anyway here are some useful links:
AspectJ quick reference
AspectJ language semantics with topics about signatures, matching etc.

Resources