You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by afedotov <al...@gmail.com> on 2017/06/22 10:51:03 UTC

Re: Ignite cache received by the client becomes null

Hi,

Please check if making cache field final will help you. There could be a
problem with inter-thread visibility.
Try changing the field signature to "private *final* IgniteCache<String,
InputFields> cache;"

Kind regards,
Alex.

On Thu, Jun 22, 2017 at 1:10 AM, mdolgonos [via Apache Ignite Users] <
ml+s70518n14036h50@n6.nabble.com> wrote:

> I have the singleton service class that creates an Ignite cache and
> provides a public method to add entries to the cache. Below is the code
> that creates cache:
>
> @Service("cacheService")
> @Scope(value = "singleton")
> public class RentdCacheService {
>         private IgniteCache<String, InputFields> cache = null;
>         public RentdCacheService() {
>                 super();
>                 createCache();
>         }
>
>         private void createCache() {
>                 try {
>                         Ignition.setClientMode(true);
>                         Ignite ignite = Ignition.start("default-config.xml");
>
>                         cache = ignite.getOrCreateCache("myCacheName");
>                         System.out.println("Created Ignite cache: " +
> cache);
>                 } catch (Exception ex) {
>                         ex.printStackTrace();
>                 }
>         }
>
> //The following method adds to the cache:
>
>         public void addRowToCache(String key, InputFields dataRow) {
>                 System.out.println("adding key="+key + " and
> dataRow="+dataRow);
>                 System.out.println("cache: " + cache);
>                 cache.put(key, dataRow);
>         }
> }
>
> In the system output I can see that the cache was created ( or received
> from the grid if created earlier). However, when the addRowToCache method
> is called the cache is null. I'm using a slightly modified
> default-config.xml where I added the grid name property and a discoverySpi
> property.
> can someone please help me understand why the cache gets dereferenced.
> Thank you.
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-ignite-users.70518.x6.nabble.com/Ignite-
> cache-received-by-the-client-becomes-null-tp14036.html
> To start a new topic under Apache Ignite Users, email
> ml+s70518n1h65@n6.nabble.com
> To unsubscribe from Apache Ignite Users, click here
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1&code=YWxleGFuZGVyLmZlZG90b2ZmQGdtYWlsLmNvbXwxfC0xMzYxNTU0NTg=>
> .
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-cache-received-by-the-client-becomes-null-tp14036p14042.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite cache received by the client becomes null

Posted by afedotov <al...@gmail.com>.
Hi,

Please properly subscribe to the mailing list so that the community can
receive email notifications for your messages.
To subscribe, send an empty email to user-subscribe@ignite.apache.org and
follow simple instructions in the reply.

Yes, static field initialization also provides interthread visibility
guarantees.

Looks like you are querying events, so you need to configure, for example,
MemoryEventStorageSpi and set it in IgniteConfiguration.


Kind regards,
Alex.

On Thu, Jun 22, 2017 at 4:03 PM, mdolgonos [via Apache Ignite Users] <
ml+s70518n14047h91@n6.nabble.com> wrote:

> Thank you Alex. I made this reference static and it worked.
> However, now I'm periodically getting the following exception:
>
> class org.apache.ignite.IgniteException: Failed to query events because
> default no-op event storage SPI is used. Consider configuring
> MemoryEventStorageSpi or another EventStorageSpi implementation via
> IgniteConfiguration.setEventStorageSpi() configuration property.
> .....
> Caused by: class org.apache.ignite.IgniteCheckedException: Failed to
> query events because default no-op event storage SPI is used. Consider
> configuring MemoryEventStorageSpi or another EventStorageSpi implementation
> via IgniteConfiguration.setEventStorageSpi() configuration property.
>
> My goal is to have the entire cache in the off-heap memory. What settings
> should I have to avoid this exception and have the off-heap cache?
>
> Thank you,
> Michael D.
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-ignite-users.70518.x6.nabble.com/Ignite-
> cache-received-by-the-client-becomes-null-tp14036p14047.html
> To start a new topic under Apache Ignite Users, email
> ml+s70518n1h65@n6.nabble.com
> To unsubscribe from Apache Ignite Users, click here
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1&code=YWxleGFuZGVyLmZlZG90b2ZmQGdtYWlsLmNvbXwxfC0xMzYxNTU0NTg=>
> .
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-cache-received-by-the-client-becomes-null-tp14036p14120.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Ignite cache received by the client becomes null

Posted by afedotov <al...@gmail.com>.
Hi,

Then just make it *volatile* like this "private *volatile* IgniteCache<String,
InputFields> cache;"


Kind regards,
Alex.

On Thu, Jun 22, 2017 at 3:21 PM, mdolgonos [via Apache Ignite Users] <
ml+s70518n14045h29@n6.nabble.com> wrote:

> Thank you, Alex, for your response.
> However, this doesn't seem to work since making it final doesn't allow me
> to set it's value within the createCache() method
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://apache-ignite-users.70518.x6.nabble.com/Ignite-
> cache-received-by-the-client-becomes-null-tp14036p14045.html
> To start a new topic under Apache Ignite Users, email
> ml+s70518n1h65@n6.nabble.com
> To unsubscribe from Apache Ignite Users, click here
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=1&code=YWxleGFuZGVyLmZlZG90b2ZmQGdtYWlsLmNvbXwxfC0xMzYxNTU0NTg=>
> .
> NAML
> <http://apache-ignite-users.70518.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Ignite-cache-received-by-the-client-becomes-null-tp14036p14046.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.