use of org.olat.core.dispatcher.mapper.manager.MapperKey in project OpenOLAT by OpenOLAT.
the class MapperServiceTest method testChangingMapper_serializableSessionChanged.
@Test
public void testChangingMapper_serializableSessionChanged() {
// create a mapper
int initialNumOfMappers = mapperService.inMemoryCount();
UserSession session = createUserSession();
PersistentMapper mapper = new PersistentMapper(UUID.randomUUID().toString());
MapperKey mapperKey = mapperService.register(session, mapper);
dbInstance.commitAndCloseSession();
// retrieve the mapper
PersistentMapper reloadedMapper = (PersistentMapper) mapperService.getMapperById(session, mapperKey.getMapperId());
Assert.assertNotNull(reloadedMapper);
Assert.assertEquals(mapper, reloadedMapper);
Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
// changing the key in the mapper
String modKey = UUID.randomUUID().toString();
reloadedMapper.setKey(modKey);
// remove in memory mappers
mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
mapperService.cleanUp(session.getSessionInfo().getSession().getId());
Assert.assertEquals(initialNumOfMappers, mapperService.inMemoryCount());
// reloaded episode 2
UserSession session2 = createUserSession();
PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(session2, mapperKey.getMapperId());
Assert.assertNotNull(reloadedMapper2);
Assert.assertEquals(modKey, reloadedMapper2.getKey());
}
use of org.olat.core.dispatcher.mapper.manager.MapperKey in project OpenOLAT by OpenOLAT.
the class BasicController method registerCacheableMapper.
/**
* Convenience method: registers a cacheable mapper which will be
* automatically deregistered upon dispose of the controller
* @param ureq
* @param cacheableMapperID
* @param m The mapper
* @param expirationTime -1 is the default bevahiour, else is expiration time in seconds
* @return
*/
protected String registerCacheableMapper(UserRequest ureq, String cacheableMapperID, Mapper m, int expirationTime) {
if (mapperKeys == null) {
mapperKeys = new ArrayList<MapperKey>(2);
}
MapperKey mapperBaseKey;
UserSession usess = ureq == null ? null : ureq.getUserSession();
if (cacheableMapperID == null) {
// use non cacheable as fallback
mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, m);
} else {
mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, cacheableMapperID, m, expirationTime);
}
// registration was successful, add to our mapper list
mapperKeys.add(mapperBaseKey);
return mapperBaseKey.getUrl();
}
use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.
the class MapperServiceTest method testCleanUpMapper_notSerializable_byMappers.
@Test
public void testCleanUpMapper_notSerializable_byMappers() {
// number of currently hold mappers
int numOfMappers = mapperService.inMemoryCount();
// create a mapper
UserSession session = createUserSession();
DummyMapper mapper = new DummyMapper();
MapperKey mapperKey = mapperService.register(session, mapper);
dbInstance.commitAndCloseSession();
// retrieve the mapper
Mapper reloadedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
Assert.assertNotNull(reloadedMapper);
Assert.assertFalse(numOfMappers == mapperService.inMemoryCount());
// cleanup
mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
// check 1
Mapper deletedMapper = mapperService.getMapperById(session, mapperKey.getMapperId());
Assert.assertNull(deletedMapper);
}
use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.
the class MapperServiceTest method testChangingMapper_serializableSessionChanged.
@Test
public void testChangingMapper_serializableSessionChanged() {
// create a mapper
int initialNumOfMappers = mapperService.inMemoryCount();
UserSession session = createUserSession();
PersistentMapper mapper = new PersistentMapper(UUID.randomUUID().toString());
MapperKey mapperKey = mapperService.register(session, mapper);
dbInstance.commitAndCloseSession();
// retrieve the mapper
PersistentMapper reloadedMapper = (PersistentMapper) mapperService.getMapperById(session, mapperKey.getMapperId());
Assert.assertNotNull(reloadedMapper);
Assert.assertEquals(mapper, reloadedMapper);
Assert.assertFalse(initialNumOfMappers == mapperService.inMemoryCount());
// changing the key in the mapper
String modKey = UUID.randomUUID().toString();
reloadedMapper.setKey(modKey);
// remove in memory mappers
mapperService.cleanUp(Collections.<MapperKey>singletonList(mapperKey));
mapperService.cleanUp(session.getSessionInfo().getSession().getId());
Assert.assertEquals(initialNumOfMappers, mapperService.inMemoryCount());
// reloaded episode 2
UserSession session2 = createUserSession();
PersistentMapper reloadedMapper2 = (PersistentMapper) mapperService.getMapperById(session2, mapperKey.getMapperId());
Assert.assertNotNull(reloadedMapper2);
Assert.assertEquals(modKey, reloadedMapper2.getKey());
}
use of org.olat.core.dispatcher.mapper.manager.MapperKey in project openolat by klemens.
the class BasicController method registerCacheableMapper.
/**
* Convenience method: registers a cacheable mapper which will be
* automatically deregistered upon dispose of the controller
* @param ureq
* @param cacheableMapperID
* @param m The mapper
* @param expirationTime -1 is the default bevahiour, else is expiration time in seconds
* @return
*/
protected String registerCacheableMapper(UserRequest ureq, String cacheableMapperID, Mapper m, int expirationTime) {
if (mapperKeys == null) {
mapperKeys = new ArrayList<MapperKey>(2);
}
MapperKey mapperBaseKey;
UserSession usess = ureq == null ? null : ureq.getUserSession();
if (cacheableMapperID == null) {
// use non cacheable as fallback
mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, m);
} else {
mapperBaseKey = CoreSpringFactory.getImpl(MapperService.class).register(usess, cacheableMapperID, m, expirationTime);
}
// registration was successful, add to our mapper list
mapperKeys.add(mapperBaseKey);
return mapperBaseKey.getUrl();
}
Aggregations