Search in sources :

Example 1 with IPageManager

use of org.apache.wicket.page.IPageManager in project wicket by apache.

the class TestApp1 method init.

@Override
protected void init() {
    getSharedResources().add("cancelButton", new DefaultButtonImageResource("Cancel"));
    setPageManagerProvider(new DefaultPageManagerProvider(this) {

        @Override
        public IPageManager get(IPageManagerContext pageManagerContext) {
            IDataStore dataStore = new HttpSessionDataStore(pageManagerContext, new PageNumberEvictionStrategy(100));
            IPageStore pageStore = new DefaultPageStore(new JavaSerializer(getApplicationKey()), dataStore, getStoreSettings().getInmemoryCacheSize());
            return new PageStoreManager(getName(), pageStore, pageManagerContext);
        }
    });
}
Also used : IPageStore(org.apache.wicket.pageStore.IPageStore) IPageManager(org.apache.wicket.page.IPageManager) PageStoreManager(org.apache.wicket.page.PageStoreManager) DefaultButtonImageResource(org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource) HttpSessionDataStore(org.apache.wicket.pageStore.memory.HttpSessionDataStore) PageNumberEvictionStrategy(org.apache.wicket.pageStore.memory.PageNumberEvictionStrategy) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) DefaultPageManagerProvider(org.apache.wicket.DefaultPageManagerProvider) IDataStore(org.apache.wicket.pageStore.IDataStore) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore)

Example 2 with IPageManager

use of org.apache.wicket.page.IPageManager in project wicket by apache.

the class AbstractWebSocketProcessor method broadcastMessage.

/**
 * Exports the Wicket thread locals and broadcasts the received message from the client to all
 * interested components and behaviors in the page with id {@code #pageId}
 * <p>
 *     Note: ConnectedMessage and ClosedMessage messages are notification-only. I.e. whatever the
 *     components/behaviors write in the WebSocketRequestHandler will be ignored because the protocol
 *     doesn't expect response from the user.
 * </p>
 *
 * @param message
 *      the message to broadcast
 */
public final void broadcastMessage(final IWebSocketMessage message) {
    IKey key = getRegistryKey();
    IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key);
    if (connection != null && (connection.isOpen() || message instanceof ClosedMessage)) {
        Application oldApplication = ThreadContext.getApplication();
        Session oldSession = ThreadContext.getSession();
        RequestCycle oldRequestCycle = ThreadContext.getRequestCycle();
        WebResponse webResponse = webSocketSettings.newWebSocketResponse(connection);
        try {
            WebSocketRequestMapper requestMapper = new WebSocketRequestMapper(application.getRootRequestMapper());
            RequestCycle requestCycle = createRequestCycle(requestMapper, webResponse);
            ThreadContext.setRequestCycle(requestCycle);
            ThreadContext.setApplication(application);
            Session session;
            if (oldSession == null || message instanceof IWebSocketPushMessage) {
                ISessionStore sessionStore = application.getSessionStore();
                session = sessionStore.lookup(webRequest);
                ThreadContext.setSession(session);
            } else {
                session = oldSession;
            }
            IPageManager pageManager = session.getPageManager();
            Page page = getPage(pageManager);
            if (page != null) {
                WebSocketRequestHandler requestHandler = webSocketSettings.newWebSocketRequestHandler(page, connection);
                WebSocketPayload payload = createEventPayload(message, requestHandler);
                if (!(message instanceof ConnectedMessage || message instanceof ClosedMessage || message instanceof AbortedMessage)) {
                    requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
                }
                IRequestHandler broadcastingHandler = new WebSocketMessageBroadcastHandler(pageId, resourceName, payload);
                requestMapper.setHandler(broadcastingHandler);
                requestCycle.processRequestAndDetach();
            } else {
                LOG.debug("Page with id '{}' has been expired. No message will be broadcast!", pageId);
            }
        } catch (Exception x) {
            LOG.error("An error occurred during processing of a WebSocket message", x);
        } finally {
            try {
                webResponse.close();
            } finally {
                ThreadContext.setApplication(oldApplication);
                ThreadContext.setRequestCycle(oldRequestCycle);
                ThreadContext.setSession(oldSession);
            }
        }
    } else {
        LOG.debug("Either there is no connection({}) or it is closed.", connection);
    }
}
Also used : IPageManager(org.apache.wicket.page.IPageManager) WebResponse(org.apache.wicket.request.http.WebResponse) ISessionStore(org.apache.wicket.session.ISessionStore) IRequestHandler(org.apache.wicket.request.IRequestHandler) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) ClosedMessage(org.apache.wicket.protocol.ws.api.message.ClosedMessage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) WebSocketPayload(org.apache.wicket.protocol.ws.api.event.WebSocketPayload) IWebSocketPushMessage(org.apache.wicket.protocol.ws.api.message.IWebSocketPushMessage) ConnectedMessage(org.apache.wicket.protocol.ws.api.message.ConnectedMessage) AbortedMessage(org.apache.wicket.protocol.ws.api.message.AbortedMessage) IKey(org.apache.wicket.protocol.ws.api.registry.IKey) Application(org.apache.wicket.Application) WebApplication(org.apache.wicket.protocol.http.WebApplication) HttpSession(javax.servlet.http.HttpSession) Session(org.apache.wicket.Session)

Example 3 with IPageManager

use of org.apache.wicket.page.IPageManager in project wicket by apache.

the class Page method dirty.

/**
 * Mark this page as modified in the session. If versioning is supported then a new version of
 * the page will be stored in {@link IPageStore page store}
 *
 * @param isInitialization
 *            a flag whether this is a page instantiation
 */
public void dirty(final boolean isInitialization) {
    checkHierarchyChange(this);
    if (getFlag(FLAG_PREVENT_DIRTY)) {
        return;
    }
    final IPageManager pageManager = getSession().getPageManager();
    if (!getFlag(FLAG_IS_DIRTY) && (isVersioned() && pageManager.supportsVersioning() || // support is broken
    isInitialization)) {
        setFlag(FLAG_IS_DIRTY, true);
        setNextAvailableId();
        if (isInitialization == false) {
            pageManager.touchPage(this);
        }
    }
}
Also used : IPageManager(org.apache.wicket.page.IPageManager)

Example 4 with IPageManager

use of org.apache.wicket.page.IPageManager in project wicket by apache.

the class PageVersioningTest method checkPageVersionsAreStored.

/**
 * Asserts that there is a version of the page for each operation that modified the page
 *
 * @param versioningPage
 */
private void checkPageVersionsAreStored(Page versioningPage) {
    IPageManager pageManager = wicketTester.getSession().getPageManager();
    int lastPageId = versioningPage.getPageId();
    while (lastPageId >= 0) {
        assertNotNull(pageManager.getPage(lastPageId));
        lastPageId--;
    }
}
Also used : IPageManager(org.apache.wicket.page.IPageManager)

Example 5 with IPageManager

use of org.apache.wicket.page.IPageManager in project wicket by apache.

the class PageVersioningTest method setup.

/**
 * setup()
 */
@Before
public void setup() {
    final PageVersioningApplication application = new PageVersioningApplication();
    wicketTester = new WicketTester(application) {

        /**
         * @see org.apache.wicket.util.tester.BaseWicketTester#newTestPageManagerProvider()
         */
        @Override
        protected IPageManagerProvider newTestPageManagerProvider() {
            return new IPageManagerProvider() {

                @Override
                public IPageManager apply(IPageManagerContext pageManagerContext) {
                    final IDataStore dataStore = new InMemoryPageStore();
                    final AsynchronousDataStore asyncDS = new AsynchronousDataStore(dataStore, 100);
                    final DefaultPageStore pageStore = new DefaultPageStore(new JavaSerializer(application.getApplicationKey()), asyncDS, 40);
                    return new PageStoreManager(application.getName(), pageStore, pageManagerContext);
                }
            };
        }
    };
}
Also used : IPageManager(org.apache.wicket.page.IPageManager) PageStoreManager(org.apache.wicket.page.PageStoreManager) AsynchronousDataStore(org.apache.wicket.pageStore.AsynchronousDataStore) WicketTester(org.apache.wicket.util.tester.WicketTester) IPageManagerProvider(org.apache.wicket.IPageManagerProvider) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) IDataStore(org.apache.wicket.pageStore.IDataStore) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore) Before(org.junit.Before)

Aggregations

IPageManager (org.apache.wicket.page.IPageManager)8 IPageManagerContext (org.apache.wicket.page.IPageManagerContext)4 PageStoreManager (org.apache.wicket.page.PageStoreManager)4 DefaultPageStore (org.apache.wicket.pageStore.DefaultPageStore)4 JavaSerializer (org.apache.wicket.serialize.java.JavaSerializer)4 IDataStore (org.apache.wicket.pageStore.IDataStore)3 IPageStore (org.apache.wicket.pageStore.IPageStore)3 DefaultPageManagerProvider (org.apache.wicket.DefaultPageManagerProvider)2 IPageManagerProvider (org.apache.wicket.IPageManagerProvider)2 DefaultButtonImageResource (org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource)2 HttpSessionDataStore (org.apache.wicket.pageStore.memory.HttpSessionDataStore)2 PageNumberEvictionStrategy (org.apache.wicket.pageStore.memory.PageNumberEvictionStrategy)2 WicketTester (org.apache.wicket.util.tester.WicketTester)2 Before (org.junit.Before)2 HttpSession (javax.servlet.http.HttpSession)1 Application (org.apache.wicket.Application)1 Page (org.apache.wicket.Page)1 Session (org.apache.wicket.Session)1 WebPage (org.apache.wicket.markup.html.WebPage)1 MockApplication (org.apache.wicket.mock.MockApplication)1