old_contents: #
  # 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.
  #
  
  from pyspark import SparkContext
  from pyspark.streaming import StreamingContext
  
  # Create a local StreamingContext with two working thread and batch interval of 1 second
  sc = SparkContext()
  ssc = StreamingContext(sc, 1)
  
  log4j = sc._jvm.org.apache.log4j
  log4j.LogManager.getRootLogger().setLevel(log4j.Level.ERROR)
  
  try:
      # Create a DStream that will connect to hostname:port, like localhost:9999
      lines = ssc.socketTextStream("localhost", 6568)
  
      # Split each line into words
      words = lines.flatMap(lambda line: line.split(" "))
  
      # Count each word in each batch
      pairs = words.map(lambda word: (word, 1))
      wordCounts = pairs.reduceByKey(lambda x, y: x + y)
  
      # Print the first ten elements of each RDD generated in this DStream to the console
      wordCounts.pprint()
  except:
      print "Unexpected error:", sys.exc_info()[0]
      pass
  
  # Start the computation
  ssc.start()             
  
  # Wait for the computation, terminating after 30s
  #ssc.awaitTerminationOrTimeout(30)  
  import time
  time.sleep(30)
  
  ssc.stop()
  
  
new_contents: #
  # 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.
  #
  
  from pyspark import SparkContext
  from pyspark.streaming import StreamingContext
  
  # Create a local StreamingContext with two working thread and batch interval of 1 second
  sc = SparkContext()
  ssc = StreamingContext(sc, 1)
  
  log4j = sc._jvm.org.apache.log4j
  log4j.LogManager.getRootLogger().setLevel(log4j.Level.ERROR)
  
  try:
      # Create a DStream to connect to the wordsocket.py random word server
      lines = ssc.socketTextStream("localhost", 6568)
  
      # Split each line into words
      words = lines.flatMap(lambda line: line.split(" "))
  
      # Count each word in each batch
      pairs = words.map(lambda word: (word, 1))
      wordCounts = pairs.reduceByKey(lambda x, y: x + y)
  
      # Print the first ten elements of each RDD generated in this DStream to the console
      wordCounts.pprint()
  except:
      print "Unexpected error:", sys.exc_info()[0]
      pass
  
  # Start the computation
  ssc.start()             
  
  # Wait for the computation, terminating after 30s
  #ssc.awaitTerminationOrTimeout(30)  
  import time
  time.sleep(30)
  
  ssc.stop()
  
  
subject: Update sparkstreaming.py