-
public final class OriginMobileOrigin Mobile Software Development Kit (SDK) entry-point.
The SDK entry-point must be initialized using an initializer. The initializer is used to configure, initialize, and install an SDK instance. After initialization, the SDK instance can be retrieved using current. At any given point in time, there may exist only one SDK instance per application instance.
SDK instances can be shut down manually, by invoking shutdown. All SDK instances, however, are tied to the lifetime of their owning context. When the configured context is garbage-collected, the corresponding SDK instance will automatically perform a shut down.
SDK instances provide a common facility for managing work. Work may be scheduled for delayed or immediate execution on the main (UI) thread or a pool of background threads, using and background, respectively.
Modules are loaded into an SDK instance to provide extended functionality, such as ad rendering or auctioning. Modules are lazily loaded; however, they can be pre-loaded by specifying a modules' provider during initialization.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classOriginMobile.InitializerOrigin Mobile SDK initializer.
Instances of this are used to initialize and install an SDK instance. At minimum, beforeinvoking initialize, an owning context must be specified.
-
Method Summary
Modifier and Type Method Description static OriginMobile.Initializerinitializer()Construct a new SDK initializer. static OriginMobilecurrent()Current SDK instance. static voidregisterInstallCallback(Consumer<OriginMobile> cb)Register callback to invoke when an SDK instance is initialized and installed. static voidderegisterInstallCallback(Consumer<OriginMobile> cb)Deregister SDK install callback. booleanisShutdown()Test whether SDK instance has been shut down. booleanisTerminated()Test whether SDK instance has been shut down and all pending SDK tasks have completed. UUIDstartupId()Startup identifier. AppDescriptorapp()Descriptor of owning application. Contextcontext()Context owning SDK instance. voidremoveSetting(String name)Remove setting value, if present. StringgetSetting(String name, String dfl)Retrieve string setting value. voidputSetting(String name, String val)Update string setting value. JSONObjectgetJsonObjectSetting(String name, JSONObject dfl)Retrieve JSON object setting value. voidputJsonObjectSetting(String name, JSONObject val)Update JSON object setting value. longgetLongSetting(String name, long dfl)Retrieve {@code long}setting value.voidputLongSetting(String name, long val)Update {@code long}setting value.ListeningScheduledExecutorServiceforeground()Foreground work pool. ListeningScheduledExecutorServicebackground()Background work pool. ListenableFuture<out Object>runInForeground(Runnable cmd)Execute command on main (UI) thread. <V> ListenableFuture<V>callInForeground(Callable<V> cmd)Execute command which computes a value, on main (UI) thread. ListenableFuture<out Object>runInBackground(Runnable cmd)Execute command on non-main (UI) thread. <V> ListenableFuture<V>callInBackground(Callable<V> cmd)Execute command which computes a value, on non-main (UI) thread. ListenableFuture<out Object>runPunting(Runnable cmd)Schedule command, on main (UI) thread, for execution on non-main thread. <V> ListenableFuture<V>callPunting(Callable<V> cmd)Schedule command which computes a value, on main (UI) thread, for execution on non-mainthread. ListenableFuture<out Object>runPuntingDelayed(Runnable cmd, long delay, TimeUnit unit)Schedule command, on main (UI) thread, for delayed execution on non-main thread. <V> ListenableFuture<V>callPuntingDelayed(Callable<V> cmd, long delay, TimeUnit unit)Schedule command which computes a value, on main (UI) thread, for delayed execution onnon-main thread. ListenableFuture<out Object>schedulePuntingWithFixedDelay(Runnable cmd, long initialDelay, long delay, TimeUnit unit)Schedule command, on main (UI) thread, for recurring execution on non-main thread. ProtobufMessagedescriptorOf(OriginModule mod)Retrieve latest descriptor of a module. voidregisterDescriptorsUpdateCallback(Consumer<Map<OriginModule, ProtobufMessage>> cb)Register callback to invoke when module descriptors are updated. voidunregisterDescriptorsUpdateCallback(Consumer<Map<OriginModule, ProtobufMessage>> cb)Unregister callback invoked when module descriptors are updated. <M extends OriginModule> MfindModule(Class<M> type)Find loaded module. <M extends OriginModule> MgetModule(Class<M> type)Get module, failing if not already loaded. <M extends OriginModule> MgetOrLoadModuleSync(Class<M> type)Get module, synchronously loading it if not already loaded. <M extends OriginModule> voidgetOrLoadModule(Class<M> type, BiConsumer<M, out Object> cons)Get module, asynchronously loading it if not already loaded. booleanawaitTermination(long timeout, TimeUnit unit)Await SDK termination. voidshutdown()Initiate SDK shut down. StringtoString()-
-
Method Detail
-
initializer
static OriginMobile.Initializer initializer()
Construct a new SDK initializer.
The initializer returned, once initialized, will set the current SDK instance to the newinitialized instance. If an SDK instance was previously initialized, it is shut down before the new SDK instance is installed.
-
current
static OriginMobile current()
Current SDK instance.
-
registerInstallCallback
static void registerInstallCallback(Consumer<OriginMobile> cb)
Register callback to invoke when an SDK instance is initialized and installed.
Callbacks are identified by instance. As such, if
{@code cb}was previouslyregistered, this simply returns. Otherwise, this registers{@code cb}as a callback toinvoke when an SDK instance is initialized and installed.Callbacks are invoked on the background work-pool of theSDK which they are called for. Additionally, if an SDK instance is currently installed and
{@code cb}is not currently registered, then{@code cb}willbe scheduled for invocation on the background work-pool of the current SDK.- Parameters:
cb- callback to register
-
deregisterInstallCallback
static void deregisterInstallCallback(Consumer<OriginMobile> cb)
Deregister SDK install callback.
If
{@code cb}was previously registered,this will deregister it. Otherwise, this simply returns.- Parameters:
cb- callback to deregister
-
isShutdown
boolean isShutdown()
Test whether SDK instance has been shut down.
-
isTerminated
boolean isTerminated()
Test whether SDK instance has been shut down and all pending SDK tasks have completed.
-
startupId
UUID startupId()
Startup identifier.
The identifier returned is a unique identifier for
{@code this}instance.
-
app
AppDescriptor app()
Descriptor of owning application.
-
removeSetting
void removeSetting(String name)
Remove setting value, if present.
- Parameters:
name- setting to remove value of
-
getSetting
String getSetting(String name, String dfl)
Retrieve string setting value.
- Parameters:
name- setting namedfl- default setting value
-
putSetting
void putSetting(String name, String val)
Update string setting value.
- Parameters:
name- setting nameval- setting value
-
getJsonObjectSetting
JSONObject getJsonObjectSetting(String name, JSONObject dfl)
Retrieve JSON object setting value.
- Parameters:
name- setting namedfl- default setting value
-
putJsonObjectSetting
void putJsonObjectSetting(String name, JSONObject val)
Update JSON object setting value.
- Parameters:
name- setting nameval- setting value
-
getLongSetting
long getLongSetting(String name, long dfl)
Retrieve
{@code long}setting value.- Parameters:
name- setting namedfl- default setting value
-
putLongSetting
void putLongSetting(String name, long val)
Update
{@code long}setting value.- Parameters:
name- setting nameval- setting value
-
foreground
ListeningScheduledExecutorService foreground()
Foreground work pool.
The pool returned executes work on the main (or UI) thread.
-
background
ListeningScheduledExecutorService background()
Background work pool.
The pool returned executes work on one or more background worker threads.
-
runInForeground
ListenableFuture<out Object> runInForeground(Runnable cmd)
Execute command on main (UI) thread.
Generic equivalent of runOnUiThread; however, if current thread is not the main (UI) thread, and foreground work pool has been shut down, this will fail with .
- Parameters:
cmd- command to run
-
callInForeground
<V> ListenableFuture<V> callInForeground(Callable<V> cmd)
Execute command which computes a value, on main (UI) thread.
Like runInForeground; however, the future returned, once successfullycompleted, will have the value computed by
{@code cmd}.- Parameters:
cmd- command to call
-
runInBackground
ListenableFuture<out Object> runInBackground(Runnable cmd)
Execute command on non-main (UI) thread.
If current thread is not the main (UI) thread, then
{@code cmd}is executed immediately; otherwise,{@code cmd}is scheduled for immediateexecution on a background worker thread.- Parameters:
cmd- command to run
-
callInBackground
<V> ListenableFuture<V> callInBackground(Callable<V> cmd)
Execute command which computes a value, on non-main (UI) thread.
Like runInBackground; however, the future returned, once successfullycompleted, will have the value computed by
{@code cmd}.- Parameters:
cmd- command to call
-
runPunting
ListenableFuture<out Object> runPunting(Runnable cmd)
Schedule command, on main (UI) thread, for execution on non-main thread.
This schedules
{@code cmd}, on main thread, for immediateexecution on a background worker thread. This is useful when{@code cmd}performs some blocking task, but its execution should only happen when foregroundwork is allowed.- Parameters:
cmd- command to run
-
callPunting
<V> ListenableFuture<V> callPunting(Callable<V> cmd)
Schedule command which computes a value, on main (UI) thread, for execution on non-mainthread.
Like runPunting; however, the future returned, once successfullycompleted, will have the value computed by
{@code cmd}.- Parameters:
cmd- command to run
-
runPuntingDelayed
ListenableFuture<out Object> runPuntingDelayed(Runnable cmd, long delay, TimeUnit unit)
Schedule command, on main (UI) thread, for delayed execution on non-main thread.
Like runPunting; however, the execution of
{@code cmd}is delayed.- Parameters:
cmd- command to rundelay- execution delayunit- unit{@code delay}is measured in
-
callPuntingDelayed
<V> ListenableFuture<V> callPuntingDelayed(Callable<V> cmd, long delay, TimeUnit unit)
Schedule command which computes a value, on main (UI) thread, for delayed execution onnon-main thread.
Like runPuntingDelayed; however, the future returned,once successfully completed, will have the value computed by
{@code cmd}.- Parameters:
cmd- command to rundelay- execution delayunit- unit{@code delay}is measured in
-
schedulePuntingWithFixedDelay
ListenableFuture<out Object> schedulePuntingWithFixedDelay(Runnable cmd, long initialDelay, long delay, TimeUnit unit)
Schedule command, on main (UI) thread, for recurring execution on non-main thread.
This schedules
{@code cmd}for execution on background workerthread, with the execution being scheduled at the specified delay on the main thread.- Parameters:
cmd- command to runinitialDelay- initial execution delaydelay- recurring execution delayunit- unit{@code initialDelay}and{@code delay}are measured in
-
descriptorOf
@Nullable() ProtobufMessage descriptorOf(OriginModule mod)
Retrieve latest descriptor of a module.
- Parameters:
mod- module to retrieve descriptor of
-
registerDescriptorsUpdateCallback
void registerDescriptorsUpdateCallback(Consumer<Map<OriginModule, ProtobufMessage>> cb)
Register callback to invoke when module descriptors are updated.
The callback specified is registered for invocation, on background work pool, whenever any descriptor of a module is updated. If
{@code cb}hasalready been registered, this simply returns. The callback specified may be unregisteredby invoking unregisterDescriptorsUpdateCallback.- Parameters:
cb- callback to register
-
unregisterDescriptorsUpdateCallback
void unregisterDescriptorsUpdateCallback(Consumer<Map<OriginModule, ProtobufMessage>> cb)
Unregister callback invoked when module descriptors are updated.
If
{@code cb}was previously registerDescriptorsUpdateCallback,then it is unregistered; otherwise, this simply returns.- Parameters:
cb- callback to unregister
-
findModule
<M extends OriginModule> M findModule(Class<M> type)
Find loaded module.
- Parameters:
type- module type class
-
getModule
<M extends OriginModule> M getModule(Class<M> type)
Get module, failing if not already loaded.
- Parameters:
type- module type class
-
getOrLoadModuleSync
@WorkerThread() <M extends OriginModule> M getOrLoadModuleSync(Class<M> type)
Get module, synchronously loading it if not already loaded.
- Parameters:
type- module type class
-
getOrLoadModule
<M extends OriginModule> void getOrLoadModule(Class<M> type, BiConsumer<M, out Object> cons)
Get module, asynchronously loading it if not already loaded.
Like getOrLoadModuleSync; however, this is safe for invocation onmain (UI) threads. If module for
{@code type}has already been loaded, invokes{@code cons},with the loaded module, immediately; otherwise, this loads the module for{@code type}asynchronously, invoking{@code cons}with the load result.- Parameters:
type- module type classcons- consumer to invoke with load result
-
awaitTermination
boolean awaitTermination(long timeout, TimeUnit unit)
Await SDK termination.
- Parameters:
timeout- maximum time to waitunit- unit of measurement{@code timeout}is specified in
-
shutdown
void shutdown()
-
-
-
-