Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java设计:锁定和监视报告_Java_Jsf_Design Patterns_Icefaces - Fatal编程技术网

Java设计:锁定和监视报告

Java设计:锁定和监视报告,java,jsf,design-patterns,icefaces,Java,Jsf,Design Patterns,Icefaces,我有以下要求 介绍 该系统为报表/内容管理系统。它允许用户对报告执行CRUD操作 业务逻辑/UI组件 当用户编辑报表时,其他用户不能编辑报表,只能查看 它包含一个带有表的页面,该表监视锁定的报表以供查看 挑战者 1) 我应该如何实现这种“锁定”机制? 2) 有什么设计模式和API可以帮助我 我当前的实现 我要上报告服务课 它将包含所有已锁定报告的hashmap(带有用于锁定管理的用户信息) 我已经完成了SCJD,并正在考虑使用我的锁定机制,但我意识到我不需要等待“锁定” 我唯一担心的问题是“锁定

我有以下要求

介绍 该系统为报表/内容管理系统。它允许用户对报告执行CRUD操作

业务逻辑/UI组件 当用户编辑报表时,其他用户不能编辑报表,只能查看

它包含一个带有表的页面,该表监视锁定的报表以供查看

挑战者 1) 我应该如何实现这种“锁定”机制? 2) 有什么设计模式和API可以帮助我

我当前的实现 我要上报告服务课 它将包含所有已锁定报告的hashmap(带有用于锁定管理的用户信息)

我已经完成了SCJD,并正在考虑使用我的锁定机制,但我意识到我不需要等待“锁定”

我唯一担心的问题是“锁定”报表(将锁添加到映射中)时的并发性问题,我相信通过使用同步可以很容易地解决这个问题

为了监视锁定的报表表,我计划在报表服务类中实现observer模式。对于每个用户/backingbean,它将“订阅”报表服务


有什么意见吗

答案很简单。。。我们可以用两个类来处理这个问题

下面给出了每个类的特性

ReportUtil:
(1) 跟踪是否有任何报表在写入模式下打开
(2) 根据可用的访问模式创建报表对象

报告:
(1) 根据给定的访问权限打开只读或可写报告
(2) 关闭时,如果当前报表是以写入模式打开的,请重置ReportUtil类中的标志。

客户端:
测试ReportUtil和Report类





输出: 报告以写入模式打开 报表以只读模式打开 报表以只读模式打开 报告以写入模式打开


我不知道我们为什么要在这里使用哈希表。可能是我不明白你的要求。此外,我还使用了同步方法来避免同步问题

如果您的要求是跟踪所有使用报告的用户,请让我知道


快乐学习

谢谢你冗长的回复+1“它包含一个带有表的页面,该表监视锁定的报告以供查看”-hashmap或表跟踪所有锁定的报告并以列表形式显示(JSF datatable)。是的,解决方案很简单,但我正在寻找一些设计模式来支持此实现,以便开发人员能够轻松理解。。
import java.util.LinkedList;

public class ReportUtil {

    private static boolean bIsWriteLockAvaialable = true;

    public static synchronized Report getReport() {
        Report reportObj = new Report(bIsWriteLockAvaialable);
        if(true == bIsWriteLockAvaialable) {
            bIsWriteLockAvaialable = false;
        }
        return reportObj;
    }   

    public static void resetLock() {
        bIsWriteLockAvaialable = true;
    }
}
public class Report {
    private boolean bICanWrite = false;

    public Report(boolean WriteAccess) {
        bICanWrite = WriteAccess;
    }

    public void open() {
        if(bICanWrite == true) {
            //Open in write mode
            System.out.println("Report open in Write mode");
        }
        else {
            //Open in readonly mode
            System.out.println("Report open in Read only mode");
        }
    }

    public synchronized void close() {
        if(bICanWrite == true) {
            ReportUtil.resetLock();
        }
    }
}
public class Client {

    public static void main(String[] args) {
        Report report1 = ReportUtil.getReport();
        report1.open(); //First time open in writable mode

        Report report2 = ReportUtil.getReport();
        report2.open(); //Opens in readonly mode

        Report report3 = ReportUtil.getReport();
        report3.open(); //Opens in readonly mode

        report1.close(); //close the write mode

        Report report4 = ReportUtil.getReport();
        report4.open(); //Opens in writable mode since the first writeable report was closed
    }

}