tailieunhanh - Patterns in JavaTM, Volume 3 Java Enterprise Java Enterprise Design Patterns phần 5

Các nhà xây dựng RedeliveryAgent bắt đầu chủ đề đó sẽ được Đây là lớp học RedeliveryAgent. Để hỗ trợ các cố gắng trả tàu không đồng bộ, các lớp RedeliveryAgent thực hiện các giao diện Runnable. Điều này cho phép nó để có thread riêng của nó. | 192 Chapter Six private static class Redelivery RemoteSubscriberIF subscriber Serializable message Serializable topic long timeOfOriginalFailure Date nextRedeliveryTime Redelivery RemoteSubscriberIF subscriber Serializable message Serializable topic subscriber message topic new Date timeOfOriginalFailure constructor class Redelivery Here is the RedeliveryAgent class. In order to support asynchronous redelivery attempts the RedeliveryAgent class implements the Runnable interface. This allows it to have its own thread. private static class RedeliveryAgent implements Runnable private TreeMap schedule new TreeMap A RedeliveryAgent object uses a TreeMap to maintain a collection of redelivery objects in the order in which their redelivery is scheduled. The RedeliveryAgent constructor starts the thread that will be responsible for redelivery attempts. RedeliveryAgent new Thread this .start constructor Here is the method that schedules redelivery attempts. synchronized void scheduleRedelivery Redelivery r long nextRedeliveryTime REDELIVERY_INTERVAL long elapsedTime if elapsedTime EXPIRATION_INTERVAL Too much time has elapsed give up. return if nextRedeliveryTime r notify scheduleRedelivery Redelivery Distributed Computing Patterns 193 The scheduleRedelivery method always schedules the next redelivery attempt into the future by a fixed amount of time. Many applications will run more efficiently with a more sophisticated policy for determining the time of the next redelivery. Such policies typically involved strategies such as randomization and using progressively longer intervals between redelivery attempts. The run method contains the top-level logic for making redelivery attempts. It waits for the next scheduled redelivery .

TỪ KHÓA LIÊN QUAN