在运行与ignite CacheEvents程序相关的github示例时,没有得到任何输出(示例链接:https://github.com/apache/ignite/blob/master/examples/src/main/java/org/apache/ignite/examples/datagrid/cacheEventsexample.java)。有人能帮我做这件事吗?
package com.example;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.util.UUID;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteException;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.events.CacheEvent;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.apache.ignite.lang.IgnitePredicate;
import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT;
import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ;
import static org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED;
/**
* This examples demonstrates events API. Note that ignite events are disabled by default and
* must be specifically enabled, just like in {@code examples/config/example-ignite.xml} file.
* <p>
* Remote nodes should always be started with special configuration file which
* enables P2P class loading: {@code 'ignite.{sh|bat} examples/config/example-ignite.xml'}.
* <p>
* Alternatively you can run {@link ExampleNodeStartup} in another JVM which will
* start node with {@code examples/config/example-ignite.xml} configuration.
*/
public class CacheEventsExample {
/** Cache name. */
private static final String CACHE_NAME = "CACHE";
Ignite ignite ;
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException, InterruptedException {
/*s*/
final Ignite ignite = Ignition.start();
try {
System.out.println();
System.out.println(">>> Cache events example started.");
// Auto-close cache at the end of the example.
IgniteCache<Integer, String> cache = ignite.getOrCreateCache(CACHE_NAME);
System.out.println(" after cache create ");
// This optional local callback is called for each event notification
// that passed remote predicate listener.
IgniteBiPredicate<UUID, CacheEvent> locLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
@Override public boolean apply(UUID uuid, CacheEvent evt) {
System.out.println("Received event [evt=" + evt.name() + ", key=" + evt.key() +
", oldVal=" + evt.oldValue() + ", newVal=" + evt.newValue());
return true; // Continue listening.
}
};
System.out.println(" after local listener");
// Remote listener which only accepts events for keys that are
// greater or equal than 10 and if event node is primary for this key.
IgnitePredicate<CacheEvent> rmtLsnr = new IgnitePredicate<CacheEvent>() {
@Override public boolean apply(CacheEvent evt) {
System.out.println("ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ");
System.out.println("Cache event [name=" + evt.name() + ", key=" + evt.key() + ']');
int key = evt.key();
return key >= 10 && ignite.affinity(CACHE_NAME).isPrimary(ignite.cluster().localNode(), key);
}
};
System.out.println(" After remote listener ");
// Subscribe to specified cache events on all nodes that have cache running.
// Cache events are explicitly enabled in examples/config/example-ignite.xml file.
ignite.events(ignite.cluster().forCacheNodes(CACHE_NAME)).remoteListen(locLsnr, rmtLsnr,
EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
// Generate cache events.
for (int i = 0; i < 20; i++){
System.out.println(" insert data into cache "+i);
cache.put(i, Integer.toString(i));
}
// Wait for a while while callback is notified about remaining puts.
Thread.sleep(2000);
}catch(Exception e){
System.out.println("ERRRROR : "+e);
}
}
}
运行时生成的日志如上例所述:
>>> ver. 2.1.0#20170720-sha1:a6ca5c8a
>>> 2017 Copyright(C) Apache Software Foundation
>>>
>>> Ignite documentation: http://ignite.apache.org
[2017-08-02 13:52:27,940][INFO ][main][IgniteKernal] Config URL: n/a
[2017-08-02 13:52:27,940][INFO ][main][IgniteKernal] Daemon mode: off
[2017-08-02 13:52:27,940][INFO ][main][IgniteKernal] OS: Linux 4.2.0-42-
generic amd64
[2017-08-02 13:52:27,940][INFO ][main][IgniteKernal] OS user: developers
[2017-08-02 13:52:27,942][INFO ][main][IgniteKernal] PID: 1343
[2017-08-02 13:52:27,942][INFO ][main][IgniteKernal] Language runtime: Java Platform API Specification ver. 1.7
[2017-08-02 13:52:27,943][INFO ][main][IgniteKernal] VM information: OpenJDK Runtime Environment 1.7.0_131-b00 Oracle Corporation OpenJDK 64-Bit Server VM 24.131-b00
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] VM total memory: 1.7GB
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] Remote Management [restart: off, REST: on, JMX (remote: off)]
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] IGNITE_HOME=null
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] VM arguments: [-DIGNITE_QUIET=false, -Dfile.encoding=UTF-8]
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] System cache's MemoryPolicy size is configured to 40 MB. Use MemoryConfiguration.systemCacheMemorySize property to change the setting.
[2017-08-02 13:52:27,944][INFO ][main][IgniteKernal] Configured caches [in 'sysMemPlc' memoryPolicy: ['ignite-sys-cache', 'ignite-hadoop-mr-sys-cache']]
[2017-08-02 13:52:27,955][WARN ][pub-#14%null%][GridDiagnostic] Initial heap size is 123MB (should be no less than 512MB, use -Xms512m -Xmx512m).
[2017-08-02 13:52:28,080][INFO ][main][IgnitePluginProcessor] Configured plugins:
[2017-08-02 13:52:28,080][INFO ][main][IgnitePluginProcessor] ^-- None
[2017-08-02 13:52:28,080][INFO ][main][IgnitePluginProcessor]
[2017-08-02 13:52:28,142][INFO ][main][TcpCommunicationSpi] Successfully bound communication NIO server to TCP port [port=47100, locHost=0.0.0.0/0.0.0.0, selectorsCnt=4, selectorSpins=0, pairedConn=false]
[2017-08-02 13:52:28,150][WARN ][main][TcpCommunicationSpi] Message queue limit is set to 0 which may lead to potential OOMEs when running cache operations in FULL_ASYNC or PRIMARY_SYNC modes due to message queues growth on sender and receiver sides.
[2017-08-02 13:52:28,180][WARN ][main][NoopCheckpointSpi] Checkpoints are disabled (to enable configure any GridCheckpointSpi implementation)
[2017-08-02 13:52:28,216][WARN ][main][GridCollisionManager] Collision resolution is disabled (all jobs will be activated upon arrival).
[2017-08-02 13:52:28,217][INFO ][main][IgniteKernal] Security status [authentication=off, tls/ssl=off]
Aug 02, 2017 1:52:28 PM java.util.logging.LogManager$RootLogger log
SEVERE: Failed to resolve default logging config file: config/java.util.logging.properties
[2017-08-02 13:52:28,564][INFO ][main][SqlListenerProcessor] SQL connector processor has started on TCP port 10800
[2017-08-02 13:52:28,621][INFO ][main][GridTcpRestProtocol] Command protocol successfully started [name=TCP binary, host=0.0.0.0/0.0.0.0, port=11211]
[2017-08-02 13:52:28,888][INFO ][main][GridJettyRestProtocol] Command protocol successfully started [name=Jetty REST, host=/0.0.0.0, port=8080]
[2017-08-02 13:52:28,917][WARN ][main][IgniteKernal] Hadoop module will not start due to exception: Failed to resolve Hadoop classpath (please define HADOOP_HOME environment variable and point it to your Hadoop distribution).
[2017-08-02 13:52:28,938][INFO ][main][IgniteKernal] Non-loopback local IPs: 00.00.00.00, fe80:0:0:0:42b0:34ff:febf:6fe%2
[2017-08-02 13:52:28,938][INFO ][main][IgniteKernal] Enabled local MACs: 40B034BF06FE
[2017-08-02 13:52:28,985][INFO ][main][TcpDiscoverySpi] Successfully bound to TCP port [port=47500, localHost=0.0.0.0/0.0.0.0, locNodeId=ee678636-f45e-4c8a-856d-c339fef7a29c]
[2017-08-02 13:52:28,990][WARN ][main][TcpDiscoveryMulticastIpFinder] TcpDiscoveryMulticastIpFinder has no pre-configured addresses (it is recommended in production to specify at least one address in TcpDiscoveryMulticastIpFinder.getAddresses() configuration property)
[2017-08-02 13:52:30,269][INFO ][exchange-worker-#34%null%][time] Started exchange init [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=0], crd=true, evt=10, node=TcpDiscoveryNode [id=ee678636-f45e-4c8a-856d-c339fef7a29c, addrs=[0:0:0:0:0:0:0:1%1, 00.00.00.00, 127.0.0.1], sockAddrs=[/00.00.00.00:47500, /127.0.0.1:47500, /0:0:0:0:0:0:0:1%1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1501662148985, loc=true, ver=2.1.0#20170720-sha1:a6ca5c8a, isClient=false], evtNode=TcpDiscoveryNode [id=ee678636-f45e-4c8a-856d-c339fef7a29c, addrs=[0:0:0:0:0:0:0:1%1, 00.00.00.00, 127.0.0.1], sockAddrs=[/00.00.00.00:47500, /127.0.0.1:47500, /0:0:0:0:0:0:0:1%1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1501662148985, loc=true, ver=2.1.0#20170720-sha1:a6ca5c8a, isClient=false], customEvt=null]
[2017-08-02 13:52:30,276][WARN ][exchange-worker-#34%null%][IgniteCacheDatabaseSharedManager] No user-defined default MemoryPolicy found; system default of 1GB size will be used.
[2017-08-02 13:52:30,576][INFO ][exchange-worker-#34%null%][GridCacheProcessor] Started cache [name=ignite-sys-cache, memoryPolicyName=sysMemPlc, mode=REPLICATED, atomicity=TRANSACTIONAL]
[2017-08-02 13:52:30,579][INFO ][exchange-worker-#34%null%][GridCacheProcessor] Started cache [name=ignite-hadoop-mr-sys-cache, memoryPolicyName=sysMemPlc, mode=REPLICATED, atomicity=TRANSACTIONAL]
[2017-08-02 13:52:30,606][INFO ][exchange-worker-#34%null%][GridDhtPartitionsExchangeFuture] Finished waiting for partition release future [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=0], waitTime=0ms]
[2017-08-02 13:52:30,687][INFO ][exchange-worker-#34%null%][GridDhtPartitionsExchangeFuture] Snapshot initialization completed [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=0], time=0ms]
[2017-08-02 13:52:30,700][INFO ][exchange-worker-#34%null%][time] Finished exchange init [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=0], crd=true]
[2017-08-02 13:52:30,707][INFO ][exchange-worker-#34%null%][GridCachePartitionExchangeManager] Skipping rebalancing (nothing scheduled) [top=AffinityTopologyVersion [topVer=1, minorTopVer=0], evt=NODE_JOINED, node=ee678636-f45e-4c8a-856d-c339fef7a29c]
[2017-08-02 13:52:30,783][INFO ][main][IgniteKernal] Performance suggestions for grid (fix if possible)
[2017-08-02 13:52:30,783][INFO ][main][IgniteKernal] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[2017-08-02 13:52:30,783][INFO ][main][IgniteKernal] ^-- Switch to the most recent 1.8 JVM version
[2017-08-02 13:52:30,783][INFO ][main][IgniteKernal] ^-- Specify JVM heap max size (add '-Xmx<size>[g|G|m|M|k|K]' to JVM options)
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal] ^-- Set max direct memory size if getting 'OOME: Direct buffer memory' (add '-XX:MaxDirectMemorySize=<size>[g|G|m|M|k|K]' to JVM options)
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal] ^-- Disable processing of calls to System.gc() (add '-XX:+DisableExplicitGC' to JVM options)
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal] Refer to this page for more performance suggestions: https://apacheignite.readme.io/docs/jvm-and-system-tuning
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal]
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat}
[2017-08-02 13:52:30,784][INFO ][main][IgniteKernal]
[2017-08-02 13:52:30,785][INFO ][main][IgniteKernal]
>>> +----------------------------------------------------------------------+
>>> Ignite ver. 2.1.0#20170720-sha1:a6ca5c8a97e9a4c9d73d40ce76d1504c14ba1940
>>> +----------------------------------------------------------------------+
>>> OS name: Linux 4.2.0-42-generic amd64
>>> CPU(s): 4
>>> Heap: 1.7GB
>>> VM name: 1343@localhost
>>> Local node [ID=EE678636-F45E-4C8A-856D-C339FEF7A29C, order=1, clientMode=false]
>>> Local node addresses: [00.00.00.00/0:0:0:0:0:0:0:1%1, /00.00.00.00, /127.0.0.1]
>>> Local ports: TCP:8080 TCP:10800 TCP:11211 TCP:47100 UDP:47400 TCP:47500
[2017-08-02 13:52:30,786][INFO ][main][GridDiscoveryManager] Topology snapshot [ver=1, servers=1, clients=0, CPUs=4, heap=1.7GB]
>>> Cache events example started.
[2017-08-02 13:52:30,802][INFO ][exchange-worker-#34%null%][time] Started exchange init [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=1], crd=true, evt=18, node=TcpDiscoveryNode [id=ee678636-f45e-4c8a-856d-c339fef7a29c, addrs=[0:0:0:0:0:0:0:1%1, 00.00.00.00, 127.0.0.1], sockAddrs=[/00.00.00.00:47500, /127.0.0.1:47500, /0:0:0:0:0:0:0:1%1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1501662148985, loc=true, ver=2.1.0#20170720-sha1:a6ca5c8a, isClient=false], evtNode=TcpDiscoveryNode [id=ee678636-f45e-4c8a-856d-c339fef7a29c, addrs=[0:0:0:0:0:0:0:1%1, 00.00.00.00, 127.0.0.1], sockAddrs=[/00.00.00.00:47500, /127.0.0.1:47500, /0:0:0:0:0:0:0:1%1:47500], discPort=47500, order=1, intOrder=1, lastExchangeTime=1501662148985, loc=true, ver=2.1.0#20170720-sha1:a6ca5c8a, isClient=false], customEvt=DynamicCacheChangeBatch [id=0d3f902ad51-474b0be6-3ed8-4797-9c9e-9a2166009164, reqs=[DynamicCacheChangeRequest [cacheName=CACHE, hasCfg=true, nodeId=ee678636-f45e-4c8a-856d-c339fef7a29c, clientStartOnly=false, stop=false, destroy=false]], exchangeActions=ExchangeActions [startCaches=[CACHE], stopCaches=null, startGrps=[CACHE], stopGrps=[], resetParts=null, stateChangeRequest=null], startCaches=false]]
[2017-08-02 13:52:30,844][INFO ][exchange-worker-#34%null%][GridCacheProcessor] Started cache [name=CACHE, memoryPolicyName=default, mode=PARTITIONED, atomicity=ATOMIC]
[2017-08-02 13:52:30,846][INFO ][exchange-worker-#34%null%][GridDhtPartitionsExchangeFuture] Finished waiting for partition release future [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=1], waitTime=0ms]
[2017-08-02 13:52:30,963][INFO ][exchange-worker-#34%null%][GridDhtPartitionsExchangeFuture] Snapshot initialization completed [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=1], time=0ms]
after cache create
[2017-08-02 13:52:30,964][INFO ][exchange-worker-#34%null%][time] Finished exchange init [topVer=AffinityTopologyVersion [topVer=1, minorTopVer=1], crd=true]
after local listener
After remote listener
[2017-08-02 13:52:30,975][INFO ][exchange-worker-#34%null%][GridCachePartitionExchangeManager] Skipping rebalancing (nothing scheduled) [top=AffinityTopologyVersion [topVer=1, minorTopVer=1], evt=DISCOVERY_CUSTOM_EVT, node=ee678636-f45e-4c8a-856d-c339fef7a29c]
[2017-08-02 13:52:30,979][WARN ][main][GridEventStorageManager] Added listener for disabled event type: CACHE_OBJECT_PUT
[2017-08-02 13:52:30,979][WARN ][main][GridEventStorageManager] Added listener for disabled event type: CACHE_OBJECT_READ
[2017-08-02 13:52:30,979][WARN ][main][GridEventStorageManager] Added listener for disabled event type: CACHE_OBJECT_REMOVED
您使用默认配置xml文件启动了Ignite。默认情况下,所有事件都是禁用的,必须专门启用。因此,使用“examples/config/example-ignite.xml”开始Ignite,就像您更改之前在examples中一样:
Ignite ignite = Ignition.start("examples/config/example-ignite.xml")
或者,您可以创建自己的配置并在其中启用某些事件:
<property name="includeEventTypes">
<list>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_PUT"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_READ"/>
<util:constant static-field="org.apache.ignite.events.EventType.EVT_CACHE_OBJECT_REMOVED"/>
</list>
</property>
我正在尝试从事件中心读取数据,但结果它只返回空值。 我将一个数据帧转换为json以发送到eventhub 这是数据的模式 我正在尝试使用从eventhub读取数据 从 pyspark.sql.类型导入数组类型, 双类型, 结构类型, 结构字段, 字符串类型, 长类型, 布尔类型
我是Windows用户。这是我的yarn-site.xml配置,还有一件事是,在手动运行这个项目之前,我只启动数据节点和名称节点,而不是通过start-all.cmd命令,还有其他需要启动的吗?只是我的想法,如资源管理器等。 yarn-site.xml
问题内容: 这是我的代码。我正在尝试使用箭头键使球移动。当我运行上述程序时 ,不显示球 ( 如果我将坐标更改为显示0,30球), 并且事件未触发,球既不移动也不跳跃 ? 问题答案:
问题内容: 我正在使用Java运行这个命令。脚本正在运行,但它没有将流重定向到文件。此外,文件没有被创建。 如果我在shell上运行这个脚本,它运行得很好。 有什么想法吗? 问题答案: 你需要使用重定向。
问题内容: 得到反馈后,我运行该程序,但在控制台中没有任何输出 程序运行,但不输出。 问题答案: 是一种阻止方法。它会等到进程退出后再返回。这样做的问题是,许多程序只有在读取/清除标准输出缓冲区后才会退出,这意味着,就您而言,它可能永远不会退出。 尝试这样的事情…
我希望看到输出正在打印(而不是在测试结束后)。 我在用Pycharm。在命令行中,我应该添加参数。