Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id AC23017763 for ; Fri, 15 May 2015 08:50:44 +0000 (UTC) Received: (qmail 60757 invoked by uid 500); 15 May 2015 08:50:44 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 60725 invoked by uid 500); 15 May 2015 08:50:44 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 60716 invoked by uid 99); 15 May 2015 08:50:44 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 May 2015 08:50:44 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 2B637C0B1C for ; Fri, 15 May 2015 08:50:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.771 X-Spam-Level: * X-Spam-Status: No, score=1.771 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id VdKZuKgQVucm for ; Fri, 15 May 2015 08:50:37 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 8D3A54547C for ; Fri, 15 May 2015 08:50:31 +0000 (UTC) Received: (qmail 60131 invoked by uid 99); 15 May 2015 08:50:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 May 2015 08:50:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 58657E35A7; Fri, 15 May 2015 08:50:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Fri, 15 May 2015 08:50:39 -0000 Message-Id: In-Reply-To: <987c688997814c9a8ae7264e44c72a0b@git.apache.org> References: <987c688997814c9a8ae7264e44c72a0b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [10/11] incubator-ignite git commit: ignite-430 Words count Socket streamer examples ignite-430 Words count Socket streamer examples Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/896b426b Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/896b426b Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/896b426b Branch: refs/heads/ignite-614 Commit: 896b426bff3e37aeebbb00f54e179492543f1a1d Parents: fe78d42 Author: agura Authored: Thu May 14 20:29:33 2015 +0300 Committer: agura Committed: Fri May 15 03:44:40 2015 +0300 ---------------------------------------------------------------------- .../streaming/StreamTransformerExample.java | 4 +- .../streaming/StreamVisitorExample.java | 4 +- .../socket/WordsSocketStreamerServer.java | 93 -------------------- .../streaming/wordcount/QueryWords.java | 4 +- .../streaming/wordcount/StreamWords.java | 4 +- .../socket/WordsSocketStreamerClient.java | 14 +-- .../socket/WordsSocketStreamerServer.java | 27 ++++-- 7 files changed, 31 insertions(+), 119 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java index 5e95892..966fce2 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamTransformerExample.java @@ -30,11 +30,9 @@ import java.util.*; * Stream random numbers into the streaming cache. * To start the example, you should: *
    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start streaming using {@link StreamTransformerExample}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class StreamTransformerExample { /** Random number generator. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java index 0fbce68..baae5af 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/StreamVisitorExample.java @@ -31,11 +31,9 @@ import java.util.*; * Stream random numbers into the streaming cache. * To start the example, you should: *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start streaming using {@link StreamVisitorExample}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class StreamVisitorExample { /** Random number generator. */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/socket/WordsSocketStreamerServer.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/socket/WordsSocketStreamerServer.java b/examples/src/main/java/org/apache/ignite/examples/streaming/socket/WordsSocketStreamerServer.java deleted file mode 100644 index 5af746d..0000000 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/socket/WordsSocketStreamerServer.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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. - */ - -package org.apache.ignite.examples.streaming.socket; - -import org.apache.ignite.*; -import org.apache.ignite.cache.affinity.*; -import org.apache.ignite.examples.*; -import org.apache.ignite.examples.streaming.wordcount.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.stream.*; -import org.apache.ignite.stream.socket.*; - -import java.io.*; -import java.net.*; -import java.util.*; - -/** - * Receives words through socket using {@link SocketStreamer} and message size based protocol - * and streams them into Ignite cache. - *

- * To start the example, you should: - *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • - *
  • Start socket server using {@link WordsSocketStreamerServer}.
  • - *
  • Start a few socket clients using {@link WordsSocketStreamerClient}.
  • - *
  • Start querying popular words using {@link QueryWords}.
  • - *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. - */ -public class WordsSocketStreamerServer { - /** Port. */ - private static final int PORT = 5555; - - /** - * @param args Args. - */ - public static void main(String[] args) throws InterruptedException, IOException { - // Mark this cluster member as client. - Ignition.setClientMode(true); - - Ignite ignite = Ignition.start("examples/config/example-ignite.xml"); - - if (!ExamplesUtils.hasServerNodes(ignite)) { - ignite.close(); - - return; - } - - // The cache is configured with sliding window holding 1 second of the streaming data. - IgniteCache stmCache = ignite.getOrCreateCache(CacheConfig.wordCache()); - - IgniteDataStreamer stmr = ignite.dataStreamer(stmCache.getName()); - - InetAddress addr = InetAddress.getLocalHost(); - - // Configure socket streamer - SocketStreamer sockStmr = new SocketStreamer<>(); - - sockStmr.setAddr(addr); - - sockStmr.setPort(PORT); - - sockStmr.setIgnite(ignite); - - sockStmr.setStreamer(stmr); - - sockStmr.setTupleExtractor(new StreamTupleExtractor() { - @Override public Map.Entry extract(String word) { - // By using AffinityUuid we ensure that identical - // words are processed on the same cluster node. - return new IgniteBiTuple<>(new AffinityUuid(word), word); - } - }); - - sockStmr.start(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java index faf8b51..58c6ef2 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/QueryWords.java @@ -28,12 +28,10 @@ import java.util.*; * Periodically query popular numbers from the streaming cache. * To start the example, you should: *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start streaming using {@link StreamWords}.
  • *
  • Start querying popular words using {@link QueryWords}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class QueryWords { /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java index 26be178..6024c4b 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/StreamWords.java @@ -27,12 +27,10 @@ import java.io.*; * Stream words into Ignite cache. * To start the example, you should: *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start streaming using {@link StreamWords}.
  • *
  • Start querying popular words using {@link QueryWords}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class StreamWords { /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java index ea3beaa..c4d7b8c 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerClient.java @@ -25,19 +25,19 @@ import java.io.*; import java.net.*; /** - * Sends words to socket server based on {@link SocketStreamer} using message delimiter based protocol. - * Example illustrates usage of TCP socket streamer in case of non-Java clients. - * In this example words are zero-terminated strings. + * Example demonstrates streaming of data from external components into Ignite cache. + *

+ * {@code WordsSocketStreamerClient} is simple socket streaming client implementation that sends words to socket server + * based on {@link SocketStreamer} using message delimiter based protocol. Example illustrates usage of TCP socket + * streamer in case of non-Java clients. In this example words are zero-terminated strings. *

* To start the example, you should: *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start socket server using {@link WordsSocketStreamerServer}.
  • *
  • Start a few socket clients using {@link WordsSocketStreamerClient}.
  • *
  • Start querying popular words using {@link QueryWords}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class WordsSocketStreamerClient { /** Port. */ @@ -59,7 +59,7 @@ public class WordsSocketStreamerClient { System.out.println("Words streaming started."); while (true) { - try (InputStream in = StreamWords.class.getResourceAsStream("../wordcount/alice-in-wonderland.txt"); + try (InputStream in = WordsSocketStreamerClient.class.getResourceAsStream("../alice-in-wonderland.txt"); LineNumberReader rdr = new LineNumberReader(new InputStreamReader(in))) { for (String line = rdr.readLine(); line != null; line = rdr.readLine()) { for (String word : line.split(" ")) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/896b426b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java ---------------------------------------------------------------------- diff --git a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java index 259c925..6a8911c 100644 --- a/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java +++ b/examples/src/main/java/org/apache/ignite/examples/streaming/wordcount/socket/WordsSocketStreamerServer.java @@ -30,19 +30,20 @@ import java.net.*; import java.util.*; /** - * Receives words through socket using {@link SocketStreamer} and message delimiter based protocol + * Example demonstrates streaming of data from external components into Ignite cache. + *

+ * {@code WordsSocketStreamerServer} is simple socket streaming server implementation that + * receives words from socket using {@link SocketStreamer} and message delimiter based protocol * and streams them into Ignite cache. Example illustrates usage of TCP socket streamer in case of non-Java clients. * In this example words are zero-terminated strings. *

* To start the example, you should: *

    - *
  • Start a few nodes using {@link ExampleNodeStartup} or by starting remote nodes as specified below.
  • + *
  • Start a few nodes using {@link ExampleNodeStartup}.
  • *
  • Start socket server using {@link WordsSocketStreamerServer}.
  • *
  • Start a few socket clients using {@link WordsSocketStreamerClient}.
  • *
  • Start querying popular words using {@link QueryWords}.
  • *
- *

- * You should start remote nodes by running {@link ExampleNodeStartup} in another JVM. */ public class WordsSocketStreamerServer { /** Port. */ @@ -52,9 +53,12 @@ public class WordsSocketStreamerServer { private static final byte[] DELIM = new byte[] {0}; /** - * @param args Args. + * Starts socket streaming server. + * + * @param args Command line arguments (none required). + * @throws Exception If failed. */ - public static void main(String[] args) throws InterruptedException, IOException { + public static void main(String[] args) throws Exception { // Mark this cluster member as client. Ignition.setClientMode(true); @@ -106,6 +110,15 @@ public class WordsSocketStreamerServer { } }); - sockStmr.start(); + try { + sockStmr.start(); + } + catch (IgniteException e) { + System.out.println("Streaming server didn't start due to an error: "); + + e.printStackTrace(); + + ignite.close(); + } } }