# Implementing an MDEX State Manager

Your State Manager must implement the two methods described in this topic.

    public void handleStateUpdate(PortletRequest request, MDEXState mdexState, QueryState newQueryState) throws QueryStateException;

    public QueryState handleStateMerge(PortletRequest request, MDEXState mdexState) throws QueryStateException;

- handleStateUpdate() is called when a portlet calls DataSource.setQueryState(qs). This method should eventually call mdexState.setQueryState(). (However, if it determines that, for whatever reason, the MDEXState's QueryState should not change, it is not required to make this call.) handleStateUpdate() is also responsible for marking any data sources impacted by the update (which could depend upon your implementation of handleStateMerge()) so that portlets that listen to them on the page will properly update. For this reason, the addEventTrigger(PortletRequest request, MDEXState ds) method is provided for you to call, with the passed in request object and any MDEXState objects that are considered changed.
- handleStateMerge() is called when a portlet calls DataSource.getQueryState(). You are expected to return the QueryState that the portlet should get access to for the data source represented by the mdexState, taking into account any data source relationships or other aspects of your State Manager that might impact query state.