JJUG CCC 2019 Spring登壇資料 (ccc_m6b)
C D G 9 602 1#5 8 0/ / 25 8 0/ / 2 .2 /1 2
View Slide
( )● Japan JBoss User Group● Red Hat Consultant● Twitter: @neverbird2
●4○ J○ E○ a○○○ J○○
5ApplicationCDI ContainerCDI APICDI SPIExtension Extension Extension●
fminamot-OSX:base fminamot$ grep -r javax.enterprise.inject.spi.Extension .Binary file ./org/wildfly/microprofile/opentracing-smallrye/main/wildfly-microprofile-opentracing-smallrye-7.2.0.GA-redhat-00005.jar matchesBinary file ./org/jboss/jts/main/narayana-jts-idlj-5.9.0.Final-redhat-00001.jar matchesBinary file ./org/jboss/resteasy/resteasy-jaxrs/main/resteasy-client-microprofile-3.6.1.SP2-redhat-00001.jarmatchesBinary file ./org/jboss/resteasy/resteasy-cdi/main/resteasy-cdi-3.6.1.SP2-redhat-00001.jar matchesBinary file ./org/jboss/narayana/txframework/main/txframework-5.9.0.Final-redhat-00001.jar matchesBinary file ./org/jboss/narayana/compensations/main/compensations-5.9.0.Final-redhat-00001.jar matchesBinary file ./org/jberet/jberet-core/main/jberet-core-1.3.1.Final-redhat-00001.jar matchesBinary file ./org/picketlink/core/main/picketlink-impl-2.5.5.SP12-redhat-2.jar matchesBinary file ./org/hibernate/validator/cdi/main/hibernate-validator-cdi-6.0.14.Final-redhat-00001.jar matchesBinary file ./org/glassfish/soteria/main/javax.security.enterprise-1.0.0.redhat-1.jar matchesBinary file ./io/smallrye/config/main/smallrye-config-1.3.4.redhat-00001.jar matchesBinary file ./javax/enterprise/api/main/cdi-api-2.0.0.SP1-redhat-00001.jar matchesBinary file ./com/sun/jsf-impl/main/jsf-impl-2.3.5.SP2-redhat-00001.jar matches6
●65 .50 ( 50 5 5 365 26 . . ))○ a S○ aP e○ J B●S D (○ . . )E I R B○ Ce f dF JE E / A( Cic78 8
8@InjectFoo foo;@Scopedpublic class FooImpl implements Foo @ApplicationScopedpublic class MyApp !
● B .● .10ApplicationCDI ContainerCDI APIBeanMetadata BeanArchivesBean .
●● I>● CA I>● T B● D < @● 11
DC●● / / / B●● B●●12
C13CDI ContainerBeanArchives1. 2. ProcessAnnotatedType3. event.add (…)Extension
● 14
15P MMB I OB IDA
B CIA16>B ; C A ( C E C AC AAE> E E ;> >>; A . > ;-B ; ( B;A A ; . )> B A D E E@Observes CDI 2.0 A D @OD LI
R E / // 17@ApplicationScopedpublic class MyBean {@Retry(maxRetries=3)public void sendMessage(String message) {/}}
● 3H S R @I318/( . .. (. ) ( .3 ). . (;;1111=
● D○ B● D○ I ■ C119
RetyExtension20public class RetryExtension implements Extension {/public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager bm) {event.addAnnotatedType(RetryInterceptor.class, RetryInterceptor.class.getName());}1public void processManagedBean(@Observes ProcessManagedBean event) {AnnotatedType> annotatedType = event.getAnnotatedBeanClass();for (AnnotatedMethod> annotatedMethod : annotatedType.getMethods()) {Retry anno= annotatedMethod.getAnnotation(Retry.class);if (anno != null && anno.maxRetries() < 1) {event.addDefinitionError(new Exception("illegal maxRetry:" + anno.maxRetries()));}}}}
21
● SmallRye config○" #$'● SmallRye fault tolerant○CircuitBreaker, Retry, Timeout%$'● SmallRye metrics○ (!&$'/ //. .22
● CDI http://cdi-spec.org/● Next Pressohttp://www.next-presso.com/● Weldhttps://tanoseam.wordpress.com/● SmallRye (Eclipse MicroProfile implementation)https://smallrye.io/https://github.com/smallrye23
Red Hat24
● E DC 25./
IBD A IC26 J J JJ J JJ JJJn Jn JJ Je JBJ a J J
.27/ b I D/ i c d E IS E I0 / : > ErnJ D -/ / . mtJ D-/ / / / 2o 0 / : > /0 / : > B >:2C /0 / : > B >:2C / 2 :1 2/ / 2 / s0 / : > B >:2C :1/ >1 <2 a e li
.28< B A >javax.enterprise.inject.spi. >A● < . ./ . -
29 / . -
CDI 2.0AnnotatedTypeConfigurator CDI 1.x CDI 2.0 AnnotatedTypeConfigurator30public interface BeforeBeanDiscovery {void addQualifier(Class extends Annotation> qualifier);void addQualifier(AnnotatedType extends Annotation> qualifier);void addScope(Class extends Annotation> scopeType, boolean normal, boolean passivating);void addStereotype(Class extends Annotation> stereotype, Annotation... stereotypeDef);void addInterceptorBinding(AnnotatedType extends Annotation> bindingType);void addInterceptorBinding(Class extends Annotation> bindingType, Annotation... bindingTypeDef);void addAnnotatedType(AnnotatedType extends Annotation> type, String id); AnnotatedTypeConfigurator addAnnotatedType(Class type, String id); AnnotatedTypeConfigurator configureQualifier(Class qualifier); AnnotatedTypeConfigurator configureInterceptorBinding(Class bt);}
CDI 2.0AnnotatedTypeConfigurator CDI 1.xCDI 2.0 AnnotatedTypeConfigurator31public interface ProcessAnnotatedType {AnnotatedType getAnnotatedType();void setAnnotatedType(AnnotatedType type);void veto();AnnotatedTypeConfigurator configureAnnotatedType();}