Reference Guide

Table Of Contents
Creating Domain Service (Business Logic)
The following information defines a service to provide Open Flow Switches functionality (The
sample application’s business logic). This service basically provides operations to create, read,
update and delete open flow switches (CRUD operations).
Service API
Service API abstracts the business logic implementation by defining an API that clients or
consumers use in order to interact with Open Flow switches. This API will act as the Open Flow
Switch service contract. The following listing shows the Open Flow Switch service API which should
be created under hm-api module.
SwitchService.java (Sample Application Service API):
package com.hp.hm.api;
import java.util.Collection;
import java.util.UUID;
import com.hp.api.Id;
import com.hp.api.NotFoundException;
import com.hp.hm.model.Switch;
...
public interface SwitchService {
public Switch create(String name);
public Collection<Switch> getAll();
public Switch get(Id<Switch, UUID> id);
public void delete(Id<Switch, UUID> id);
}
Services expose methods that use transfer objects, primitive types, object value types and common
data structures in their signatures; thus, these entities become part of the API and they remain the
same no matter the implementation we choose for our services.
The Switch service depends on the hm-model module because model objects are defined there,
thus the hm-api POM file needs to resolve the dependencies. Open the hm-api/pom.xml file and
add the XML extract from the following listing to the <dependencies> node. After updating the
POM file update the Eclipse project dependencies (see Updating Project Dependencies on page
146).
Application Model Dependency:
<dependency>
<groupId>com.hp.hm</groupId>
<artifactId>hm-model</artifactId>
<version>${project.version}</version>
</dependency>
156