Skip to content

Commit c06c56f

Browse files
committed
Polish code
1 parent 0c6e55e commit c06c56f

File tree

19 files changed

+136
-32
lines changed

19 files changed

+136
-32
lines changed

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/beans/manager/StandardBeanManager.java

+37-10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import org.geektimes.enterprise.inject.standard.context.mananger.ContextManager;
3535
import org.geektimes.enterprise.inject.standard.disposer.DisposerMethodManager;
3636
import org.geektimes.enterprise.inject.standard.event.*;
37+
import org.geektimes.enterprise.inject.standard.event.application.*;
38+
import org.geektimes.enterprise.inject.standard.observer.ObserverMethodManager;
3739
import org.geektimes.enterprise.inject.standard.producer.ProducerFieldBeanAttributes;
3840
import org.geektimes.enterprise.inject.standard.producer.ProducerFieldFactory;
3941
import org.geektimes.enterprise.inject.standard.producer.ProducerMethodBeanAttributes;
@@ -50,17 +52,13 @@
5052
import javax.enterprise.event.Event;
5153
import javax.enterprise.event.Observes;
5254
import javax.enterprise.event.ObservesAsync;
53-
import javax.enterprise.inject.Disposes;
54-
import javax.enterprise.inject.Instance;
55-
import javax.enterprise.inject.Produces;
56-
import javax.enterprise.inject.Stereotype;
55+
import javax.enterprise.inject.*;
5756
import javax.enterprise.inject.spi.*;
5857
import javax.enterprise.util.TypeLiteral;
5958
import java.lang.annotation.Annotation;
6059
import java.lang.reflect.Method;
6160
import java.lang.reflect.Type;
6261
import java.lang.reflect.TypeVariable;
63-
import java.lang.reflect.WildcardType;
6462
import java.util.*;
6563
import java.util.function.Function;
6664

@@ -180,8 +178,8 @@ public Object getReference(Bean<?> bean, Type beanType, CreationalContext<?> ctx
180178
assertAfterDeploymentValidation();
181179
if (!Objects.equals(beanType.getTypeName(), bean.getBeanClass().getTypeName())) {
182180
throw new IllegalArgumentException(format("The given type[%s] is not a bean type[%s] of the given bean!",
183-
beanType.getTypeName(),
184-
bean.getBeanClass()));
181+
beanType.getTypeName(),
182+
bean.getBeanClass()));
185183
}
186184
Class<? extends Annotation> scope = bean.getScope();
187185
Context context = getContext(scope);
@@ -253,12 +251,12 @@ public void validate(InjectionPoint injectionPoint) {
253251
*
254252
* @param injectionPoint {@link InjectionPoint}
255253
* @throws DefinitionException If an injection point type is a type variable, the container automatically
256-
* detects the problem and treats it as a definition error.
254+
* detects the problem and treats it as a definition error.
257255
*/
258256
private void validateInjectionPointType(InjectionPoint injectionPoint) throws DefinitionException {
259257
Type type = injectionPoint.getType();
260-
if(type instanceof TypeVariable){
261-
throw newDefinitionException("A type variable[%s] is not a legal injection point[%s] type",type,injectionPoint);
258+
if (type instanceof TypeVariable) {
259+
throw newDefinitionException("A type variable[%s] is not a legal injection point[%s] type", type, injectionPoint);
262260
}
263261
}
264262

@@ -539,6 +537,26 @@ public void initialize() {
539537
// TODO
540538
}
541539

540+
/**
541+
* When an application is stopped, the container performs the following steps:
542+
* <ol>
543+
* <li>the container must destroy all contexts.</li>
544+
* <li>the container must fire an event of type {@link BeforeShutdown}</li>
545+
* </ol>
546+
*/
547+
public void shutdown() {
548+
destroyContexts();
549+
fireBeforeShutdownEvent();
550+
}
551+
552+
private void destroyContexts() {
553+
contextManager.destroy();
554+
}
555+
556+
private void fireBeforeShutdownEvent() {
557+
fireEvent(new BeforeShutdownEvent(this));
558+
}
559+
542560

543561
/**
544562
* Is defining annotation type or not.
@@ -937,6 +955,15 @@ private void fireBeforeBeanDiscoveryEvent() {
937955
fireEvent(new BeforeBeanDiscoveryEvent(this));
938956
}
939957

958+
/**
959+
* The container must fire an event, before it processes a type, for every Java class, interface
960+
* (excluding annotation type, a special kind of interface type) or enum discovered as defined
961+
* in Type discovery.
962+
* An event is not fired for any type annotated with {@link Vetoed @Vetoed},
963+
* or in a package annotated with {@link Vetoed @Vetoed}
964+
*
965+
* @param annotatedType {@link AnnotatedType}
966+
*/
940967
private void fireProcessAnnotatedTypeEvent(AnnotatedType<?> annotatedType) {
941968
if (!isAnnotatedVetoed(annotatedType.getJavaClass())) {
942969
fireEvent(new ProcessAnnotatedTypeEvent(annotatedType, this));

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/context/mananger/ContextManager.java

+4
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,8 @@ public boolean isPassivatingScope(Class<? extends Annotation> annotationType) {
101101
// Extensions
102102
syntheticNormalScopes.getOrDefault(annotationType, Boolean.FALSE);
103103
}
104+
105+
public void destroy() {
106+
// TODO
107+
}
104108
}

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/event/ProcessObserverMethodEvent.java

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.geektimes.enterprise.inject.standard.annotation.ReflectiveAnnotatedMethod;
2020
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
21+
import org.geektimes.enterprise.inject.standard.observer.ReflectiveObserverMethod;
2122

2223
import javax.enterprise.inject.spi.AnnotatedMethod;
2324
import javax.enterprise.inject.spi.ObserverMethod;
+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.event.application;
1818

1919
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
2020

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.event.application;
1818

1919
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
2020

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.event.application;
1818

1919
import org.geektimes.enterprise.inject.standard.beans.manager.BeanArchiveManager;
2020
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
@@ -34,7 +34,7 @@
3434
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
3535
* @since 1.0.0
3636
*/
37-
public class AfterTypeDiscoveryEvent extends ContainerEvent implements AfterTypeDiscovery {
37+
public class AfterTypeDiscoveryEvent extends ApplicationEvent implements AfterTypeDiscovery {
3838

3939
private final StandardBeanManager standardBeanManager;
4040

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/event/ContainerEvent.java projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/standard/event/application/ApplicationEvent.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.event.application;
1818

1919
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
2020
import javax.enterprise.inject.spi.Extension;
2121
import java.util.EventObject;
2222

2323
import static java.lang.String.format;
24-
import static org.geektimes.enterprise.inject.standard.event.ReflectiveObserverMethod.getBeanInstance;
24+
import static org.geektimes.enterprise.inject.standard.observer.ReflectiveObserverMethod.getBeanInstance;
2525

2626
/**
2727
* Container Event
2828
*
2929
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
3030
* @since 1.0.0
3131
*/
32-
public class ContainerEvent extends EventObject {
32+
public class ApplicationEvent extends EventObject {
3333

3434
/**
3535
* Constructs a prototypical Event.
3636
*
3737
* @param source The object on which the Event initially occurred.
3838
* @throws IllegalArgumentException if source is null.
3939
*/
40-
public ContainerEvent(Object source) {
40+
public ApplicationEvent(Object source) {
4141
super(source);
4242
}
4343

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.event.application;
1818

1919
import org.geektimes.enterprise.inject.standard.beans.manager.BeanArchiveManager;
2020
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
@@ -32,7 +32,7 @@
3232
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
3333
* @since 1.0.0
3434
*/
35-
public class BeforeBeanDiscoveryEvent extends ContainerEvent implements BeforeBeanDiscovery {
35+
public class BeforeBeanDiscoveryEvent extends ApplicationEvent implements BeforeBeanDiscovery {
3636

3737
private final StandardBeanManager standardBeanManager;
3838

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.geektimes.enterprise.inject.standard.event.application;
18+
19+
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
20+
21+
import javax.enterprise.inject.spi.BeforeShutdown;
22+
23+
/**
24+
* {@link BeforeShutdown} Event
25+
*
26+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
27+
* @since 1.0.0
28+
*/
29+
public class BeforeShutdownEvent extends ApplicationEvent implements BeforeShutdown {
30+
31+
public BeforeShutdownEvent(StandardBeanManager standardBeanManager) {
32+
super(standardBeanManager);
33+
}
34+
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.observer;
1818

1919
import javax.enterprise.inject.spi.Bean;
2020
import javax.enterprise.inject.spi.ObserverMethod;
+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.observer;
1818

1919
import org.geektimes.commons.function.Streams;
2020
import org.geektimes.commons.reflect.util.ClassUtils;
@@ -24,6 +24,7 @@
2424
import org.geektimes.enterprise.inject.standard.annotation.ReflectiveAnnotatedMethod;
2525
import org.geektimes.enterprise.inject.standard.annotation.ReflectiveAnnotatedParameter;
2626
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
27+
import org.geektimes.enterprise.inject.standard.event.*;
2728

2829
import javax.enterprise.event.Event;
2930
import javax.enterprise.event.NotificationOptions;
+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.observer;
1818

1919
import javax.enterprise.inject.spi.ObserverMethod;
2020
import java.lang.annotation.Annotation;
+1-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.observer;
1818

19-
import org.geektimes.enterprise.inject.standard.event.ObserverMethodParameter;
2019
import org.geektimes.enterprise.inject.util.Events;
2120

2221
import javax.enterprise.event.Observes;
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.geektimes.enterprise.inject.standard.event;
17+
package org.geektimes.enterprise.inject.standard.observer;
1818

1919
import javax.enterprise.inject.spi.BeanManager;
2020
import javax.enterprise.inject.spi.ObserverMethod;

projects/stage-1/middleware-frameworks/my-cdi/src/main/java/org/geektimes/enterprise/inject/util/Events.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
package org.geektimes.enterprise.inject.util;
1818

19-
import org.geektimes.enterprise.inject.standard.event.ObserverMethodParameter;
19+
import org.geektimes.enterprise.inject.standard.observer.ObserverMethodParameter;
2020

2121
import javax.enterprise.event.Observes;
2222
import javax.enterprise.event.ObservesAsync;
@@ -35,7 +35,7 @@
3535
import static java.util.Arrays.asList;
3636
import static java.util.Collections.emptyList;
3737
import static org.geektimes.commons.lang.util.AnnotationUtils.isAnnotationPresent;
38-
import static org.geektimes.enterprise.inject.standard.event.ObserverMethodParameter.*;
38+
import static org.geektimes.enterprise.inject.standard.observer.ObserverMethodParameter.*;
3939

4040
/**
4141
* The utilities class for CDI Events

projects/stage-1/middleware-frameworks/my-cdi/src/test/java/org/geektimes/enterprise/inject/standard/event/BeforeBeanDiscoveryEventTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.geektimes.enterprise.inject.standard.event;
1818

1919
import org.geektimes.enterprise.inject.standard.beans.manager.StandardBeanManager;
20+
import org.geektimes.enterprise.inject.standard.event.application.BeforeBeanDiscoveryEvent;
2021
import org.junit.Test;
2122

2223
import javax.enterprise.inject.Default;

projects/stage-1/middleware-frameworks/my-commons/src/main/java/org/geektimes/commons/reflect/util/TypeUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static List<ParameterizedType> getAllGenericInterfaces(Type type, Predica
226226
.map(ParameterizedType.class::cast)
227227
.collect(toList());
228228

229-
return unmodifiableList(filter(allGenericInterfaces, typeFilters));
229+
return filter(allGenericInterfaces, typeFilters);
230230
}
231231

232232
public static String getClassName(Type type) {
@@ -372,7 +372,7 @@ public static Set<Type> getAllSuperTypes(Type type, Predicate<Type>... typeFilte
372372
superType = superClass.getGenericSuperclass();
373373
}
374374

375-
return unmodifiableSet(filter(allSuperTypes, typeFilters));
375+
return filter(allSuperTypes, typeFilters);
376376
}
377377

378378
/**
@@ -406,7 +406,7 @@ public static Set<Type> getAllInterfaces(Type type, Predicate<Type>... typeFilte
406406
allSuperInterfaces.addAll(getAllInterfaces(superType));
407407
}
408408

409-
return unmodifiableSet(filter(allSuperInterfaces, typeFilters));
409+
return filter(allSuperInterfaces, typeFilters);
410410
}
411411

412412
public static Set<Type> getAllTypes(Type type, Predicate<Type>... typeFilters) {
@@ -420,7 +420,7 @@ public static Set<Type> getAllTypes(Type type, Predicate<Type>... typeFilters) {
420420
// add all super interfaces
421421
allTypes.addAll(getAllInterfaces(type));
422422

423-
return unmodifiableSet(filter(allTypes, typeFilters));
423+
return filter(allTypes, typeFilters);
424424
}
425425

426426
public static Set<ParameterizedType> findParameterizedTypes(Class<?> sourceClass) {

projects/stage-1/shopizer/sc-sm-shop/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
4141
</dependency>
4242

43+
<!-- Spring Cloud OpenFeign -->
44+
<dependency>
45+
<groupId>org.springframework.cloud</groupId>
46+
<artifactId>spring-cloud-starter-openfeign</artifactId>
47+
</dependency>
48+
4349
<!-- Testing -->
4450
<dependency>
4551
<groupId>org.springframework.cloud</groupId>

0 commit comments

Comments
 (0)