public class DirectlyConnectedDevice
extends java.lang.Object
implements java.io.Closeable
DirectlyConnectedDevice
for sending messages to, and receiving messages from, the server.Modifier and Type | Field and Description |
---|---|
protected TrustedAssetsManager |
trustedAssetsManager |
Constructor and Description |
---|
DirectlyConnectedDevice()
Constructs a new
DirectlyConnectedDevice instance that will use a
custom or default TrustedAssetsManager to store, load and handle the device
configuration. |
DirectlyConnectedDevice(java.lang.Object context)
Constructs a new
DirectlyConnectedDevice instance with a
platform specific context. |
DirectlyConnectedDevice(java.lang.String configFilePath,
java.lang.String configFilePassword)
Constructs a new
DirectlyConnectedDevice instance that will load
the device configuration from the given file path and password. |
DirectlyConnectedDevice(java.lang.String configFilePath,
java.lang.String configFilePassword,
java.lang.Object context)
Constructs a new
DirectlyConnectedDevice instance with a
platform specific context. |
Modifier and Type | Method and Description |
---|---|
void |
activate(java.lang.String... deviceModels)
Activate the device.
|
void |
close()
Implementation of java.io.Closeable interface required of Client
|
StorageObject |
createStorageObject(java.lang.String uri)
Create a new
StorageObject from the URI for a named object in storage. |
StorageObject |
createStorageObject(java.lang.String name,
java.lang.String contentType)
Create a new
StorageObject that will have a name with the given
object name prefixed with the device's endpoint ID and a directory
separator. |
boolean |
equals(java.lang.Object obj)
Compare
DirectlyConnectedDevice devices |
oracle.iot.client.DeviceModel |
getDeviceModel(java.lang.String deviceModel)
Get the
DeviceModel for the device model urn. |
java.lang.String |
getEndpointId()
Return the endpoint identifier of this directly-connected
device.
|
int |
hashCode() |
boolean |
isActivated()
Returns whether the device is activated.
|
void |
offer(Message... messages)
Offer messages to be sent to the server.
|
RequestMessage |
receive(long timeout)
Receive a
RequestMessage from the server, if any. |
void |
send(Message... messages)
Send messages to the server.
|
protected final TrustedAssetsManager trustedAssetsManager
public DirectlyConnectedDevice() throws java.security.GeneralSecurityException
DirectlyConnectedDevice
instance that will use a
custom or default TrustedAssetsManager
to store, load and handle the device
configuration.java.security.GeneralSecurityException
- if the configuration could not be loaded.public DirectlyConnectedDevice(java.lang.Object context) throws java.security.GeneralSecurityException
DirectlyConnectedDevice
instance with a
platform specific context. A custom or default TrustedAssetsManager
will be used to store, load and handle the device trust material.
See configuration for details.context
- a platform specific object (e.g. application context),
that needs to be associated with this client. In
the case of Android, this is an android.content.Context
provided by the application or service. In the case of Java SE,
the parameter is not used and the value may be null
.java.security.GeneralSecurityException
- if the trust material could not be
loaded.public DirectlyConnectedDevice(java.lang.String configFilePath, java.lang.String configFilePassword) throws java.security.GeneralSecurityException
DirectlyConnectedDevice
instance that will load
the device configuration from the given file path and password.
See configuration for details.configFilePath
- the path of the configuration fileconfigFilePassword
- the configuration file password,
or null
if the configurationFile is not encryptedjava.security.GeneralSecurityException
- if the configuration could not be
loaded.public DirectlyConnectedDevice(java.lang.String configFilePath, java.lang.String configFilePassword, java.lang.Object context) throws java.security.GeneralSecurityException
DirectlyConnectedDevice
instance with a
platform specific context. The device configuration will be loaded
from the given file path and password.
See configuration for details.configFilePath
- the path of the configuration fileconfigFilePassword
- the configuration file password,
or null
if the configurationFile is not encryptedcontext
- a platform specific object (e.g. application context),
that needs to be associated with this client. In
the case of Android, this is an android.content.Context
provided by the application or service. In the case of Java SE,
the parameter is not used and the value may be null
.java.security.GeneralSecurityException
- if the configuration could not be
loaded.public StorageObject createStorageObject(java.lang.String name, java.lang.String contentType) throws java.io.IOException, java.security.GeneralSecurityException
StorageObject
that will have a name with the given
object name prefixed with the device's endpoint ID and a directory
separator. The prefix addition can be disabled by setting the
oracle.iot.client.disable_storage_object_prefix
to true
.
If contentType
is null
, the mime-type defaults to
"application/octet-stream".
name
- the unique name to be used to reference the content in
storagecontentType
- The mime-type of the content or null
java.io.IOException
- if there is an IOException
raised by the
runtime, or an abnormal response from the storage cloudjava.security.GeneralSecurityException
- if there is an exception establishing
a secure connection to the storage cloudpublic StorageObject createStorageObject(java.lang.String uri) throws java.io.IOException, java.security.GeneralSecurityException
StorageObject
from the URI for a named object in storage.uri
- the URI of the object in the storage cloudjava.io.IOException
- if there is an IOException
raised by the runtime,
or a failure reported by the storage cloudjava.security.GeneralSecurityException
- if there is an exception establishing a secure connection to the storage cloudpublic final void activate(java.lang.String... deviceModels) throws java.io.IOException, java.security.GeneralSecurityException
If the device is already activated, this method will throw an
IllegalStateException. The user should call the isActivated()
method prior to calling activate.
deviceModels
- should contain the device model type URNs of this directly connected device.
The device is activated with the given device models.
The deviceModels
parameter is zero or more, comma separated, device model URNs.java.io.IOException
- if there is an I/O exception.java.security.GeneralSecurityException
- when key or signature algorithm class
cannot be loaded, or the key is not in
the trusted assets store, or the
private key is invalidjava.lang.IllegalStateException
- if the device is already activatedisActivated()
public final boolean isActivated()
public final void send(Message... messages) throws java.io.IOException, java.security.GeneralSecurityException
oracle.iot.client.responseTimeout
.messages
- zero or more DataMessage
, AlertMessage
,
ResponseMessage
and/or ResourceMessage
objects.java.io.IOException
- if there is an I/O exception when trying to send
messages.java.security.GeneralSecurityException
- when key or signature algorithm class
cannot be loaded, or the key is not in
the trusted assets store, or the
private key is invalidjava.lang.IllegalStateException
- if the gateway device has not been
authenticated with the server.public final void offer(Message... messages) throws java.io.IOException, java.security.GeneralSecurityException
send(Message...)
.
Depending on the policies, it is possible that all, some, or none of
the messages will be sent.
If messages are sent, this call will block until the server
responds to the message delivery, or a network timeout occurs. The
network timeout can be configured by setting the system property
oracle.iot.client.responseTimeout
.
messages
- zero or more DataMessage
, AlertMessage
,
ResponseMessage
and/or ResourceMessage
objects.java.io.IOException
- if there is an I/O exception when trying to send
messages.java.security.GeneralSecurityException
- when key or signature algorithm class
cannot be loaded, or the key is not in
the trusted assets store, or the
private key is invalidjava.lang.IllegalStateException
- if the gateway device has not been
authenticated with the server.public final RequestMessage receive(long timeout) throws java.io.IOException, java.security.GeneralSecurityException
RequestMessage
from the server, if any. This call may
block if the implementation sends a message to the server to poll
for requests (see send(Message...)
). This call may return null
if there are no requests from the server.timeout
- maximum time, in milliseconds, to wait for a response from
the server or -1 for an infinite timeoutnull
.java.io.IOException
- if there is an I/O exception when trying to receive
messages.java.security.GeneralSecurityException
- when key or signature algorithm class
cannot be loaded, or the key is not in
the trusted assets store, or the
private key is invalidjava.lang.IllegalStateException
- if the gateway device has not been
authenticated with the server.public final java.lang.String getEndpointId()
activate(String...)
public final oracle.iot.client.DeviceModel getDeviceModel(java.lang.String deviceModel) throws java.io.IOException, java.security.GeneralSecurityException
DeviceModel
for the device model urn. This method may
return null
if there is no device model for the URN. Null
may also be
returned if the device model is a "draft" and the property
com.oracle.iot.client.device.allow_draft_device_models
is set to
false
, which is the default.deviceModel
- the URN of the device modelnull
if it does not existjava.lang.NullPointerException
- if deviceModel is null
java.io.IOException
- if there is an I/O error when communicating
with the serverjava.security.GeneralSecurityException
- when key or signature algorithm class
cannot be loaded, or the key is not in
the trusted assets store, or the
private key is invalidpublic boolean equals(java.lang.Object obj)
DirectlyConnectedDevice
devicesequals
in class java.lang.Object
obj
- DirectlyConnectedDevice
to compare with this
true
if equal.public int hashCode()
hashCode
in class java.lang.Object
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
- if an I/O error occurs