Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Repair invalid cached services in the Service Locator pattern

The Verified Service Locator pattern ensures cached services' validity

  • Print
  • Feedback

Page 5 of 5

AlarmClock
The AlarmClock class acts as an alarm clock for ServiceLocatorVerifier. Internally, it maintains a low priority thread that "rings" according to the frequency period. When your initialization code invokes VerifiedServiceLocator.setVerifier(...), a ServiceLocatorVerifier is created, triggering the creation of an AlarmClock. The AlarmClock rings to signal ServiceLocatorVerifier that it should check the cached services.

WaitingAlarm
ServiceLocatorVerifier implements the WaitingAlarm interface and has the method alarmRinging(). The AlarmClock invokes alarmRinging() each time it rings.

Stop cached services errors

The Verified Service Locator pattern presented in this article enhances the Service Locator pattern, neutralizing potential problems often caused by cached services. The enhanced solution maintains the original pattern benefits and, through a periodic verification mechanism, detects and removes invalid cached services, preventing inappropriate usage of invalid services. This solution preserves the simplicity of Service Locator, so you receive the pattern's benefits without complicating your code.

About the author

Paulo Caroli, who has a master's degree in software engineering, is a senior Java developer with more than eight years of experience in application development. He is an expert in object-oriented techniques and has been using J2EE in Web applications for the past four years. He currently works in an IT designer consulting position at Cisco Systems.

Read more about Enterprise Java in JavaWorld's Enterprise Java section.

  • Print
  • Feedback

Resources