public class Network extends java.lang.Object implements java.lang.Iterable<Device>
User can own multiple networks and a user can be part of
networks that are owned by others on basis of invitation Network.ConnectArgs
from the owner of the network.
Networks can contain Device, Zone, Scene, Rule.
All the network that user currently part of can be
queried using CocoClient.getAllNetworks(CocoClient.NetworkListListener)
List<Network> userNetworks = CocoClient
.getInstance()
.getAllNetworks((networkList, throwable) -> {
if (null == list)
return;
// client specific code
});
| Modifier | Constructor and Description |
|---|---|
protected |
Network(java.lang.String id)
The constructor of the class.
|
| Modifier and Type | Method and Description |
|---|---|
void |
connect()
To connect to an individual network.
|
void |
connect(int port)
To connect to an individual network.This function must be used to connect to single network.
|
static boolean |
containsClearFlag(Network.State state)
A function to check if the state contains a clear flag for network i.e, if state is either of
Network.State.NETWORK_RESET, Network.State.CONNECTION_ERROR, Network.State.DISCONNECTED. |
boolean |
containsDevice(long deviceNodeId)
A function to check if network the
Device given the ID. |
boolean |
containsRule(int ruleId)
A function to check if networks contains
Rule. |
boolean |
containsScene(int sceneId)
A function to check if scene with given ID is present in the network.
|
boolean |
containsZone(int zoneId)
A function to check if a given
Zone is present in the network. |
static int |
createClearOnDisconnectionFlag(Network.State... states)
A function to create flags to clear network from memory in case of disconnection.
|
void |
createRule(java.lang.String ruleName,
Network.NetworkManagementStatusListener listener)
A function to create rule in the network.
|
void |
createScene(java.lang.String sceneName,
Network.NetworkManagementStatusListener listener)
A function to create scene in a network.
|
void |
createZone(java.lang.String zoneName,
Network.NetworkManagementStatusListener listener)
A function to create a zone in the network.
|
void |
deleteRule(Rule[] rules,
Network.NetworkManagementStatusListener listener)
A function to delete multiple rules in a network.
|
void |
deleteRule(Rule rule,
Network.NetworkManagementStatusListener listener)
A function to delete rule in a network.
|
void |
deleteScene(Scene[] scenes,
Network.NetworkManagementStatusListener listener)
A function to delete multiple scenes in a network.
|
void |
deleteScene(Scene scene,
Network.NetworkManagementStatusListener listener)
A function to delete a scene from the network.
|
void |
deleteZone(Zone[] zones,
Network.NetworkManagementStatusListener listener)
A function to delete multiple zones from the network.
|
void |
deleteZone(Zone zone,
Network.NetworkManagementStatusListener listener)
A function to delete a zone from the network.
|
void |
disconnect()
This function is used to disconnect from a network and delete from local database accordingly.
|
Network.AccessType |
getAccessType()
This function is used to return the access type of the user.
|
ConnectivityStateManager.State |
getConnectivityManagerState()
This function is used to get the connectivity state of the network.
|
<T extends Device> |
getDevice(long deviceNodeId)
This function is used to get device in the network given the deviceId.
|
java.lang.Iterable<Device> |
getDeviceIterable()
This function fetches device iterable to traverse over list of devices.
|
java.util.Map<java.lang.Long,Device> |
getDeviceMap()
This function is used to return the HashMap that the sdk uses to map the DeviceIds
to the Device Objects.
|
java.lang.String |
getId()
This function is used to get the ID that uniquely identifies this Network.
|
java.lang.String |
getMetadata()
A function to get metadata of the network.
|
java.lang.String |
getName()
This function is used to get the Name of the network.
|
Network.NetworkType |
getNetworkType()
This function is used to get the type of the network.
|
java.util.List<Network.ResourceTemplate> |
getResourceTemplates()
This function is used to get the list of resource templates that belongs to the network.
|
<T extends Rule> |
getRule(int ruleId)
This function is used to get the rule of this network give the ruleId.
|
java.lang.Iterable<Rule> |
getRuleIterable()
This function fetches device iterable to traverse over list of rules.
|
java.util.Map<java.lang.Integer,Rule> |
getRuleMap()
This function is used to return the HashMap that the sdk uses to map
the ruleIds to the Rule Objects.
|
<T extends Scene> |
getScene(int sceneId)
This function is used to get the scene of this network given the scene.
|
java.lang.Iterable<Scene> |
getSceneIterable()
This function fetches device iterable to traverse over list of scenes.
|
java.util.Map<java.lang.Integer,Scene> |
getSceneMap()
This function is used to return the HashMap that the sdk uses to map
the sceneIds to the Scene Objects.
|
Network.State |
getState()
This function is used to get the current state of the Network.
|
Network.UserRole |
getUserRole()
This function is used to get role of the current user in this network.
|
<T extends Zone> |
getZone(int zoneId)
This function is used to get the zone of this network given the zoneId.
|
java.lang.Iterable<Zone> |
getZoneIterable()
This function fetches device iterable to traverse over list of zones.
|
java.util.Map<java.lang.Integer,Zone> |
getZoneMap()
This function is used to return the HashMap that the sdk uses to map
the zoneIds to the Zone Objects.
|
int |
hashCode() |
protected void |
internalAddDevice(Device device)
A function that will get called when a device is added to network.
|
protected void |
internalAddRule(Rule rule)
A function that would be triggered when a
Rule is added to network. |
protected void |
internalAddScene(Scene scene)
A function that would be triggered when a
Scene is added to network. |
protected void |
internalAddZone(Zone zone)
A function that would be triggered when a
Zone is added to network. |
protected void |
internalRemoveDevice(long deviceNodeId)
A function that would be triggered when a device is removed from network.
|
protected void |
internalRemoveNetwork()
A function that will get called when network is removed.
|
protected void |
internalRemoveRule(int ruleId)
A function that would be triggered when
Rule is removed from network. |
protected void |
internalRemoveScene(int sceneId)
A function that would be triggered when a
Scene is removed from network. |
protected void |
internalRemoveZone(int zoneId)
A function that would be triggered when a zone is removed.
|
protected void |
internalSetAccessType(Network.AccessType accessType)
A function that would be triggered when
accessType is updated. |
protected void |
internalSetConnectivityState(ConnectivityStateManager.State state)
A function that would be triggered when
connectivityManagerState is updated. |
protected void |
internalSetMetadata(java.lang.String metadata)
A function that would be triggered when
metadata is updated. |
protected void |
internalSetName(java.lang.String name)
A function that would be triggered when
name of the network is updated. |
protected void |
internalSetNetworkType(Network.NetworkType type)
A function that would be triggered when
networkType is updated. |
protected void |
internalSetResourceTemplates(java.util.List<Network.ResourceTemplate> resourceTemplates)
A function that will get called when
Network.ResourceTemplate's is updated. |
protected void |
internalSetState(Network.State state)
A function that would be triggered when
state is updated. |
protected void |
internalSetUserRole(Network.UserRole userRole)
A function that would be triggered when
Network.UserRole is updated. |
java.util.Iterator<Device> |
iterator() |
void |
leave(Network.LeaveStatusListener listener)
This function is used to leave the network.
|
void |
moveResources(Zone fromZone,
Zone toZone,
Resource[] resources,
Network.NetworkManagementStatusListener listener)
A function to move resources of a zone to another zone.
|
void |
restoreNetworkState(java.lang.String networkState)
A function to restore network information from the provided jsonString.
|
java.lang.String |
saveState()
A function to serialize the instance of this class.
|
void |
sendContentInfo(long contentTime,
java.lang.String data,
long[] nodeIds)
An api to send data to the specified nodes or all nodes of network with an
additional param of time to achieve content synchronization.
|
void |
sendData(java.lang.String data,
long[] nodeIds)
An api to send data to the specified nodes or all nodes of network.
|
void |
sendNetworkManagementCommand(Command<Network.CommandId> command,
Network.NetworkManagementStatusListener listener)
A function to send networkManagementCommands such as
createScene(String, NetworkManagementStatusListener),
createZone(String, NetworkManagementStatusListener) ... |
java.lang.String |
toString() |
protected Network(java.lang.String id)
id - ID of the current network.public static int createClearOnDisconnectionFlag(Network.State... states)
states - array of statespublic static boolean containsClearFlag(Network.State state)
Network.State.NETWORK_RESET, Network.State.CONNECTION_ERROR, Network.State.DISCONNECTED.state - State under interest to check for clearpublic void connect()
java.lang.RuntimeException - Throws an exception on failure during communication.public void connect(int port)
port - This function takes a port over which the communication will
take place NOTE: The port should be a free port or this call
will fail If 0 is passed there will be a search and free port
will be chosen automatically.java.lang.RuntimeException - Throws an exception on failure during communication.public void disconnect()
connect()java.lang.RuntimeException - Throw an exception on failures during communication.public void leave(Network.LeaveStatusListener listener)
networkTobeLeft
.leave(commandStatus, throwable -> {
if (null != throwable) {
// client specific code
}
});
listener - The listener that would be triggered with result.public void sendNetworkManagementCommand(Command<Network.CommandId> command, Network.NetworkManagementStatusListener listener)
createScene(String, NetworkManagementStatusListener),
createZone(String, NetworkManagementStatusListener) ...
network
.sendNetworkManagementCommand(new createZone("livingRoom"),
(response, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
command - The command which has to be sentlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void createZone(java.lang.String zoneName,
Network.NetworkManagementStatusListener listener)
network
.createZone(newZoneName,
(commandStatus, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
zoneName - The name of the zone.listener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteZone(Zone zone, Network.NetworkManagementStatusListener listener)
network.
deleteZone(zoneTobeDeleted,
(status, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
zone - The zone which has to deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteZone(Zone[] zones, Network.NetworkManagementStatusListener listener)
Zone[] zonesToBeDeleted = new Zone[] {livingZone, parkingArea};
network
.deleteZone(zoneToBeDeleted,
(command, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
zones - The zones which are to deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void moveResources(Zone fromZone, Zone toZone, Resource[] resources, Network.NetworkManagementStatusListener listener)
Resources[] resourcesTobeMoved = newResources[] {
fan, light, airConditioner
};
network
.moveResources(defaultZone, livingArea, resourcesTobeMoved,
(command, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
fromZone - The zone from which the resources have to be movedtoZone - The zone to which the resource has to be movedresources - The resources the needs to be moved.listener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void createScene(java.lang.String sceneName,
Network.NetworkManagementStatusListener listener)
network
.createScene(newSceneName, (commandStatus, throwable) -> {
if (null != throwable) {
// code specific code.
}
});
sceneName - The name of the scenelistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteScene(Scene scene, Network.NetworkManagementStatusListener listener)
network
.deleteScene(sceneTobeDeleted, (command, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
scene - Scene which has to be deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteScene(Scene[] scenes, Network.NetworkManagementStatusListener listener)
scenes - The scenes to be deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void createRule(java.lang.String ruleName,
Network.NetworkManagementStatusListener listener)
network
.createRule(nameOfNewRule, (commandStatus, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
ruleName - The name of the rulelistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteRule(Rule rule, Network.NetworkManagementStatusListener listener)
network
.delete(ruleTobeDeleted, (commandStatus, throwable) -> {
if (null != throwable) {
// client specific code.
}
});
rule - Rule which has to be deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public void deleteRule(Rule[] rules, Network.NetworkManagementStatusListener listener)
rules - The rules to be deletedlistener - The listener which will be triggered with
CallbacksInterface.networkManagementCommandCallback(buzz.getcoco.iot.Network, buzz.getcoco.iot.CommandResponse<?>)public final java.lang.String getId()
public java.lang.String getName()
public Network.State getState()
public ConnectivityStateManager.State getConnectivityManagerState()
ConnectivityStateManager.getInstance().public Network.UserRole getUserRole()
public Network.AccessType getAccessType()
public Network.NetworkType getNetworkType()
public java.util.Map<java.lang.Long,Device> getDeviceMap()
public java.util.Map<java.lang.Integer,Zone> getZoneMap()
public java.util.Map<java.lang.Integer,Scene> getSceneMap()
public java.util.Map<java.lang.Integer,Rule> getRuleMap()
public java.util.List<Network.ResourceTemplate> getResourceTemplates()
List<ResourceTemplates> resourceTemplates = network
.getResourceTemplates();
if (!resourceTemplates.isEmpty()) {
// client specific code.
}
public final <T extends Device> T getDevice(long deviceNodeId)
Device device = network
.getDevice(deviceId);
if (null != device) {
// success case.
}
T - capture for casting.deviceNodeId - ID of the Device that needs to be looked up.public final <T extends Zone> T getZone(int zoneId)
Zone livingRoom = network
.getZone(livingRoomId);
if (null != livingRoom) {
// success case.
}
T - capture for castingzoneId - ID of zone that needs to be looked up.public final <T extends Scene> T getScene(int sceneId)
Scene party = network
.getScene(parentSceneId);
if (null != party) {
// success case.
}
T - capture for casting.sceneId - ID of the Scene that needs to be looked up.public final <T extends Rule> T getRule(int ruleId)
Rule temperatureControl = network
.getRule(temperatureControlRuleId)
if (null != temperatureControl) {
// success case.
}
public java.lang.String saveState()
String networkJsonString = network.saveState();
CocoClient.restoreNetworkState(String)public void restoreNetworkState(java.lang.String networkState)
networkState - JSON string which was serialized to memory during
saveState()CocoClient.restoreNetworkState(String)protected void internalRemoveNetwork()
protected void internalSetResourceTemplates(java.util.List<Network.ResourceTemplate> resourceTemplates)
Network.ResourceTemplate's is updated.resourceTemplates - Updated resource template's.protected void internalAddDevice(Device device)
device - Device which is added.protected void internalRemoveDevice(long deviceNodeId)
deviceNodeId - ID of device that is removed.public boolean containsDevice(long deviceNodeId)
Device given the ID.deviceNodeId - ID of device that's needs to be looked up.protected void internalAddZone(Zone zone)
Zone is added to network.zone - Zone which is added.protected void internalRemoveZone(int zoneId)
zoneId - ID of zone which is removed.public boolean containsZone(int zoneId)
Zone is present in the network.zoneId - ID of the zone that's needs to looked up.protected void internalAddScene(Scene scene)
Scene is added to network.scene - Scene which is added to network.protected void internalRemoveScene(int sceneId)
Scene is removed from network.sceneId - SceneId which is removed from network.public boolean containsScene(int sceneId)
sceneId - ID of scene that needs to be looked up.protected void internalAddRule(Rule rule)
Rule is added to network.rule - Rule which is added to network.protected void internalRemoveRule(int ruleId)
Rule is removed from network.ruleId - ID of rule which is removed.public boolean containsRule(int ruleId)
Rule.ruleId - ID which needs to be looked up.protected void internalSetName(java.lang.String name)
name of the network is updated.name - Updated name of the network.protected void internalSetUserRole(Network.UserRole userRole)
Network.UserRole is updated.userRole - Updated user role of the network.protected void internalSetAccessType(Network.AccessType accessType)
accessType is updated.accessType - Updated access type of the network.protected void internalSetState(Network.State state)
state is updated.state - Updated state of the network.protected void internalSetConnectivityState(ConnectivityStateManager.State state)
connectivityManagerState is updated.state - Updated state.protected void internalSetNetworkType(Network.NetworkType type)
networkType is updated.type - Updated network type of the network.protected void internalSetMetadata(java.lang.String metadata)
metadata is updated.metadata - Updated metadata of the network.public java.lang.String getMetadata()
public final int hashCode()
hashCode in class java.lang.Objectpublic java.util.Iterator<Device> iterator()
iterator in interface java.lang.Iterable<Device>public java.lang.Iterable<Device> getDeviceIterable()
public java.lang.Iterable<Zone> getZoneIterable()
public java.lang.Iterable<Scene> getSceneIterable()
public java.lang.Iterable<Rule> getRuleIterable()
public void sendData(java.lang.String data,
long[] nodeIds)
data - The data that has to be sentnodeIds - The nodes which will get the data.
null to send to all nodes.public void sendContentInfo(long contentTime,
java.lang.String data,
long[] nodeIds)
contentTime - The time at which the data is sentdata - The data that has to be sentnodeIds - The nodes which will get the data.
null to send to all nodes.public java.lang.String toString()
toString in class java.lang.Object