Dạ em chào anh, em có pull source code ezyfox server và chạy thử example hello word của anh.
Em có đọc qua source code nhưng vẫn chưa hiểu hết, và có một số thắc mắc, có gì nhờ anh giúp đỡ ạ:
Em thấy trong source example của anh có ví dụ sau:
@Setter
@EzyPrototype
@EzyObjectBinding(write = false)
@EzyRequestListener(GREET)
public class GreetRequestHandler
extends ClientRequestHandler
implements EzyDataBinding {
private String who;
@EzyAutoBind
private Greeting greeting;
@Override
protected void execute() throws EzyBadRequestException {
responseFactory.newObjectResponse()
.command(GREET)
.param("message", greeting.greet(who))
.session(session)
.execute();
}
}
Và trước kia em thắc mắc làm sao để biết command nào để biết listen handler tương ứng. Sau khi đọc thì em thấy anh quản lý các lớp này bằng cách đưa nó vào một cái singletonSet ở EzySimpleFactoryClass. Và lúc có request gửi lên anh dựa vào command id để lấy listener tương ứng. Tuy nhiên em "KHÔNG THẤY" đoạn anh khởi tạo và add các listener này vào singletonSet ở EzySimpleFactoryClass. Em chỉ thấy đoạn get này ở EzyUserRequestSingletonController:
private Map<String, EzyUserRequestHandlerProxy> extractRequestHandlersFromListener() {
List<Object> clientRequestHandlers = getClientRequestHandlers();
Map<String, EzyUserRequestHandlerProxy> handlers = new HashMap<>();
for (Object handler : clientRequestHandlers) {
Class<?> handleType = handler.getClass();
EzyRequestListener annotation = handleType.getAnnotation(EzyRequestListener.class);
String command = EzyRequestListenerAnnotations.getCommand(annotation);
handlers.put(command, new EzyUserRequestHandlerProxy((EzyUserRequestHandler) handler));
logger.debug("add command {} and request handler {}", command, handler);
}
return handlers;
}
private List<Object> getClientRequestHandlers() {
return singletonFactory.getSingletons(EzyRequestListener.class);
}
và getSingletons ở EzySimpleSingletonFactory là anh duyệt qua singletonSet để tìm instance có chưa annotation EzyRequestListener
public List getSingletons(Class... annotationClasses) {
return this.getSingletons((o) -> {
Class[] var2 = annotationClasses;
int var3 = annotationClasses.length;
for(int var4 = 0; var4 < var3; ++var4) {
Class annotationClass = var2[var4];
if (o.getClass().isAnnotationPresent(annotationClass)) {
return true;
}
}
return false;
});
}
public List getSingletons(Predicate filter) {
List list = new ArrayList();
Iterator var3 = this.singletonSet.iterator();
while(var3.hasNext()) {
Object object = var3.next();
if (filter.test(object)) {
list.add(object);
}
}
return list;
}