com.github.fge.msgsimple.provider
Class LoadingMessageSourceProvider

java.lang.Object
  extended by com.github.fge.msgsimple.provider.LoadingMessageSourceProvider
All Implemented Interfaces:
MessageSourceProvider

@ThreadSafe
public final class LoadingMessageSourceProvider
extends Object
implements MessageSourceProvider

A caching, on-demand loading message source provider with configurable expiry

This class uses a MessageSourceLoader internally to look up message sources. As is the case for StaticMessageSourceProvider, you can also set a default source if the loader fails to grab a source.

Apart from the loader, you can customize two aspects of the provider:

Note that the expiry time is periodic only, and not per source. The loading result (success or failure) is recorded permanently until the expiry time kicks in.

In the event of a timeout, the task remains active until it gets a result; this means, for instance, that if you set up a timeout of 500 milliseconds, but the task takes 2 seconds to complete, during these two seconds, the default source will be returned instead.

You can also configure a loader so that it never expires.

You cannot instantiate that class directly; use newBuilder() to obtain a builder class and set up your provider.

See Also:
LoadingMessageSourceProvider.Builder

Nested Class Summary
static class LoadingMessageSourceProvider.Builder
          Builder class for a LoadingMessageSourceProvider
 
Method Summary
 MessageSource getMessageSource(Locale locale)
          Provide a message source for a given locale
static LoadingMessageSourceProvider.Builder newBuilder()
          Create a new builder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newBuilder

public static LoadingMessageSourceProvider.Builder newBuilder()
Create a new builder

Returns:
an empty builder

getMessageSource

public MessageSource getMessageSource(Locale locale)
Description copied from interface: MessageSourceProvider
Provide a message source for a given locale

Specified by:
getMessageSource in interface MessageSourceProvider
Parameters:
locale - the locale
Returns:
a matching message source; null if none is found