Skip to content

Commit

Permalink
Removed unused methods and dead ends, smaller optimizations
Browse files Browse the repository at this point in the history
- foreach, avoiding for-keys-find-value, Vector replaced by ArrayList
- formatting, generics, javadocs

Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
  • Loading branch information
dmatej committed Mar 20, 2023
1 parent 224fb08 commit 14602ed
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 1,010 deletions.
Expand Up @@ -37,6 +37,12 @@ public interface EjbMessageBeanDescriptor extends EjbDescriptor, MessageDestinat

boolean hasQueueDest();

/**
* The resource-adapter-mid is optional.
* It is set when a resource adapter is responsible for delivering messages
* to the message-driven bean.
*/
// Reflection in EjbNode
void setResourceAdapterMid(String resourceAdapterMid);

Set<EnvironmentProperty> getActivationConfigProperties();
Expand Down
Expand Up @@ -120,7 +120,6 @@
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.Vector;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -4256,25 +4255,17 @@ protected String[] getMonitoringMethodsArray() {
}

protected String[] getMonitoringMethodsArray(boolean hasGeneratedClasses) {
String[] method_sigs = null;
if (hasGeneratedClasses) {
List<String> methodList = new ArrayList<>();
for (Class clz : monitoredGeneratedClasses) {
for (Method m : clz.getDeclaredMethods()) {
methodList.add(EjbMonitoringUtils.stringify(m));
}
}
method_sigs = methodList.toArray(new String[methodList.size()]);
return methodList.toArray(new String[methodList.size()]);
} else {
Vector methodVec = ejbDescriptor.getMethods();
int sz = methodVec.size();
method_sigs = new String[sz];
for (int i = 0; i < sz; i++) {
method_sigs[i] = EjbMonitoringUtils.stringify((Method) methodVec.get(i));
}
return ejbDescriptor.getMethods().stream().map(EjbMonitoringUtils::stringify).toArray(String[]::new);
}

return method_sigs;
}

protected void doFlush(EjbInvocation inv) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -73,11 +73,11 @@ protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbCon

Method annMethod = (Method) ainfo.getAnnotatedElement();
Set<MethodDescriptor> txBusMethods = ejbDesc.getTxBusinessMethodDescriptors();
for (MethodDescriptor next : txBusMethods) {
Method m = next.getMethod(ejbDesc);
if (TypeUtil.sameMethodSignature(m, annMethod) && ejbDesc.getContainerTransactionFor(next) == null) {
for (MethodDescriptor md : txBusMethods) {
Method method = md.getMethod(ejbDesc);
if (TypeUtil.sameMethodSignature(method, annMethod) && ejbDesc.getContainerTransactionFor(md) == null) {
// override by xml
ejbDesc.setContainerTransactionFor(next, containerTransaction);
ejbDesc.setContainerTransactionFor(md, containerTransaction);
}
}

Expand All @@ -104,15 +104,15 @@ protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbCon
}
// stateful lifecycle callback txn attr type EJB spec
if (sd.isStateful() && containerTransaction != null) {
String tattr = containerTransaction.getTransactionAttribute();
if (tattr != null && !tattr.equals(ContainerTransaction.REQUIRES_NEW)
&& !tattr.equals(ContainerTransaction.NOT_SUPPORTED)) {
String txAttr = containerTransaction.getTransactionAttribute();
if (txAttr != null && !txAttr.equals(ContainerTransaction.REQUIRES_NEW)
&& !txAttr.equals(ContainerTransaction.NOT_SUPPORTED)) {
logger.log(Level.WARNING,
MessageFormat.format(
"Stateful session bean {0} lifecycle callback method {1} has transaction "
+ "attribute {2} with container-managed transaction demarcation. "
+ "The transaction attribute should be either REQUIRES_NEW or NOT_SUPPORTED",
sd.getName(), m.getName(), tattr));
sd.getName(), m.getName(), txAttr));
}
}
// override by xml
Expand Down
Expand Up @@ -22,9 +22,12 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import java.util.logging.Level;
import java.util.stream.Collectors;

import org.glassfish.deployment.common.Descriptor;
import org.glassfish.ejb.deployment.BeanMethodCalculatorImpl;
Expand Down Expand Up @@ -86,37 +89,34 @@ public String getStateImplClassName() {
return this.stateImplClassName;
}

@Override
public Vector<Field> getFields() {
Vector<Field> fields = new Vector<>();
private List<Field> getFields() {
if (isEJB20()) {
// All cmp "fields" are abstract, so we can't construct
// java.lang.reflect.Field elements from them. Use
// getFieldDescriptors() instead.
} else {
fields = super.getFields();
return Collections.emptyList();
}
return fields;
Class<?> ejb = null;
try {
ClassLoader cl = getEjbBundleDescriptor().getClassLoader();
ejb = cl.loadClass(getEjbClassName());
} catch (ClassNotFoundException e) {
throw new IllegalStateException("Class could not be loaded: " + getEjbClassName(), e);
}
return Arrays.asList(ejb.getFields());
}

@Override
public Vector<FieldDescriptor> getFieldDescriptors() {
Vector<FieldDescriptor> fieldDescriptors = new Vector<>();
public List<FieldDescriptor> getFieldDescriptors() {
if (isEJB20()) {
try {
ClassLoader cl = getEjbBundleDescriptor().getClassLoader();
BeanMethodCalculatorImpl bmc = new BeanMethodCalculatorImpl();
fieldDescriptors = bmc.getPossibleCmpCmrFields(cl, this.getEjbClassName());
} catch (Throwable t) {
String errorMsg = localStrings.getLocalString("enterprise.deployment.errorloadingejbclass",
"error loading the ejb class {0} in getFields" + " on EjbDescriptor\n {1}",
new Object[] {this.getEjbClassName(), t.toString()});
_logger.log(Level.FINE, errorMsg);
return bmc.getPossibleCmpCmrFields(cl, getEjbClassName());
} catch (Exception e) {
throw new IllegalStateException("Class could not be loaded: " + getEjbClassName(), e);
}
} else {
fieldDescriptors = super.getFieldDescriptors();
}
return fieldDescriptors;
return getFields().stream().map(FieldDescriptor::new).collect(Collectors.toList());
}


Expand Down Expand Up @@ -162,24 +162,6 @@ public boolean isEJB20() {
}


@Override
public Vector<ContainerTransaction> getPossibleTransactionAttributes() {
Vector<ContainerTransaction> txAttributes = null;
if (isEJB20()) {
txAttributes = new Vector<>();
txAttributes.add(new ContainerTransaction(ContainerTransaction.REQUIRED, ""));
txAttributes.add(new ContainerTransaction(ContainerTransaction.REQUIRES_NEW, ""));
txAttributes.add(new ContainerTransaction(ContainerTransaction.MANDATORY, ""));
if (isTimedObject()) {
txAttributes.add(new ContainerTransaction(ContainerTransaction.NOT_SUPPORTED, ""));
}
} else {
txAttributes = super.getPossibleTransactionAttributes();
}
return txAttributes;
}


public void setPersistenceDescriptor(PersistenceDescriptor pd) {
this.pers = pd;
pd.setParentDescriptor(this);
Expand Down

0 comments on commit 14602ed

Please sign in to comment.