Search in sources :

Example 1 with EzyBindingContext

use of com.tvd12.ezyfox.binding.EzyBindingContext in project ezyfox-server by youngmonkeys.

the class EzySimpleAppEntry method createBeanContext.

protected EzyBeanContext createBeanContext(EzyAppContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory appResponseFactory = createAppResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyAppSetting appSetting = context.getApp().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("appContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("userManager", context.getApp().getUserManager()).addSingleton("appResponseFactory", appResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(appSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (appSetting.getPackageName() != null) {
        scanablePackages.add(appSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyAppEventController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
    beanContextBuilder.scan(scanablePackages);
    setupBeanContext(context, beanContextBuilder);
    return beanContextBuilder.build();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Example 2 with EzyBindingContext

use of com.tvd12.ezyfox.binding.EzyBindingContext in project ezyfox-server by youngmonkeys.

the class EzySimplePluginEntry method createBeanContext.

private EzyBeanContext createBeanContext(EzyPluginContext context) {
    EzyBindingContext bindingContext = createBindingContext();
    EzyMarshaller marshaller = bindingContext.newMarshaller();
    EzyUnmarshaller unmarshaller = bindingContext.newUnmarshaller();
    EzyResponseFactory pluginResponseFactory = createPluginResponseFactory(context, marshaller);
    ScheduledExecutorService executorService = context.get(ScheduledExecutorService.class);
    EzyPluginSetting pluginSetting = context.getPlugin().getSetting();
    EzyBeanContextBuilder beanContextBuilder = EzyBeanContext.builder().addSingleton("pluginContext", context).addSingleton("marshaller", marshaller).addSingleton("unmarshaller", unmarshaller).addSingleton("executorService", executorService).addSingleton("zoneContext", context.getParent()).addSingleton("serverContext", context.getParent().getParent()).addSingleton("pluginResponseFactory", pluginResponseFactory).addSingleton("featureCommandManager", new EzyFeatureCommandManager()).addSingleton("requestCommandManager", new EzyRequestCommandManager()).activeProfiles(pluginSetting.getActiveProfiles());
    Class[] singletonClasses = getSingletonClasses();
    beanContextBuilder.addSingletonClasses(singletonClasses);
    Class[] prototypeClasses = getPrototypeClasses();
    beanContextBuilder.addPrototypeClasses(prototypeClasses);
    Set<String> scanablePackages = internalGetScanableBeanPackages();
    if (pluginSetting.getPackageName() != null) {
        scanablePackages.add(pluginSetting.getPackageName());
    }
    EzyReflection reflection = new EzyReflectionProxy(scanablePackages);
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedExtendsClasses(EzyEventHandler.class, EzyPluginEventController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestController.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyExceptionHandler.class));
    beanContextBuilder.addSingletonClasses((Set) reflection.getAnnotatedClasses(EzyRequestInterceptor.class));
    beanContextBuilder.scan(scanablePackages);
    setupBeanContext(context, beanContextBuilder);
    return beanContextBuilder.build();
}
Also used : EzyResponseFactory(com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) EzyFeatureCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager) EzyRequestCommandManager(com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager) EzyPluginSetting(com.tvd12.ezyfoxserver.setting.EzyPluginSetting) EzyUnmarshaller(com.tvd12.ezyfox.binding.EzyUnmarshaller) EzyMarshaller(com.tvd12.ezyfox.binding.EzyMarshaller) EzyBeanContextBuilder(com.tvd12.ezyfox.bean.EzyBeanContextBuilder) EzyReflectionProxy(com.tvd12.ezyfox.reflect.EzyReflectionProxy) EzyReflection(com.tvd12.ezyfox.reflect.EzyReflection)

Example 3 with EzyBindingContext

use of com.tvd12.ezyfox.binding.EzyBindingContext in project calabash by youngmonkeys.

the class LocalMapPersistExample method newEntityCodec.

protected EzyEntityCodec newEntityCodec() {
    EzyBindingContext bindingContext = EzyBindingContext.builder().scan("com.tvd12.calabash.server.core.test.localmappersit").build();
    EzyMessageSerializer messageSerializer = new MsgPackSimpleSerializer();
    EzyMessageDeserializer messageDeserializer = new MsgPackSimpleDeserializer();
    return EzyBindingEntityCodec.builder().marshaller(bindingContext.newMarshaller()).unmarshaller(bindingContext.newUnmarshaller()).messageSerializer(messageSerializer).messageDeserializer(messageDeserializer).build();
}
Also used : EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext)

Example 4 with EzyBindingContext

use of com.tvd12.ezyfox.binding.EzyBindingContext in project ezyfox-examples by tvd12.

the class MsgpackExample method main.

public static void main(String[] args) {
    final EzyBindingContext bindingContext = EzyBindingContext.builder().scan("com.tvd12.ezyfox.example.msgpack").build();
    final EzyEntityCodec codec = EzyBindingEntityCodec.builder().marshaller(bindingContext.newMarshaller()).unmarshaller(bindingContext.newUnmarshaller()).messageSerializer(new MsgPackSimpleSerializer()).messageDeserializer(new MsgPackSimpleDeserializer()).build();
    final Transfer transfer = new Transfer(300, 100);
    final byte[] serializedBytes = codec.serialize(transfer);
    System.out.println(serializedBytes.length);
    System.out.println(Arrays.toString(serializedBytes));
    System.out.println(EzyPrints.printHex(serializedBytes));
    final Transfer deserializedObj = codec.deserialize(serializedBytes, Transfer.class);
    System.out.println(deserializedObj);
}
Also used : EzyBindingContext(com.tvd12.ezyfox.binding.EzyBindingContext) MsgPackSimpleSerializer(com.tvd12.ezyfox.codec.MsgPackSimpleSerializer) MsgPackSimpleDeserializer(com.tvd12.ezyfox.codec.MsgPackSimpleDeserializer) EzyEntityCodec(com.tvd12.ezyfox.codec.EzyEntityCodec)

Aggregations

EzyBindingContext (com.tvd12.ezyfox.binding.EzyBindingContext)4 EzyBeanContextBuilder (com.tvd12.ezyfox.bean.EzyBeanContextBuilder)2 EzyMarshaller (com.tvd12.ezyfox.binding.EzyMarshaller)2 EzyUnmarshaller (com.tvd12.ezyfox.binding.EzyUnmarshaller)2 EzyReflection (com.tvd12.ezyfox.reflect.EzyReflection)2 EzyReflectionProxy (com.tvd12.ezyfox.reflect.EzyReflectionProxy)2 EzyResponseFactory (com.tvd12.ezyfoxserver.support.factory.EzyResponseFactory)2 EzyFeatureCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyFeatureCommandManager)2 EzyRequestCommandManager (com.tvd12.ezyfoxserver.support.manager.EzyRequestCommandManager)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 EzyEntityCodec (com.tvd12.ezyfox.codec.EzyEntityCodec)1 MsgPackSimpleDeserializer (com.tvd12.ezyfox.codec.MsgPackSimpleDeserializer)1 MsgPackSimpleSerializer (com.tvd12.ezyfox.codec.MsgPackSimpleSerializer)1 EzyAppSetting (com.tvd12.ezyfoxserver.setting.EzyAppSetting)1 EzyPluginSetting (com.tvd12.ezyfoxserver.setting.EzyPluginSetting)1