简体   繁体   English

流内容到JSF UI

[英]Streaming content to JSF UI

I was quite happy with my JSF app which read the contents of MQ messages received and supplied them to the UI like this: 我对JSF应用程序感到非常满意,该应用程序读取收到的MQ消息的内容并将其提供给UI,如下所示:

<rich:panel>
<snip>
  <rich:panelMenuItem label="mylabel"  action="#{MyBacking.updateCurrent}">
    <f:param name="current" value="mylog.log" />    
  </rich:panelMenuItem>
</snip>
</rich:panel>

<rich:panel>
  <a4j:outputPanel ajaxRendered="true">
    <rich:insert content="#{MyBacking.log}" highlight="groovy" />
  </a4j:outputPanel>
</rich:panel>

and in MyBacking.java 在MyBacking.java中

private String logFile = null;
...

    public String updateCurrent() {
        FacesContext context=FacesContext.getCurrentInstance();
        setCurrent((String)context.getExternalContext().getRequestParameterMap().get("current"));
        setLog(getCurrent());
        return null;
    }

    public void setLog(String log) {
        sendMsg(log);
        msgBody = receiveMsg(moreargs);
        logFile = msgBody;
    }

    public String getLog() {
        return logFile;
    }

until the contents of one of the messages was too big and tomcat fell over. 直到其中一条消息的内容太大而tomcat摔倒了。 Obviously, I thought, I need to change the way it works so that I return some form of stream so that no one object grows so big that the container dies and the content returned by successive messages is streamed to the UI as it comes in. 显然,我认为,我需要更改其工作方式,以便返回某种形式的流,这样就没有一个对象变得太大,以至于容器死了,并且连续消息返回的内容在传入时被流送到UI。

Am I right in thinking that I can replace the work I'm doing now on a String object with a BufferedOutputStream object ie no change to the JSF code and something like this changing at the back end: 我是否认为我可以用BufferedOutputStream对象代替我现在在String对象上所做的工作,即,无需更改JSF代码,并且在后端进行如下更改:

private BufferedOutputStream logFile = null;

    public void setLog(String log) {
        sendMsg(args);
        logFile = (BufferedOutputStream) receiveMsg(moreargs); 
    }

    public String getLog() {
        return logFile;
    }

If Tomcat fell over that, it must be over 128MB large or maybe double (which is the minimum default memory size of certain Tomcat versions). 如果Tomcat失败了,那么它必须超过128MB,或者可能是两倍(这是某些Tomcat版本的最小默认内存大小)。 I don't think that users would value to visit a webpage which is that big. 我认为用户不会喜欢访问这么大的网页。 It may feel fast when acting as both server and client at localhost, but it will be up to 100 times slower when served over internets. 在本地主机上同时充当服务器和客户端时,感觉可能很快,但是通过Internet提供服务时,它的速度可能会慢100倍。

Introduce paging/filtering. 介绍分页/过滤。 Query and show just 100 entries at once or so. 一次查询并仅显示100个条目。 Add a filter which returns specific results, such as logs of a certain time range or of certain user, etc. 添加一个返回特定结果的过滤器,例如特定时间范围或特定用户的日志等。

Google also doesn't show all the zillion available results at once in a single webpage, their servers would certainly "fell over" as well :) Google也不会一次在一个网页上显示所有不计其数的可用结果,它们的服务器也肯定会“掉下来” :)

Update as per the comment: Is the bean been put in the session scope or so? 根据注释进行更新 :Bean是否已放入会话范围中? This way it will indeed accumulate in the memory soon. 这样,它的确会很快在内存中累积。 Streaming is only possible if you have an InputStream at the one side and an OutputStream at the other side. 仅当一侧具有InputStream而另一侧具有OutputStream时,才可以进行流传输。 There is no way to convert a String to a stream that way as your casting attempt so that it won't be stored in the Java memroy anymore. 没有任何一种方法可以像尝试转换那样将String转换为流,从而不再将其存储在Java内存中。 The source has to stay at the other side and it has to be retrieved byte by byte over the line. 源必须留在另一端,并且必须通过该行逐字节地进行检索。 The only feasible approach would be to use an <iframe> whose src points to some HttpServlet which directly streams the data from the source to the response. 唯一可行的方法是使用<iframe>src指向某个HttpServlet ,该HttpServlet直接将数据从源流传输到响应。

Your best bet is likely to store the whole thing in a database or --if it doesn't contain user specific data-- in the application scope and share it among all sessions/requests. 最好的选择是将整个内容存储在数据库中,或者-如果其中不包含用户特定的数据,则存储在应用程序范围内,并在所有会话/请求中共享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM