2016-12-04 44 views
0

有一個連貫性集羣(按名稱mycache高速緩存),其IP地址xxx.xxx.xxx.xxx運行過程中出現(不是localhost)連接Oracle Coherence的遠程集羣,我試圖將它連接並使用java從緩存中讀取。 這是我的閱讀器類:我如何使用Java

import com.tangosol.net.CacheFactory; 
import com.tangosol.net.NamedCache; 

public class Reader { 
    public static void main(String[] args) { 
     NamedCache cache = CacheFactory.getCache("mycache"); 
     System.out.println("Value in cache is: " + cache.get("key1")); 
    } 
} 

我使用Intellije想法,供讀者VM選項我加入這一行:

-Dtangosol.coherence.cacheconfig=mycache.xml 

,這是mycache.xml文件:

<?xml version='1.0'?> 
<coherence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://xmlns.oracle.com/coherence/coherence-operational-config" 
      xsi:schemaLocation="http://xmlns.oracle.com/coherence/coherence-operational-config 
      coherence-operational-config.xsd" 
      xml-override="{tangosol.coherence.override /tangosol-coherence-override-{mode}.xml}"> 

    <cluster-config> 
     <member-identity> 
      <cluster-name>RemoteCluster</cluster-name> 
     </member-identity> 

     <unicast-listener> 
      <well-known-addresses> 
       <socket-address id="1"> 
        <address>192.168.104.160</address> 
        <port>8088</port> 
       </socket-address> 
      </well-known-addresses> 
     </unicast-listener> 
    </cluster-config> 

</coherence> 

當我運行reader.main()我得到這個異常:

Problem : An ElementProcessor could not be located for the element [coherence] 
Advice : The specified element is unknown to the NamespaceHandler implementation. Perhaps the xml element is foreign to the Xml Namespace? 

    at com.tangosol.util.Base.ensureRuntimeException(Base.java:286) 
    at com.tangosol.net.ScopedCacheFactoryBuilder.instantiateFactory(ScopedCacheFactoryBuilder.java:433) 
    at com.tangosol.net.ScopedCacheFactoryBuilder.buildFactory(ScopedCacheFactoryBuilder.java:385) 
    at com.tangosol.net.ScopedCacheFactoryBuilder.getFactory(ScopedCacheFactoryBuilder.java:267) 
    at com.tangosol.net.ScopedCacheFactoryBuilder.getConfigurableCacheFactory(ScopedCacheFactoryBuilder.java:119) 
    at com.tangosol.net.CacheFactory.getConfigurableCacheFactory(CacheFactory.java:127) 
    at com.tangosol.net.CacheFactory.getCache(CacheFactory.java:205) 
    at com.tangosol.net.CacheFactory.getCache(CacheFactory.java:182) 
    at Reader.main(Reader.java:11) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) 
Caused by: com.tangosol.config.ConfigurationException: Configuration Exception 
----------------------- 
Problem : An ElementProcessor could not be located for the element [coherence] 
Advice : The specified element is unknown to the NamespaceHandler implementation. Perhaps the xml element is foreign to the Xml Namespace? 

我真的陷入了它。我GOOGLE了很多,沒有發現任何支持這一點。

謝謝先進。

回答

0

它看起來像mycache.xml中的問題。這些元素用於在要連接客戶端時設置羣集成員。

假設「mycache」存在遠程集羣模式嘗試用以下改變mycache.xml:

<?xml version="1.0"?> 
<!DOCTYPE cache-config SYSTEM "cache-config.dtd"> 

<cache-config xmlns="http://schemas.tangosol.com/cache"> 
    <caching-scheme-mapping> 
     <cache-mapping> 
      <cache-name>mycache</cache-name> 
      <scheme-name>extend-dist</scheme-name> 
     </cache-mapping>  
    </caching-scheme-mapping> 
    <caching-schemes> 
     <remote-cache-scheme> 
      <scheme-name>extend-dist</scheme-name> 
      <service-name>ExtendTcpCacheService</service-name> 
      <initiator-config> 
       <tcp-initiator> 
        <remote-addresses> 
         <socket-address> 
          <address>192.168.104.160</address> 
          <port>8088</port> 
         </socket-address> 
        </remote-addresses> 
       </tcp-initiator> 
       <outgoing-message-handler> 
        <request-timeout>20s</request-timeout> 
       </outgoing-message-handler> 
      </initiator-config> 
     </remote-cache-scheme> 
    </caching-schemes> 
</cache-config> 

注意:如果遠程集羣使用POF序列化mycache你就必須添加POF映射和配置-Dtangosol.pof.enabled = true

+1

謝謝你這麼much.This的工作完美:) – mohammad

0

您的xml文件是可操作的配置而不是緩存配置。要使用此配置,運行與你PROGRAMM:

-Dtangosol.coherence.override=mycache.xml 

代替:

-Dtangosol.coherence.cacheconfig=mycache.xml 

BTW你應該重命名mycache.xml到例如operational-config.xml,以便不會將其與緩存配置混淆。

+0

謝謝你這麼much.your答案幫我解決一些其他問題和@阿爾卡季的答案。不幸的是解決目前的例外,因爲我是新來的StackOverflow無法給予好評答案。 – mohammad