Single write, multiple read of stateful objects

Scenario:

  • One data input feed (call this Source)
  • Multiple objects (call these Layer1) read this Source, and analyze the feed. This analysis is stateful.
  • Layer1 objects have configuration parameters. For example, new FooLayer1(10, 20) will do different analysis than new FooLayer1(20, 20) will do different analysis than new FooLayer1(20, 30)
    • The Layer1 analysis is done asynchronously.
  • Still other objects (call these Layer2) readonly the output of the Layer1 objects and process those results. This analysis is also stateful.
  • Guice object creation hierarchy
  • Needed Layer1 objects are accessed often enough that it doesn’t matter if they are created lazily, as long as they remain in memory after they’re created the first time.
  • The needs of Layer2 objects are hardcoded; no good way to know in advance which Layer1 objects will be needed.

I want to be able to reuse the work of the Layer1 objects. For example, lets say I have:

  • AlphaLayer2 object that reads the output of FooLayer1 and BarLayer1
  • BetaLayer2 reads the output of BarLayer1 and BazLayer1
  • QuuxLayer1 is implemented, but I don’t want my server to compute the value of QuuxLayer1 unless there is a Layer2 object that needs it.

Currently, I have a factory that all Layer2 objects have access to, that only creates the appropriate Layer1 object as needed, and stores all created Layer1 objects in a Map. But, since Layer1 objects also have configuration parameters, I need to make sure that I’m storing the Layer1 objects in a good data structure. But the Layer1 functionality needs to be flexible, and I figure as I create more kinds of Layer1 objects, this kind of a Map could get really complicated. I am asking this question because, while it’s fine now, as the complexity grows, maintaining the data structure in this way seems to become really difficult.

Trying to do some sort of nested Map data structure should get me O(1) access times on finding these Layer1 objects, but will make the caching super complicated. Alternatively, I could keep them in a much flatter structure, and iterate over the list of all the Layer1 objects and see if they have the right parameters. If none found, create the new one. As long as Layer2 objects keep the reference, this should only happen once.
Yet another option would be to create a Map<Class, Set<Layer1>> so that it only needs to iterate through the created Layer1 objects of the correct class.

Has anyone seen this kind of scenario before? Which of the options I’ve mentioned is preferred? Or, is there something I haven’t mentioned yet? Also, is there any way to use Guice to create Layer1 objects in a way where I can get reuse them (which I need to do, because they’re stateful)

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật