Can java code look up cache in server without Ignition.start(cfg)

classic Classic list List threaded Threaded
10 messages Options
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Can java code look up cache in server without Ignition.start(cfg)

Explaining my scenario

 I have my Ignite Server started using ignite.bat with grid name FirstGrid
 I have a java class CacheOperations with putCache() and getCache() as methods and acts as client to get and put data to the cache in the Ignite server.
 In CacheOperations I am using

   Ignite ignite = Ignition.start(cfg);

I am able to put and get data from cache.

Is there a way to do the same without using Ignite ignite = Ignition.start(cfg); in my java code. The reason I am looking for this is Whenever Ignition.start(cfg) gets executed it takes about 2 to 3 seconds in my machine to start the client and be part of the grid.

I tried using Ignition.ignite("FirstGrid") but could not succeed and I am not sure about the usage of  Ignition.ignite().

Appreciate if anyone in this group can throw some light.

Thanks
Saji

 

 
 
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Saji,

No, you need to start the client to access the cluster. Note that you can start it once for the whole application and reuse everywhere. It's thread safe and designed to be used by multiple threads concurrently.

-Val
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Hi Val,

Thank you very much for your quick response.
Could you please verify if the below approach will work or is there a better way to do it.

1. Declare a static variable igniteVar of type Ignite in my CacheOperations  class
2. Declare a method getIgniteObject() which will check if igniteVar is not null else will invoke Ignition.start(cfg) and assign to igniteVar .
3. myGetCache() and puctCache uses getIgniteObject() to get the ignite object.


Also another doubt was what is the purpose of Ignition.ignite().

Thanks
Saji
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Saji,

Ignition.ignite() is used to get the already started Ignite instance. There is also Ignition.getOrStart() method that actually implements the logic you described, so you can just use it.

-Val
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Thanks Very much!

That exactly matched my logic and it is perfectly working. 

I noticed that getOrStart takes IgniteConfiguration object.Is there a way to create that from example-ignite.xml file rather than doing it java setters?

Thanks
Saji

On Wed, Nov 16, 2016 at 3:09 PM, vkulichenko [via Apache Ignite Users] <[hidden email]> wrote:
Saji,

Ignition.ignite() is used to get the already started Ignite instance. There is also Ignition.getOrStart() method that actually implements the logic you described, so you can just use it.

-Val


To unsubscribe from Can java code look up cache in server without Ignition.start(cfg), click here.
NAML



--
Thanks and Regards
Saji
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Saji,

This is weird, I though there are several versions of it. You can use Ignition.loadSpringBean() to work around this. Load the IgniteConfiguration bean from the XML and then pass it getOrStart.

-Val
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Hi  Val,

That was the perfect one for me. It worked with XML using  Ignition.loadSpringBean() .

Appreciate all your help in this regard. Thank You !

Thanks
Saji

On Thu, Nov 17, 2016 at 3:27 PM, vkulichenko [via Apache Ignite Users] <[hidden email]> wrote:
Saji,

This is weird, I though there are several versions of it. You can use Ignition.loadSpringBean() to work around this. Load the IgniteConfiguration bean from the XML and then pass it getOrStart.

-Val


To unsubscribe from Can java code look up cache in server without Ignition.start(cfg), click here.
NAML



--
Thanks and Regards
Saji
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

In reply to this post by vkulichenko
Hi Val,

I remember you helping me with getOrStart(IgniteConfiguration) to ensure that Ignite is started only once. Currently I am having an issue

try (Ignite ignite = Ignition.getOrStart(ClientConfigurationFactory.createConfiguration())) {

when the above code is executed the Ignite node is starting up every time I execute this code instead of getting the already started instance.

Would you be able to throw some light to the above issue?

Thanks
Saji


On Fri, Nov 18, 2016 at 11:20 AM, Sajin Mathew <[hidden email]> wrote:
Hi  Val,

That was the perfect one for me. It worked with XML using  Ignition.loadSpringBean() .

Appreciate all your help in this regard. Thank You !

Thanks
Saji

On Thu, Nov 17, 2016 at 3:27 PM, vkulichenko [via Apache Ignite Users] <[hidden email]> wrote:
Saji,

This is weird, I though there are several versions of it. You can use Ignition.loadSpringBean() to work around this. Load the IgniteConfiguration bean from the XML and then pass it getOrStart.

-Val


To unsubscribe from Can java code look up cache in server without Ignition.start(cfg), click here.
NAML



--
Thanks and Regards
Saji



--
Thanks and Regards
Saji
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Saji,

You're using try-with-resources syntax, which calls Ignite.close() at the end and therefore stops the node. Getting rid of it will do the trick.

-Val
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Can java code look up cache in server without Ignition.start(cfg)

Thanks Val. It worked when I removed try()

On Wed, Jun 14, 2017 at 5:54 PM, vkulichenko [via Apache Ignite Users] <[hidden email]> wrote:
Saji,

You're using try-with-resources syntax, which calls Ignite.close() at the end and therefore stops the node. Getting rid of it will do the trick.

-Val


To unsubscribe from Can java code look up cache in server without Ignition.start(cfg), click here.
NAML



--
Thanks and Regards
Sajin
Loading...