-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PAYARA-4197 Minor but large cleanup in ejb-container and related things #4325
PAYARA-4197 Minor but large cleanup in ejb-container and related things #4325
Conversation
- sorted imports, removed unused - code formatting - preferred shorter block first - preferred positive if without negation - preferred fast return - collisions of these rules resolved appropriately - removed 10 years old TODOs - using generics where it is clear - trivial optimizations - declaring variables - preferred final instead of changing the default value - removed redundant keywords (public method in interface, ie) - removed redundant class typing - using addSuppressed/cause rather than masking exceptions - improved logging - log entry to important method at least as finest - removed some duplicit logs
...ectors/work-management/src/main/java/com/sun/enterprise/connectors/work/WorkCoordinator.java
Show resolved
Hide resolved
...ectors/work-management/src/main/java/com/sun/enterprise/connectors/work/WorkCoordinator.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
...erver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSessionContextImpl.java
Show resolved
Hide resolved
...erver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
Outdated
Show resolved
Hide resolved
...erver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
Show resolved
Hide resolved
...erver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
Show resolved
Hide resolved
@@ -465,7 +457,7 @@ | |||
// an EJB Remote interface to be a subtype of the Service Endpoint | |||
// Interface. In that case, it's ambiguous to do a lookup based only | |||
// on a java.lang.reflect.Method | |||
protected Map webServiceInvocationInfoMap = new HashMap(); | |||
protected Map<Method, InvocationInfo> webServiceInvocationInfoMap = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see, it should be final. But it is protected, so Eclipse was afraid that it could break something. It could, but not in Payara.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be in favour of making it final
. Also I wonder if those map should not be concurrent ones. BaseContainer
sounds like multiple threads to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, there is too much synchronization (or none here). But I'm afraid of that, TCK is sequential and slow, but I'm not sure with applications with thousands of threads. The code is not much well prepared for concurrency and we don't have much tests for that.
I will try to create some later ...
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/BaseContainer.java
Show resolved
Hide resolved
...r/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContainerTransactionManager.java
Show resolved
Hide resolved
...r/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContainerTransactionManager.java
Show resolved
Hide resolved
...r/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContainerTransactionManager.java
Outdated
Show resolved
Hide resolved
...r/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContainerTransactionManager.java
Show resolved
Hide resolved
...r/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EJBContainerTransactionManager.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/SessionContextImpl.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Outdated
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/StatefulSessionContainer.java
Outdated
Show resolved
Hide resolved
...rver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/WebServiceInvocationHandler.java
Show resolved
Hide resolved
...rver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/WebServiceInvocationHandler.java
Outdated
Show resolved
Hide resolved
...rver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/WebServiceInvocationHandler.java
Show resolved
Hide resolved
appserver/ejb/ejb-full-container/src/main/java/org/glassfish/ejb/mdb/MessageBeanContainer.java
Show resolved
Hide resolved
appserver/ejb/ejb-internal-api/src/main/java/org/glassfish/ejb/api/EJBInvocation.java
Show resolved
Hide resolved
...rver/transaction/jta/src/main/java/com/sun/enterprise/transaction/JavaEETransactionImpl.java
Show resolved
Hide resolved
public void setRollbackOnly() throws IllegalStateException, SystemException { | ||
checkTransationActive(); | ||
if ( jtsTx != null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say no to if/else in negation!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all depends. Readability is not about following a set of rules. Its a property of the whole. There might be cases where a negation reads better and nobody should start asking to apply some rule. Here on the other hand flipping makes it more readable :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the case. Maybe I should use smileys :)
Usually negation is maybe most usual cause of misunderstandings. Especially when I am tired and it is used in a sequence of ternary operators ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was a big PR. Please if you do bigger cleanups split them into pure "cosmetic" changes which don't require a deeper reasoning on all changes and those that do semantic changes that a reviewer checks if they are the right thing to do in the particular situation. Especially full class formatting and other fully automated cosmetic changes should be kept separate.
You did change logging to use lambdas to avoid "doing work" with string concatenation. These usually did have a closure on a local variable or method parameter which means the lambda will be created for each invocation. Not sure this is saving us anything. So if we want to avoid doing unnecessary work we either need a if-guard or use a log method where pattern and arguments are passed separately.
I stopped marking all occurrences at some point and this isn't terribly important but it maybe should be consistent in style however you want to have this done.
When it comes to if-return sequences I prefer to not have them use else
. Somehow this makes it look more complicated than it is. I stopped marking those at some point.
I did also mark a couple of HashMap
usages that I suspected should really be ConcurrentHashMap
s. Not your change but still something we should maybe look at.
So overall there isn't one thing you really need to change but I made a lot of comments so I imagine there will be a number of changes.
@@ -412,6 +419,7 @@ public String toString() { | |||
* @param state CREATED or Either STARTED or COMPLETED or TIMEDOUT | |||
*/ | |||
public synchronized void setState(int state) { | |||
logger.finest(() -> String.format("setState(state=%s)", state)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This lambda might save a unneeded format
but costs creating a fresh lambda instance son each call of setState
since it captures the state
variable.
If we truly want to make this less expensive we have to do the ugly if
level check around it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would defend suppliers, because the code is optimized by JVM and I believe it is still faster than if block with JUL formatter; especially when you enable finest.
But we can argue about nanoseconds, the JUL logging is extremely slow by default because of poor implementation of handlers and formatters, concatenating strings, etc.
If I remember well, the lambda here is created pretty fast, because it is not generated in runtime b some other method, it uses some template and even JIT can inline it.
But for sure, I will create some test for that, because I don't believe too much what I wrote :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See test results I posted somewhere in the begining. It surprised even me - you can safely use lambdas where posiible, I'm pretty sure that if you don't use a method to generate new lambda, it is still the same.
{ | ||
|
||
public class EjbInvocation // | ||
extends ComponentInvocation // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am happy with using these guides for a automatic formatter but we never discussed something like it in the team as far as I am aware. Maybe it is time to talk about this before use it extensively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I don't know any other option to have stable formatting. This only prevents manually formatted code before automatic reformatting which will someone do and would not notice that something breaks when he tries to fix something else ...
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Show resolved
Hide resolved
appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
Outdated
Show resolved
Hide resolved
@@ -111,43 +118,37 @@ | |||
// Data members for Remote business view. Any objects representing the | |||
// Remote business interface are not subtypes of EJBObject. | |||
private EJBObjectImpl theRemoteBusinessObjectImpl = null; | |||
private Map<String, java.rmi.Remote> theRemoteBusinessStubs = | |||
new HashMap<String, java.rmi.Remote>(); | |||
private final Map<String, Remote> theRemoteBusinessStubs = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another non concurrent map where I'd expect something else. hm.
...tainer/src/main/java/org/glassfish/persistence/ejb/entitybean/container/EntityContainer.java
Show resolved
Hide resolved
public void setRollbackOnly() throws IllegalStateException, SystemException { | ||
checkTransationActive(); | ||
if ( jtsTx != null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all depends. Readability is not about following a set of rules. Its a property of the whole. There might be cases where a negation reads better and nobody should start asking to apply some rule. Here on the other hand flipping makes it more readable :)
...ion/jta/src/main/java/com/sun/enterprise/transaction/JavaEETransactionManagerSimplified.java
Outdated
Show resolved
Hide resolved
...ion/jta/src/main/java/com/sun/enterprise/transaction/JavaEETransactionManagerSimplified.java
Outdated
Show resolved
Hide resolved
- reduced concats - sometimes reduced complexity
Jenkins test please |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have lost track a bit on the things beyond your changes that we might want to check but I think you got this. Good work!
Description
This is an enhancement for better readibility and also to provide better informations in logs.
EJB timeout warnings are now printed immediately when the transaction is set to the rollback only state, and later are printed another informations about the rollback - why it is done. These messages are not duplicated, but together lead the developer to some idead what happened and why.
Important Info
Dependant PRs
Blockers
This PR continues the work started in #4323 in much larger scale
Testing
New tests
Experimental test will be pushed in #4263
Testing Performed
Test suites executed
Testing Environment
Manual tests: Kubuntu 19.10, OpenJDK11
TestContainers: Debian 11, OpenJDK11
TCK: JDK8
Notes for Reviewers
The code needs much more love :-)