# An Actor-Based Formal Model and Runtime Environment for Resource-Bounded IoT Services +
## 3 IoT Service Definition
### IoT Service Definition  
A service receives input contributions from some contributing source, processes them, and creates output contributions for some clients. We call these contributions _service feeds_. In a system of IoT services, we treat every client and contributor as a service: they are called the client service and the contributing service of the particular IoT service. In other words, the client service could simply be an end user receiving a feed from a service, but not necessarily producing a derivative service for another service; a contributing service, similarly, could be just a sensor without any service contributing to it. We model an IoT service by a set of _ports_ and a set of _agents_. Ports can be one of two types: input or output. A service receives input feeds from contributing services through its input ports and sends output feeds to client services through its output ports. Agents implement the service's logic and convert the feeds arriving from contributing services into the feeds required by client services. Our definition for an IoT service is as follows:  
**Definition 1** (Service). : _An IoT service has one or more input ports, which receive feeds from contributing services, and one or more output ports, which send feeds to client services, and a set of agents, which are responsible for implementing the service's logic._  
From this definition, a service has two types of components: ports and agents. Both ports and agents are active objects. Consequently, a service can be defined as a set of active objects. Input ports are receptionists of data. Therefore, contributing services must know the names of input ports of client services in order to send data messages--through their output ports--to them. In a system of services, each service could be either a contributing or consuming service, or both at the same time. We consider each client and contributor in the system as a service, as they all fit Definition 1. A client is deemed a service because it has a non-empty finite set of input ports, at least one output port, and a non-empty finite set of agents. Similarly, a contributor, which has at least one input port, a non-empty finite set of output ports, and a non-empty finite set of agents, can also be considered as a service for the same reason. Furthermore, a single sensor can also be considered as a particular case of a contributing service because it has an empty set of input ports, a single output port, and a single agent, which is responsible for sampling sensor data at a particular sampling rate. In a system of IoT services, the required communication between services is carried out by sending and receiving asynchronous messages. Messages can be of one of two types: control messages or data messages. Control messages (also called _inter-service_ messages) are communicated between services for administrative purposes. In contrast, the data messages are used to send service feeds from contributing services to client services. Each service has a dedicated agent called the _service coordinator_, which is responsible for handling control messages between its home service and other services in the system. When a control message is sent to a service, the message is received by its coordinator agent. The rest of the agents implement the service logic and process the received data messages. Figure 2 illustrates the interaction between services. A rectangle represents a service's boundary. Each service has a set of ports using which it could communicate with other services in the system. The figure also illustrates the components of a service. Ovals are agents serving the service, white circles are input ports, black circles are output ports, and the lines with arrows represent message flows; the service encapsulates a set of agents implementing its logic. These agents are invisible to other services.