Search in sources :

Example 6 with App

use of act.app.App in project actframework by actframework.

the class SimpleEventListenerMetaInfo method convert.

public static List<BeanSpec> convert(List<String> paramTypes, String className, String methodName, $.Var<Method> methodHolder) {
    int sz = paramTypes.size();
    App app = Act.app();
    ClassLoader cl = app.classLoader();
    Class c = $.classForName(className, cl);
    Class[] paramClasses = new Class[sz];
    int i = 0;
    for (String s : paramTypes) {
        paramClasses[i++] = $.classForName(s, cl);
    }
    Method method = $.getMethod(c, methodName, paramClasses);
    method.setAccessible(true);
    methodHolder.set(method);
    if (0 == sz) {
        return C.list();
    }
    List<BeanSpec> retVal = new ArrayList<>(sz);
    Type[] types = method.getGenericParameterTypes();
    Annotation[][] annotations = method.getParameterAnnotations();
    DependencyInjector injector = app.injector();
    for (i = 0; i < types.length; ++i) {
        retVal.add(BeanSpec.of(types[i], annotations[i], null, injector));
    }
    return C.list(retVal);
}
Also used : App(act.app.App) DependencyInjector(act.inject.DependencyInjector) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) Type(java.lang.reflect.Type) BeanSpec(org.osgl.inject.BeanSpec)

Example 7 with App

use of act.app.App in project actframework by actframework.

the class RouterTestBase method prepareClass.

@BeforeClass
public static void prepareClass() throws Exception {
    AppConfig config = appConfig();
    app = mock(App.class);
    when(app.config()).thenReturn(config);
    when(app.file(anyString())).thenAnswer(new Answer<File>() {

        @Override
        public File answer(InvocationOnMock invocation) throws Throwable {
            String path = (String) invocation.getArguments()[0];
            return new File(BASE, path);
        }
    });
    Field f = App.class.getDeclaredField("INST");
    f.setAccessible(true);
    f.set(null, app);
}
Also used : App(act.app.App) AppConfig(act.conf.AppConfig) Field(java.lang.reflect.Field) InvocationOnMock(org.mockito.invocation.InvocationOnMock) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 8 with App

use of act.app.App in project actframework by actframework.

the class RythmView method loadTemplate.

@Override
protected Template loadTemplate(String resourcePath) {
    App app = Act.app();
    if (isDev) {
        return loadTemplateFromResource(resourcePath, app);
    }
    if (missings.containsKey(resourcePath)) {
        return null;
    }
    Template template = templates.get(resourcePath);
    if (null == template) {
        Template newTemplate = loadTemplateFromResource(resourcePath, app);
        if (null != newTemplate) {
            template = templates.putIfAbsent(resourcePath, newTemplate);
            if (null == template) {
                template = newTemplate;
            }
        } else {
            missings.put(resourcePath, resourcePath);
        }
    }
    return template;
}
Also used : App(act.app.App) Template(act.view.Template) ITemplate(org.rythmengine.template.ITemplate)

Example 9 with App

use of act.app.App in project actframework by actframework.

the class ActHttpHandler method createActionContext.

private ActionContext createActionContext(HttpServerExchange exchange) {
    App app = client.app();
    AppConfig config = app.config();
    return ActionContext.create(app, req(exchange, config), resp(exchange, config));
}
Also used : App(act.app.App) AppConfig(act.conf.AppConfig)

Example 10 with App

use of act.app.App in project actframework by actframework.

the class NetworkBase method start.

@Override
public void start() {
    bootUp();
    for (int port : registry.keySet()) {
        NetworkHandler client = registry.get(port);
        if (!trySetUpClient(client, port, securePorts.contains(port))) {
            failed.put(port, client);
        } else {
            Act.LOGGER.info("network client hooked on port: %s", port);
        }
    }
    started = true;
    App app = Act.app();
    if (null != app) {
        app.registerHotReloadListener(new App.HotReloadListener() {

            @Override
            public void preHotReload() {
                simpleWebSocketConnector = null;
            }
        });
    }
}
Also used : App(act.app.App)

Aggregations

App (act.app.App)19 AppConfig (act.conf.AppConfig)2 SubClassFinder (act.util.SubClassFinder)2 Type (java.lang.reflect.Type)2 Act (act.Act)1 SysEventListenerBase (act.event.SysEventListenerBase)1 DependencyInjector (act.inject.DependencyInjector)1 DuplicateRouteMappingException (act.route.DuplicateRouteMappingException)1 AnnotatedClassFinder (act.util.AnnotatedClassFinder)1 ClassInfoRepository (act.util.ClassInfoRepository)1 ClassNode (act.util.ClassNode)1 Template (act.view.Template)1 File (java.io.File)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 NotNull (javax.validation.constraints.NotNull)1 BeforeClass (org.junit.BeforeClass)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1