public class Internal extends Object
Note that you should call init() after any modification of the token, otherwise the behavior of this
class is not defined.
| Constructor and Description |
|---|
Internal() |
| Modifier and Type | Method and Description |
|---|---|
static void |
clean()
Cleans the cache -- that is, removes every object that is not valid anymore from it (see
Descriptor.isValid()). |
static void |
clear()
Fully clears the cache, but keeps the token.
|
static void |
init()
Connects to the server & tries to access the logged-user's ID.
|
static void |
requestToken(String username,
String password)
Requests a token using a username and a password.
|
static void |
reset()
Resets the API.
|
static void |
setCantConnectHandler(Consumer<net.wildfyre.http.Request.CantConnectException> consumer)
Registers a handler for the case where the API cannot connect to the server.
|
static void |
setNoSuchEntityHandler(Consumer<NoSuchEntityException> consumer)
Registers a handler for the case where an Entity that was queried for update does not exist.
|
static void |
setToken(String token)
Sets the token used by the API.
|
static void |
submit(Runnable task)
Submits a new task to be executed concurrently.
|
static <D extends Descriptor> |
submitUpdate(D descriptor)
Submits a new task to be executed concurrently, that updates a Descriptor.
|
static void |
throwCantConnect(net.wildfyre.http.Request.CantConnectException e)
Call this method if you need to tell the client of this API that the server is unreachable at the moment, if you
are in a concurrent context.
|
static String |
token()
Returns the token used for authentication.
|
public static void clear()
Only remove the data that has expiredpublic static void clean()
Descriptor.isValid()).public static void reset()
This means that the user's token is removed, and the cache is fully cleared.
public static String token()
public static void setNoSuchEntityHandler(Consumer<NoSuchEntityException> consumer)
consumer - the handler.public static void throwCantConnect(net.wildfyre.http.Request.CantConnectException e)
e - the exception that was thrown during the request.public static void setCantConnectHandler(Consumer<net.wildfyre.http.Request.CantConnectException> consumer)
consumer - the handler.public static void submit(Runnable task)
task - the task to be executed concurrently.public static <D extends Descriptor> void submitUpdate(D descriptor)
descriptor - the descriptor to be updated concurrently.public static void requestToken(String username, String password) throws net.wildfyre.http.Request.CantConnectException, InvalidCredentialsException
username - the user's usernamepassword - the user's passwordRequest.CantConnectException - if the API cannot connect to the serverInvalidCredentialsExceptionpublic static void setToken(String token)
init() for that purpose.token - the new tokenpublic static void init()
throws net.wildfyre.http.Request.CantConnectException
Request.CantConnectException - if the API cannot connect to the server