Skip to content

Commit

Permalink
Merge pull request #108 from TheKojuEffect/master
Browse files Browse the repository at this point in the history
Realtime update all clients on update
  • Loading branch information
koju committed Aug 31, 2013
2 parents 04d86bf + eedb398 commit 0549dc1
Show file tree
Hide file tree
Showing 41 changed files with 338 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,33 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.remoting.rmi.RmiServiceExporter;

import devopsdistilled.operp.server.data.entity.Entiti;
import devopsdistilled.operp.server.data.service.EntityService;

public abstract class AbstractEntityModel<E extends Entiti<?>, ES extends EntityService<E, ?>, EO extends EntityModelObserver>
extends AbstractModel<EO> implements EntityModel<E, ES, EO> {

@Inject
private ApplicationContext context;

protected List<E> entities;

public AbstractEntityModel() {
Expand Down Expand Up @@ -68,16 +86,66 @@ private Method getUpdateMethod() {
}

@Override
// @Transactional
public E saveAndUpdateModel(E entity) {
E savedEntity = getService().save(entity);
update();
getService().notifyClientsForUpdate();
return savedEntity;
}

@Override
public void deleteAndUpdateModel(E entity) {
getService().delete(entity);
update();
getService().notifyClientsForUpdate();
}

@PostConstruct
public void registerWithServer() {
AutowireCapableBeanFactory factory = context
.getAutowireCapableBeanFactory();
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) factory;
GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
beanDefinition.setBeanClass(RmiServiceExporter.class);
beanDefinition.setAutowireCandidate(true);

MutablePropertyValues propertyValues = new MutablePropertyValues();

Class<?> serviceInterface = this.getClass().getInterfaces()[0];

propertyValues.addPropertyValue("serviceInterface", serviceInterface);
String serviceName = serviceInterface.getCanonicalName();
propertyValues.addPropertyValue("serviceName", serviceName);
propertyValues.addPropertyValue("service", this);
propertyValues.addPropertyValue("registryPort", "1099");
beanDefinition.setPropertyValues(propertyValues);

registry.registerBeanDefinition(serviceName, beanDefinition);
context.getBean(serviceName); // Need this else
// NotBoundException

try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
NetworkInterface network = networkInterfaces.nextElement();

if (!network.isUp() || network.isLoopback()
|| network.isVirtual())
continue;

Enumeration<InetAddress> addresses = network.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress netAddr = addresses.nextElement();

if (!netAddr.isLoopbackAddress()
&& (netAddr instanceof Inet4Address)) {
getService().registerClient(netAddr.getHostAddress());
break;
}

}
}
} catch (SocketException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package devopsdistilled.operp.client.business.purchases.models;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.client.business.purchases.models.observers.PurchaseDescModelObserver;
import devopsdistilled.operp.server.data.entity.business.PurchaseDesc;
import devopsdistilled.operp.server.data.service.business.PurchaseDescService;

public interface PurchaseDescModel
extends
EntityModel<PurchaseDesc, PurchaseDescService, PurchaseDescModelObserver> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package devopsdistilled.operp.client.business.purchases.models;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.client.business.purchases.models.observers.SaleDescModelObserver;
import devopsdistilled.operp.server.data.entity.business.SaleDesc;
import devopsdistilled.operp.server.data.service.business.SaleDescService;

public interface SaleDescModel extends
EntityModel<SaleDesc, SaleDescService, SaleDescModelObserver> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devopsdistilled.operp.client.business.purchases.models.observers;

import devopsdistilled.operp.client.abstracts.EntityModelObserver;

public interface PurchaseDescModelObserver extends EntityModelObserver {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devopsdistilled.operp.client.business.purchases.models.observers;

import devopsdistilled.operp.client.abstracts.EntityModelObserver;

public interface SaleDescModelObserver extends EntityModelObserver {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package devopsdistilled.operp.client.commons.models;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.client.commons.models.observers.AddressModelObserver;
import devopsdistilled.operp.server.data.entity.commons.Address;
import devopsdistilled.operp.server.data.service.commons.AddressService;

public interface AddressModel extends
EntityModel<Address, AddressService, AddressModelObserver> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package devopsdistilled.operp.client.commons.models;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.client.commons.models.observers.ContactInfoModelObserver;
import devopsdistilled.operp.server.data.entity.commons.ContactInfo;
import devopsdistilled.operp.server.data.service.commons.ContactInfoService;

public interface ContactInfoModel extends
EntityModel<ContactInfo, ContactInfoService, ContactInfoModelObserver> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devopsdistilled.operp.client.commons.models.observers;

import devopsdistilled.operp.client.abstracts.EntityModelObserver;

public interface AddressModelObserver extends EntityModelObserver {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devopsdistilled.operp.client.commons.models.observers;

import devopsdistilled.operp.client.abstracts.EntityModelObserver;

public interface ContactInfoModelObserver extends EntityModelObserver {

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,16 @@ public ManufacturerModel manufacturerModel() {
return new ManufacturerModelImpl();
}

// @Bean
// public RmiServiceExporter rmiEmployeeServiceExporter() {
// RmiServiceExporter rmiServiceExportor = new RmiServiceExporter();
// rmiServiceExportor.setServiceInterface(ItemModel.class);
// // String serviceName = rmiServiceExportor.getServiceInterface()
// // .getCanonicalName();
// rmiServiceExportor.setServiceName("ItemModel");
// rmiServiceExportor.setService(itemModel());
// rmiServiceExportor.setRegistryPort(1099);
// System.out.println(rmiServiceExportor);
// return rmiServiceExportor;
// }
}
10 changes: 8 additions & 2 deletions OpERP/src/main/java/devopsdistilled/operp/server/ServerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,22 @@

public class ServerApp {

private static ApplicationContext context;

public static ApplicationContext getApplicationContext() {
return context;
}

public static void main(String[] args) {

if (args.length > 0 && args[0].equalsIgnoreCase("init"))
System.setProperty("hibernate.hbm2ddl.auto", "create");
else
System.setProperty("hibernate.hbm2ddl.auto", "update");

ApplicationContext context = new AnnotationConfigApplicationContext(
AppContext.class);
context = new AnnotationConfigApplicationContext(AppContext.class);

System.out.println(context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public interface EntityService<E extends Entiti<?>, ID extends Serializable>

public boolean isEntityNameValidForTheEntity(ID id, String entityName);

void registerClient(String clientAddress);

void notifyClientsForUpdate();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import org.springframework.data.jpa.repository.JpaRepository;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.server.data.entity.account.Account;
import devopsdistilled.operp.server.data.service.impl.AbstractEntityService;

public abstract class AccountServiceImpl<A extends Account<?>, AR extends JpaRepository<A, Long>>
extends AbstractEntityService<A, Long, AR> {
public abstract class AccountServiceImpl<A extends Account<?>, AR extends JpaRepository<A, Long>, AM extends EntityModel<A, ?, ?>>
extends AbstractEntityService<A, Long, AR, AM> {

private static final long serialVersionUID = 8694809412525181588L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import devopsdistilled.operp.client.account.models.PaidTransactionModel;
import devopsdistilled.operp.server.data.entity.account.PaidTransaction;
import devopsdistilled.operp.server.data.repo.account.PaidTransactionRepository;
import devopsdistilled.operp.server.data.service.account.PaidTransactionService;
import devopsdistilled.operp.server.data.service.account.PayableAccountService;

@Service
public class PaidTransactionServiceImpl extends
TransactionServiceImpl<PaidTransaction, PaidTransactionRepository>
public class PaidTransactionServiceImpl
extends
TransactionServiceImpl<PaidTransaction, PaidTransactionRepository, PaidTransactionModel>
implements PaidTransactionService {

private static final long serialVersionUID = 8946536638729817665L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

import org.springframework.stereotype.Service;

import devopsdistilled.operp.client.account.models.PayableAccountModel;
import devopsdistilled.operp.server.data.entity.account.PayableAccount;
import devopsdistilled.operp.server.data.repo.account.PayableAccountRepository;
import devopsdistilled.operp.server.data.service.account.PayableAccountService;

@Service
public class PayableAccountServiceImpl extends
AccountServiceImpl<PayableAccount, PayableAccountRepository> implements
PayableAccountService {
public class PayableAccountServiceImpl
extends
AccountServiceImpl<PayableAccount, PayableAccountRepository, PayableAccountModel>
implements PayableAccountService {

private static final long serialVersionUID = -2228578598359971560L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

import org.springframework.stereotype.Service;

import devopsdistilled.operp.client.account.models.ReceivableAccountModel;
import devopsdistilled.operp.server.data.entity.account.ReceivableAccount;
import devopsdistilled.operp.server.data.repo.account.ReceivableAccountRepository;
import devopsdistilled.operp.server.data.service.account.ReceivableAccountService;

@Service
public class ReceivableAccountServiceImpl extends
AccountServiceImpl<ReceivableAccount, ReceivableAccountRepository>
public class ReceivableAccountServiceImpl
extends
AccountServiceImpl<ReceivableAccount, ReceivableAccountRepository, ReceivableAccountModel>
implements ReceivableAccountService {

private static final long serialVersionUID = -2228578598359971560L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import devopsdistilled.operp.client.account.models.ReceivedTransactionModel;
import devopsdistilled.operp.server.data.entity.account.ReceivedTransaction;
import devopsdistilled.operp.server.data.repo.account.ReceivedTransactionRepository;
import devopsdistilled.operp.server.data.service.account.ReceivableAccountService;
Expand All @@ -15,7 +16,7 @@
@Service
public class ReceivedTransactionServiceImpl
extends
TransactionServiceImpl<ReceivedTransaction, ReceivedTransactionRepository>
TransactionServiceImpl<ReceivedTransaction, ReceivedTransactionRepository, ReceivedTransactionModel>
implements ReceivedTransactionService {

private static final long serialVersionUID = -8134555856017276841L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import org.springframework.data.jpa.repository.JpaRepository;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.server.data.entity.account.Transaction;
import devopsdistilled.operp.server.data.service.impl.AbstractEntityService;

public abstract class TransactionServiceImpl<T extends Transaction<?>, TR extends JpaRepository<T, Long>>
extends AbstractEntityService<T, Long, TR> {
public abstract class TransactionServiceImpl<T extends Transaction<?>, TR extends JpaRepository<T, Long>, TM extends EntityModel<T, ?, ?>>
extends AbstractEntityService<T, Long, TR, TM> {

private static final long serialVersionUID = -4898201898165854461L;

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import org.springframework.data.jpa.repository.JpaRepository;

import devopsdistilled.operp.client.abstracts.EntityModel;
import devopsdistilled.operp.server.data.entity.business.BusinessDesc;
import devopsdistilled.operp.server.data.service.business.BusinessDescService;
import devopsdistilled.operp.server.data.service.impl.AbstractEntityService;

public abstract class BusinessDescServiceImpl<B extends BusinessDesc<?, ?>, R extends JpaRepository<B, Long>>
extends AbstractEntityService<B, Long, R> implements
public abstract class BusinessDescServiceImpl<B extends BusinessDesc<?, ?>, R extends JpaRepository<B, Long>, BDM extends EntityModel<B, ?, ?>>
extends AbstractEntityService<B, Long, R, BDM> implements
BusinessDescService<B> {

private static final long serialVersionUID = 2019639925021618876L;
Expand Down
Loading

0 comments on commit 0549dc1

Please sign in to comment.