You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "F.D." <fr...@gmail.com> on 2018/07/31 13:50:19 UTC
Distributed closure and cache.
Hi,
First, I want sat thank you for your job, and for the help you gave me.
I've a new question for you. I need to get a cache value inside the method
Call of my closure. Is it possibile? I need to start a new node?!? (ignite
= Ignition::Start(cfg)) Can I use an already initialized variable?!?
Thanks,
F.D.
Re: Distributed closure and cache.
Posted by "F.D." <fr...@gmail.com>.
Perfect!! You saved me!
Thanks,
F.D.
On Tue, Jul 31, 2018 at 4:05 PM Dmitriy Govorukhin <
dmitriy.govorukhin@gmail.com> wrote:
> HI,
>
> Yes, you can. Try to do something like this
>
> ignite.compute().call(() -> {
> // Get local ignite instance (local in compute task).
> Ignite remoteIg = Ignition.localIgnite();
>
> IgniteCache<Object, Object> cache = remoteIg.cache("cacheName");
>
> Object val = cache.get("someKey");
>
> return "result";
> });
>
> or use @IgniteInstanceResource.
>
> ignite.compute().call(new MyComputeTask());
>
> class MyComputeTask implements IgniteCallable<Object> {
> @IgniteInstanceResource
> private Ignite ignite;
>
> @Override public Object call() throws IgniteCheckedException {
>
> IgniteCache<Object, Object> cache = remoteIg.cache("cacheName");
>
> Object val = cache.get("someKey");
>
> return "result";
> }
> }
>
>
>
> On Tue, Jul 31, 2018 at 4:50 PM F.D. <fr...@gmail.com> wrote:
>
>> Hi,
>>
>> First, I want sat thank you for your job, and for the help you gave me.
>> I've a new question for you. I need to get a cache value inside the method
>> Call of my closure. Is it possibile? I need to start a new node?!? (ignite
>> = Ignition::Start(cfg)) Can I use an already initialized variable?!?
>>
>> Thanks,
>> F.D.
>>
>
Re: Distributed closure and cache.
Posted by Dmitriy Govorukhin <dm...@gmail.com>.
HI,
Yes, you can. Try to do something like this
ignite.compute().call(() -> {
// Get local ignite instance (local in compute task).
Ignite remoteIg = Ignition.localIgnite();
IgniteCache<Object, Object> cache = remoteIg.cache("cacheName");
Object val = cache.get("someKey");
return "result";
});
or use @IgniteInstanceResource.
ignite.compute().call(new MyComputeTask());
class MyComputeTask implements IgniteCallable<Object> {
@IgniteInstanceResource
private Ignite ignite;
@Override public Object call() throws IgniteCheckedException {
IgniteCache<Object, Object> cache = remoteIg.cache("cacheName");
Object val = cache.get("someKey");
return "result";
}
}
On Tue, Jul 31, 2018 at 4:50 PM F.D. <fr...@gmail.com> wrote:
> Hi,
>
> First, I want sat thank you for your job, and for the help you gave me.
> I've a new question for you. I need to get a cache value inside the method
> Call of my closure. Is it possibile? I need to start a new node?!? (ignite
> = Ignition::Start(cfg)) Can I use an already initialized variable?!?
>
> Thanks,
> F.D.
>