use of org.apache.wicket.serialize.ISerializer in project wicket by apache.
the class AsynchronousPageStoreTest method storeReturnsSameInstanceOnClosePageRequest.
/**
* Store returns the same page instance from queue when there is a close request for it back
* again.
*
* @throws InterruptedException
*/
@Test
public void storeReturnsSameInstanceOnClosePageRequest() throws InterruptedException {
ISerializer serializer = new DeflatedJavaSerializer("applicationKey");
// ISerializer serializer = new DummySerializer();
IDataStore dataStore = new DiskDataStore("applicationName", new File("./target"), Bytes.bytes(10000l));
// IPageStore pageStore = new DummyPageStore(new File("target/store"));
IPageStore pageStore = spy(new DefaultPageStore(serializer, dataStore, 0));
IPageStore asyncPageStore = new AsynchronousPageStore(pageStore, 100);
int pageId = 0;
String sessionId = "sessionId";
DummyPage page = new DummyPage(pageId, 1000, 1000, sessionId);
asyncPageStore.storePage(sessionId, page);
Thread.sleep(500);
IManageablePage pageBack = asyncPageStore.getPage(sessionId, pageId);
verify(pageStore, never()).getPage(sessionId, pageId);
assertEquals(page, pageBack);
}
use of org.apache.wicket.serialize.ISerializer in project wicket by apache.
the class DefaultPageManagerProvider method newPageStore.
protected IPageStore newPageStore(IDataStore dataStore) {
int inmemoryCacheSize = getStoreSettings().getInmemoryCacheSize();
ISerializer pageSerializer = application.getFrameworkSettings().getSerializer();
return new DefaultPageStore(pageSerializer, dataStore, inmemoryCacheSize);
}
use of org.apache.wicket.serialize.ISerializer in project wicket by apache.
the class PageWindowColumn method populateItem.
@Override
public void populateItem(Item<ICellPopulator<PageWindowDescription>> cellItem, String componentId, IModel<PageWindowDescription> rowModel) {
String label;
PageWindowDescription windowDescription = rowModel.getObject();
if ("name".equals(getPropertyExpression())) {
int pageId = windowDescription.getId();
DebugPageManagerProvider pageManagerProvider = (DebugPageManagerProvider) Application.get().getPageManagerProvider();
DebugDiskDataStore dataStore = pageManagerProvider.getDataStore();
String sessionId = windowDescription.getSessionId();
byte[] data = dataStore.getData(sessionId, pageId);
ISerializer serializer = Application.get().getFrameworkSettings().getSerializer();
Object page = serializer.deserialize(data);
label = page.getClass().getName();
} else if ("id".equals(getPropertyExpression())) {
label = Integer.toString(windowDescription.getId());
} else if ("size".equals(getPropertyExpression())) {
label = Integer.toString(windowDescription.getSize());
} else {
label = "unknown: " + getPropertyExpression();
}
cellItem.add(new Label(componentId, label));
}
use of org.apache.wicket.serialize.ISerializer in project wicket by apache.
the class WicketObjects method cloneObject.
/**
* Makes a deep clone of an object by serializing and deserializing it. The object must be fully
* serializable to be cloned. No extra debug info is gathered.
*
* @param object
* The object to clone
* @return A deep copy of the object
* @see #cloneModel(Object)
*/
public static <T> T cloneObject(final T object) {
if (object == null) {
return null;
} else {
ISerializer serializer = null;
if (Application.exists()) {
serializer = Application.get().getFrameworkSettings().getSerializer();
}
if (serializer == null || serializer instanceof JavaSerializer) {
// WICKET-6334 create a new instance of JavaSerializer that doesn't use custom IObjectCheckers
serializer = new JavaSerializer(SerializingObjectSizeOfStrategy.class.getName());
}
byte[] serialized = serializer.serialize(object);
if (serialized == null) {
throw new IllegalStateException("A problem occurred while serializing an object. " + "Please check the earlier logs for more details. Problematic object: " + object);
}
Object deserialized = serializer.deserialize(serialized);
return (T) deserialized;
}
}
use of org.apache.wicket.serialize.ISerializer in project wicket by apache.
the class AsynchronousPageStoreTest method runTest.
private List<Metrics> runTest(int sessions, int pages, long writeMillis, long readMillis, int asyncPageStoreCapacity) throws InterruptedException {
List<Metrics> results = new ArrayList<>();
final CountDownLatch lock = new CountDownLatch(pages * sessions);
// ISerializer serializer = new DummySerializer();
ISerializer serializer = new DeflatedJavaSerializer("applicationKey");
IDataStore dataStore = new DiskDataStore("applicationName", new File("./target"), Bytes.bytes(10000l));
// IPageStore pageStore = new DummyPageStore(new File("target/store")) {
IPageStore pageStore = new DefaultPageStore(serializer, dataStore, 0) {
@Override
public void storePage(String sessionId, IManageablePage page) {
super.storePage(sessionId, page);
lock.countDown();
}
};
IPageStore asyncPageStore = new AsynchronousPageStore(pageStore, asyncPageStoreCapacity);
Stopwatch stopwatch = Stopwatch.createUnstarted();
for (int pageId = 1; pageId <= pages; pageId++) {
for (int i = 1; i <= sessions; i++) {
String sessionId = String.valueOf(i);
Metrics metrics = new Metrics();
stopwatch.reset();
DummyPage page = new DummyPage(pageId, around(writeMillis), around(readMillis), sessionId);
stopwatch.start();
asyncPageStore.storePage(sessionId, page);
metrics.storedPage = page;
metrics.storingMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
stopwatch.reset();
stopwatch.start();
metrics.restoredPage = DummyPage.class.cast(asyncPageStore.getPage(sessionId, pageId));
metrics.restoringMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
results.add(metrics);
}
}
lock.await(pages * sessions * (writeMillis + readMillis), TimeUnit.MILLISECONDS);
return results;
}
Aggregations