Source code

    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 echo topology application. This Java application builds a
    013* simple topology that echos its command line arguments to standard output.
    014* <BR>
    015* The application implements the typical pattern of code that declares a
    016* topology followed by submission of the topology to a Streams context
    017* {@code com.ibm.streamsx.topology.context.StreamsContext}.
    018* <BR>
    019* This demonstrates passing in values (the command line arguments) into a topology,
    020* so that the same application can produce different ouput depending on the passed
    021* in values.
    022* <P>
    023* This topology is always executed in embedded mode,
    024* within this JVM.
    025* <BR>
    026* This may be executed from the {@code samples/java/functional} directory as:
    027* <UL>
    028* <LI>{@code ant run.echo} - Using Apache Ant, this will run in embedded
    029* mode.</LI>
    030* <LI>
    031* {@code java -cp functionalsamples.jar:../../../com.ibm.streamsx.topology/lib/com.ibm.streamsx.topology.jar:$STREAMS_INSTALL/lib/com.ibm.streams.operator.samples.jar
    032*  simple.Echo text to echo
    033* } - Run directly from the command line in embedded mode.
    034* <LI>
    035* An application execution within your IDE once you set the class path to include the correct jars.</LI>
    036* </UL>
    037* </P>
    038*/
    039public class Echo {
    040
    041    /**
    042     * Sample Echo topology application. This Java application builds a
    043     * simple topology that echos its command line arguments to standard output.
    044     * <BR>
    045     * The application implements the typical pattern
    046     * of code that declares a topology followed by
    047     * submission of the topology to a Streams context
    048     * (@code com.ibm.streamsx.topology.context.StreamsContext}.
    049
    050     * @param args Arguments to be echoed to standard out.
    051     * @throws Exception
    052     */
    053    public static void main(String[] args) throws Exception {
    054
    055        Topology topology = new Topology("Echo");
    056
    057        /*
    058         * The command line arguments (args) are captured by
    059         * the strings() method and will be used at runtime
    060         * as the contents of the echo stream.
    061         */
    062        TStream<String> echo = topology.strings(args);
    063        echo.print();
    064
    065        /*
    066         * At this point the topology is declared with a single
    067         * stream that is printed to System.out.
    068         */
    069
    070        /*
    071         * Now execute the topology by submitting to an
    072         * embedded (within this JVM) StreamsContext.
    073         */
    074        StreamsContextFactory.getEmbedded().submit(topology).get();
    075    }
    076}