Package nl.vpro.util
Class URLResource<T>
java.lang.Object
nl.vpro.util.URLResource<T>
- All Implemented Interfaces:
Supplier<T>
,URLResourceMXBean
A simple http client wrapping exactly one external resource, keeping track of cache headers.
- Since:
- 0.37
- Author:
- Michiel Meeuwissen
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Function<InputStream,
Map<String, String>> static final Function<InputStream,
Properties> -
Constructor Summary
ConstructorsConstructorDescriptionURLResource
(URI url, Function<InputStream, T> reader, Consumer<T>... callbacks) URLResource
(URI url, Function<InputStream, T> reader, T empty, Consumer<T>... callbacks) -
Method Summary
Modifier and TypeMethodDescriptionstatic <S> Function<InputStream,
List<S>> beansFromProperties
(Function<String, S> constructor) static <S> URLResource<List<S>>
void
callBack()
void
expire()
get()
Returns the supplied value backed by thegetUrl()
.long
long
@MonotonicNonNull Integer
getCode()
The HTTP status code on the last invocation ofget()
long
long
long
long
getUrl()
boolean
isAsync()
static URLResource<Map<String,
String>> static URLResource<Properties>
properties
(URI url, Consumer<Properties>... callbacks) void
setAsync
(boolean async) final URLResource<T>
setCallbacks
(Consumer<T>... callbacks) void
setConnectTimeout
(Duration connectTimeout) setErrorCache
(Duration errorCache) void
setReadTimeout
(Duration readTimeout) toString()
-
Field Details
-
PROPERTIES
-
MAP
-
-
Constructor Details
-
URLResource
@SafeVarargs public URLResource(URI url, Function<InputStream, T> reader, T empty, Consumer<T>... callbacks) -
URLResource
-
-
Method Details
-
properties
@SafeVarargs public static URLResource<Properties> properties(URI url, Consumer<Properties>... callbacks) -
map
@SafeVarargs public static URLResource<Map<String,String>> map(URI url, Consumer<Map<String, String>>... callbacks) -
beansFromProperties
@SafeVarargs public static <S> URLResource<List<S>> beansFromProperties(Function<String, S> constructor, URI url, Consumer<List<S>>... callbacks) -
get
-
callBack
public void callBack() -
expire
public void expire()- Specified by:
expire
in interfaceURLResourceMXBean
-
setMaxAge
-
setMinAge
-
setErrorCache
-
setCallbacks
-
setAsync
-
toString
-
beansFromProperties
-
getLastLoad
-
getLastTry
-
getCode
The HTTP status code on the last invocation ofget()
- Returns:
null
if never called,-1
if no status code could be obtained e.g. because of socket exceptions.
-
getUrl
-
getLastModified
-
getExpires
-
getMaxAge
-
getMinAge
-
getErrorCache
-
getOkCount
public long getOkCount() -
getNotModifiedCount
public long getNotModifiedCount() -
getNotCheckedCount
public long getNotCheckedCount() -
getCheckedCount
public long getCheckedCount() -
getChangesCount
public long getChangesCount() -
getErrorCount
public long getErrorCount() -
isAsync
public boolean isAsync() -
setConnectTimeout
-
getConnectTimeout
-
setReadTimeout
-
getReadTimeout
-
setAccept
-
getAccept
-