You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Shawn Du <sh...@neulion.com.cn> on 2016/10/31 02:44:12 UTC

答复: dynamic data structure with binaryobject

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.


Re: 答复: dynamic data structure with binaryobject

Posted by vkulichenko <va...@gmail.com>.
Hi Shawn,

invoke() allows to avoid sending the value across network. So unless you
need the whole value on the client, it's always preferable operation,
especially if values are large.

-Val



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