[英]Problems using javax.swing.SwingWorker while trying to connect to a Serial Port
[英]Swing, serial port and JSF
我只需要解決這個問題的想法:我們制作了一個Swing應用程序來捕獲串行端口上的數據,該捕獲會觸發一些警報(在JPane中呈現),同時此信息存儲在數據庫中以提供一些統計信息(使用JFreechart和JasperReports)。 現在,我們希望在Web界面中提供相同的信息,並且我們正在考慮基於Apache Tomcat 7應用程序的JSF + Primefaces。
統計信息不是問題,我們關心的是如何通知Web應用程序串行端口發生火災,以顯示與客戶端瀏覽器中顯示的Swing應用程序捕獲相同的警報? 最終用戶希望保留兩種格式:本地視圖(Swing)和用於管理員的Web視圖。
我們的建議是否正確(Swing-> JSF + Primefaces)?,還有其他替代方法嗎?
預先感謝您的任何想法
我找到了解決問題的方法。 我首先在這里找到了找到的解決方案:1.為了測試該解決方案,我使用Glassfish 3.1.2.2代替了Tomcat 7,Netbeans 7.3和PrimeFaces 3.5。2.我基於本教程制作了一個示例應用程序。 3.我實現了PrimeFaces演示頁面的PimePush Counter示例。 4.我制作了一個Swing應用程序,帶有一個按鈕來模擬串行端口捕獲的操作,該應用程序使用ws將內容推送到Web應用程序中。 5. GF已啟用彗星和Web套接字支持。
但是有一個問題,每次我重新啟動Glassfish時,都必須取消部署該應用程序,然后重新部署它們,以便Web服務可用。 為什么會這樣?我想念東西嗎?
這里的代碼:
ws類:
@WebService(serviceName = "BotonService")
@Stateless
public class BotonService {
private boolean push = false;
@EJB
private ServiceShare servicio;
/**
* This is a sample web service operation
*/
@WebMethod(operationName = "hello")
public String hello(@WebParam(name = "name") String txt) {
return "Hello " + txt + " !";
}
/**
* Web service operation
*/
@WebMethod(operationName = "setPush")
public void setPush(@WebParam(name = "push") boolean push) {
this.push = push;
servicio.setPush(push);
servicio.firePush();
}
/**
* Web service operation
*/
@WebMethod(operationName = "getPush")
public Boolean getPush() {
return this.push;
}
}
這里是ManagedBean類:
@Stateless
@ManagedBean(name = "globalCounter")
@ApplicationScoped
public class GlobalCounterBean implements Serializable {
private int count;
private String CHANNEL = "/counter";
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public synchronized void increment() {
count++;
PushContext pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push(CHANNEL, String.valueOf(count));
}
}
這里是一個用於將WS與Managedbean通信的EJB:
@Stateless
public class ServiceShare {
@EJB
private GlobalCounterBean counter;
private boolean push = false;
public boolean getPush() {
return push;
}
public void setPush(boolean push){
this.push = push;
}
public void firePush(){
if(this.push){
counter.increment();
}
}
}
JSF頁面與PrimeFaces演示中的頁面完全相同。
每次我在擺動應用程序中按下按鈕時,連接的每台機器上的計數器都會更新,這就是最終應用程序的想法。 但是再次,為什么我必須重新部署Web應用程序以便Swing應用程序中的ws客戶端可以找到它? 為了避免這種行為,GF服務器中是否缺少任何配置?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.