Here are the examples of the java api org.apache.ignite.Ignite taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
183 Examples
19
Source : IgniteInstance.java
with Apache License 2.0
from mini188
with Apache License 2.0
from mini188
public clreplaced IgniteInstance {
private static IgniteInstance _instance = new IgniteInstance();
private Ignite ignite;
private IgniteInstance() {
}
public synchronized static IgniteInstance getInstance() {
return _instance;
}
public synchronized Ignite getIgnite() {
if (ignite == null) {
ignite = Ignition.start();
}
return ignite;
}
}
19
Source : IgniteCacheResolver.java
with Apache License 2.0
from MarcGiffing
with Apache License 2.0
from MarcGiffing
public clreplaced IgniteCacheResolver implements AsyncCacheResolver {
private Ignite ignite;
public IgniteCacheResolver(Ignite ignite) {
this.ignite = ignite;
}
@Override
public ProxyManager<String> resolve(String cacheName) {
org.apache.ignite.IgniteCache<String, GridBucketState> cache = ignite.cache(cacheName);
return Bucket4j.extension(io.github.bucket4j.grid.ignite.Ignite.clreplaced).proxyManagerForCache(cache);
}
}
19
Source : TestMapReduceOSHDBIgnite.java
with GNU Lesser General Public License v3.0
from GIScience
with GNU Lesser General Public License v3.0
from GIScience
abstract clreplaced TestMapReduceOSHDBIgnite extends TestMapReduce {
static final Ignite ignite;
static {
int rndPort = 47577 + (int) (Math.random() * 1000);
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClreplacedLoadingEnabled(true);
cfg.setIgniteInstanceName("OSHDB-Unit-Tests_" + rndPort);
cfg.setBinaryConfiguration((new BinaryConfiguration()).setCompactFooter(false));
cfg.setGridLogger(new Slf4jLogger());
cfg.setWorkDirectory("/tmp");
cfg.setDiscoverySpi((new TcpDiscoverySpi()).setLocalPort(rndPort).setLocalPortRange(0).setIpFinder((new TcpDiscoveryVmIpFinder()).setAddresses(List.of("127.0.0.1:" + rndPort))));
ignite = Ignition.start(cfg);
}
public TestMapReduceOSHDBIgnite(OSHDBIgnite oshdb) throws Exception {
super(oshdb);
final String prefix = "tests";
oshdb.prefix(prefix);
OSHDBH2 oshdbH2 = new OSHDBH2("./src/test/resources/test-data");
this.keytables = oshdbH2;
Ignite ignite = ((OSHDBIgnite) this.oshdb).getIgnite();
ignite.cluster().state(ClusterState.ACTIVE);
CacheConfiguration<Long, GridOSHNodes> cacheCfg = new CacheConfiguration<>(TableNames.T_NODES.toString(prefix));
cacheCfg.setStatisticsEnabled(true);
cacheCfg.setBackups(0);
cacheCfg.setCacheMode(CacheMode.PARreplacedIONED);
IgniteCache<Long, GridOSHNodes> cache = ignite.getOrCreateCache(cacheCfg);
cache.clear();
// dummy caches for ways+relations (at the moment we don't use them in the actual TestMapReduce)
ignite.getOrCreateCache(new CacheConfiguration<>(TableNames.T_WAYS.toString(prefix)));
ignite.getOrCreateCache(new CacheConfiguration<>(TableNames.T_RELATIONS.toString(prefix)));
// load test data into ignite cache
try (IgniteDataStreamer<Long, GridOSHNodes> streamer = ignite.dataStreamer(cache.getName())) {
Connection h2Conn = oshdbH2.getConnection();
Statement h2Stmt = h2Conn.createStatement();
streamer.allowOverwrite(true);
try (final ResultSet rst = h2Stmt.executeQuery("select level, id, data from " + TableNames.T_NODES.toString())) {
while (rst.next()) {
final int level = rst.getInt(1);
final long id = rst.getLong(2);
final ObjectInputStream ois = new ObjectInputStream(rst.getBinaryStream(3));
final GridOSHNodes grid = (GridOSHNodes) ois.readObject();
streamer.addData(CellId.getLevelId(level, id), grid);
}
} catch (IOException | ClreplacedNotFoundException e) {
e.printStackTrace();
fail(e.toString());
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
fail(e.toString());
}
ignite.cluster().state(ClusterState.ACTIVE_READ_ONLY);
}
}
19
Source : MockIgniteServer.java
with GNU General Public License v2.0
from futurewei-cloud
with GNU General Public License v2.0
from futurewei-cloud
public clreplaced MockIgniteServer {
private static final String LOCAL_ADDRESS = "127.0.0.1";
private static final int LISTEN_PORT = 11801;
private static final int CLIENT_CONNECT_PORT = 10800;
private static final int LISTEN_PORT_RANGE = 10;
private static Ignite igniteServer = null;
@BeforeClreplaced
public static void init() {
if (igniteServer == null) {
try {
org.apache.ignite.configuration.IgniteConfiguration cfg = new org.apache.ignite.configuration.IgniteConfiguration();
// make this ignite server isolated
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(Collections.singletonList(LOCAL_ADDRESS + ":" + LISTEN_PORT + ".." + (LISTEN_PORT + LISTEN_PORT_RANGE)));
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
tcpDiscoverySpi.setIpFinder(ipFinder);
tcpDiscoverySpi.setLocalAddress(LOCAL_ADDRESS);
tcpDiscoverySpi.setLocalPort(LISTEN_PORT);
tcpDiscoverySpi.setLocalPortRange(LISTEN_PORT_RANGE);
cfg.setDiscoverySpi(tcpDiscoverySpi);
// cfg.setPeerClreplacedLoadingEnabled(true);
ClientConnectorConfiguration clientConfig = new ClientConnectorConfiguration();
clientConfig.setPort(CLIENT_CONNECT_PORT);
cfg.setClientConnectorConfiguration(clientConfig);
igniteServer = Ignition.start(cfg);
// Properties properties = System.getProperties();
// properties.setProperty("ignite.port", String.valueOf(ListenPort));
} catch (IgniteException e) {
throw new RuntimeException(e);
}
}
}
@AfterClreplaced
public static void close() {
// if(igniteServer != null){
// igniteServer.close();
// igniteServer = null;
// }
}
public static Ignite getIgnite() {
// if no need create a real ignite server, we return a mock Ignite client
return Objects.requireNonNullElseGet(igniteServer, IgniteNodeClientMock::new);
}
/**
* mock a {@link Ignite} clreplaced for unit test
*/
private static clreplaced IgniteNodeClientMock extends IgniteKernal {
public IgniteNodeClientMock() {
}
@Override
public <K, V> IgniteCache<K, V> getOrCreateCache(String cacheName) {
return new IgniteCacheProxyImpl();
}
@Override
public <K, V> IgniteCache<K, V> getOrCreateCache(CacheConfiguration<K, V> cacheCfg) {
return new IgniteCacheProxyImpl();
}
}
}
19
Source : IgniteCacheFactory.java
with GNU General Public License v2.0
from futurewei-cloud
with GNU General Public License v2.0
from futurewei-cloud
public clreplaced IgniteCacheFactory implements ICacheFactory {
private final Ignite ignite;
private final int tryLockInterval;
private final int expireTime;
public IgniteCacheFactory(Ignite ignite, int interval, int expire) {
this.ignite = ignite;
this.tryLockInterval = interval;
this.expireTime = expire;
}
@Override
public <K, V> ICache<K, V> getCache(Clreplaced<V> v) {
return new IgniteDbCache<>(ignite, v.getName());
}
@Override
public <K, V> ICache<K, V> getCache(Clreplaced<V> v, String cacheName) {
return new IgniteDbCache<>(ignite, cacheName);
}
@Override
public <K, V> ICache<K, V> getExpireCache(Clreplaced<V> v, long timeout, TimeUnit timeUnit) {
ExpiryPolicy ep = CreatedExpiryPolicy.factoryOf(new Duration(timeUnit, timeout)).create();
return new IgniteDbCache<K, V>(ignite, v.getName(), ep);
}
@Override
public <V> IDistributedLock getDistributedLock(Clreplaced<V> t) {
return new IgniteDistributedLock(ignite, LOCK_PREFIX + t.getName(), this.tryLockInterval, this.expireTime);
}
@Override
public Transaction getTransaction() {
return new IgniteTransaction(ignite);
}
}
19
Source : IgniteConfig.java
with Apache License 2.0
from cording
with Apache License 2.0
from cording
@Bean
@ConditionalOnMissingBean
public Ignite igniteInit() {
/**
* 配置IGNITE_HOME
*/
// igniteCfg.setIgniteHome("D:\\Test");
/**
* 持久化配置
*/
// DataStorageConfiguration dcfg = igniteCfg.getDataStorageConfiguration();
// dcfg.getDefaultDataRegionConfiguration()
// .setMaxSize(4L * 1024 * 1024 * 1024) //设置默认区域的最大可用内存
// .setPersistenceEnabled(true);//默认区域开启持久化
// /**设置持久化路径*/
// dcfg.setStoragePath();
// dcfg.setWalPath();
// dcfg.setWalArchivePath();
Ignite ignite = Ignition.start(igniteCfg);
log.info("-----------ignite service is started.----------");
return ignite;
}
19
Source : StormIgniteStreamerSelfTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests for {@link StormStreamer}.
*/
public clreplaced StormIgniteStreamerSelfTest extends GridCommonAbstractTest {
/**
* Cache name.
*/
private static final String TEST_CACHE = "testCache";
/**
* Ignite test configuration file.
*/
private static final String GRID_CONF_FILE = "example-ignite.xml";
/**
* Ignite instance.
*/
private Ignite ignite;
/**
* Parallelization in Storm.
*/
private static final int STORM_EXECUTORS = 2;
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
IgniteConfiguration cfg = loadConfiguration(GRID_CONF_FILE);
cfg.setClientMode(false);
ignite = startGrid("igniteServerNode", cfg);
}
/**
* {@inheritDoc}
*/
@Override
protected void afterTest() throws Exception {
stopAllGrids();
}
/**
* Tests for the streamer bolt. Ignite started in bolt based on what is specified in the configuration file.
*
* @throws TimeoutException
* @throws InterruptedException
*/
@Test
public void testStormStreamerIgniteBolt() throws TimeoutException, InterruptedException {
final StormStreamer<String, String> stormStreamer = new StormStreamer<>();
stormStreamer.setAutoFlushFrequency(10L);
stormStreamer.setAllowOverwrite(true);
stormStreamer.setCacheName(TEST_CACHE);
stormStreamer.setIgniteTupleField(TestStormSpout.IGNITE_TUPLE_FIELD);
stormStreamer.setIgniteConfigFile(GRID_CONF_FILE);
Config daemonConf = new Config();
daemonConf.put(Config.STORM_LOCAL_MODE_ZMQ, false);
MkClusterParam mkClusterParam = new MkClusterParam();
mkClusterParam.setDaemonConf(daemonConf);
mkClusterParam.setSupervisors(4);
final CountDownLatch latch = new CountDownLatch(TestStormSpout.CNT);
IgniteBiPredicate<UUID, CacheEvent> putLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
@Override
public boolean apply(UUID uuid, CacheEvent evt) {
replacedert evt != null;
latch.countDown();
return true;
}
};
final UUID putLsnrId = ignite.events(ignite.cluster().forCacheNodes(TEST_CACHE)).remoteListen(putLsnr, null, EVT_CACHE_OBJECT_PUT);
Testing.withSimulatedTimeLocalCluster(mkClusterParam, new TestJob() {
@Override
public void run(ILocalCluster cluster) throws IOException, InterruptedException {
// Creates a test topology.
TopologyBuilder builder = new TopologyBuilder();
TestStormSpout testStormSpout = new TestStormSpout();
builder.setSpout("test-spout", testStormSpout);
builder.setBolt("ignite-bolt", stormStreamer, STORM_EXECUTORS).shuffleGrouping("test-spout");
StormTopology topology = builder.createTopology();
// Prepares a mock data for the spout.
MockedSources mockedSources = new MockedSources();
mockedSources.addMockData("test-spout", getMockData());
// Prepares the config.
Config conf = new Config();
conf.setMessageTimeoutSecs(10);
IgniteCache<Integer, String> cache = ignite.cache(TEST_CACHE);
CompleteTopologyParam completeTopologyParam = new CompleteTopologyParam();
completeTopologyParam.setTimeoutMs(10000);
completeTopologyParam.setMockedSources(mockedSources);
completeTopologyParam.setStormConf(conf);
// Checks the cache doesn't contain any entries yet.
replacedertEquals(0, cache.size(CachePeekMode.PRIMARY));
Testing.completeTopology(cluster, topology, completeTopologyParam);
// Checks events successfully processed in 20 seconds.
replacedertTrue(latch.await(10, TimeUnit.SECONDS));
ignite.events(ignite.cluster().forCacheNodes(TEST_CACHE)).stopRemoteListen(putLsnrId);
// Validates all entries are in the cache.
replacedertEquals(TestStormSpout.CNT, cache.size(CachePeekMode.PRIMARY));
for (Map.Entry<Integer, String> entry : TestStormSpout.getKeyValMap().entrySet()) replacedertEquals(entry.getValue(), cache.get(entry.getKey()));
}
});
}
/**
* Prepares entry values for test input.
*
* @return Array of entry values.
*/
@NotNull
private static Values[] getMockData() {
final int SIZE = 10;
ArrayList<Values> mockData = new ArrayList<>();
for (int i = 0; i < TestStormSpout.CNT; i += SIZE) mockData.add(new Values(TestStormSpout.getKeyValMap().subMap(i, i + SIZE)));
return mockData.toArray(new Values[mockData.size()]);
}
}
19
Source : GridSpringTransactionManagerSpringBeanSelfTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public clreplaced GridSpringTransactionManagerSpringBeanSelfTest extends GridSpringTransactionManagerAbstractTest {
/**
*/
private Ignite ignite;
/**
*/
private GridSpringTransactionService service;
@Override
public IgniteCacheProxy<Integer, String> cache() {
return new IgniteNodeCacheProxy<>(ignite.cache(CACHE_NAME));
}
@Override
public GridSpringTransactionService service() {
return service;
}
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
ApplicationContext appCtx = new GenericXmlApplicationContext("config/spring-transactions-ignite-spring-bean.xml");
// To produce multiple calls of ApplicationListener::onApplicationEvent
GenericXmlApplicationContext child = new GenericXmlApplicationContext();
child.setParent(appCtx);
child.refresh();
ignite = (Ignite) appCtx.getBean("mySpringBean");
service = (GridSpringTransactionService) appCtx.getBean("gridSpringTransactionService");
}
@Override
protected void afterTest() throws Exception {
super.afterTest();
stopAllGrids();
}
}
19
Source : IgniteNodeProxy.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Implementation of {@link IgniteProxy} that provides access to Ignite cluster through {@link Ignite} instance.
*/
public clreplaced IgniteNodeProxy implements IgniteProxy {
/**
* {@link Ignite} instance to which operations are delegated.
*/
protected final Ignite ignite;
/**
*/
public IgniteNodeProxy(Ignite ignite) {
this.ignite = ignite;
}
/**
* {@inheritDoc}
*/
@Override
public <K, V> IgniteCacheProxy<K, V> getOrCreateCache(String name) {
return new IgniteNodeCacheProxy<>(ignite.getOrCreateCache(name));
}
/**
* {@inheritDoc}
*/
@Override
public <K, V> IgniteCacheProxy<K, V> cache(String name) {
IgniteCache<K, V> cache = ignite.cache(name);
return cache == null ? null : new IgniteNodeCacheProxy<>(cache);
}
/**
* @return {@link Ignite} instance to which operations are delegated.
*/
public Ignite delegate() {
return ignite;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object other) {
if (this == other)
return true;
if (other == null || getClreplaced() != other.getClreplaced())
return false;
return Objects.equals(ignite, ((IgniteNodeProxy) other).ignite);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return ignite.hashCode();
}
}
19
Source : SpringCacheTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests for {@link SpringCache}
*/
public clreplaced SpringCacheTest extends GridCommonAbstractTest {
/**
*/
private static Ignite ignite;
/**
* Wrapped cache.
*/
private IgniteCache nativeCache;
/**
* Working cache.
*/
private SpringCache springCache;
/**
*/
private String cacheName;
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
ignite = startGrid();
}
/**
* {@inheritDoc}
*/
@Override
protected void afterTestsStopped() throws Exception {
G.stop(true);
}
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
protected void beforeTest() throws Exception {
super.beforeTest();
cacheName = String.valueOf(System.currentTimeMillis());
nativeCache = ignite.getOrCreateCache(cacheName);
springCache = new SpringCache(new IgniteNodeCacheProxy<>(nativeCache), null);
}
/**
* {@inheritDoc}
*/
@Override
protected void afterTest() throws Exception {
super.afterTest();
ignite.destroyCache(cacheName);
}
/**
* @throws Exception If failed.
*/
@Test
public void testGetName() throws Exception {
replacedertEquals(cacheName, springCache.getName());
}
/**
* @throws Exception If failed.
*/
@Test
public void testGetNativeCache() throws Exception {
replacedertEquals(nativeCache, springCache.getNativeCache());
}
/**
* @throws Exception If failed.
*/
@Test
public void testGetByKey() throws Exception {
String key = "key";
String value = "value";
springCache.put(key, value);
replacedertEquals(value, springCache.get(key).get());
replacedertNull(springCache.get("wrongKey"));
}
/**
* @throws Exception If failed.
*/
@Test
public void testGetByKeyType() throws Exception {
String key = "key";
String value = "value";
springCache.put(key, value);
replacedertEquals(value, springCache.get(key, String.clreplaced));
try {
springCache.get(key, Integer.clreplaced);
fail("Missing exception");
} catch (Exception e) {
replacedertTrue(e.getMessage().startsWith("Cached value is not of required type [cacheName=" + cacheName));
}
}
/**
* @throws Exception If failed.
*/
@Test
public void testPut() throws Exception {
String key = "key";
replacedertNull(springCache.get(key));
String value = "value";
springCache.put(key, value);
replacedertEquals(value, springCache.get(key).get());
}
/**
* @throws Exception If failed.
*/
@Test
public void testPutIfAbsent() throws Exception {
String key = "key";
String expected = "value";
replacedertNull(springCache.putIfAbsent(key, expected));
replacedertEquals(expected, springCache.putIfAbsent(key, "wrongValue").get());
replacedertEquals(expected, springCache.get(key).get());
}
/**
* @throws Exception If failed.
*/
@Test
public void testEvict() throws Exception {
String key = "key";
replacedertNull(springCache.get(key));
springCache.put(key, "value");
replacedertNotNull(springCache.get(key));
springCache.evict(key);
replacedertNull(springCache.get(key));
}
/**
* @throws Exception If failed.
*/
@Test
public void testClear() throws Exception {
String key;
springCache.put((key = "key1"), "value1");
replacedertNotNull(springCache.get(key));
springCache.put((key = "key2"), "value2");
replacedertNotNull(springCache.get(key));
springCache.put((key = "key3"), "value3");
replacedertNotNull(springCache.get(key));
springCache.clear();
replacedertNull(springCache.get("key1"));
replacedertNull(springCache.get("key2"));
replacedertNull(springCache.get("key3"));
}
}
19
Source : PubSubStreamerSelfTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests for {@link PubSubStreamer}.
*/
public clreplaced PubSubStreamerSelfTest {
/**
* Cache name.
*/
private static final String DEFAULT_CACHE_NAME = "testCache";
/**
* Ignite test configuration file.
*/
private static final String GRID_CONF_FILE = "config/example-ignite.xml";
/**
* Subscription Name.
*/
private static final String SUBSCRIPTION = "ignite_subscription";
/**
* Count.
*/
private static final int CNT = 100;
/**
* Messages per request.
*/
private static final int MESSAGES_PER_REQUEST = 10;
/**
* Topic message key prefix.
*/
private static final String KEY_PREFIX = "192.168.2.";
/**
* Topic message value URL.
*/
private static final String VALUE_URL = ",www.example.com,";
/**
*/
private static final String JSON_KEY = "key";
/**
*/
private static final String JSON_VALUE = "value";
/**
*/
private Ignite ignite;
/**
*/
private static MockPubSubServer mockPubSubServer = new MockPubSubServer();
@Before
public void beforeTest() throws InterruptedException {
this.ignite = Ignition.start(GRID_CONF_FILE);
IgniteCache<Integer, String> igniteCache = ignite.getOrCreateCache(defaultCacheConfiguration());
}
@After
public void afterTest() {
ignite.cache(DEFAULT_CACHE_NAME).clear();
Ignition.stop(true);
}
/**
* @return New cache configuration with modified defaults.
*/
public static CacheConfiguration<Integer, String> defaultCacheConfiguration() {
CacheConfiguration cfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
cfg.setAtomicityMode(ATOMIC);
cfg.setWriteSynchronizationMode(FULL_SYNC);
return cfg;
}
/**
* Tests Pub/Sub streamer.
*
* @throws TimeoutException If timed out.
* @throws InterruptedException If interrupted.
*/
@Test
public void testPubSubStreamer() throws Exception {
Map<String, String> keyValMap = produceStream();
consumerStream(ProjectTopicName.of(MockPubSubServer.PROJECT, MockPubSubServer.TOPIC_NAME), keyValMap);
}
/**
* Consumes Pub/Sub stream via Ignite.
*
* @param topic Topic name.
* @param keyValMap Expected key value map.
* @throws TimeoutException If timed out.
* @throws InterruptedException If interrupted.
*/
private void consumerStream(ProjectTopicName topic, Map<String, String> keyValMap) throws InterruptedException, IOException {
PubSubStreamer<String, String> pubSubStmr = null;
try (IgniteDataStreamer<String, String> stmr = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
stmr.allowOverwrite(true);
stmr.autoFlushFrequency(MESSAGES_PER_REQUEST);
// Configure Pub/Sub streamer.
pubSubStmr = new PubSubStreamer<>();
// Get the cache.
IgniteCache<String, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
// Set Ignite instance.
pubSubStmr.setIgnite(ignite);
// Set data streamer instance.
pubSubStmr.setStreamer(stmr);
// Set the topic.
pubSubStmr.setTopic(Arrays.asList(topic));
// Set subscription name
pubSubStmr.setSubscriptionName(ProjectSubscriptionName.format(PROJECT, SUBSCRIPTION));
// Set the number of threads.
pubSubStmr.setThreads(4);
// Set the SubScriber Stub settings.
pubSubStmr.setSubscriberStubSettings(mockPubSubServer.createSubscriberStub());
pubSubStmr.setSingleTupleExtractor(singleTupleExtractor());
final CountDownLatch latch = new CountDownLatch(CNT);
IgniteBiPredicate<UUID, CacheEvent> locLsnr = new IgniteBiPredicate<UUID, CacheEvent>() {
@IgniteInstanceResource
private Ignite ig;
@LoggerResource
private IgniteLogger log;
/**
* {@inheritDoc}
*/
@Override
public boolean apply(UUID uuid, CacheEvent evt) {
latch.countDown();
if (log.isInfoEnabled()) {
IgniteEx igEx = (IgniteEx) ig;
UUID nodeId = igEx.localNode().id();
log.info("Receive event=" + evt + ", nodeId=" + nodeId);
}
return true;
}
};
ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).remoteListen(locLsnr, null, EVT_CACHE_OBJECT_PUT);
// Start Pub/Sub streamer.
pubSubStmr.start();
// Checks all events successfully processed in 10 seconds.
replacedertTrue("Failed to wait latch completion, still wait " + latch.getCount() + " events", latch.await(10, TimeUnit.SECONDS));
for (Map.Entry<String, String> entry : keyValMap.entrySet()) replacedertEquals(entry.getValue(), cache.get(entry.getKey()));
} finally {
if (pubSubStmr != null)
pubSubStmr.stop();
}
}
/**
* Sends messages to Pub/Sub.
*
* @return Map of key value messages.
*/
private Map<String, String> produceStream() throws Exception {
List<Integer> subnet = new ArrayList<>();
for (int i = 1; i <= CNT; i++) subnet.add(i);
Collections.shuffle(subnet);
List<PubsubMessage> messages = new ArrayList<>();
Map<String, String> keyValMap = new HashMap<>();
for (int evt = 0; evt < CNT; evt++) {
long runtime = System.currentTimeMillis();
String ip = KEY_PREFIX + subnet.get(evt);
String msg = runtime + VALUE_URL + ip;
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty(JSON_KEY, ip);
jsonObject.addProperty(JSON_VALUE, msg);
ByteString byteString = ByteString.copyFrom(jsonObject.toString(), Charset.defaultCharset());
PubsubMessage pubsubMessage = PubsubMessage.newBuilder().setData(byteString).build();
messages.add(pubsubMessage);
String messageId = mockPubSubServer.getPublisher(TOPIC_NAME).publish(pubsubMessage).get();
keyValMap.put(ip, msg);
}
return keyValMap;
}
/**
* @return {@link StreamSingleTupleExtractor} for testing.
*/
private static StreamSingleTupleExtractor<PubsubMessage, String, String> singleTupleExtractor() {
return new StreamSingleTupleExtractor<PubsubMessage, String, String>() {
@Override
public Map.Entry<String, String> extract(PubsubMessage msg) {
String dataStr = msg.getData().toStringUtf8();
JsonElement jsonElement = new JsonParser().parse(dataStr).getAsJsonObject();
JsonObject jsonObject = jsonElement.getAsJsonObject();
return new GridMapEntry<>(jsonObject.get(JSON_KEY).getreplacedtring(), jsonObject.get(JSON_VALUE).getreplacedtring());
}
};
}
/**
* @return {@link StreamMultipleTupleExtractor} for testing.
*/
private static StreamMultipleTupleExtractor<PubsubMessage, String, String> multipleTupleExtractor() {
return new StreamMultipleTupleExtractor<PubsubMessage, String, String>() {
@Override
public Map<String, String> extract(PubsubMessage msg) {
String dataStr = msg.getData().toStringUtf8();
JsonElement jsonElement = new JsonParser().parse(dataStr).getAsJsonObject();
JsonArray jsonArray = jsonElement.getAsJsonArray();
final Map<String, String> answer = new HashMap<>();
for (int i = 0; i < jsonArray.size(); i++) {
JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
String key = jsonObject.get(JSON_KEY).getreplacedtring();
String value = jsonObject.get(JSON_VALUE).getreplacedtring();
answer.put(key, value);
}
return answer;
}
};
}
}
19
Source : IgniteSource.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Sets Ignite instance.
*
* @param ignite Ignite instance.
*/
public void setIgnite(Ignite ignite) {
this.ignite = ignite;
}
19
Source : IgniteSetComponentConfiguration.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public void setIgnite(Ignite ignite) {
this.ignite = ignite;
}
19
Source : Components.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Produces
@ApplicationScoped
@Unremovable
@Named("ignite-set")
IgniteSetComponent igniteIgniteSetComponent() {
final Ignite ignite = Mockito.mock(Ignite.clreplaced);
return IgniteSetComponent.fromIgnite(ignite);
}
18
Source : CustomMqttClientIgnite.java
with Mozilla Public License 2.0
from xjc-opensource
with Mozilla Public License 2.0
from xjc-opensource
/**
* @author ben
* @replacedle: basic
* @Description:
*/
public clreplaced CustomMqttClientIgnite extends CustomMqttClient {
@Resource
private Ignite ignite;
@Override
public void init(MqttClient nettyClient) {
super.init(nettyClient);
String clientId = nettyClient.mqttOptions().getClientIdentifier();
CacheList<MessageData> consumerCache = new CacheListIgnite<MessageData>("mqttclient-consumer-" + clientId, ignite);
CacheList<MessageData> procedureCache = new CacheListIgnite<MessageData>("mqttclient-procedure-" + clientId, ignite);
CacheList<UniqueIdInteger> idCache = new CacheListIgnite<UniqueIdInteger>("mqttclient-gid-" + clientId, ignite);
nettyClient.consumer().setGlobalUniqueIdCache(idCache);
nettyClient.consumer().setCacheList(consumerCache);
nettyClient.consumer().setConsumerListener(new DefautMqttConsumerListener());
nettyClient.producer().setGlobalUniqueIdCache(idCache);
nettyClient.producer().setCacheList(procedureCache);
}
}
18
Source : AbstractIgniteProcessor.java
with Apache License 2.0
from wangrenlei
with Apache License 2.0
from wangrenlei
/**
* Base clreplaced for Ignite processors
*/
public abstract clreplaced AbstractIgniteProcessor extends AbstractProcessor {
/**
* Ignite spring configuration file
*/
public static final PropertyDescriptor IGNITE_CONFIGURATION_FILE = new PropertyDescriptor.Builder().displayName("Ignite Spring Properties Xml File").name("ignite-spring-properties-xml-file").description("Ignite spring configuration file, <path>/<ignite-configuration>.xml. If the " + "configuration file is not provided, default Ignite configuration " + "configuration is used which binds to 127.0.0.1:47500..47509").required(false).addValidator(StandardValidators.NON_EMPTY_VALIDATOR).build();
/**
* Success relation
*/
public static final Relationship REL_SUCCESS = new Relationship.Builder().name("success").description("All FlowFiles that are written to Ignite cache are routed to this relationship").build();
/**
* Failure relation
*/
public static final Relationship REL_FAILURE = new Relationship.Builder().name("failure").description("All FlowFiles that cannot be written to Ignite cache are routed to this relationship").build();
/**
* The ignite instance
*/
private transient Ignite ignite;
/**
* Get ignite instance
* @return ignite instance
*/
protected Ignite getIgnite() {
return ignite;
}
/**
* Close ignite instance
*/
public void closeIgnite() {
if (ignite != null) {
getLogger().info("Closing ignite client");
ignite.close();
ignite = null;
}
}
/**
* Initialize ignite instance
* @param context process context
*/
public void initializeIgnite(ProcessContext context) {
if (getIgnite() != null) {
getLogger().info("Ignite already initialized");
return;
}
synchronized (Ignition.clreplaced) {
List<Ignite> grids = Ignition.allGrids();
if (grids.size() == 1) {
getLogger().info("Ignite grid already available");
ignite = grids.get(0);
return;
}
Ignition.setClientMode(true);
String configuration = context.getProperty(IGNITE_CONFIGURATION_FILE).getValue();
getLogger().info("Initializing ignite with configuration {} ", new Object[] { configuration });
if (StringUtils.isEmpty(configuration)) {
ignite = Ignition.start();
} else {
ignite = Ignition.start(configuration);
}
}
}
}
18
Source : MovieTerminateCriteria.java
with Apache License 2.0
from techbysample
with Apache License 2.0
from techbysample
/**
* Represents the terminate condition for Movie Genetic algorithm <br/>
*
* Clreplaced terminates Genetic algorithm when fitnessScore > 32 <br/>
*
* <br/>
*
* @author turik.campbell
*/
public clreplaced MovieTerminateCriteria implements ITerminateCriteria {
private IgniteLogger igniteLogger = null;
private Ignite ignite = null;
public MovieTerminateCriteria(Ignite ignite) {
this.ignite = ignite;
this.igniteLogger = ignite.log();
}
public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore, int currentGeneration) {
boolean isTerminate = true;
igniteLogger.info("##########################################################################################");
igniteLogger.info("Generation: " + currentGeneration);
igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
igniteLogger.info("Chromsome: " + fittestChromosome);
printMovies(GAGridUtils.getGenesForChromosome(ignite, fittestChromosome));
igniteLogger.info("##########################################################################################");
if (!(fittestChromosome.getFitnessScore() > 32)) {
isTerminate = false;
}
return isTerminate;
}
/**
* Helper to print change detail
*
* @param genes
*/
private void printMovies(List<Gene> genes) {
for (Gene gene : genes) {
igniteLogger.info("Name: " + ((Movie) gene.getValue()).getName().toString());
igniteLogger.info("Genres: " + ((Movie) gene.getValue()).getGenre().toString());
igniteLogger.info("IMDB Rating: " + ((Movie) gene.getValue()).getImdbRating());
}
}
}
18
Source : HelloWorldTerminateCriteria.java
with Apache License 2.0
from techbysample
with Apache License 2.0
from techbysample
/**
* Represents the terminate condition for HelloWorld Genetic algorithm
*
* Clreplaced terminates Genetic algorithm when fitnessScore > 10
*
* @author turik.campbell
*/
public clreplaced HelloWorldTerminateCriteria implements ITerminateCriteria {
private IgniteLogger igniteLogger = null;
private Ignite ignite = null;
public HelloWorldTerminateCriteria(Ignite ignite) {
this.ignite = ignite;
this.igniteLogger = ignite.log();
}
public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore, int currentGeneration) {
boolean isTerminate = true;
igniteLogger.info("##########################################################################################");
igniteLogger.info("Generation: " + currentGeneration);
igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
igniteLogger.info("Chromosome: " + fittestChromosome);
printPhrase(GAGridUtils.getGenesInOrderForChromosome(ignite, fittestChromosome));
igniteLogger.info("Avg Chromosome Fitness: " + averageFitnessScore);
igniteLogger.info("##########################################################################################");
if (!(fittestChromosome.getFitnessScore() > 10)) {
isTerminate = false;
}
return isTerminate;
}
/**
* Helper to print Phrase
*
* @param genes
*/
private void printPhrase(List<Gene> genes) {
StringBuffer sbPhrase = new StringBuffer();
for (Gene gene : genes) {
sbPhrase.append(((Character) gene.getValue()).toString());
}
igniteLogger.info(sbPhrase.toString());
}
}
18
Source : OptimizeMakeChangeTerminateCriteria.java
with Apache License 2.0
from techbysample
with Apache License 2.0
from techbysample
/**
* Terminate Condition implementation for OptimizeMakeChangeGATest <br/>
*
* @author turik.campbell
*/
public clreplaced OptimizeMakeChangeTerminateCriteria implements ITerminateCriteria {
private IgniteLogger igniteLogger = null;
private Ignite ignite = null;
public OptimizeMakeChangeTerminateCriteria(Ignite ignite) {
this.ignite = ignite;
this.igniteLogger = ignite.log();
}
public boolean isTerminationConditionMet(Chromosome fittestChromosome, double averageFitnessScore, int currentGeneration) {
boolean isTerminate = true;
igniteLogger.info("##########################################################################################");
igniteLogger.info("Generation: " + currentGeneration);
igniteLogger.info("Fittest is Chromosome Key: " + fittestChromosome);
igniteLogger.info("Chromsome: " + fittestChromosome);
printCoins(GAGridUtils.getGenesForChromosome(ignite, fittestChromosome));
igniteLogger.info("Avg Chromsome Fitness: " + averageFitnessScore);
igniteLogger.info("##########################################################################################");
if (!(currentGeneration > 5)) {
isTerminate = false;
}
return isTerminate;
}
/**
* Helper to print change detail
*
* @param genes
*/
private void printCoins(List<Gene> genes) {
for (Gene gene : genes) {
igniteLogger.info("Coin Type: " + ((Coin) gene.getValue()).getCoinType().toString());
igniteLogger.info("Number of Coins: " + ((Coin) gene.getValue()).getNumberOfCoins());
}
}
}
18
Source : GAGridUtils.java
with Apache License 2.0
from techbysample
with Apache License 2.0
from techbysample
/**
* Retrieve chromosomes
*
* @param ignite
* @param query
* @return
*/
public static List<Chromosome> getChromosomes(Ignite ignite, String query) {
List<Chromosome> chromosomes = new ArrayList();
IgniteCache<Long, Chromosome> populationCache = ignite.getOrCreateCache(PopulationCacheConfig.populationCache());
SqlQuery sql = new SqlQuery(Chromosome.clreplaced, query);
try (QueryCursor<Entry<Long, Chromosome>> cursor = populationCache.query(sql)) {
for (Entry<Long, Chromosome> e : cursor) chromosomes.add(e.getValue());
}
return chromosomes;
}
18
Source : IgniteExpiryExample.java
with GNU General Public License v3.0
from srecon
with GNU General Public License v3.0
from srecon
public static void main(String[] args) {
// Start Ignite cluster
Ignite ignite = Ignition.start("default-config.xml");
// get or create cache
IgniteCache<Integer, Person> cache = ignite.getOrCreateCache("testCache");
Person p1 = new Person(37, "Shamim");
Person p2 = new Person(2, "Mishel");
Person p3 = new Person(55, "scott");
Person p4 = new Person(5, "Tiger");
cache.put(1, p1);
cache.put(2, p2);
cache.put(3, p3);
cache.put(4, p4);
System.out.println("Enter crtl-x to quite the application!!!");
}
18
Source : StartCacheNode.java
with GNU General Public License v3.0
from srecon
with GNU General Public License v3.0
from srecon
public static void main(String[] args) {
try (Ignite ignite = Ignition.start("org/book/examples/cache-node-config.xml")) {
System.out.println("Presse ENTER to exit!");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
18
Source : AsyncBankServiceImpl.java
with GNU General Public License v3.0
from srecon
with GNU General Public License v3.0
from srecon
/**
* Created by mikl on 26.10.16.
*/
public clreplaced AsyncBankServiceImpl implements AsyncBankService, Service {
@IgniteInstanceResource
private Ignite ignite;
IgniteCache<AccountCacheKey, AccountCacheData> accountCache;
private String zeroMqBrokerAddress;
public AsyncBankServiceImpl(String zeroMqBrokerAddress) {
this.zeroMqBrokerAddress = zeroMqBrokerAddress;
}
@Override
public void cancel(ServiceContext serviceContext) {
}
@Override
public void init(ServiceContext serviceContext) throws Exception {
accountCache = ignite.getOrCreateCache(BankDataGenerator.ACCOUNT_CACHE);
}
@Override
public void execute(ServiceContext serviceContext) throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
Context context = ZMQ.context(1);
// Socket to talk to server
Socket responder = context.socket(ZMQ.REP);
responder.connect(zeroMqBrokerAddress);
ZMQ.PollItem[] items = { new ZMQ.PollItem(responder, ZMQ.Poller.POLLIN) };
while (!Thread.currentThread().isInterrupted() && !serviceContext.isCancelled()) {
// Wait for next request from client
int rc = ZMQ.poll(items, 1000);
if (rc == -1) {
continue;
}
if (items[0].isReadable()) {
String reqStr = responder.recvStr(0);
System.out.printf("Received request: [%s]\n", reqStr);
ValidateRequest req = objectMapper.readValue(reqStr, ValidateRequest.clreplaced);
ValidateResponse result = validateOperation(req.getAccount(), req.getSum());
System.out.printf("send response request: [%s]\n", result);
responder.send(objectMapper.writeValuereplacedtring(result));
}
}
System.out.println("Stop async read!");
// We never get here but clean up anyhow
responder.close();
context.term();
}
private ValidateResponse validateOperation(String account, BigDecimal sum) {
AccountKey key = new AccountKey(account);
Lock lock = accountCache.lock(key);
try {
lock.lock();
AccountData accountData = (AccountData) accountCache.get(key);
if (accountData == null) {
return ValidateResponse.error("Account not found!");
}
// clean today operations
if (!accountData.getToday().equals(LocalDate.now())) {
accountData.setTodayOperationSum(new BigDecimal(0));
accountData.setToday(LocalDate.now());
accountCache.put(key, accountData);
}
BigDecimal newOperationSum = accountData.getTodayOperationSum().add(sum);
if (newOperationSum.compareTo(accountData.getDailyLimit()) > 0) {
return ValidateResponse.DENIED;
} else {
accountData.setTodayOperationSum(newOperationSum);
accountCache.put(key, accountData);
return ValidateResponse.OK;
}
} finally {
lock.unlock();
}
}
}
18
Source : DataLoaderService.java
with Apache License 2.0
from Romeh
with Apache License 2.0
from Romeh
/**
* Created by romeh on 11/08/2017.
*/
@Service
public clreplaced DataLoaderService {
@Autowired
private Ignite ignite;
@Autowired
private AlertsConfiguration alertsConfig;
@PostConstruct
public void init() {
final Cache<String, AlertConfigEntry> alertsConfigCache = ignite.getOrCreateCache(CacheNames.AlertsConfig.name());
this.alertsConfig.getAlertConfigurations().forEach(alertConfigEnreplacedy -> {
alertsConfigCache.putIfAbsent(alertConfigEnreplacedy.getServiceCode() + "_" + alertConfigEnreplacedy.getErrorCode(), alertConfigEnreplacedy);
});
}
}
18
Source : CleanExpiredAlertsService.java
with Apache License 2.0
from Romeh
with Apache License 2.0
from Romeh
/**
* Created by romeh on 22/08/2017.
*/
@Service
public clreplaced CleanExpiredAlertsService {
private static final Logger logger = LoggerFactory.getLogger(CleanExpiredAlertsService.clreplaced);
@Autowired
Ignite ignite;
@Scheduled(initialDelayString = "${initialDelay}", fixedDelayString = "${fixedDelay}")
public // un comment if u need to test it otherwise it will clear ur alerts cache during startup
void cleanExpiredRecords() {
/* // query the matching records first
logger.debug("Starting the clean up job to clear the expired records");
long towMinutesRange = System.currentTimeMillis()-900000;
final IgniteCache<String, List<AlertEntry>> alertsCache = getAlertsCache();
final String sql = "select * from AlertEntry where timestamp <= ?";
SqlQuery<String,AlertEntry> query = new SqlQuery(AlertEntry.clreplaced,sql);
query.setArgs(towMinutesRange);
final List<Cache.Entry<String, AlertEntry>> toDeleteAlerts = alertsCache.query(query).getAll();
// then call remove all as this will remove the records from the cache and the persistent file system as sql delete will just delete it from the cache layer not the file system
// or the persistent store
if(toDeleteAlerts!=null && !toDeleteAlerts.isEmpty()){
logger.debug("Finished cleaning out {} records",toDeleteAlerts.size());
alertsCache.removeAll(new HashSet(toDeleteAlerts
.stream()
.map(Cache.Entry::getKey)
.collect(Collectors.toList())));
}*/
}
// get alerts cache store
protected IgniteCache<String, List<AlertEntry>> getAlertsCache() {
return ignite.cache(CacheNames.Alerts.name());
}
}
18
Source : DataGridCompute.java
with Apache License 2.0
from Romeh
with Apache License 2.0
from Romeh
/**
* generic utility clreplaced for map reduce call
*/
@Component
public clreplaced DataGridCompute {
@Autowired
private Ignite ignite;
/**
* @param jobs the list of jobs to be distributed into the data grid nodes from the master node
* @param igniteReducer the ignite reducer which will be used to determine the reduction and collection logic
* @param callback the callback to be invoked upon receiving the reduced final response
* @param <R> generic response type from the jobs
* @param <E> generic map reduced response type
* @throws IgniteException
*
* a generic async map reduced call inside ignite compute grid
*/
public <R, E> void executeMapReduceFailFast(Collection<IgniteCallable<R>> jobs, IgniteReducer<R, E> igniteReducer, Consumer<E> callback) throws IgniteException {
// you need to define your cluster group and if any defined in your data grid
IgniteCompute igniteCompute = ignite.compute(ignite.cluster().forPredicate(clusterNode -> !clusterNode.isClient()));
// execute the list of jobs in map reduce fashion and preplaced the custom reducer as well
IgniteFuture<E> future = igniteCompute.callAsync(jobs, igniteReducer);
// then async listen for the result to invoke your post call back
future.listen(result -> callback.accept(result.get()));
}
/**
* @param jobs the list of jobs to be distributed into the data grid nodes from the master node
* @param igniteReducer the ignite reducer which will be used to determine the reduction and collection logic
* @param <R> generic response type from the jobs
* @param <E> generic map reduced response type
* @throws IgniteException
* @return <E> generic map reduced response type
* a generic sync map reduced call inside ignite compute grid
*/
public <R, E> E executeMapReduceFailFastSync(Collection<IgniteCallable<R>> jobs, IgniteReducer<R, E> igniteReducer) throws IgniteException {
// you need to define your cluster group and if any defined in your data grid
IgniteCompute igniteCompute = ignite.compute(ignite.cluster().forPredicate(clusterNode -> !clusterNode.isClient()));
// execute the list of jobs in map reduce fashion and preplaced the custom reducer as well
return igniteCompute.call(jobs, igniteReducer);
}
}
18
Source : JournalStoreInterceptor.java
with Apache License 2.0
from Romeh
with Apache License 2.0
from Romeh
/**
* journal cache interceptor to keep tracking the highest sequence of specific persistent entry every time there is an insert
*/
public clreplaced JournalStoreInterceptor extends CacheInterceptorAdapter<Long, JournalItem> {
@IgniteInstanceResource
private transient Ignite ignite;
@Override
public void onAfterPut(Cache.Entry<Long, JournalItem> entry) {
IgniteCache<String, Long> sequenceNumberTrack = ignite.getOrCreateCache("sequenceNumberTrack");
sequenceNumberTrack.invoke(entry.getValue().getPersistenceId(), (mutableEntry, objects) -> {
if (mutableEntry.exists() && mutableEntry.getValue() != null) {
// if it is less than the new sequence value , use it
if (mutableEntry.getValue() < entry.getKey()) {
mutableEntry.setValue(entry.getKey());
}
} else {
// if does not exist , just use it
mutableEntry.setValue(entry.getKey());
}
// by api design nothing needed here
return null;
});
}
}
18
Source : OSHDBIgnite.java
with GNU Lesser General Public License v3.0
from GIScience
with GNU Lesser General Public License v3.0
from GIScience
/**
* OSHDB database backend connector to a Ignite system.
*/
public clreplaced OSHDBIgnite extends OSHDBDatabase implements AutoCloseable {
public enum ComputeMode {
LocalPeek, ScanQuery, AffinityCall
}
private final transient Ignite ignite;
private ComputeMode computeMode = ComputeMode.LocalPeek;
private IgniteRunnable onCloseCallback = null;
public OSHDBIgnite() {
this(new File("ignite-config.xml"));
}
public OSHDBIgnite(Ignite ignite) {
this.ignite = ignite;
}
public OSHDBIgnite(String igniteConfigFilePath) {
this(new File(igniteConfigFilePath));
}
/**
* Opens a connection to oshdb data stored on an Ignite cluster.
*
* @param igniteConfig ignite configuration file
*/
public OSHDBIgnite(File igniteConfig) {
Ignition.setClientMode(true);
this.ignite = Ignition.start(igniteConfig.toString());
}
@Override
public OSHDBIgnite prefix(String prefix) {
return (OSHDBIgnite) super.prefix(prefix);
}
@Override
public <X extends OSHDBMapReducible> MapReducer<X> createMapReducer(Clreplaced<X> forClreplaced) {
MapReducer<X> mapReducer;
Collection<String> allCaches = this.getIgnite().cacheNames();
Collection<String> expectedCaches = Stream.of(OSMType.values()).map(TableNames::forOSMType).filter(Optional::isPresent).map(Optional::get).map(t -> t.toString(this.prefix())).collect(Collectors.toList());
if (!allCaches.containsAll(expectedCaches)) {
throw new OSHDBTableNotFoundException(Joiner.on(", ").join(expectedCaches));
}
switch(this.computeMode()) {
case LocalPeek:
mapReducer = new MapReducerIgniteLocalPeek<X>(this, forClreplaced);
break;
case ScanQuery:
mapReducer = new MapReducerIgniteScanQuery<X>(this, forClreplaced);
break;
case AffinityCall:
mapReducer = new MapReducerIgniteAffinityCall<X>(this, forClreplaced);
break;
default:
throw new UnsupportedOperationException("Backend not implemented for this compute mode.");
}
return mapReducer;
}
@Override
public String metadata(String property) {
// todo: implement this
return null;
}
public Ignite getIgnite() {
return this.ignite;
}
public void close() {
this.ignite.close();
}
/**
* Sets the compute mode.
*
* @param computeMode the compute mode to be used in calculations on this oshdb backend
* @return this backend
*/
public OSHDBIgnite computeMode(ComputeMode computeMode) {
this.computeMode = computeMode;
return this;
}
/**
* Gets the set compute mode.
*
* @return the currently set compute mode
*/
public ComputeMode computeMode() {
return this.computeMode;
}
/**
* Sets a callback to be executed on all ignite workers after the query has been finished.
*
* <p>This can be used to close connections to (temporary) databases that were used to store or
* retrieve intermediate data.</p>
*
* @param action the callback to execute after a query is done
* @return the current oshdb database object
*/
public OSHDBIgnite onClose(IgniteRunnable action) {
this.onCloseCallback = action;
return this;
}
/**
* Gets the onClose callback.
*
* @return the currently set onClose callback
*/
public Optional<IgniteRunnable> onClose() {
if (this.onCloseCallback == null) {
return Optional.empty();
} else {
return Optional.of(this.onCloseCallback);
}
}
}
18
Source : IgniteTransaction.java
with GNU General Public License v2.0
from futurewei-cloud
with GNU General Public License v2.0
from futurewei-cloud
public clreplaced IgniteTransaction implements Transaction {
private static final Logger logger = LoggerFactory.getLogger();
private final Ignite client;
private org.apache.ignite.transactions.Transaction transaction;
public IgniteTransaction(Ignite client) {
this.client = client;
}
@Override
public Transaction start() throws CacheException {
transaction = client.transactions().txStart(PESSIMISTIC, SERIALIZABLE);
return this;
}
@Override
public void commit() throws CacheException {
try {
transaction.commit();
} catch (IgniteException e) {
logger.log(Level.WARNING, "IgniteTransaction commit error:" + e.getMessage());
throw new CacheException("IgniteTransaction commit error:" + e.getMessage());
}
}
@Override
public void rollback() throws CacheException {
try {
transaction.rollback();
} catch (IgniteException e) {
logger.log(Level.WARNING, "IgniteTransaction rollback error:" + e.getMessage());
throw new CacheException("IgniteTransaction rollback error:" + e.getMessage());
}
}
@Override
public void close() throws CacheException {
if (transaction != null) {
try {
transaction.close();
} catch (IgniteException e) {
logger.log(Level.WARNING, "IgniteTransaction close error: " + e.getMessage());
throw new CacheException("IgniteTransaction close error: " + e.getMessage());
}
}
}
}
18
Source : SqlDataProcessing.java
with Apache License 2.0
from dmagda
with Apache License 2.0
from dmagda
/**
* @param args
*/
public static void main(String[] args) {
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start("config/ignite-config.xml")) {
IgniteCache cityCache = ignite.cache(CITY_CACHE_NAME);
IgniteCache countryCache = ignite.cache(COUNTRY_CACHE_NAME);
IgniteCache languageCache = ignite.cache(COUNTRY_LANGUAGE_CACHE_NAME);
getMostPopulatedCities(countryCache);
getTopCitiesInThreeCountries(countryCache);
getCityDetails(cityCache, 5);
}
}
18
Source : KeyValueDataProcessing.java
with Apache License 2.0
from dmagda
with Apache License 2.0
from dmagda
/**
* @param args
*/
public static void main(String[] args) {
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start("config/ignite-config.xml")) {
IgniteCache<CityKey, City> cityCache = ignite.cache(CITY_CACHE_NAME);
accessCityCache(cityCache);
migrateBetweenCities(ignite, cityCache);
}
}
18
Source : KeyValueBinaryDataProcessing.java
with Apache License 2.0
from dmagda
with Apache License 2.0
from dmagda
/**
* @param args
*/
public static void main(String[] args) {
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start("config/ignite-config.xml")) {
IgniteCache<BinaryObject, BinaryObject> cityCacheBinary = ignite.cache(CITY_CACHE_NAME).withKeepBinary();
accessCityCache(ignite, cityCacheBinary);
migrateBetweenCities(ignite, cityCacheBinary);
}
}
18
Source : IgniteUtil.java
with Apache License 2.0
from cording
with Apache License 2.0
from cording
/**
* @author: cord
* @date: 2019/4/24 0:01
*/
@Component
public clreplaced IgniteUtil {
@Autowired
private Ignite ignite;
/**
* jdbc批量插入
* @param sqls
* @throws SQLException
*/
public void igniteJdbcBatchInsert(String[] sqls) throws SQLException {
String url = "jdbc:ignite:thin://127.0.0.1/";
// Properties properties = new Properties();
// properties.setProperty(IgniteJdbcDriver.PROP_STREAMING, "true");
// properties.setProperty(IgniteJdbcDriver.PROP_STREAMING_ALLOW_OVERWRITE, "true");
// try (Connection conn = DriverManager.getConnection(url, properties)){
try (Connection conn = DriverManager.getConnection(url)) {
Statement statement = conn.createStatement();
statement.execute("set streaming on ordered");
for (String sql : sqls) {
statement.addBatch(sql);
}
statement.executeBatch();
statement.execute("set streaming off");
}
}
private static final int pageSize = 500;
/**
* 将ignite的数据迭代写进关系型数据库
* 相关mapper如下
*
* <insert id="batchInsert" parameterType="java.util.Map">
* insert into ${tableName}
* <foreach collection="fields" item="field" open="(" close=")" separator=",">
* ${field}
* </foreach>
* values
* <foreach collection="nestList" item="item1" separator=",">
* <foreach collection="item1" item="item2" open="(" close=")" separator=",">
* #{item2}
* </foreach>
* </foreach>
* </insert>
* @param tableName
*/
public void loadFromIgniteToDb(String tableName) {
IgniteCache<String, BinaryObject> cache = ignite.cache(tableName.toLowerCase()).withKeepBinary();
if (cache.size() == 0) {
return;
}
String sql = String.format("SELECT * FROM %s", tableName);
try (FieldsQueryCursor<List<?>> qc = cache.query(new SqlFieldsQuery(sql).setLazy(true))) {
int columns = qc.getColumnsCount();
List<String> fields = IntStream.range(0, columns).mapToObj(c -> qc.getFieldName(c)).collect(Collectors.toList());
Map<String, Object> maps = new HashMap<>(2);
maps.put("tableName", tableName.toLowerCase());
maps.put("fields", fields);
Iterator<List<?>> iterator = qc.iterator();
int count = 0;
List<List<?>> data = new ArrayList<>();
while (iterator.hasNext()) {
data.add(iterator.next());
count++;
if (count == pageSize) {
List<List<?>> copy = data;
Map<String, Object> params = new HashMap<>(maps);
if (CollectionUtils.isEmpty(copy)) {
return;
}
params.put("nestList", copy);
// daoService.batchInsertData(params);
count = 0;
data = new ArrayList<>();
}
}
Map<String, Object> params = new HashMap<>(maps);
if (CollectionUtils.isEmpty(data)) {
return;
}
params.put("nestList", data);
// daoService.batchInsertData(params);
// Log.info(String.format("------syn data from ignite to db success, tableName[%s].\n", tableName));
} catch (Exception e) {
// Log.error(String.format("------syn data from ignite to db error, tableName[%s].\n", tableName), e);
}
}
}
18
Source : CacheInit.java
with Apache License 2.0
from cording
with Apache License 2.0
from cording
/**
* @author: cord
* @date: 2019/3/21 21:08
* 主键字段缓存初始化
*/
@Component
public clreplaced CacheInit implements CommandLineRunner {
@Autowired
private Ignite ignite;
@Autowired
private JdbcTemplate jdbcTemplate;
private IgniteCache<String, List<String>> pkFields;
private static final String TABLE_PK_FIELD = "table_pk_field";
/**
* 初始化缓存
*/
@Override
public void run(String... strings) {
pkFields = ignite.getOrCreateCache(new CacheConfiguration<String, List<String>>().setName(TABLE_PK_FIELD).setCacheMode(CacheMode.REPLICATED).setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.HOURS, 3L))));
}
/**
* 根据缓存名获取对应主键字段
* @param cacheName 缓存名
* @return
* @throws SQLException
*/
public List<String> getPkFields(String cacheName) throws SQLException {
List<String> ret = pkFields.get(cacheName);
// 如果cache中有则返回,如果没有则从集群中查询元数据重新获取
if (!CollectionUtils.isEmpty(ret)) {
return ret;
} else {
return queryPkFields(cacheName);
}
}
/**
* 根据缓存名从ignite中获取源数据读取主键相关字段
* @param cacheName 缓存名
* @return
* @throws SQLException
*/
public List<String> queryPkFields(String cacheName) throws SQLException {
// try (Connection connection = jdbcTemplate.getDataSource().getConnection()) {
try (Connection connection = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800,127.0.0.1:10801/")) {
DatabaseMetaData meta = connection.getMetaData();
ResultSet rs = meta.getPrimaryKeys(null, null, cacheName.toUpperCase());
List<String> list = new ArrayList<>();
while (rs.next()) {
String columnName = rs.getString("COLUMN_NAME");
if (columnName.equals("_KEY")) {
// 单个主键
list.add(rs.getString("PK_NAME").toLowerCase());
return list;
} else {
// 联合主键
list.add(columnName.toLowerCase());
}
}
// 如果查到不为空,则将查询结果加入ignite集合并返回,否则返回null
if (!CollectionUtils.isEmpty(list)) {
ignite.cache(TABLE_PK_FIELD).put(cacheName, list);
pkFields = ignite.cache(TABLE_PK_FIELD);
return list;
} else {
return null;
}
}
}
}
18
Source : AffinityMappedController.java
with Apache License 2.0
from cording
with Apache License 2.0
from cording
/**
* @author: cord
* @date: 2018/8/15 23:18
*/
public clreplaced AffinityMappedController {
@Autowired
private Ignite ignite;
private static AtomicBoolean initflag = new AtomicBoolean(false);
@RequestMapping("/testWithAfty")
@ResponseBody
public String testWithAfty(HttpServletRequest request, HttpServletResponse response) {
if (!initflag.get()) {
return "please execute init.";
}
/**
* 用sql查询缓存
*/
System.out.println("=====并置跨缓存查询=====");
long stime = System.nanoTime();
sqlQueryWithJoin();
System.out.format("testWithAfty cost time [%s].\n", System.nanoTime() - stime);
return "all executed.";
}
@RequestMapping("/testNoAfty")
@ResponseBody
public String testNoAfty(HttpServletRequest request, HttpServletResponse response) {
if (!initflag.get()) {
return "please execute init.";
}
/**
* 启用非并置的分布式关联
* 查询映射的节点就会从远程节点通过发送广播或者单播请求的方式获取缺失的数据(本地不存在的数据)
*/
System.out.println("=====非并置跨缓存查询=====");
long stime = System.nanoTime();
sqlQueryWithDistributedJoin();
System.out.format("testNoAfty cost time [%s].\n", System.nanoTime() - stime);
return "all executed.";
}
@RequestMapping("/init")
@ResponseBody
public String affinityInit(HttpServletRequest request, HttpServletResponse response) {
if (initflag.get()) {
return "already init.";
}
/**
* 并置针对的是分区模式的数据
*/
CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>("Organizations");
orgCacheCfg.setCacheMode(CacheMode.PARreplacedIONED).setIndexedTypes(Long.clreplaced, Organization.clreplaced);
CacheConfiguration<PersonKey, Person> colPersonCacheCfg = new CacheConfiguration<>("CollocatedPersons");
colPersonCacheCfg.setCacheMode(CacheMode.PARreplacedIONED).setIndexedTypes(PersonKey.clreplaced, Person.clreplaced);
CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<>("Persons");
personCacheCfg.setCacheMode(CacheMode.PARreplacedIONED).setIndexedTypes(Long.clreplaced, Person.clreplaced);
/**
* 创建缓存
*/
ignite.destroyCache("Organizations");
ignite.destroyCache("CollocatedPersons");
ignite.destroyCache("Persons");
ignite.getOrCreateCache(orgCacheCfg);
ignite.getOrCreateCache(colPersonCacheCfg);
ignite.getOrCreateCache(personCacheCfg);
/**
* *****************************************************************************************
*/
IgniteCache<Long, Organization> orgCache = ignite.cache("Organizations");
// Clear cache before running the example.
orgCache.clear();
// Organizations.
Organization org1 = new Organization("ApacheIgnite");
Organization org2 = new Organization("Other");
orgCache.put(org1.id(), org1);
orgCache.put(org2.id(), org2);
IgniteCache<PersonKey, Person> colPersonCache = ignite.cache("CollocatedPersons");
IgniteCache<Long, Person> personCache = ignite.cache("Persons");
// Clear caches before running the example.
colPersonCache.clear();
personCache.clear();
// People.
Person p1 = new Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.");
Person p2 = new Person(org1, "Jane", "Doe", 1000, "Jane Doe has Bachelor Degree.");
Person p3 = new Person(org2, "John", "Smith", 1000, "John Smith has Bachelor Degree.");
Person p4 = new Person(org2, "Jane", "Smith", 2000, "Jane Smith has Master Degree.");
// Note that in this example we use custom affinity key for Person objects
// to ensure that all persons are collocated with their organizations.
colPersonCache.put(new PersonKey(p1.id, org1.id()), p1);
colPersonCache.put(new PersonKey(p2.id, org1.id()), p2);
colPersonCache.put(new PersonKey(p3.id, org2.id()), p3);
colPersonCache.put(new PersonKey(p4.id, org2.id()), p4);
// These Person objects are not collocated with their organizations.
personCache.put(p1.id, p1);
personCache.put(p2.id, p2);
personCache.put(p3.id, p3);
personCache.put(p4.id, p4);
initflag.set(true);
return "all executed.";
}
/**
* 并置查询
*/
private void sqlQueryWithJoin() {
IgniteCache<PersonKey, Person> cache = ignite.cache("CollocatedPersons");
// ignite.cluster().forRemotes().ignite().cache("CollocatedPersons").lock(1);
/**
* 关联的缓存需要指定模式名(缓存名)
* 例如下面这个sql关联Organization的时候需要加上Organizations作为前缀
* 而Person的缓存Persons会作为默认模式名,所以不需要额外指定
*/
String joinSql = "from Person, \"Organizations\".Organization as org " + "where Person.orgId = org.id " + "and lower(org.name) = lower(?)";
print("Following people are 'ApacheIgnite' employees: ", cache.query(new SqlQuery<PersonKey, Person>(Person.clreplaced, joinSql).setArgs("ApacheIgnite")).getAll());
print("Following people are 'Other' employees: ", cache.query(new SqlQuery<PersonKey, Person>(Person.clreplaced, joinSql).setArgs("Other")).getAll());
}
/**
* 非并置查询
*/
private void sqlQueryWithDistributedJoin() {
IgniteCache<Long, Person> cache = ignite.cache("Persons");
String joinSql = "from Person, \"Organizations\".Organization as org " + "where Person.orgId = org.id " + "and lower(org.name) = lower(?)";
SqlQuery<Long, Person> qry = new SqlQuery<>(Person.clreplaced, joinSql);
/**
* 启用非并置的分布式关联
* 查询映射的节点就会从远程节点通过发送广播或者单播请求的方式获取缺失的数据(本地不存在的数据)
*/
qry.setDistributedJoins(true);
print("Following people are 'ApacheIgnite' employees (distributed join): ", cache.query(qry.setArgs("ApacheIgnite")).getAll());
print("Following people are 'Other' employees (distributed join): ", cache.query(qry.setArgs("Other")).getAll());
}
private static void print(String msg, Iterable<?> col) {
System.out.println(">>> " + msg);
System.out.println(">>> " + col);
}
}
18
Source : IgniteZeroMqStreamerTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* @return Cache listener.
*/
private CacheListener subscribeToPutEvents() {
Ignite ignite = grid();
// Listen to cache PUT events and expect as many as messages as test data items.
CacheListener listener = new CacheListener();
ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).localListen(listener, EVT_CACHE_OBJECT_PUT);
return listener;
}
18
Source : IgniteZeroMqStreamerTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* @param listener Cache listener.
*/
private void unsubscribeToPutEvents(CacheListener listener) {
Ignite ignite = grid();
ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).stopLocalListen(listener, EVT_CACHE_OBJECT_PUT);
}
18
Source : IgniteTwitterStreamerTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* @param lsnr Cache listener.
*/
private void unsubscribeToPutEvents(CacheListener lsnr) {
Ignite ignite = grid();
ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).stopLocalListen(lsnr, EVT_CACHE_OBJECT_PUT);
}
18
Source : IgniteTwitterStreamerTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* @return Cache listener.
*/
private CacheListener subscribeToPutEvents() {
Ignite ignite = grid();
// Listen to cache PUT events and expect as many as messages as test data items.
CacheListener lsnr = new CacheListener();
ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).localListen(lsnr, EVT_CACHE_OBJECT_PUT);
return lsnr;
}
18
Source : IgniteSpringDataConnectionConfigurationTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests repository configuration in case {@link IgniteConfiguration} that refers to existing Ignite node instance
* is used to access the Ignite cluster.
*/
@Test
public void testRepositoryWithExistingIgniteInstance() throws Exception {
try (Ignite ignored = startGrid(getIgniteConfiguration(CLI_NAME, true))) {
checkRepositoryConfiguration(IgniteConfigurationApplication.clreplaced);
replacedertNotNull(Ignition.ignite(CLI_NAME));
}
}
18
Source : IgniteSpringDataConnectionConfigurationTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests repository configuration in case {@link IgniteConfiguration} that refers to existing Ignite node instance
* used to access the Ignite cluster.
*/
@Test
public void testRepositoryWithExistingIgniteInstance() throws Exception {
try (Ignite ignored = startGrid(getIgniteConfiguration(CLI_NAME, true))) {
checkRepositoryConfiguration(IgniteConfigurationApplication.clreplaced, IgniteConfigRepository.clreplaced);
replacedertNotNull(Ignition.ignite(CLI_NAME));
}
}
18
Source : AutoConfigureClientExample.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Main method of the application.
*/
public static void main(String[] args) {
// Starting Ignite server node outside of Spring Boot application so client can connect to it.
Ignite serverNode = Ignition.start(new IgniteConfiguration());
// Creating caches.
serverNode.createCache("my-cache1");
serverNode.createCache("my-cache2");
SpringApplication.run(AutoConfigureClientExample.clreplaced);
}
18
Source : FlinkIgniteSourceSelfTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Tests for {@link IgniteSource}.
*/
public clreplaced FlinkIgniteSourceSelfTest {
/**
* Cache name.
*/
private static final String TEST_CACHE = "testCache";
/**
* Flink source context.
*/
private SourceFunction.SourceContext<CacheEvent> ctx;
/**
* Ignite instance.
*/
private Ignite ignite;
/**
* Cluster Group
*/
private ClusterGroup clsGrp;
/**
* Ignite Source instance
*/
private IgniteSource igniteSrc;
/**
*/
@SuppressWarnings("unchecked")
@Before
public void setUpTest() throws Exception {
ctx = mock(SourceFunction.SourceContext.clreplaced);
ignite = mock(Ignite.clreplaced);
clsGrp = mock(ClusterGroup.clreplaced);
IgniteEvents igniteEvts = mock(IgniteEvents.clreplaced);
IgniteCluster igniteCluster = mock(IgniteCluster.clreplaced);
TaskRemoteFilter taskRemoteFilter = mock(TaskRemoteFilter.clreplaced);
when(ctx.getCheckpointLock()).thenReturn(new Object());
when(ignite.events(clsGrp)).thenReturn(igniteEvts);
when(ignite.cluster()).thenReturn(igniteCluster);
igniteSrc = new IgniteSource(TEST_CACHE);
igniteSrc.setIgnite(ignite);
igniteSrc.setEvtBatchSize(1);
igniteSrc.setEvtBufTimeout(1);
igniteSrc.setRuntimeContext(createRuntimeContext());
IgniteBiPredicate locLsnr = igniteSrc.getLocLsnr();
when(igniteEvts.remoteListen(locLsnr, taskRemoteFilter, EventType.EVT_CACHE_OBJECT_PUT)).thenReturn(UUID.randomUUID());
when(igniteCluster.forCacheNodes(TEST_CACHE)).thenReturn(clsGrp);
}
/**
*/
@After
public void tearDownTest() {
igniteSrc.cancel();
}
/**
* Creates streaming runtime context
*/
private RuntimeContext createRuntimeContext() {
StreamingRuntimeContext runtimeCtx = mock(StreamingRuntimeContext.clreplaced);
when(runtimeCtx.isCheckpointingEnabled()).thenReturn(true);
return runtimeCtx;
}
/**
* Tests Ignite source run operation.
*
* @throws Exception If failed.
*/
@Test
public void testIgniteSourceRun() throws Exception {
IgniteInternalFuture f = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
try {
igniteSrc.start(null, EventType.EVT_CACHE_OBJECT_PUT);
igniteSrc.run(ctx);
} catch (Throwable e) {
igniteSrc.cancel();
throw new replacedertionError("Unexpected failure.", e);
}
}
});
long endTime = System.currentTimeMillis() + 2000;
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return f.isDone() || System.currentTimeMillis() > endTime;
}
}, 3000);
igniteSrc.cancel();
f.get(3000);
}
}
18
Source : IgniteCamelStreamerTest.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
/**
* Subscribe to cache put events.
*/
private CountDownLatch subscribeToPutEvents(int expect) {
Ignite ignite = grid();
// Listen to cache PUT events and expect as many as messages as test data items
final CountDownLatch latch = new CountDownLatch(expect);
@SuppressWarnings("serial")
IgniteBiPredicate<UUID, CacheEvent> callback = new IgniteBiPredicate<UUID, CacheEvent>() {
@Override
public boolean apply(UUID uuid, CacheEvent evt) {
latch.countDown();
return true;
}
};
remoteLsnr = ignite.events(ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME)).remoteListen(callback, null, EVT_CACHE_OBJECT_PUT);
return latch;
}
18
Source : Components.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Produces
@ApplicationScoped
@Unremovable
@Named("ignite-compute")
IgniteComputeComponent igniteComputeComponent() {
final Ignite ignite = Mockito.mock(Ignite.clreplaced);
return IgniteComputeComponent.fromIgnite(ignite);
}
18
Source : Components.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Produces
@ApplicationScoped
@Unremovable
@Named("ignite-queue")
IgniteQueueComponent igniteQueueComponent() {
final Ignite ignite = Mockito.mock(Ignite.clreplaced);
return IgniteQueueComponent.fromIgnite(ignite);
}
18
Source : Components.java
with Apache License 2.0
from apache
with Apache License 2.0
from apache
@Produces
@ApplicationScoped
@Unremovable
@Named("ignite-idgen")
IgniteIdGenComponent igniteIdgenComponent() {
final Ignite ignite = Mockito.mock(Ignite.clreplaced);
return IgniteIdGenComponent.fromIgnite(ignite);
}
18
Source : IgniteClientTestBase.java
with MIT License
from aliyun
with MIT License
from aliyun
/**
* Common test clreplaced.
*/
public clreplaced IgniteClientTestBase {
protected static final String DEFAULT_CACHE_NAME = "usertable";
/**
*/
protected static Ignite cluster;
/**
*/
protected DB client;
/**
*/
@After
public void tearDown() throws Exception {
client.cleanup();
}
/**
*/
@AfterClreplaced
public static void afterClreplaced() {
cluster.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test
public void scanNotImplemented() {
cluster.cache(DEFAULT_CACHE_NAME).clear();
final String key = "key";
final Map<String, String> input = new HashMap<>();
input.put("field0", "value1");
input.put("field1", "value2");
final Status status = client.insert(DEFAULT_CACHE_NAME, key, StringByteIterator.getByteIteratorMap(input));
replacedertThat(status, is(Status.OK));
replacedertThat(cluster.cache(DEFAULT_CACHE_NAME).size(), is(1));
final Vector<HashMap<String, ByteIterator>> results = new Vector<>();
final Status scan = client.scan(DEFAULT_CACHE_NAME, key, 1, null, results);
replacedertThat(scan, is(Status.NOT_IMPLEMENTED));
}
}
18
Source : ApacheIgniteManager.java
with GNU General Public License v3.0
from alain898
with GNU General Public License v3.0
from alain898
public clreplaced ApacheIgniteManager {
private static Ignite ignite = null;
private static Config config = ConfigHolder.getInstance();
private static final String cluster = config.getString("ignite.cluster");
private static final int metaPort = config.getInt("ignite.meta_port");
private static final int dataPort = config.getInt("ignite.data_port");
private static final long maxMemoryBytes = config.getLong("ignite.max_memory_bytes");
private static final boolean persistenceEnabled = config.getBoolean("ignite.persistence_enabled");
private static final String persistencePath = config.getString("ignite.persistence_path");
private static final String workPath = String.format("%s/work", persistencePath);
private static final String walPath = String.format("%s/wal", persistencePath);
private static final String walArchivePath = String.format("%s/wal_archive", persistencePath);
private static List<String> parseClusterHosts(String cluster, int metaPort) {
Preconditions.checkNotNull(cluster, "cluster is null");
Preconditions.checkArgument(StringUtils.containsNone(":"), "cluster[%s] must not contain port number", cluster);
Preconditions.checkArgument(metaPort > 0, "metaPort[%d] must be positive", metaPort);
String[] splits = cluster.split(",");
Preconditions.checkArgument(splits.length > 0, "invalid cluster[%s]", cluster);
List<String> hosts = new ArrayList<>();
for (String split : splits) {
if (StringUtils.isNotEmpty(split)) {
hosts.add(String.format("%s:%d", split, metaPort));
}
}
return hosts;
}
private static void init() {
IgniteConfiguration cfg = new IgniteConfiguration();
// configApp discovery port, used to transport meta data
TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
discoverySpi.setLocalPort(metaPort);
discoverySpi.setLocalPortRange(0);
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
ipFinder.setAddresses(parseClusterHosts(cluster, metaPort));
discoverySpi.setIpFinder(ipFinder);
cfg.setDiscoverySpi(discoverySpi);
// configApp communication port, used to transport data
TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
commSpi.setLocalPort(dataPort);
cfg.setCommunicationSpi(commSpi);
// configApp ignite memory
DataStorageConfiguration storageCfg = new DataStorageConfiguration();
storageCfg.getDefaultDataRegionConfiguration().setMaxSize(maxMemoryBytes);
storageCfg.getDefaultDataRegionConfiguration().setPersistenceEnabled(persistenceEnabled);
storageCfg.setStoragePath(workPath);
storageCfg.setWalPath(walPath);
storageCfg.setWalArchivePath(walArchivePath);
cfg.setDataStorageConfiguration(storageCfg);
ignite = Ignition.start(cfg);
ignite.active(true);
}
public static Ignite instance() {
if (ignite != null) {
return ignite;
}
synchronized (ApacheIgniteManager.clreplaced) {
if (ignite != null) {
return ignite;
}
init();
return ignite;
}
}
}
17
Source : MigniteBootstrap.java
with Apache License 2.0
from XiaoMi
with Apache License 2.0
from XiaoMi
public static void main(String[] args) {
log.info("ignite start");
IgniteConfiguration cfg = new IgniteConfiguration();
// cfg.setClientMode(true);
cfg.setPeerClreplacedLoadingEnabled(true);
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500..47509"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
Ignite ignite = Ignition.start(cfg);
IgniteCache<String, String> cache = ignite.getOrCreateCache("myCache");
cache.put("name", "zzy");
log.info(">> Created the cache and add the values.");
System.out.println(cache.get("name"));
}
See More Examples