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

classic Classic list List threaded Threaded
14 messages Options
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|

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
|

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
|

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
|

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
|

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
|

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
|

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
|

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
|

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
|

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
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|

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

In reply to this post by vkulichenko
Hi Val

Quick Question

I am trying to run the Ignite client from a J2EE application which is deployed in Weblogic Server  and the client starts running when the method id invoked. I try to Monitor it with the Visor app and I can see the server and Client running. I tried to kill the client instance from the visor application and it kills the client. Unfortunately it brings down the weblogic server also. Have you experienced this and Any thoughts why this happens and how can we avoid it?

Thanks
Saji

On Thu, Jun 15, 2017 at 11:55 AM, Sajin Mathew <[hidden email]> wrote:
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
Saji



--
Thanks and Regards
Saji
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

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

Hi Saji,

Kill command kill the process, it's designed more for standalone server nodes rather than embedded clients. What is the condition when you may want to stop the client?

-Val
StartCoding StartCoding
Reply | Threaded
Open this post in threaded view
|

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

Hi Val,

Thanks for the response.

The scenario is I will start the client and at some point the machine is  getting stuck (due to high cpu utilisation) and I need to kill the entire servers and client to regain my system. At this time I use the Visor App to kill the instances one by one. But As I kill the client I it makes the entire Weblogic server down. I dont know if there would be another scenario where I need to kill the client in future. But if there is a case to kill the client after day end of the day or so what is the safe way to do it?

Thanks
Saji

On Mon, Jul 10, 2017 at 9:00 PM, vkulichenko [via Apache Ignite Users] <[hidden email]> wrote:
Hi Saji,

Kill command kill the process, it's designed more for standalone server nodes rather than embedded clients. What is the condition when you may want to stop the client?

-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
|

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

Saji,

Ignite node in this case is embedded into the application. So it's up to this application to control the lifecycle. To stop an embedded node just call Ignition.stop().

-Val