ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mauricio Arroqui <mauriarro...@gmail.com>
Subject Re: How to configure MongoDB Client? I'm getting NotSerializableException
Date Fri, 24 Feb 2017 19:43:42 GMT
Thanks AG. 
I did what you suggest and now my code runs okey, but when I start a second
node on the same machine the first started node throws 
java.io.NotSerializableException:
org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$ThreadLocalSession

My new xml configuration and code is: 

<bean class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="name" value="local_simulation"/>
                    <property name="cacheMode" value="LOCAL"/>
                    <property name="atomicityMode" value="ATOMIC"/>
                    <property name="copyOnRead" value="true"/>
                    <property name="cacheStoreSessionListenerFactories">
                      <bean
class="org.apache.ignite.configuration.IgniteReflectionFactory">
                        <property name="componentClass"  
value="uniagro.simugant.db.grid.mongodb.SimulationCacheMongoStoreSessionListener"/>
                      </bean>
                  </property>
                  
                  <property name="cacheStoreFactory">
                      <bean
class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
                        <constructor-arg>
                          <bean
class="uniagro.simugant.db.grid.mongodb.SimulationCacheMongoStore">
                          </bean>
                        </constructor-arg>
                      </bean>
                  </property>
                  <property name="writeThrough" value="true"/>
                  <property name="writeBehindEnabled" value="true"/>
        </bean>

public class SimulationCacheMongoStoreSessionListener implements
LifecycleAware, CacheStoreSessionListener {

    public SimulationCacheMongoStoreSessionListener() {

    }

    private MongoClient mongoClient;

    @Override
    public void start() throws IgniteException {
        mongoClient = new MongoClient();
    }

    @Override
    public void stop() throws IgniteException {
        if (mongoClient != null) {
            mongoClient.close();

        }
    }

    @Override
    public void onSessionStart(CacheStoreSession ses) {
        if (ses.attachment() == null) {
            ses.attach(mongoClient);
        }

    }

    @Override
    public void onSessionEnd(CacheStoreSession ses, boolean commit) {
        ses.attach(null);
    }

public class SimulationCacheMongoStore extends CacheStoreAdapter<Long,
SimulationCache> implements Serializable{

    /**
     * Logger.
     */
    @LoggerResource
    private IgniteLogger log;

    @CacheStoreSessionResource
    private CacheStoreSession ses;

    public SimulationCacheMongoStore() {
        
    }
    
 
    @Override
    public SimulationCache load(Long k) throws CacheLoaderException {
        //NO-OP
    }

    @Override
    public void write(Cache.Entry<? extends Long, ? extends SimulationCache>
entry) throws CacheWriterException {
        MongoClient mongoClient = ses.attachment();
        Datastore morphia = new Morphia().createDatastore(mongoClient,
"test");
        morphia.save(entry.getValue());
        if (log.isDebugEnabled()) {
            log.debug("Stored Simulation: " + entry.getValue());
        }

    }

    @Override
    public void delete(Object o) throws CacheWriterException {
       NO-OP
    }

As I said, my code is running okey, but I don't know what are the back
effects that exception could have. 
I leave here the complete exception:

at
org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:84)
	at
org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:70)
	at
org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:98)
	at
org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.marshal(AbstractNodeNameAwareMarshaller.java:58)
	at
org.apache.ignite.internal.util.IgniteUtils.marshal(IgniteUtils.java:9861)
	at
org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi.collectExchangeData(TcpDiscoverySpi.java:1685)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processNodeAddedMessage(ServerImpl.java:4092)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processJoinRequestMessage(ServerImpl.java:3740)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2532)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2362)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$MessageWorkerAdapter.body(ServerImpl.java:6436)
	at
org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.body(ServerImpl.java:2445)
	at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.io.NotSerializableException:
org.apache.ignite.internal.processors.cache.store.GridCacheStoreManagerAdapter$ThreadLocalSession
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at java.util.ArrayList.writeObject(ArrayList.java:762)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:988)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at
java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at
java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at
org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal0(JdkMarshaller.java:79)
	... 12 more

Regards,
Mauricio



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-configure-MongoDB-Client-I-m-getting-NotSerializableException-tp10767p10875.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message