@AstrixServiceExport(Ping.class) public class PingBean implements Ping { @Override public String ping(String msg) { return msg; } }
public void addServiceProvider(Object bean) { if (!bean.getClass().isAnnotationPresent(AstrixServiceExport.class)) { throw new IllegalArgumentException("Service provider beans must be annotated with @AstrixServiceExport. bean: " + bean.getClass().getName()); } AstrixServiceExport serviceExport = bean.getClass().getAnnotation(AstrixServiceExport.class); for (Class<?> providedServiceType : serviceExport.value()) { Object previousProvider = serviceProviderByType.putIfAbsent(providedServiceType, bean); if (previousProvider != null) { throw new IllegalStateException(String.format("Multiple providers for same serviceApi detected. serviceApi=%s beanA=%s beanB=%s", providedServiceType.getName(), previousProvider.getClass().getName(), bean.getClass().getName())); } } }
@AstrixServiceExport(PublicLunchFeeder.class) public class PublicLunchFeederImpl implements PublicLunchFeeder { // Since this is part of the same subsystem, this app is allowed to invoke it private InternalLunchFeeder internalLunchFeeder; @Autowired public PublicLunchFeederImpl(InternalLunchFeeder internalLunchFeeder) { this.internalLunchFeeder = internalLunchFeeder; } @Override public void addLunchRestaurant(LunchRestaurant restaurant) { this.internalLunchFeeder.addLunchRestaurant(restaurant); } }
@AstrixServiceExport(ServiceAdministrator.class) public class ServiceAdministratorImpl implements ServiceAdministrator { private ServiceRegistryExporter serviceRegistryExporter; @AstrixInject public void setServiceRegistryExporter(ServiceRegistryExporter serviceRegistryExporter) { this.serviceRegistryExporter = serviceRegistryExporter; } @Override public void setPublishServices(boolean published) { this.serviceRegistryExporter.setPublished(published); } }
@AstrixServiceExport(PublicLunchFeeder.class) public class PublicLunchFeederImpl implements PublicLunchFeeder { // Since this is part of the same subsystem, this app is allowed to invoke it private InternalLunchFeeder internalLunchFeeder; @Autowired public PublicLunchFeederImpl(InternalLunchFeeder internalLunchFeeder) { this.internalLunchFeeder = internalLunchFeeder; } @Override public void addLunchRestaurant(LunchRestaurant restaurant) { this.internalLunchFeeder.addLunchRestaurant(restaurant); } }
@AstrixServiceExport({LunchService.class, InternalLunchFeeder.class}) public class LunchServiceImpl implements LunchService, InternalLunchFeeder { private final GigaSpace gigaSpace; @Autowired public LunchServiceImpl(GigaSpace gigaSpace) { this.gigaSpace = gigaSpace; } @Override public List<LunchRestaurant> getAllLunchRestaurants() { LunchRestaurant template = new LunchRestaurant(); return Arrays.asList(gigaSpace.readMultiple(template)); } @Override public void addLunchRestaurant(LunchRestaurant restaurant) { this.gigaSpace.write(restaurant); } @Override public LunchRestaurant getLunchRestaurant(String name) { return this.gigaSpace.readById(LunchRestaurant.class, name); } }
@AstrixServiceExport(AccountService.class) public class AccountServiceImpl implements AccountService {
@AstrixServiceExport(LunchService.class) public class LunchServiceImpl implements LunchService { private GigaSpace gigaSpace; @Autowired public LunchServiceImpl(GigaSpace gigaSpace) { this.gigaSpace = gigaSpace; } @Override public List<String> getAllRestaurants() { LunchRestaurant[] restaurants = gigaSpace.readMultiple(new LunchRestaurant()); List<String> result = new ArrayList<>(); for (LunchRestaurant restaurant : restaurants) { result.add(restaurant.getName()); } return result; } @Override public void addLunchRestaurant(@Routing String name) { LunchRestaurant r = new LunchRestaurant(); r.setName(name); gigaSpace.write(r); } }
@AstrixServiceExport(LunchRestaurantGrader.class) public class LunchRestaurantGraderImpl implements LunchRestaurantGrader {
@AstrixServiceExport(LunchRestaurantGrader.class) public class LunchRestaurantGraderImpl implements LunchRestaurantGrader {
@AstrixServiceExport(AstrixServiceRegistry.class) public class AstrixServiceRegistryImpl implements AstrixServiceRegistry {
@AstrixServiceExport({LunchService.class, InternalLunchFeeder.class}) public class LunchServiceImpl implements LunchService, InternalLunchFeeder {
@AstrixServiceExport(AstrixServiceRegistry.class) public class InMemoryServiceRegistry implements DynamicConfigSource, AstrixServiceRegistry, MutableConfigSource {