在OSGI环境中com.hazelcast.nio.serialization.HazelcastSerializationException

时间:2015-12-09 12:29:32

标签: java serialization osgi hazelcast

我正在使用felix maven插件运行OSGI插件项目(N bundle),我已将hazelcast集成到其中。班级" ConfigurationService"创建hazelcast实例的标记是singleton,我使用默认配置创建hazelcast实例。

以下是代码段。

private static ROIConfigurationServer configService;

private HazelcastInstance hazelcastInstance;


public static ROIConfigurationServer getConfigurationService()throws ConfigServerInitializationException{

if(configService==null){
            synchronized(ROIConfigurationServer.class){
                try{
                    logger.debug("initialized ROIConfigurationServer");
                    HazelcastInstance hazelcastInstance=Hazelcast.newHazelcastInstance();
                    List<String> imapkeys=new ArrayList<>();
                    IMap<String,String> configGroupKeys=hazelcastInstance.getMap(ConfigurationConstant.CONFIG_GROUP_KEYS);
                    configService=new ROIConfigurationServer(hazelcastInstance,configGroupKeys);
                }catch(Exception exp){
                    logger.error("ROIConfigurationServer initializatiob error", exp);
                    throw new ConfigServerInitializationException("Failed to initialize the ConfigServer",exp);
                }
            }
        }
        return configService;
    }//end of singleton method

单身类&#34; ConfigurationService&#34;有一个addConfiguration()方法,它将ConfigurationUnit(pojo类)对象添加到hazelcast map对象中,getConfiguration()从hazelcast Map获取ConfigurationUnit对象并部署为bundle&#34; config-service&#34;束。

另一个名为&#34; feature-extender-v3&#34;使用扩展模式调用addConfiguration()并成功将配置数据添加到hazelcast但是在调用getConfiguration()时出现以下错误

完整堆栈跟踪:

ERROR: Bundle feature-extender-v3 [157] EventDispatcher: Error during dispatch. (com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.getusroi.config.server.ConfigurationUnit)
com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: com.getusroi.config.server.ConfigurationUnit
    at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.read(DefaultSerializers.java:201)
    at com.hazelcast.nio.serialization.StreamSerializerAdapter.read(StreamSerializerAdapter.java:41)
    at com.hazelcast.nio.serialization.SerializationServiceImpl.toObject(SerializationServiceImpl.java:276)
    at com.hazelcast.spi.impl.NodeEngineImpl.toObject(NodeEngineImpl.java:200)
    at com.hazelcast.map.impl.MapServiceContextImpl.toObject(MapServiceContextImpl.java:281)
    at com.hazelcast.map.impl.proxy.MapProxySupport.toObject(MapProxySupport.java:1114)
    at com.hazelcast.map.impl.proxy.MapProxyImpl.get(MapProxyImpl.java:82)
    at com.getusroi.config.server.ROIConfigurationServer.getConfiguration(ROIConfigurationServer.java:133)
    at com.getusroi.feature.config.impl.FeatureConfigurationService.getFeatureConfiguration(FeatureConfigurationService.java:41)
    at com.getusroi.feature.config.impl.FeatureConfigurationService.addFeatureConfiguration(FeatureConfigurationService.java:28)
    at com.getusroi.feature.resources.helper.FMIResources.getFeaturesImplementationResource(FMIResources.java:111)
    at com.getusroi.feature.resources.helper.FMIResources.getEventResources(FMIResources.java:37)
    at com.getusroi.feature.extender.FeatureMetaInfoExtender.addedBundle(FeatureMetaInfoExtender.java:89)
    at com.getusroi.feature.bundle.tracker.BundleTracker$1.bundleChanged(BundleTracker.java:65)
    at org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:870)
    at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:791)
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:515)
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4650)
    at org.apache.felix.framework.Felix$4.run(Felix.java:2123)
    at org.apache.felix.framework.Felix.runInContext(Felix.java:2147)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2121)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
    at org.apache.karaf.shell.osgi.InstallBundle.doExecute(InstallBundle.java:51)
    at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
    at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)
    at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)
    at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
    at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
    at org.apache.karaf.shell.console.jline.Console.run(Console.java:189)
    at java.lang.Thread.run(Thread.java:745)
    at org.apache.karaf.shell.ssh.ShellFactoryImpl$ShellImpl$4.doRun(ShellFactoryImpl.java:158)
    at org.apache.karaf.shell.ssh.ShellFactoryImpl$ShellImpl$4$1.run(ShellFactoryImpl.java:149)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:47)
    at org.apache.karaf.shell.ssh.ShellFactoryImpl$ShellImpl$4.run(ShellFactoryImpl.java:147)
Caused by: java.lang.ClassNotFoundException: com.getusroi.config.server.ConfigurationUnit
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:125)
    at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:114)
    at com.hazelcast.nio.IOUtil$1.resolveClass(IOUtil.java:113)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1612)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
    at com.hazelcast.nio.serialization.DefaultSerializers$ObjectSerializer.read(DefaultSerializers.java:196)
    ... 39 more

我看了另外一个类似问题的堆栈跟踪&#34; com.hazelcast.nio.serialization.HazelcastSerializationException&#34;但是不明白。我应该如何使用默认配置而不是使用hazelcast配置解决此问题?

1 个答案:

答案 0 :(得分:1)

您是否可以通过为指定的Config提供已配置的类加载器(类加载器可以通过setClassLoader()方法设置)来创建Hazelcast实例,该方法知道类com.getusroi.config.server.ConfigurationUnit

问候。