Apache wicket – page store – error while using AsynchronousPageStore
Problem Description:
I am trying to use AsynchronousPageStore for our Application, by doing the following
First I created an asynchronous DiskPageStore
public class McAsynchronousDiskPageStore extends DiskPageStore
{
public McAsynchronousDiskPageStore()
{
super( PortalApp.this.getName(), PortalApp.this.getStoreSettings().getFileStoreFolder(), Bytes.kilobytes( 40000));
}
@Override
public boolean canBeAsynchronous(IPageContext context)
{
return true;
}
}
To pass it as delegate for an implementation of AsynchronousPageStore
public class CustomPageStoreManeger extends AsynchronousPageStore
{
private final IPageStore delegate;
public CustomPageStoreManeger(IPageStore delegate)
{
super( delegate, 100);
this.delegate = delegate;
}
@Override
public void destroy()
{
Logger.getLogger( this).logInfo( " page store Size" + ((IPersistentPageStore)delegate).getTotalSize());
}
@Override
public void addPage(IPageContext context, IManageablePage page)
{
if( INotPersistentPage.class.isAssignableFrom( page.getClass()))
{
Logger.getLogger( this).debug( " ignoring page persitence" + page.getClass());
}
else
{
super.addPage( context, page);
}
}
I’m setting it as follows in my WicketApplication class
setPageManagerProvider( new DefaultPageManagerProvider( this)
{
@Override
protected IPageStore newPersistentStore()
{
return new CustomPageStoreManeger( new McAsynchronousDiskPageStore());
}
});
yet , I get the following error in the console
09:31:44,699 ERROR [AsynchronousPageStore$PageAddingRunnable] (Wicket-AsyncPageStor) An error occurred while saving asynchronously 'PendingAdd [sessionId=6A4jzJpJbU8YMgb9J-_npsnLGsywu6xi0jJmkAiY, pageId=7, pageClass=org.apache.wicket.pageStore.SerializedPage]': org.apache.wicket.WicketRuntimeException: session attribute can not be changed asynchronuously
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AsynchronousPageStore$PendingAdd.getSessionAttribute(AsynchronousPageStore.java:198)
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AsynchronousPageStore$PendingAdd.getSessionAttribute(AsynchronousPageStore.java:201)
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AbstractPersistentPageStore.getSessionIdentifier(AbstractPersistentPageStore.java:149)
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AbstractPersistentPageStore.canBeAsynchronous(AbstractPersistentPageStore.java:76)
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AsynchronousPageStore.addPage(AsynchronousPageStore.java:369)
at deployment.xx-12.0.ear.web.war/xxx.PortalApp$CustomPageStoreManeger.addPage(PortalApp.java:206)
at deployment.xx-12.0.ear//org.apache.wicket.pageStore.AsynchronousPageStore$PageAddingRunnable.run(AsynchronousPageStore.java:292
any idea what I might be doing wrong here?
Solution – 1
IMO there is no need of McAsynchronousDiskPageStore
.
Instead of overriding #newPersistentStore()
in DefaultPageManagerProvider
you should override protected IPageStore newAsynchronousStore(IPageStore pageStore)
and return McAsynchronousDiskPageStore
without any delegates.