Java Code Examples for org.apache.ignite.Ignition#setClientMode()
The following examples show how to use
org.apache.ignite.Ignition#setClientMode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AlertMonitoring.java From ignite-book-code-samples with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws Exception { // Mark this cluster member as client. Ignition.setClientMode(true); try (Ignite ignite = Ignition.start("example-ignite.xml")) { if (!ExamplesUtils.hasServerNodes(ignite)) return; CacheConfiguration<String, Alert> alert_Cfg = new CacheConfiguration<>("alerts"); IgniteCache<String, Alert> instCache = ignite.getOrCreateCache(alert_Cfg); SqlFieldsQuery top3qry = new SqlFieldsQuery(QUERY_RED); while(true){ // Execute queries. List<List<?>> top3 = instCache.query(top3qry).getAll(); System.out.println("Service Health Monitoring"); ExamplesUtils.printQueryResults(top3); Thread.sleep(1000); } } }
Example 2
Source File: QueryStatus.java From ignite-book-code-samples with GNU General Public License v3.0 | 6 votes |
public static void main(String[] args) throws Exception { // Mark this cluster member as client. Ignition.setClientMode(true); try (Ignite ignite = Ignition.start("example-ignite.xml")) { if (!ExamplesUtils.hasServerNodes(ignite)) return; // query code goes here. CacheConfiguration<String, ServiceStatus> healthchecksCfg = new CacheConfiguration<>("healthchecks"); IgniteCache<String, ServiceStatus> instCache = ignite.getOrCreateCache(healthchecksCfg); SqlFieldsQuery query = new SqlFieldsQuery(QUERY_404); while(true){ // Execute queries. List<List<?>> res = instCache.query(query).getAll(); System.out.println("Service Health check status"); ExamplesUtils.printQueryResults(res); Thread.sleep(1000); } } }
Example 3
Source File: AbstractIgniteProcessor.java From localization_nifi with Apache License 2.0 | 5 votes |
/** * Initialize ignite instance * @param context process context */ public void initializeIgnite(ProcessContext context) { if ( getIgnite() != null ) { getLogger().info("Ignite already initialized"); return; } synchronized(Ignition.class) { 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); } } }
Example 4
Source File: HealthCheckStreamer.java From ignite-book-code-samples with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception{ System.out.println("Streamer for service health check!!"); // Mark this cluster member as client. Ignition.setClientMode(true); try(Ignite ignite = Ignition.start("example-ignite.xml")){ if(!ExamplesUtils.hasServerNodes(ignite)) return; // healthcheck cache configuration CacheConfiguration<String, ServiceStatus> healthcheck_cfg = new CacheConfiguration<>("healthchecks"); // set window to 5 second // Note: data will evicts after 5 seconds //healthcheck_cfg.setExpiryPolicyFactory(FactoryBuilder.factoryOf(new CreatedExpiryPolicy(new Duration(SECONDS, 15)))); // set index healthcheck_cfg.setIndexedTypes(String.class, ServiceStatus.class); IgniteCache<String, ServiceStatus> healthCheckCache = ignite.getOrCreateCache(healthcheck_cfg); try(IgniteDataStreamer<String, ServiceStatus> healthCheckStreamer = ignite.dataStreamer(healthCheckCache.getName())){ healthCheckStreamer.allowOverwrite(true); while(true ){ int idx_service_name = RAND.nextInt(SERVICE_NAME.length); int idx_code = RAND.nextInt(STATUS_CODE.length); ServiceStatus serviceStatus = new ServiceStatus(SERVICE_NAME[idx_service_name], STATUS_CODE[idx_code]); healthCheckStreamer.addData(SERVICE_NAME[idx_service_name], serviceStatus); } } } }
Example 5
Source File: AbstractQueryTableLockAndConnectionPoolSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Test DDL operation on table with high load queries. * * @throws Exception If failed. */ @Test public void testMultipleNodesWithTablesLockQueryAndDDLMultithreaded() throws Exception { Ignite srv0 = startGrid(0); Ignite srv1 = startGrid(1); startGrid(2); Ignite cli; try { Ignition.setClientMode(true); cli = startGrid(3); } finally { Ignition.setClientMode(false); } populateBaseQueryData(srv0, 1); checkTablesLockQueryAndDDLMultithreaded(srv0); checkTablesLockQueryAndDDLMultithreaded(srv1); checkTablesLockQueryAndDDLMultithreaded(cli); checkTablesLockQueryAndDropColumnMultithreaded(srv0); checkTablesLockQueryAndDropColumnMultithreaded(srv1); // TODO: +++ DDL DROP COLUMN CacheContext == null on CLI // checkTablesLockQueryAndDropColumnMultithreaded(cli); }
Example 6
Source File: AbstractQueryTableLockAndConnectionPoolSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** * Test DDL operation on table with high load queries. * * @throws Exception If failed. */ @Test public void testMultipleNodesWithParallelismTablesLockQueryAndDDLMultithreaded() throws Exception { Ignite srv0 = startGrid(0); Ignite srv1 = startGrid(1); startGrid(2); Ignite cli; try { Ignition.setClientMode(true); cli = startGrid(3); } finally { Ignition.setClientMode(false); } populateBaseQueryData(srv0, 4); checkTablesLockQueryAndDDLMultithreaded(srv0); checkTablesLockQueryAndDDLMultithreaded(srv1); checkTablesLockQueryAndDDLMultithreaded(cli); checkTablesLockQueryAndDropColumnMultithreaded(srv0); checkTablesLockQueryAndDropColumnMultithreaded(srv1); // TODO: +++ DDL DROP COLUMN CacheContext == null on CLI // checkTablesLockQueryAndDropColumnMultithreaded(cli); }
Example 7
Source File: PlatformAbstractBootstrap.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void init(long dataPtr) { final PlatformInputStream input = new PlatformExternalMemory(null, dataPtr).input(); Ignition.setClientMode(input.readBoolean()); processInput(input); }
Example 8
Source File: IgfsAbstractBaseSelfTest.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void beforeTestsStarted() throws Exception { igfsSecondaryFileSystem = createSecondaryFileSystemStack(); nodes = new Ignite[nodeCount()]; for (int i = 0; i < nodes.length; i++) { String nodeName = i == 0 ? "ignite" : "ignite" + i; nodes[i] = startGridWithIgfs(nodeName, "igfs", mode, igfsSecondaryFileSystem, PRIMARY_REST_CFG, primaryIpFinder); } igfs = (IgfsImpl) nodes[0].fileSystem("igfs"); if (client()) { // Start client. Ignition.setClientMode(true); try { Ignite ignite = startGridWithIgfs("ignite-client", "igfs", mode, igfsSecondaryFileSystem, PRIMARY_REST_CFG, primaryIpFinder); igfs = (IgfsImpl) ignite.fileSystem("igfs"); } finally { Ignition.setClientMode(false); } } }
Example 9
Source File: ServicesExample.java From ignite with Apache License 2.0 | 5 votes |
/** * Executes example. * * @param args Command line arguments, none required. * @throws Exception If example execution failed. */ public static void main(String[] args) throws Exception { // Mark this node as client node. Ignition.setClientMode(true); try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { if (!ExamplesUtils.hasServerNodes(ignite)) return; // Deploy services only on server nodes. IgniteServices svcs = ignite.services(ignite.cluster().forServers()); try { // Deploy cluster singleton. svcs.deployClusterSingleton("myClusterSingletonService", new SimpleMapServiceImpl()); // Deploy node singleton. svcs.deployNodeSingleton("myNodeSingletonService", new SimpleMapServiceImpl()); // Deploy 2 instances, regardless of number nodes. svcs.deployMultiple("myMultiService", new SimpleMapServiceImpl(), 2 /*total number*/, 0 /*0 for unlimited*/); // Example for using a service proxy // to access a remotely deployed service. serviceProxyExample(ignite); // Example for auto-injecting service proxy // into remote closure execution. serviceInjectionExample(ignite); } finally { // Undeploy all services. ignite.services().cancelAll(); } } }
Example 10
Source File: StreamWords.java From ignite with Apache License 2.0 | 5 votes |
/** * Starts words streaming. * * @param args Command line arguments (none required). * @throws Exception If failed. */ public static void main(String[] args) throws Exception { // Mark this cluster member as client. Ignition.setClientMode(true); try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { if (!ExamplesUtils.hasServerNodes(ignite)) return; // The cache is configured with sliding window holding 1 second of the streaming data. IgniteCache<AffinityUuid, String> stmCache = ignite.getOrCreateCache(CacheConfig.wordCache()); try (IgniteDataStreamer<AffinityUuid, String> stmr = ignite.dataStreamer(stmCache.getName())) { // Stream words from "alice-in-wonderland" book. while (true) { InputStream in = StreamWords.class.getResourceAsStream("alice-in-wonderland.txt"); try (LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in))) { for (String line = rdr.readLine(); line != null; line = rdr.readLine()) { for (String word : line.split(" ")) if (!word.isEmpty()) // Stream words into Ignite. // By using AffinityUuid we ensure that identical // words are processed on the same cluster node. stmr.addData(new AffinityUuid(word), word); } } } } } }
Example 11
Source File: AbstractIgniteProcessor.java From nifi with Apache License 2.0 | 5 votes |
/** * Initialize ignite instance * @param context process context */ public void initializeIgnite(ProcessContext context) { if ( getIgnite() != null ) { getLogger().info("Ignite already initialized"); return; } synchronized(Ignition.class) { 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); } } }
Example 12
Source File: CamelStreamerMediation.java From ignite-book-code-samples with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception{ System.out.println("Camel Streamer Mediation ingestion!"); Ignition.setClientMode(true); Ignite ignite = Ignition.start("example-ignite.xml"); // Create a CamelContext with a custom route that will: // (1) consume from our Jetty endpoint. // (2) transform incoming JSON into a Java object with Jackson. // (3) uses JSR 303 Bean Validation to validate the object. // (4) dispatches to the direct:ignite.ingest endpoint, where the streamer is consuming from. // camel_cache cache configuration CacheConfiguration<String, String> camel_cache_cfg = new CacheConfiguration<>("camel-direct"); camel_cache_cfg.setIndexedTypes(String.class, String.class); IgniteCache<String, String> camel_cache = ignite.getOrCreateCache(camel_cache_cfg); // Create an streamer pipe which ingests into the 'camel_cache' cache. IgniteDataStreamer<String, String> pipe = ignite.dataStreamer(camel_cache.getName()); // does the tricks pipe.autoFlushFrequency(1l); pipe.allowOverwrite(true); // Create a Camel streamer and connect it. CamelStreamer<String, String> streamer = new CamelStreamer<>(); streamer.setIgnite(ignite); streamer.setStreamer(pipe); streamer.setEndpointUri("direct:ignite.ingest"); CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("jetty:http://127.0.0.1:8081/ignite?httpMethodRestrict=POST") .unmarshal().json(JsonLibrary.Jackson) .to("bean-validator:validate") .to("direct:ignite.ingest"); } }); // Remember our Streamer is now consuming from the Direct endpoint above. streamer.setCamelContext(context); streamer.setSingleTupleExtractor(new StreamSingleTupleExtractor<Exchange, String, String>() { @Override public Map.Entry<String, String> extract(Exchange exchange) { String stationId = exchange.getIn().getHeader("X-StationId", String.class); String temperature = exchange.getIn().getBody(String.class); System.out.println("StationId:" + stationId + " temperature:" + temperature); return new GridMapEntry<>(stationId, temperature); } }); streamer.start(); //streamer.start(); }
Example 13
Source File: CamelStreamerMediationIngestion.java From ignite-book-code-samples with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) throws Exception { System.out.println("Camel Streamer Mediation ingestion!"); Ignition.setClientMode(true); Ignite ignite = Ignition.start("example-ignite.xml"); if (!ExamplesUtils.hasServerNodes(ignite)) return; if (getFileLocation() == null || getFileLocation().isEmpty()){ System.out.println("properties file is empty or null!"); return; } // camel_cache cache configuration CacheConfiguration<String, String> camel_cache_cfg = new CacheConfiguration<>("camel-direct"); camel_cache_cfg.setIndexedTypes(String.class, String.class); IgniteCache<String, String> camel_cache = ignite.getOrCreateCache(camel_cache_cfg); // Create an streamer pipe which ingests into the 'camel_cache' cache. IgniteDataStreamer<String, String> pipe = ignite.dataStreamer(camel_cache.getName()); // does the tricks pipe.autoFlushFrequency(1l); pipe.allowOverwrite(true); // Create a Camel streamer and connect it. CamelStreamer<String, String> streamer = new CamelStreamer<>(); streamer.setIgnite(ignite); streamer.setStreamer(pipe); streamer.setEndpointUri("direct:ignite.ingest"); CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file://"+getFileLocation()) .unmarshal().json(JsonLibrary.Jackson, MnpRouting.class) .bean(new RouteProcessor(), "process") .to("direct:ignite.ingest"); } }); streamer.setCamelContext(context); streamer.setSingleTupleExtractor(new StreamSingleTupleExtractor<Exchange, String, String>() { @Override public Map.Entry<String, String> extract(Exchange exchange) { String key = exchange.getIn().getHeader("key", String.class); String routeMsg = exchange.getIn().getBody(String.class); return new GridMapEntry<>(key, routeMsg); } }); streamer.start(); }
Example 14
Source File: CamelStreamerDirectIngestion.java From ignite-book-code-samples with GNU General Public License v3.0 | 4 votes |
public static void main(String[] args) { System.out.println("Camel Streamer Direct ingestion!"); Ignition.setClientMode(true); Ignite ignite = Ignition.start("example-ignite.xml"); if (!ExamplesUtils.hasServerNodes(ignite)) return; if(getFileLocation() == null || getFileLocation().isEmpty()){ System.out.println("Properties file is empty or null!"); return; } // camel_cache cache configuration CacheConfiguration<String, MnpRouting> camel_cache_cfg = new CacheConfiguration<>("camel-direct"); camel_cache_cfg.setIndexedTypes(String.class, MnpRouting.class); IgniteCache<String, MnpRouting> camel_cache = ignite.getOrCreateCache(camel_cache_cfg); // Create an streamer pipe which ingests into the 'camel_cache' cache. IgniteDataStreamer<String, MnpRouting> pipe = ignite.dataStreamer(camel_cache.getName()); // does the tricks pipe.autoFlushFrequency(1l); pipe.allowOverwrite(true); // Create a Camel streamer and connect it. CamelStreamer<String, MnpRouting> streamer = new CamelStreamer<>(); streamer.setIgnite(ignite); streamer.setStreamer(pipe); streamer.setEndpointUri("file://"+getFileLocation()); streamer.setSingleTupleExtractor(new StreamSingleTupleExtractor<Exchange, String, MnpRouting>() { @Override public Map.Entry<String, MnpRouting> extract(Exchange exchange) { // (1) convert the JSON to java object // (2) add the key value as telephone // (3) store the java object into Cache ObjectMapper mapper = new ObjectMapper(); String msgBody = exchange.getIn().getBody(String.class); System.out.println("MsgBody:" + msgBody); MnpRouting obj = null; try { obj = mapper.readValue(msgBody, MnpRouting.class); } catch (IOException e) { e.printStackTrace(); } if (obj != null){ return new GridMapEntry<String, MnpRouting>(obj.getTelephone(), obj); } return new GridMapEntry<String, MnpRouting>(null, null); } }); // Start the streamer. streamer.start(); }
Example 15
Source File: AbstractQueryTableLockAndConnectionPoolSelfTest.java From ignite with Apache License 2.0 | 4 votes |
/** * Check query execution with multiple topology nodes. * * @param parallelism Query parallelism. * @throws Exception If failed. */ public void checkMultipleNodes(int parallelism) throws Exception { Ignite srv1 = startGrid(0); Ignite srv2 = startGrid(1); Ignite cli; try { Ignition.setClientMode(true); cli = startGrid(2); } finally { Ignition.setClientMode(false); } populateBaseQueryData(cli, parallelism); checkBaseOperations(srv1); checkBaseOperations(srv2); checkBaseOperations(cli); // Test originating node leave. FieldsQueryCursor<List<?>> cursor = execute(cli, baseQuery().setPageSize(PAGE_SIZE_SMALL)); Iterator<List<?>> iter = cursor.iterator(); for (int i = 0; i < 30; i++) iter.next(); stopGrid(2); // Test server node leave with active worker. FieldsQueryCursor<List<?>> cursor2 = execute(srv1, baseQuery().setPageSize(PAGE_SIZE_SMALL)); try { Iterator<List<?>> iter2 = cursor2.iterator(); for (int i = 0; i < 30; i++) iter2.next(); stopGrid(1); } finally { cursor2.close(); } }
Example 16
Source File: QueryWords.java From ignite with Apache License 2.0 | 4 votes |
/** * Schedules words query execution. * * @param args Command line arguments (none required). * @throws Exception If failed. */ public static void main(String[] args) throws Exception { // Mark this cluster member as client. Ignition.setClientMode(true); try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) { if (!ExamplesUtils.hasServerNodes(ignite)) return; CacheConfiguration<AffinityUuid, String> cfg = CacheConfig.wordCache(); // The cache is configured with sliding window holding 1 second of the streaming data. try (IgniteCache<AffinityUuid, String> stmCache = ignite.getOrCreateCache(cfg)) { // Select top 10 words. SqlFieldsQuery top10Qry = new SqlFieldsQuery( "select _val, count(_val) as cnt from String group by _val order by cnt desc limit 10", true /*collocated*/ ); // Select average, min, and max counts among all the words. SqlFieldsQuery statsQry = new SqlFieldsQuery( "select avg(cnt), min(cnt), max(cnt) from (select count(_val) as cnt from String group by _val)"); // Query top 10 popular numbers every 5 seconds. while (true) { // Execute queries. List<List<?>> top10 = stmCache.query(top10Qry).getAll(); List<List<?>> stats = stmCache.query(statsQry).getAll(); // Print average count. List<?> row = stats.get(0); if (row.get(0) != null) System.out.printf("Query results [avg=%d, min=%d, max=%d]%n", row.get(0), row.get(1), row.get(2)); // Print top 10 words. ExamplesUtils.printQueryResults(top10); Thread.sleep(5000); } } finally { // Distributed cache could be removed from cluster only by #destroyCache() call. ignite.destroyCache(cfg.getName()); } } }