我如何使用 java 连接 oracle coherence 远程集群

how can i connect oracle coherence remote cluster using java

有一个 coherence 集群(有一个名为 mycache 的缓存)运行nig 在 IP 地址 xxx.xxx.xxx.xxx(不是本地主机)上,我正在尝试连接它并使用java。 这是我的 Reader class:

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 IDEA,在 reader 的 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?

我真的被它困住了。我在谷歌上搜索了很多,但没有找到任何支持这一点的东西。

在此先致谢。

看起来像是 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>

注意:如果远程集群对mycache使用POF序列化,则必须添加POF映射和配置-Dtangosol.pof.enabled=true

您的 xml 文件是操作配置而不是缓存配置。要使用此配置,运行 您的程序具有:

-Dtangosol.coherence.override=mycache.xml

而不是:

-Dtangosol.coherence.cacheconfig=mycache.xml

顺便说一句,您应该将 mycache.xml 重命名为例如operational-config.xml 为了不与缓存配置混淆。