use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.
the class BukkitCommandsI18nManifestTask method execute.
@Override
public void execute(OkaeriBukkitPlugin platform) {
BeanManifest manifest = platform.getInjector().get("manifest", BeanManifest.class).orElseThrow(() -> new RuntimeException("Cannot hook i18n-platform-commands without manifest being present!"));
ClassLoader classLoader = platform.getClass().getClassLoader();
ComponentCreator creator = platform.getCreator();
manifest.withDepend(BeanManifest.of(classLoader, I18nCommandsMessages.class, creator, false).name("i18n-platform-commands"));
}
use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.
the class ListenerComponentResolver method make.
@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
long start = System.currentTimeMillis();
Class<?> manifestType = manifest.getType();
Object instance = injector.createInstance(manifestType);
Listener listener = (Listener) instance;
this.plugin.getProxy().getPluginManager().registerListener(this.plugin, listener);
long took = System.currentTimeMillis() - start;
creator.log(ComponentHelper.buildComponentMessage().type("Added listener").name(listener.getClass().getSimpleName()).took(took).meta("methods", Arrays.stream(listener.getClass().getDeclaredMethods()).filter(method -> method.getAnnotation(EventHandler.class) != null).map(Method::getName).collect(Collectors.toList())).build());
creator.increaseStatistics("listeners", 1);
return listener;
}
use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.
the class RequestHandlerComponentResolver method make.
@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
long start = System.currentTimeMillis();
BeanManifest parent = manifest.getParent();
Class<?> parentClass = parent.getType();
Method method = manifest.getMethod();
RequestHandlerMeta handlerMeta = RequestHandlerMeta.of(parentClass, method);
int[] contextIndexes = handlerMeta.getContextIndexes();
Map<Integer, Object[]> prefilledCallCache = new CacheMap<>(256);
Handler handler = context -> {
Object[] call = null;
try {
call = this.getCall(prefilledCallCache, handlerMeta, context, injector);
method.invoke(parent.getObject(), call);
this.flushCall(call, contextIndexes, handlerMeta);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
this.logger.error("Handler (" + method + ") failure [" + Arrays.toString(call) + "]", exception);
}
};
HandlerType handlerType = handlerMeta.getType();
String handlerPath = handlerMeta.getPath();
SimpleRouteRole[] handlerPermittedRoles = handlerMeta.getPermittedRoles();
this.javalin.addHandler(handlerType, handlerPath, handler, handlerPermittedRoles);
long took = System.currentTimeMillis() - start;
creator.log(ComponentHelper.buildComponentMessage().type("Added handler").name(parentClass.getSimpleName() + "#" + method.getName()).took(took).meta("path", handlerPath).meta("type", handlerType).meta("permittedRoles", Arrays.stream(handlerPermittedRoles).map(SimpleRouteRole::getName).collect(Collectors.toList())).build());
creator.increaseStatistics("handlers", 1);
return handler;
}
use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.
the class BeanManifestExecuteTask method execute.
@Override
public void execute(OkaeriPlatform platform) {
// find manifest
BeanManifest beanManifest = platform.getInjector().get("manifest", BeanManifest.class).orElseThrow(() -> new RuntimeException("Cannot execute manifest without manifest being present!"));
// resolve resource provider
ExternalResourceProvider resourceProvider = platform.getInjector().get("externalResourceProvider", ExternalResourceProvider.class).orElse(NULL_RESOURCE_PROVIDER);
// execute component tree and register everything
beanManifest.execute(platform.getCreator(), platform.getInjector(), resourceProvider);
// sub-components do not require manual injecting because
// these are filled at the initialization by the DI itself
// plugin instance however is not, so here it goes
ComponentHelper.injectComponentFields(platform, platform.getInjector());
// call PostConstruct
ComponentHelper.invokePostConstruct(platform, platform.getInjector());
}
use of eu.okaeri.platform.core.component.manifest.BeanManifest in project okaeri-platform by OkaeriPoland.
the class ListenerComponentResolver method make.
@Override
public Object make(@NonNull ComponentCreator creator, @NonNull BeanManifest manifest, @NonNull Injector injector) {
long start = System.currentTimeMillis();
Class<?> manifestType = manifest.getType();
Object instance = injector.createInstance(manifestType);
Listener listener = (Listener) instance;
this.plugin.getServer().getPluginManager().registerEvents(listener, this.plugin);
long took = System.currentTimeMillis() - start;
creator.log(ComponentHelper.buildComponentMessage().type("Added listener").name(listener.getClass().getSimpleName()).took(took).meta("methods", Arrays.stream(listener.getClass().getDeclaredMethods()).filter(method -> method.getAnnotation(EventHandler.class) != null).map(Method::getName).collect(Collectors.toList())).build());
creator.increaseStatistics("listeners", 1);
return listener;
}
Aggregations