Java Reference
In-Depth Information
using Terracotta. A client manipulates a CustomerServiceImpl class, shown here, which is an
implementation of CustomerService , which implements the following interface:
package
com.apress.springenterpriserecipes.distributedspring.terracotta.customerconsole.service;
import
com.apress.springenterpriserecipes.distributedspring.terracotta.customerconsole.entity.Custo
mer;
import java.util.Date;
import java.util.Collection;
public interface CustomerService {
Customer getCustomerById( String id ) ;
Customer createCustomer(
String firstName, String lastName, Date birthdate ) ;
Customer removeCustomer( String id ) ;
Customer updateCustomer(
String id, String firstName,
String lastName, Date birthdate ) ;
Collection<Customer > getAllCustomers() ;
}
As this is meant to be a gentle introduction to Terracotta, I'll forego building a complete Hibernate
and Spring-based solution. The implementation will be an in-memory implementation.
package
com.apress.springenterpriserecipes.distributedspring.terracotta.customerconsole.service;
import com.apress.springenterpriserecipes.distributedspring.terracotta.
customerconsole.entity.Customer;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import java.util.*;
public class CustomerServiceImpl implements CustomerService {
private final Set<Customer> customers;
public CustomerServiceImpl() {
customers = Collections.synchronizedSet(new HashSet<Customer>());
}
public Customer updateCustomer(
String id, String firstName, String lastName, Date birthdate) {
Customer customer;
synchronized (customers) {
customer = getCustomerById(id);
customer.setBirthday(birthdate);
customer.setFirstName(firstName);
customer.setLastName(lastName);
Search WWH ::




Custom Search