You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ignite.apache.org by Alexey Goncharuk <al...@gmail.com> on 2015/12/11 11:02:15 UTC

BinaryObjectBuilder in EntryProcessor

Igniters,

I was creating an example showing how to use BinaryObjects and
EntryProcessor for the case when server nodes do not have cache classes
definitions and realized that there is no straightforward way to get an
instance of BinaryObjectBuilder inside of an EntryProcessor.

Currently the only way to do this is to inject an instance of Ignite to the
instance of EntryProcessor and get a reference to IgniteBinary from it,
which looks a bit too verbose to me:

class MyEntryProcessor {
    @IgniteInstanceResource
    private Ignite ignite;

    BinaryObject invoke(...) {
        BinaryObjectBulder bld = ignite.binary().builder(entry.getValue());

        entry.setValue(bld.setField("a", 2).build());
    }
}

I think we can add something like a "BinaryBuilder buildCopy();" method to
the BinaryObject interface which will create a new binary builder
initialized with the current binary object. Now the above EntryProcessor
will look as follows:

class MyEntryProcessor {
    BinaryObject invoke(...) {
        entry.setValue(entry.getValue().buildCopy().setField("a",
2).build());
    }
}

Thoughts?

Re: BinaryObjectBuilder in EntryProcessor

Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Fri, Dec 11, 2015 at 6:03 AM, Alexey Goncharuk <
alexey.goncharuk@gmail.com> wrote:

> >
> > I like it.
>
>
> I will add this method if there will be no objections.
>

Alexey, do you think we should also add “rawBytes()” method to the
IgniteObject?

>
>
> > Also, does it make sense to pass a copy of the BinaryObject into
> > the EntryProcessor?
>
>
> I am not sure I understood the question correctly. We never copy
> BinaryObject since it is immutable.
>

Got it.

Re: BinaryObjectBuilder in EntryProcessor

Posted by Alexey Goncharuk <al...@gmail.com>.
>
> I like it.


I will add this method if there will be no objections.


> Also, does it make sense to pass a copy of the BinaryObject into
> the EntryProcessor?


I am not sure I understood the question correctly. We never copy
BinaryObject since it is immutable.

Re: BinaryObjectBuilder in EntryProcessor

Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Fri, Dec 11, 2015 at 3:44 AM, Yakov Zhdanov <yz...@apache.org> wrote:

> how about "toBuilder()"?
>

I like it. Also, does it make sense to pass a copy of the BinaryObject into
the EntryProcessor?


>
> --Yakov
>
> 2015-12-11 13:02 GMT+03:00 Alexey Goncharuk <al...@gmail.com>:
>
> > Igniters,
> >
> > I was creating an example showing how to use BinaryObjects and
> > EntryProcessor for the case when server nodes do not have cache classes
> > definitions and realized that there is no straightforward way to get an
> > instance of BinaryObjectBuilder inside of an EntryProcessor.
> >
> > Currently the only way to do this is to inject an instance of Ignite to
> the
> > instance of EntryProcessor and get a reference to IgniteBinary from it,
> > which looks a bit too verbose to me:
> >
> > class MyEntryProcessor {
> >     @IgniteInstanceResource
> >     private Ignite ignite;
> >
> >     BinaryObject invoke(...) {
> >         BinaryObjectBulder bld =
> ignite.binary().builder(entry.getValue());
> >
> >         entry.setValue(bld.setField("a", 2).build());
> >     }
> > }
> >
> > I think we can add something like a "BinaryBuilder buildCopy();" method
> to
> > the BinaryObject interface which will create a new binary builder
> > initialized with the current binary object. Now the above EntryProcessor
> > will look as follows:
> >
> > class MyEntryProcessor {
> >     BinaryObject invoke(...) {
> >         entry.setValue(entry.getValue().buildCopy().setField("a",
> > 2).build());
> >     }
> > }
> >
> > Thoughts?
> >
>

Re: BinaryObjectBuilder in EntryProcessor

Posted by Yakov Zhdanov <yz...@apache.org>.
how about "toBuilder()"?

--Yakov

2015-12-11 13:02 GMT+03:00 Alexey Goncharuk <al...@gmail.com>:

> Igniters,
>
> I was creating an example showing how to use BinaryObjects and
> EntryProcessor for the case when server nodes do not have cache classes
> definitions and realized that there is no straightforward way to get an
> instance of BinaryObjectBuilder inside of an EntryProcessor.
>
> Currently the only way to do this is to inject an instance of Ignite to the
> instance of EntryProcessor and get a reference to IgniteBinary from it,
> which looks a bit too verbose to me:
>
> class MyEntryProcessor {
>     @IgniteInstanceResource
>     private Ignite ignite;
>
>     BinaryObject invoke(...) {
>         BinaryObjectBulder bld = ignite.binary().builder(entry.getValue());
>
>         entry.setValue(bld.setField("a", 2).build());
>     }
> }
>
> I think we can add something like a "BinaryBuilder buildCopy();" method to
> the BinaryObject interface which will create a new binary builder
> initialized with the current binary object. Now the above EntryProcessor
> will look as follows:
>
> class MyEntryProcessor {
>     BinaryObject invoke(...) {
>         entry.setValue(entry.getValue().buildCopy().setField("a",
> 2).build());
>     }
> }
>
> Thoughts?
>