Search in sources :

Example 1 with LongPollData

use of com.serotonin.m2m2.web.dwr.longPoll.LongPollData in project ma-core-public by infiniteautomation.

the class BaseDwr method initializeLongPoll.

@DwrPermission(anonymous = true)
public Map<String, Object> initializeLongPoll(int pollSessionId, LongPollRequest request) {
    LongPollData data = getLongPollData(pollSessionId, true);
    data.setRequest(request);
    return doLongPoll(pollSessionId);
}
Also used : LongPollData(com.serotonin.m2m2.web.dwr.longPoll.LongPollData) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 2 with LongPollData

use of com.serotonin.m2m2.web.dwr.longPoll.LongPollData in project ma-modules-public by infiniteautomation.

the class WatchListDwr method resetWatchListState.

@DwrPermission(anonymous = true)
public void resetWatchListState(int pollSessionId) {
    LongPollData data = getLongPollData(pollSessionId, false);
    synchronized (data.getState()) {
        WatchListCommon.getWatchListStates(data).clear();
        WatchListVO wl = getWatchList();
        for (DataPointVO dp : wl.getPointList()) dp.resetLastValue();
    }
    notifyLongPollImpl(data.getRequest());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) LongPollData(com.serotonin.m2m2.web.dwr.longPoll.LongPollData) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 3 with LongPollData

use of com.serotonin.m2m2.web.dwr.longPoll.LongPollData in project ma-modules-public by infiniteautomation.

the class GraphicalViewLongPollDefinition method handleLongPoll.

@Override
public void handleLongPoll(LongPollData data, Map<String, Object> response, User user) {
    boolean view = false;
    boolean viewEdit = false;
    boolean anon = false;
    if (data.getRequest().hasHandler("graphicalView") && user != null)
        view = true;
    else if (data.getRequest().hasHandler("graphicalViewEdit") && user != null)
        viewEdit = true;
    else if (data.getRequest().hasHandler("graphicalViewAnon"))
        anon = true;
    if (view || viewEdit || anon) {
        LongPollState state = data.getState();
        List<ViewComponentState> graphicalViewStates = GraphicalViewsCommon.getGraphicalViewListStates(data);
        List<ViewComponentState> newStates;
        synchronized (state) {
            if (anon)
                newStates = graphicalViewDwr.getViewPointDataAnon(data.getRequest().getRefId());
            else
                newStates = graphicalViewDwr.getViewPointData(viewEdit);
            List<ViewComponentState> differentStates = new ArrayList<ViewComponentState>();
            for (ViewComponentState newState : newStates) {
                ViewComponentState oldState = getGraphicalViewState(newState.getId(), graphicalViewStates);
                if (oldState == null)
                    differentStates.add(newState);
                else {
                    ViewComponentState copy = newState.clone();
                    copy.removeEqualValue(oldState);
                    if (!copy.isEmpty())
                        differentStates.add(copy);
                }
            }
            if (!differentStates.isEmpty()) {
                response.put("viewStates", differentStates);
                GraphicalViewsCommon.setGraphicalViewListStates(data, newStates);
            }
        }
    }
}
Also used : LongPollState(com.serotonin.m2m2.web.dwr.longPoll.LongPollState) ArrayList(java.util.ArrayList)

Example 4 with LongPollData

use of com.serotonin.m2m2.web.dwr.longPoll.LongPollData in project ma-modules-public by infiniteautomation.

the class WatchListLongPollHandler method handleLongPoll.

@Override
public void handleLongPoll(LongPollData data, Map<String, Object> response, User user) {
    if (data.getRequest().hasHandler(key) && user != null) {
        LongPollState state = data.getState();
        List<WatchListState> watchListStates = WatchListCommon.getWatchListStates(data);
        synchronized (state) {
            List<WatchListState> newStates = watchListDwr.getPointData();
            List<WatchListState> differentStates = new ArrayList<WatchListState>();
            for (WatchListState newState : newStates) {
                WatchListState oldState = getWatchListState(newState.getId(), watchListStates);
                if (oldState == null)
                    differentStates.add(newState);
                else {
                    WatchListState copy = newState.clone();
                    copy.removeEqualValue(oldState);
                    if (!copy.isEmpty())
                        differentStates.add(copy);
                }
            }
            if (!differentStates.isEmpty()) {
                response.put("watchListStates", differentStates);
                state.setAttribute("watchListStates", newStates);
            }
        }
    }
}
Also used : LongPollState(com.serotonin.m2m2.web.dwr.longPoll.LongPollState) ArrayList(java.util.ArrayList)

Example 5 with LongPollData

use of com.serotonin.m2m2.web.dwr.longPoll.LongPollData in project ma-core-public by infiniteautomation.

the class BaseDwr method getLongPollData.

protected LongPollData getLongPollData(int pollSessionId, boolean refreshState) {
    List<LongPollData> dataList = getLongPollData();
    LongPollData data = getDataFromList(dataList, pollSessionId);
    if (data == null) {
        synchronized (dataList) {
            data = getDataFromList(dataList, pollSessionId);
            if (data == null) {
                data = new LongPollData(pollSessionId);
                refreshState = true;
                dataList.add(data);
            }
        }
    }
    if (refreshState)
        data.setState(new LongPollState());
    return data;
}
Also used : LongPollState(com.serotonin.m2m2.web.dwr.longPoll.LongPollState) LongPollData(com.serotonin.m2m2.web.dwr.longPoll.LongPollData)

Aggregations

LongPollData (com.serotonin.m2m2.web.dwr.longPoll.LongPollData)6 LongPollState (com.serotonin.m2m2.web.dwr.longPoll.LongPollState)5 DwrPermission (com.serotonin.m2m2.web.dwr.util.DwrPermission)4 ArrayList (java.util.ArrayList)3 LongPollRequest (com.serotonin.m2m2.web.dwr.longPoll.LongPollRequest)2 IMangoLifecycle (com.serotonin.m2m2.IMangoLifecycle)1 EventDao (com.serotonin.m2m2.db.dao.EventDao)1 EventInstance (com.serotonin.m2m2.rt.event.EventInstance)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 User (com.serotonin.m2m2.vo.User)1 PointDetailsState (com.serotonin.m2m2.web.dwr.beans.PointDetailsState)1 LongPollHandler (com.serotonin.m2m2.web.dwr.longPoll.LongPollHandler)1 HashMap (java.util.HashMap)1 List (java.util.List)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1