You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by lq...@apache.org on 2016/09/28 15:25:23 UTC
svn commit: r1762681 - in /qpid/java/trunk:
broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java
broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java
Author: lquack
Date: Wed Sep 28 15:25:23 2016
New Revision: 1762681
URL: http://svn.apache.org/viewvc?rev=1762681&view=rev
Log:
QPID-7438: [Java Broker] Add changesConfiguredObjectState parameter to ManagedOperations to have it automatically execute on the config Thread
Modified:
qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java
qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java
Modified: qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java?rev=1762681&r1=1762680&r2=1762681&view=diff
==============================================================================
--- qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java (original)
+++ qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/ConfiguredObjectFactoryGenerator.java Wed Sep 28 15:25:23 2016
@@ -23,8 +23,10 @@ package org.apache.qpid.server.model;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.StringWriter;
import java.util.Collections;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
import javax.annotation.processing.AbstractProcessor;
@@ -39,6 +41,7 @@ import javax.lang.model.element.Executab
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.PrimitiveType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.tools.Diagnostic;
@@ -119,7 +122,12 @@ public class ConfiguredObjectFactoryGene
pw.println("import static org.apache.qpid.server.security.access.Operation.METHOD;");
pw.println();
pw.println("import java.util.Map;");
+ pw.println("import java.util.concurrent.ExecutionException;");
pw.println();
+ pw.println("import com.google.common.util.concurrent.Futures;");
+ pw.println("import com.google.common.util.concurrent.ListenableFuture;");
+ pw.println();
+ pw.println("import org.apache.qpid.server.configuration.updater.Task;");
pw.println("import org.apache.qpid.server.util.FixedKeyMapCreator;");
pw.println();
pw.println("final class " + childClassSimpleName + " extends "+ objectSimpleName);
@@ -159,7 +167,7 @@ public class ConfiguredObjectFactoryGene
pw.println(" }");
pw.println();
- generateAccessCheckedMethods(classElement, pw, new HashSet<TypeElement>(), new HashSet<String>());
+ generateAccessCheckedMethods(childClassSimpleName, classElement, pw, new HashSet<TypeElement>(), new HashSet<String>());
pw.println("}");
@@ -176,7 +184,8 @@ public class ConfiguredObjectFactoryGene
}
- private void generateAccessCheckedMethods(final TypeElement typeElement,
+ private void generateAccessCheckedMethods(final String className,
+ final TypeElement typeElement,
final PrintWriter pw,
final HashSet<TypeElement> processedClasses,
final HashSet<String> processedMethods) throws ClassNotFoundException
@@ -186,7 +195,7 @@ public class ConfiguredObjectFactoryGene
Element superClassElement = processingEnv.getTypeUtils().asElement(typeElement.getSuperclass());
if(superClassElement instanceof TypeElement)
{
- generateAccessCheckedMethods((TypeElement) superClassElement, pw, processedClasses, processedMethods);
+ generateAccessCheckedMethods(className, (TypeElement) superClassElement, pw, processedClasses, processedMethods);
}
for(TypeMirror ifMirror : typeElement.getInterfaces())
@@ -194,7 +203,7 @@ public class ConfiguredObjectFactoryGene
Element ifElement = processingEnv.getTypeUtils().asElement(ifMirror);
if(ifElement instanceof TypeElement)
{
- generateAccessCheckedMethods((TypeElement) ifElement, pw, processedClasses, processedMethods);
+ generateAccessCheckedMethods(className, (TypeElement) ifElement, pw, processedClasses, processedMethods);
}
}
@@ -206,7 +215,7 @@ public class ConfiguredObjectFactoryGene
{
if(annotationMirror.getAnnotationType().toString().equals("org.apache.qpid.server.model.ManagedOperation"))
{
- processManagedOperation(pw, (ExecutableElement) element);
+ processManagedOperation(pw, className, (ExecutableElement) element, annotationMirror);
break;
}
}
@@ -216,7 +225,7 @@ public class ConfiguredObjectFactoryGene
}
- private void processManagedOperation(final PrintWriter pw, final ExecutableElement methodElement)
+ private void processManagedOperation(final PrintWriter pw, final String className, final ExecutableElement methodElement, final AnnotationMirror annotationMirror)
{
if(!methodElement.getParameters().isEmpty())
@@ -264,39 +273,129 @@ public class ConfiguredObjectFactoryGene
pw.print(" authorise(METHOD(\"");
pw.print(methodElement.getSimpleName().toString());
pw.print("\")");
+ final String parameterList = getParameterList(methodElement);
+
if(!methodElement.getParameters().isEmpty())
{
pw.print(", ");
pw.print(methodElement.getSimpleName().toString().replaceAll("([A-Z])", "_$1").toUpperCase() + "_MAP_CREATOR");
- pw.print(".createMap(");
- first = true;
- for(VariableElement param : methodElement.getParameters())
+ pw.print(".createMap" + parameterList);
+ }
+ pw.println(");");
+ pw.println();
+
+ final Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues =
+ processingEnv.getElementUtils().getElementValuesWithDefaults(annotationMirror);
+ for (ExecutableElement executableElement : elementValues.keySet())
+ {
+ if ("changesConfiguredObjectState".contentEquals(executableElement.getSimpleName()))
{
- if(first)
+ final String callToSuper = "super." + methodElement.getSimpleName().toString() + parameterList;
+
+ pw.print(" ");
+ if (methodElement.getReturnType().getKind() != TypeKind.VOID)
{
- first = false;
+ pw.print("return ");
+ }
+ if ((Boolean) elementValues.get(executableElement).getValue())
+ {
+ pw.println(wrapByDoOnConfigThread(callToSuper, className, methodElement));
}
else
{
- pw.print(", ");
+ pw.println(callToSuper + ";");
}
- pw.print(getParamName(param));
- }
- pw.print(")");
+ break;
+ }
}
- pw.println(");");
+
+ pw.println(" }");
pw.println();
+ }
+
+ private String wrapByDoOnConfigThread(final String callToWrap,
+ final String className,
+ final ExecutableElement methodElement)
+ {
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter pw = new PrintWriter(stringWriter);
+ String boxedReturnTypeName = getBoxedReturnTypeAsString(methodElement);
+ pw.println("doSync(doOnConfigThread(new Task<ListenableFuture<"
+ + boxedReturnTypeName
+ + ">, RuntimeException>()");
+ pw.println(" {");
+ pw.println(" @Override");
+ pw.println(" public ListenableFuture<"
+ + boxedReturnTypeName
+ + "> execute()");
+ pw.println(" {");
+ if (methodElement.getReturnType().getKind() != TypeKind.VOID)
+ {
+ pw.println(" return Futures.<"
+ + boxedReturnTypeName
+ + ">immediateFuture("
+ + className
+ + "."
+ + callToWrap
+ + ");");
+ }
+ else
+ {
+ pw.println(" " + className + "." + callToWrap + ";");
+ pw.println(" return Futures.<"
+ + boxedReturnTypeName
+ + ">immediateFuture(null);");
+ }
+ pw.println(" }");
+
+ pw.println(" @Override");
+ pw.println(" public String getObject()");
+ pw.println(" {");
+ pw.println(" return " + className + ".this.toString();");
+ pw.println(" }");
+
+ pw.println(" @Override");
+ pw.println(" public String getAction()");
+ pw.println(" {");
+ pw.println(" return \"" + methodElement.getSimpleName() + "\";");
+ pw.println(" }");
+
+ pw.println(" @Override");
+ pw.println(" public String getArguments()");
+ pw.println(" {");
+ pw.println(" return null;");
+ pw.println(" }");
+
+ pw.println(" }));");
+ return stringWriter.toString();
+ }
- pw.print(" ");
- if(methodElement.getReturnType().getKind() != TypeKind.VOID)
+ private String getBoxedReturnTypeAsString(final ExecutableElement methodElement)
+ {
+ TypeMirror returnType = methodElement.getReturnType();
+ String returnTypeName;
+ if (returnType.getKind().isPrimitive())
{
- pw.print("return ");
+ TypeElement returnTypeElement =
+ processingEnv.getTypeUtils().boxedClass((PrimitiveType) returnType);
+ returnTypeName = returnTypeElement.asType().toString();
}
- pw.print("super.");
- pw.print(methodElement.getSimpleName().toString());
- pw.print("(");
- first = true;
+ else if (returnType.getKind() == TypeKind.VOID)
+ {
+ returnTypeName = "Void";
+ }
+ else
+ {
+ returnTypeName = methodElement.getReturnType().toString();
+ }
+ return returnTypeName;
+ }
+
+ private String getParameterList(final ExecutableElement methodElement)
+ {
+ StringBuilder parametersStringBuilder = new StringBuilder("(");
+ boolean first = true;
for(VariableElement param : methodElement.getParameters())
{
if(first)
@@ -305,13 +404,12 @@ public class ConfiguredObjectFactoryGene
}
else
{
- pw.print(", ");
+ parametersStringBuilder.append(", ");
}
- pw.print(getParamName(param));
+ parametersStringBuilder.append(getParamName(param));
}
- pw.println(");");
- pw.println(" }");
- pw.println();
+ parametersStringBuilder.append(")");
+ return parametersStringBuilder.toString();
}
private String getParamName(final VariableElement param)
Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java?rev=1762681&r1=1762680&r2=1762681&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java (original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManagedOperation.java Wed Sep 28 15:25:23 2016
@@ -33,5 +33,5 @@ public @interface ManagedOperation
boolean nonModifying() default false;
boolean secure() default false;
String paramRequiringSecure() default "";
-
+ boolean changesConfiguredObjectState() default true;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org