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);
}
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();
}
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);
}
}
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);
}
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);
}
Aggregations