org.redisson.api.RLiveObjectService Java Examples

The following examples show how to use org.redisson.api.RLiveObjectService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TracingRedissonClient.java    From java-redis-client with Apache License 2.0 4 votes vote down vote up
@Override
public RLiveObjectService getLiveObjectService() {
  return redissonClient.getLiveObjectService();
}
 
Example #2
Source File: LiveObjectServiceExamples.java    From redisson-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    // connects to 127.0.0.1:6379 by default
    RedissonClient redisson = Redisson.create();

    RLiveObjectService liveObjectService = redisson.getLiveObjectService();

    Customer customer = new Customer("12");
    // customer object is becoming "live" object
    customer = liveObjectService.merge(customer);
    
    customer.setName("Alexander Pushkin");
    customer.setPhone("+7193127489123");
    customer.setAddress("Moscow, Tverskaya str");

    Product product = new Product(1L, "FoodBox");
    // product object is becoming "live" object
    product = liveObjectService.merge(product);
    
    product.getItemName2Amount().put("apple", 1);
    product.getItemName2Amount().put("banana", 12);
    product.setPrice(BigDecimal.valueOf(10));
    product.setUnitsInStock(12);

    Order order = new Order(customer);
    // order object is becoming "live" object
    order = liveObjectService.merge(order);
    
    order.setDate(new Date());
    order.setShipAddress("Moscow, Gasheka str");
    order.setShipName("James Bond");
    order.setShipPostalCode("141920");

    OrderDetail od = new OrderDetail(order, product);
    // OrderDetail object is becoming "live" object
    od = liveObjectService.merge(od);
    od.setPrice(BigDecimal.valueOf(9));
    od.setQuantity(1);
    order.getOrderDetails().add(od);
    customer.getOrders().add(order);

    // "live" object could be get on other JVM.

    Customer attachedCustomer = liveObjectService.get(Customer.class, "12");
    for (Order attachedOrder : attachedCustomer.getOrders()) {
        for (OrderDetail orderDetail : attachedOrder.getOrderDetails()) {
             // ...

        }

    }

    Product attachedProduct = liveObjectService.get(Product.class, 1L);

    // ...
    redisson.shutdown();
}