ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shawn Du" <shawn...@neulion.com.cn>
Subject 答复: dynamic data structure with binaryobject
Date Mon, 31 Oct 2016 02:44:12 GMT
Thanks Val.

I write below code snippet and tested it, it works fine. But still have some
questions:
I have to call invoke method to do this, how to understand invoke,
especially for performance/latency? It is a recommended practice?

Thanks.
Shawn

============================================================================
================================
public class PartialUpdate{
    private static final String CACHE_NAME =
PartialUpdate.class.getSimpleName();
    public static void main(String[] args) throws IgniteException{
        Ignition.setClientMode(true);
        try (Ignite ignite = Ignition.start("config/ss.xml")){
            CacheConfiguration<Integer, Employee> cfg = new
CacheConfiguration<>();
            cfg.setName(CACHE_NAME);
            IgniteCache<Integer, Employee> cache =
ignite.getOrCreateCache(cfg);
            Employee employee = new Employee(1,"bob");
            cache.put(1, employee);
            try (IgniteCache<Integer, BinaryObject> binaryCache =
ignite.getOrCreateCache(cfg).withKeepBinary()){
                binaryCache.invoke(1, new EntryProcessor<Integer,
BinaryObject, Object>(){
                    @Override
                    public Object process(MutableEntry<Integer,
BinaryObject> mutableEntry, Object... objects) throws
EntryProcessorException{
                        if (mutableEntry.getValue() != null){
                            BinaryObjectBuilder builder =
mutableEntry.getValue().toBuilder().setField("age", 25);
                            mutableEntry.setValue(builder.build());
                        }
                        return null;
                    }
                });
            }
        }
    }

    static class Employee implements Serializable{
        @QuerySqlField(index = true)
        private int id;
        @QuerySqlField(index = true)
        private String name;
        @QuerySqlField
        private int age;

        public Employee(int id, String name){
            this.id = id;
            this.name = name;
        }
    }





-----邮件原件-----
发件人: vkulichenko [mailto:valentin.kulichenko@gmail.com] 
发送时间: 2016年10月29日 3:04
收件人: user@ignite.apache.org
主题: Re: dynamic data structure with binaryobject

Hi Shawn,

Yes, binary format provides direct support for this. You can change the
class definition on the client and transparently use the new version.
Another option is to use builder [1] to modify the object.

[1]
https://apacheignite.readme.io/docs/binary-marshaller#modifying-binary-objec
ts-using-binaryobjectbuilder

-Val



--
View this message in context:
http://apache-ignite-users.70518.x6.nabble.com/dynamic-data-structure-with-b
inaryobject-tp8581p8595.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Mime
View raw message