public class IotProvider extends java.lang.Object implements TopologyProvider, DirectSubmitter<Topology,Job>
IotDevice
to communicate
with an IoT scale message hub.
Publish-subscribe
is
used to allow multiple topologies to communicate through the single
connection.
This provider registers these services:
control
- An instance of JsonControlService
.application
- An instance of AppService
.publish-subscribe
- An instance of ProviderPubSub
java.util.pref.Preferences
to store application
and service preferences. A Preferences
node is created if the provider is created with
a name that is not null
. if the preferences implementation supports persistence
then any preferences will be maintained across provider and JVM restarts when creating a
provider with the same name. The Preferences
node is a user node.
IotDevice
using IotDevicePubSub
.
Applications using this provider that want to connect
to the message hub for device events and commands must create an instance of
IotDevice
using IotDevicePubSub.addIotDevice(org.apache.edgent.topology.TopologyElement)
edgentControl
.
An IotProvider
is created with a provider and submitter that it delegates
the creation and submission of topologies to.
IotDevice
,
IotDevicePubSub
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CONTROL_APP_NAME
IoT control using device commands application name.
|
Constructor and Description |
---|
IotProvider(Function<Topology,IotDevice> iotDeviceCreator)
Create an
IotProvider that uses its own DirectProvider . |
IotProvider(java.lang.String name,
DirectProvider provider,
Function<Topology,IotDevice> iotDeviceCreator)
Create an
IotProvider that uses the passed in DirectProvider . |
IotProvider(java.lang.String name,
Function<Topology,IotDevice> iotDeviceCreator)
Create an
IotProvider that uses its own DirectProvider . |
IotProvider(java.lang.String name,
TopologyProvider provider,
DirectSubmitter<Topology,Job> submitter,
Function<Topology,IotDevice> iotDeviceCreator)
Create an
IotProvider . |
Modifier and Type | Method and Description |
---|---|
protected void |
createIotCommandToControlApp()
Create application connects
edgentControl device commands
to the control service. |
protected void |
createIotDeviceApp()
Create application that connects to the message hub.
|
protected void |
createJobMonitorApp()
Create Job monitor application.
|
protected IotDevice |
createMessageHubDevice(Topology topology)
Create the connection to the message hub.
|
ApplicationService |
getApplicationService()
Get the application service.
|
protected JsonControlService |
getControlService() |
java.lang.String |
getName()
Return the name of this provider.
|
ServiceContainer |
getServices()
Access to services.
|
Topology |
newTopology()
Create a new topology with a generated name.
|
Topology |
newTopology(java.lang.String name)
Create a new topology with a given name.
|
protected void |
registerApplicationService() |
protected void |
registerControlService() |
protected void |
registerPreferencesService() |
protected void |
registerPublishSubscribeService() |
void |
registerTopology(java.lang.String applicationName,
BiConsumer<IotDevice,com.google.gson.JsonObject> builder)
Register an application that uses an
IotDevice . |
void |
start()
Start this provider by starting its system applications.
|
java.util.concurrent.Future<Job> |
submit(Topology topology)
Submit an executable.
|
java.util.concurrent.Future<Job> |
submit(Topology topology,
com.google.gson.JsonObject config)
Submit an executable.
|
public static final java.lang.String CONTROL_APP_NAME
public IotProvider(Function<Topology,IotDevice> iotDeviceCreator)
IotProvider
that uses its own DirectProvider
.
No name is assigned to the provider so a preferences service is not created.iotDeviceCreator
- How the IotDevice
is created.DirectProvider
public IotProvider(java.lang.String name, Function<Topology,IotDevice> iotDeviceCreator)
IotProvider
that uses its own DirectProvider
.name
- Name of the provider, if the value is not null
then a preferences service is created.iotDeviceCreator
- How the IotDevice
is created.DirectProvider
public IotProvider(java.lang.String name, DirectProvider provider, Function<Topology,IotDevice> iotDeviceCreator)
IotProvider
that uses the passed in DirectProvider
.name
- Name of the provider, if the value is not null
then a preferences service is created.provider
- DirectProvider
to use for topology creation and submission.iotDeviceCreator
- How the IotDevice
is created.DirectProvider
public IotProvider(java.lang.String name, TopologyProvider provider, DirectSubmitter<Topology,Job> submitter, Function<Topology,IotDevice> iotDeviceCreator)
IotProvider
.name
- Name of the provider, if the value is not null
then a preferences service is created.provider
- How topologies are created.submitter
- How topologies will be submitted.iotDeviceCreator
- How the IotDevice
is created.public java.lang.String getName()
null
.public ApplicationService getApplicationService()
public ServiceContainer getServices()
getServices
in interface DirectSubmitter<Topology,Job>
public final Topology newTopology()
newTopology
in interface TopologyProvider
public final Topology newTopology(java.lang.String name)
newTopology
in interface TopologyProvider
name
- name for topologypublic final java.util.concurrent.Future<Job> submit(Topology topology)
submit(executable, new JsonObject())
.public final java.util.concurrent.Future<Job> submit(Topology topology, com.google.gson.JsonObject config)
submit
in interface Submitter<Topology,Job>
topology
- executable to submitconfig
- context information for the submissionprotected void registerControlService()
protected void registerApplicationService()
protected void registerPublishSubscribeService()
protected void registerPreferencesService()
java.util.prefs.BackingStoreException
protected JsonControlService getControlService()
protected void createIotDeviceApp()
IotDevicePubSub
,
createMessageHubDevice(Topology)
protected void createJobMonitorApp()
JobMonitorApp
protected void createIotCommandToControlApp()
edgentControl
device commands
to the control service.
Subscribes to device
commands of type Commands.CONTROL_SERVICE
and sends the payload into the JSON control service
to invoke the control operation.public void start() throws java.lang.Exception
java.lang.Exception
- on failure starting applications.protected IotDevice createMessageHubDevice(Topology topology)
IotDevice
used to communicate with the message hub. This
provider creates and submits an application
that subscribes to published events to send
as device events and publishes device commands.
IotDevicePubSub.createApplication(IotDevice)
.
IotDevice
is created using the function
passed into the constructor.topology
- Topology the IotDevice
will be contained in.IotDevice
,
IotDevicePubSub
public void registerTopology(java.lang.String applicationName, BiConsumer<IotDevice,com.google.gson.JsonObject> builder)
IotDevice
.
ApplicationService.registerTopology(String, BiConsumer)
that passes in an IotDevice
and configuration to the supplied
function builder
that builds the application. The passed
in IotDevice
is created using IotDevicePubSub.addIotDevice(org.apache.edgent.topology.TopologyElement)
.
builder
obtains a reference to its topology using
TopologyElement.topology()
.
When the application is
submitted
builder.accept(iotDevice, config)
is called to build the application's graph.
applicationName
- Application namebuilder
- Function that builds the topology.Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641