You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Swetad90 <sw...@gmail.com> on 2017/05/25 20:53:22 UTC

BinaryObjects in IgniteCallable

Hi,

Is my understanding correct that we cannot use BinaryObjects in
IgniteCallable as it already uses serializable interface?

I am using IgniteCallable to retrieve a customClass object using
BinaryObject but facing a type cast exception.(ExchangeRate cannot be cast
to org.apache.ignite.binary.BinaryObject)

CacheConfiguration<ExchangeRateKey, ExchangeRate> cacheCfg = new
CacheConfiguration<>("ExchangeRateCache");
		 cacheCfg.setCacheMode(CacheMode.REPLICATED);
		 IgniteCache<ExchangeRateKey, ExchangeRate> cache =
ignite.getOrCreateCache(cacheCfg);
		 IgniteDataStreamer<ExchangeRateKey, ExchangeRate> Cachestmr =
ignite.dataStreamer(cache.getName());
Cachestmr.addData(rate.getRateKey(), rate);

IgniteCache<ExchangeRateKey, BinaryObject> binaryCache =
ignite.cache("ExchangeRateCache").withKeepBinary(); 
	   ExchangeRate obj = binaryCache .get(key);
	   System.out.println("Cache in : " + obj.getOfferRate() ); 	------> This
works

BinaryObject rate1 = ignite.compute().call(
	    		 
	    		    new IgniteCallable<BinaryObject>() {
		                private static final long serialVersionUID = 1L;
		         
		                
		                public BinaryObject call() throws UnknownHostException {
							System.out.println(binaryCache.get(key));
						    BinaryObject obj = binaryCache.get(key);     -------> This gives
error 
					return obj;
		    	        }
		                
		                
		    	    });	 



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/BinaryObjects-in-IgniteCallable-tp13152.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: BinaryObjects in IgniteCallable

Posted by Swetad90 <sw...@gmail.com>.
Hi Denis,

Thanks. It worked that way.

return(BinaryObject)
ignite.cache("ExchangeRateCache").withKeepBinary().get(Key);



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/BinaryObjects-in-IgniteCallable-tp13152p13294.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: BinaryObjects in IgniteCallable

Posted by Denis Magda <dm...@apache.org>.
Looks like “binaryCache” reference was not serialized properly.

Try to get a reference to the binary cache from the callable implementation executing the code like “ignite.cache(“name”).withKeepBinary().get(…).

Let us know if it works for you.

—
Denis

> On May 25, 2017, at 1:53 PM, Swetad90 <sw...@gmail.com> wrote:
> 
> Hi,
> 
> Is my understanding correct that we cannot use BinaryObjects in
> IgniteCallable as it already uses serializable interface?
> 
> I am using IgniteCallable to retrieve a customClass object using
> BinaryObject but facing a type cast exception.(ExchangeRate cannot be cast
> to org.apache.ignite.binary.BinaryObject)
> 
> CacheConfiguration<ExchangeRateKey, ExchangeRate> cacheCfg = new
> CacheConfiguration<>("ExchangeRateCache");
> 		 cacheCfg.setCacheMode(CacheMode.REPLICATED);
> 		 IgniteCache<ExchangeRateKey, ExchangeRate> cache =
> ignite.getOrCreateCache(cacheCfg);
> 		 IgniteDataStreamer<ExchangeRateKey, ExchangeRate> Cachestmr =
> ignite.dataStreamer(cache.getName());
> Cachestmr.addData(rate.getRateKey(), rate);
> 
> IgniteCache<ExchangeRateKey, BinaryObject> binaryCache =
> ignite.cache("ExchangeRateCache").withKeepBinary(); 
> 	   ExchangeRate obj = binaryCache .get(key);
> 	   System.out.println("Cache in : " + obj.getOfferRate() ); 	------> This
> works
> 
> BinaryObject rate1 = ignite.compute().call(
> 	    		 
> 	    		    new IgniteCallable<BinaryObject>() {
> 		                private static final long serialVersionUID = 1L;
> 		         
> 		                
> 		                public BinaryObject call() throws UnknownHostException {
> 							System.out.println(binaryCache.get(key));
> 						    BinaryObject obj = binaryCache.get(key);     -------> This gives
> error 
> 					return obj;
> 		    	        }
> 		                
> 		                
> 		    	    });	 
> 
> 
> 
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/BinaryObjects-in-IgniteCallable-tp13152.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.