Search in sources :

Example 1 with RemotingConfiguration

use of com.canoo.dp.impl.server.config.RemotingConfiguration in project dolphin-platform by canoo.

the class TestGarbageCollection method createGarbageCollection.

private GarbageCollector createGarbageCollection(final GarbageCollectionCallback gcConsumer) {
    Assert.requireNonNull(gcConsumer, "gcConsumer");
    final RemotingConfiguration configuration = new RemotingConfiguration();
    return new GarbageCollector(configuration, gcConsumer);
}
Also used : RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration)

Example 2 with RemotingConfiguration

use of com.canoo.dp.impl.server.config.RemotingConfiguration in project dolphin-platform by canoo.

the class TestGarbageCollection method testDeactivatedGC.

@Test
public void testDeactivatedGC() {
    GarbageCollectionCallback gcConsumer = new GarbageCollectionCallback() {

        @Override
        public void onReject(Set<Instance> instances) {
            fail("GC should be deactivated!");
        }
    };
    Properties properties = new Properties();
    properties.setProperty("garbageCollectionActive", "false");
    RemotingConfiguration configuration = new RemotingConfiguration(new ServerConfiguration(properties));
    GarbageCollector garbageCollector = new GarbageCollector(configuration, gcConsumer);
    BeanWithLists parentBeanA = new BeanWithLists(garbageCollector);
    garbageCollector.onBeanCreated(parentBeanA, true);
    BeanWithProperties childBean = new BeanWithProperties(garbageCollector);
    garbageCollector.onBeanCreated(childBean, false);
    BeanWithProperties childBeanB = new BeanWithProperties(garbageCollector);
    garbageCollector.onBeanCreated(childBeanB, false);
    childBean.beanProperty().set(childBeanB);
    parentBeanA.getBeansList2().add(childBeanB);
    parentBeanA.getBeansList2().add(childBean);
    assertEquals(garbageCollector.getManagedInstancesCount(), 0);
    garbageCollector.gc();
    parentBeanA.getBeansList2().remove(childBean);
    assertEquals(garbageCollector.getManagedInstancesCount(), 0);
    garbageCollector.gc();
}
Also used : Set(java.util.Set) RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration) ServerConfiguration(com.canoo.dp.impl.server.config.ServerConfiguration) Properties(java.util.Properties) Test(org.testng.annotations.Test)

Example 3 with RemotingConfiguration

use of com.canoo.dp.impl.server.config.RemotingConfiguration in project dolphin-platform by canoo.

the class RemotingModule method initialize.

@Override
public void initialize(ServerCoreComponents coreComponents) throws ModuleInitializationException {
    LOG.info("Starting Dolphin Platform");
    try {
        final ServletContext servletContext = coreComponents.getInstance(ServletContext.class);
        final ClasspathScanner classpathScanner = coreComponents.getInstance(ClasspathScanner.class);
        final ManagedBeanFactory beanFactory = coreComponents.getInstance(ManagedBeanFactory.class);
        final RemotingConfiguration configuration = new RemotingConfiguration(coreComponents.getConfiguration());
        final ClientSessionProvider sessionProvider = coreComponents.getInstance(ClientSessionProvider.class);
        final DolphinContextFactory dolphinContextFactory = new DefaultDolphinContextFactory(configuration, sessionProvider, beanFactory, classpathScanner);
        final DolphinContextCommunicationHandler communicationHandler = new DolphinContextCommunicationHandler(sessionProvider, dolphinContextFactory);
        final DolphinContextProvider contextProvider = new DolphinContextProvider() {

            @Override
            public DolphinContext getContext(final ClientSession clientSession) {
                return communicationHandler.getContext(clientSession);
            }

            @Override
            public DolphinContext getContextById(String clientSessionId) {
                return communicationHandler.getContextById(clientSessionId);
            }

            @Override
            public DolphinContext getCurrentDolphinContext() {
                return communicationHandler.getCurrentDolphinContext();
            }
        };
        coreComponents.provideInstance(DolphinContextProvider.class, contextProvider);
        final ClientSessionLifecycleHandler lifecycleHandler = coreComponents.getInstance(ClientSessionLifecycleHandler.class);
        servletContext.addServlet(DOLPHIN_SERVLET_NAME, new DolphinPlatformServlet(communicationHandler)).addMapping(configuration.getDolphinPlatformServletMapping());
        servletContext.addServlet(INTERRUPT_SERVLET_NAME, new InterruptServlet(contextProvider)).addMapping(configuration.getDolphinPlatformInterruptServletMapping());
        LOG.debug("Dolphin Platform initialized under context \"" + servletContext.getContextPath() + "\"");
        LOG.debug("Dolphin Platform endpoint defined as " + configuration.getDolphinPlatformServletMapping());
        Iterator<EventBusProvider> iterator = ServiceLoader.load(EventBusProvider.class).iterator();
        boolean providerFound = false;
        boolean flag = false;
        while (iterator.hasNext()) {
            EventBusProvider provider = iterator.next();
            if (configuration.getEventbusType().equals(provider.getType())) {
                if (providerFound) {
                    throw new IllegalStateException("More than 1 event bus provider found");
                }
                LOG.debug("Using event bus of type {} with provider class {}", provider.getType(), provider.getClass());
                providerFound = true;
                RemotingEventBus eventBus = provider.create(configuration);
                if (eventBus instanceof AbstractEventBus) {
                    ((AbstractEventBus) eventBus).init(contextProvider, lifecycleHandler);
                }
                coreComponents.provideInstance(RemotingEventBus.class, eventBus);
                flag = true;
            }
        }
        if (!flag) {
            throw new ModuleInitializationException("Configured event bus is not on the classpath.");
        }
    } catch (ControllerValidationException cve) {
        throw new ModuleInitializationException("Can not start Remote Presentation Model support based on bad controller definition", cve);
    }
}
Also used : DolphinContextCommunicationHandler(com.canoo.dp.impl.server.context.DolphinContextCommunicationHandler) InterruptServlet(com.canoo.dp.impl.server.servlet.InterruptServlet) AbstractEventBus(com.canoo.dp.impl.server.event.AbstractEventBus) ModuleInitializationException(com.canoo.platform.server.spi.ModuleInitializationException) DolphinPlatformServlet(com.canoo.dp.impl.server.servlet.DolphinPlatformServlet) ClasspathScanner(com.canoo.platform.server.spi.components.ClasspathScanner) RemotingEventBus(com.canoo.platform.remoting.server.event.RemotingEventBus) ClientSessionProvider(com.canoo.dp.impl.server.client.ClientSessionProvider) DolphinContextFactory(com.canoo.dp.impl.server.context.DolphinContextFactory) DefaultDolphinContextFactory(com.canoo.dp.impl.server.context.DefaultDolphinContextFactory) DefaultDolphinContextFactory(com.canoo.dp.impl.server.context.DefaultDolphinContextFactory) DolphinContextProvider(com.canoo.dp.impl.server.context.DolphinContextProvider) RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration) EventBusProvider(com.canoo.platform.remoting.server.event.spi.EventBusProvider) ClientSession(com.canoo.platform.server.client.ClientSession) ManagedBeanFactory(com.canoo.platform.server.spi.components.ManagedBeanFactory) ServletContext(javax.servlet.ServletContext) ControllerValidationException(com.canoo.dp.impl.server.controller.ControllerValidationException) ClientSessionLifecycleHandler(com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)

Example 4 with RemotingConfiguration

use of com.canoo.dp.impl.server.config.RemotingConfiguration in project dolphin-platform by canoo.

the class AbstractDolphinBasedTest method createBeanManager.

protected BeanManager createBeanManager(ServerModelStore serverModelStore, BeanRepository beanRepository, EventDispatcher dispatcher) {
    final Converters converters = new Converters(beanRepository);
    final PresentationModelBuilderFactory builderFactory = new ServerPresentationModelBuilderFactory(serverModelStore);
    final ClassRepository classRepository = new ClassRepositoryImpl(serverModelStore, converters, builderFactory);
    final ListMapper listMapper = new ListMapperImpl(serverModelStore, classRepository, beanRepository, builderFactory, dispatcher);
    final RemotingConfiguration configurationForGc = new RemotingConfiguration();
    final GarbageCollector garbageCollector = new GarbageCollector(configurationForGc, new GarbageCollectionCallback() {

        @Override
        public void onReject(Set<Instance> instances) {
        }
    });
    final BeanBuilder beanBuilder = new ServerBeanBuilderImpl(classRepository, beanRepository, listMapper, builderFactory, dispatcher, garbageCollector);
    return new BeanManagerImpl(beanRepository, beanBuilder);
}
Also used : Instance(com.canoo.dp.impl.server.gc.Instance) ClassRepository(com.canoo.dp.impl.remoting.ClassRepository) Converters(com.canoo.dp.impl.remoting.Converters) BeanBuilder(com.canoo.dp.impl.remoting.BeanBuilder) ServerPresentationModelBuilderFactory(com.canoo.dp.impl.server.model.ServerPresentationModelBuilderFactory) PresentationModelBuilderFactory(com.canoo.dp.impl.remoting.PresentationModelBuilderFactory) RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration) ServerPresentationModelBuilderFactory(com.canoo.dp.impl.server.model.ServerPresentationModelBuilderFactory) GarbageCollectionCallback(com.canoo.dp.impl.server.gc.GarbageCollectionCallback) ServerBeanBuilderImpl(com.canoo.dp.impl.server.model.ServerBeanBuilderImpl) BeanManagerImpl(com.canoo.dp.impl.remoting.BeanManagerImpl) ListMapper(com.canoo.dp.impl.remoting.ListMapper) ListMapperImpl(com.canoo.dp.impl.remoting.collections.ListMapperImpl) ClassRepositoryImpl(com.canoo.dp.impl.remoting.ClassRepositoryImpl) GarbageCollector(com.canoo.dp.impl.server.gc.GarbageCollector)

Example 5 with RemotingConfiguration

use of com.canoo.dp.impl.server.config.RemotingConfiguration in project dolphin-platform by canoo.

the class AbstractDolphinBasedTest method createBeanManager.

protected BeanManager createBeanManager(ServerModelStore serverModelStore) {
    final EventDispatcher dispatcher = new ServerEventDispatcher(serverModelStore);
    final BeanRepositoryImpl beanRepository = new BeanRepositoryImpl(serverModelStore, dispatcher);
    final Converters converters = new Converters(beanRepository);
    final PresentationModelBuilderFactory builderFactory = new ServerPresentationModelBuilderFactory(serverModelStore);
    final ClassRepository classRepository = new ClassRepositoryImpl(serverModelStore, converters, builderFactory);
    final ListMapper listMapper = new ListMapperImpl(serverModelStore, classRepository, beanRepository, builderFactory, dispatcher);
    final RemotingConfiguration configurationForGc = new RemotingConfiguration();
    final GarbageCollector garbageCollector = new GarbageCollector(configurationForGc, new GarbageCollectionCallback() {

        @Override
        public void onReject(Set<Instance> instances) {
        }
    });
    final BeanBuilder beanBuilder = new ServerBeanBuilderImpl(classRepository, beanRepository, listMapper, builderFactory, dispatcher, garbageCollector);
    return new BeanManagerImpl(beanRepository, beanBuilder);
}
Also used : ServerEventDispatcher(com.canoo.dp.impl.server.model.ServerEventDispatcher) Instance(com.canoo.dp.impl.server.gc.Instance) ClassRepository(com.canoo.dp.impl.remoting.ClassRepository) Converters(com.canoo.dp.impl.remoting.Converters) BeanBuilder(com.canoo.dp.impl.remoting.BeanBuilder) BeanRepositoryImpl(com.canoo.dp.impl.remoting.BeanRepositoryImpl) ServerPresentationModelBuilderFactory(com.canoo.dp.impl.server.model.ServerPresentationModelBuilderFactory) PresentationModelBuilderFactory(com.canoo.dp.impl.remoting.PresentationModelBuilderFactory) ServerEventDispatcher(com.canoo.dp.impl.server.model.ServerEventDispatcher) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) RemotingConfiguration(com.canoo.dp.impl.server.config.RemotingConfiguration) ServerPresentationModelBuilderFactory(com.canoo.dp.impl.server.model.ServerPresentationModelBuilderFactory) GarbageCollectionCallback(com.canoo.dp.impl.server.gc.GarbageCollectionCallback) ServerBeanBuilderImpl(com.canoo.dp.impl.server.model.ServerBeanBuilderImpl) BeanManagerImpl(com.canoo.dp.impl.remoting.BeanManagerImpl) ListMapper(com.canoo.dp.impl.remoting.ListMapper) ListMapperImpl(com.canoo.dp.impl.remoting.collections.ListMapperImpl) ClassRepositoryImpl(com.canoo.dp.impl.remoting.ClassRepositoryImpl) GarbageCollector(com.canoo.dp.impl.server.gc.GarbageCollector)

Aggregations

RemotingConfiguration (com.canoo.dp.impl.server.config.RemotingConfiguration)5 BeanBuilder (com.canoo.dp.impl.remoting.BeanBuilder)2 BeanManagerImpl (com.canoo.dp.impl.remoting.BeanManagerImpl)2 ClassRepository (com.canoo.dp.impl.remoting.ClassRepository)2 ClassRepositoryImpl (com.canoo.dp.impl.remoting.ClassRepositoryImpl)2 Converters (com.canoo.dp.impl.remoting.Converters)2 ListMapper (com.canoo.dp.impl.remoting.ListMapper)2 PresentationModelBuilderFactory (com.canoo.dp.impl.remoting.PresentationModelBuilderFactory)2 ListMapperImpl (com.canoo.dp.impl.remoting.collections.ListMapperImpl)2 GarbageCollectionCallback (com.canoo.dp.impl.server.gc.GarbageCollectionCallback)2 GarbageCollector (com.canoo.dp.impl.server.gc.GarbageCollector)2 Instance (com.canoo.dp.impl.server.gc.Instance)2 ServerBeanBuilderImpl (com.canoo.dp.impl.server.model.ServerBeanBuilderImpl)2 ServerPresentationModelBuilderFactory (com.canoo.dp.impl.server.model.ServerPresentationModelBuilderFactory)2 BeanRepositoryImpl (com.canoo.dp.impl.remoting.BeanRepositoryImpl)1 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)1 ClientSessionLifecycleHandler (com.canoo.dp.impl.server.client.ClientSessionLifecycleHandler)1 ClientSessionProvider (com.canoo.dp.impl.server.client.ClientSessionProvider)1 ServerConfiguration (com.canoo.dp.impl.server.config.ServerConfiguration)1 DefaultDolphinContextFactory (com.canoo.dp.impl.server.context.DefaultDolphinContextFactory)1