001/* 002# Licensed Materials - Property of IBM 003# Copyright IBM Corp. 2015 004 */ 005package simple; 006 007import com.ibm.streamsx.topology.TStream; 008import com.ibm.streamsx.topology.Topology; 009import com.ibm.streamsx.topology.context.StreamsContextFactory; 010 011/** 012 * Sample Hello World topology application. This Java application builds a 013 * simple topology that prints Hello World to standard output. <BR> 014 * The application implements the typical pattern of code that declares a 015 * topology followed by submission of the topology to a Streams context 016 * {@code com.ibm.streamsx.topology.context.StreamsContext}. 017 * <BR> 018 * This demonstrates the mechanics of declaring a topology and executing it. 019 * <P> 020 * This may be executed from the {@code samples/java/functional} directory as: 021 * <UL> 022 * <LI>{@code ant run.helloworld} - Using Apache Ant, this will run in embedded 023 * mode.</LI> 024 * <LI> 025 * {@code java -jar funcsamples.jar:../com.ibm.streamsx.topology/lib/com.ibm.streamsx.topology.jar:$STREAMS_INSTALL/lib/com.ibm.streams.operator.samples.jar 026 * simple.HelloWorld [CONTEXT_TYPE] 027 * } - Run directly from the command line. 028 * </LI> 029 * If no arguments are provided then the topology is executed in embedded mode, 030 * within this JVM. 031 * <BR> 032 * <i>CONTEXT_TYPE</i> is one of: 033 * <UL> 034 * <LI>{@code DISTRIBUTED} - Run as an IBM Streams distributed 035 * application.</LI> 036 * <LI>{@code STANDALONE} - Run as an IBM Streams standalone 037 * application.</LI> 038 * <LI>{@code EMBEDDED} - Run embedded within this JVM.</LI> 039 * <LI>{@code BUNDLE} - Create an IBM Streams application bundle.</LI> 040 * <LI>{@code TOOLKIT} - Create an IBM Streams application toolkit.</LI> 041 * </UL> 042 * </LI> 043 * <LI> 044 * An application execution within your IDE once you set the class path to include the correct jars.</LI> 045 * </UL> 046 * </P> 047 */ 048public class HelloWorld { 049 050 /** 051 * Sample Hello World topology application. 052 * This Java application builds a simple topology 053 * that prints Hello World to standard output. 054 * <BR> 055 * The application implements the typical pattern 056 * of code that declares a topology followed by 057 * submission of the topology to a Streams context 058 * (@code com.ibm.streamsx.topology.context.StreamsContext}. 059 060 * @param args 061 * @throws Exception 062 */ 063 public static void main(String[] args) throws Exception { 064 065 /* 066 * Create the container for the topology that will 067 * hold the streams of tuples. 068 */ 069 Topology topology = new Topology("HelloWorld"); 070 071 /* 072 * Declare a source stream (hw) with String tuples containing two tuples, 073 * "Hello" and "World!". 074 */ 075 TStream<String> hw = topology.strings("Hello", "World!"); 076 077 /* 078 * Sink hw by printing each of its tuples to System.out. 079 */ 080 hw.print(); 081 082 /* 083 * At this point the topology is declared with a single 084 * stream that is printed to System.out. 085 */ 086 087 /* 088 * Now execute the topology by submitting to a StreamsContext. 089 * If no argument is provided then the topology is executed 090 * within this JVM (StreamsContext.Type.EMBEDDED). 091 * Otherwise the first and only argument is taken as the 092 * String representation of the 093 */ 094 if (args.length == 0) 095 StreamsContextFactory.getEmbedded().submit(topology).get(); 096 else 097 StreamsContextFactory.getStreamsContext(args[0]).submit(topology) 098 .get(); 099 } 100}