Topic
3 replies Latest Post - ‏2013-05-02T01:28:57Z by waldstein
waldstein
waldstein
33 Posts
ACCEPTED ANSWER

Pinned topic Why shutdown() can not be executed in java operator?

‏2013-04-16T03:01:58Z |

Hi all,

My purpose is receiving Strings from a TCP client and computing a average of received Strings (of course, I need to transform them to Doubles) when the receiving String is empty.

The source code of .SPL is as follows (very simple one):

use com.ibm.crl.operatortest::AverageComputer;
composite TestGVP{
graph
  stream<rstring Message> Input = TCPSource(){
    param role         : server;
          port     : 9091u;
      
  }
  stream <Data_Processed> Output = AverageComputer(Input) {}  //AverageComputer is a java operator

  () as Sink = FileSink(Output){
     param
          format : csv;
          file : "output.txt";
  }
}

The source code of java operator is as follows:

public class AverageComputer implements Operator {
    private OperatorContext context;

    @Override
    public void allPortsReady() throws Exception {
        System.out.println("all ports ready");
    }

    @Override
    public void initialize(OperatorContext context) throws Exception {
        this.context = context;
    }
    
    static double sum = 0.0;
    static int counter = 0;
    
    static String  routeid = "";
    static long timeSeconds = 0;

    @Override
    public void process(StreamingInput<Tuple> inputPort, Tuple inputTuple)
            throws Exception {
        String curMessage = inputTuple.getString(0);
        
        if(curMessage.equals("+"))
        {
            
            StreamingOutput<OutputTuple> output = context.getStreamingOutputs().get(0);
            OutputTuple outTuple = output.newTuple();
            
            outTuple.setString(0, routeid);
            outTuple.setLong(1, timeSeconds);
            outTuple.setDouble(2, sum / counter);
            
            sum = 0;
            counter = 0;

            output.submit(outTuple);
            output.punctuate(Punctuation.FINAL_MARKER);  
        }
        else
        {
            String temp = curMessage;
            
            String a[] = temp.split(",");
            
            routeid = a[0];
            
            timeSeconds = Long.parseLong(a[2]);
                
            sum += Double.parseDouble(a[3]);
            counter++;
        }
    }

    @Override
    public void processPunctuation(StreamingInput<Tuple> arg0, Punctuation arg1)
            throws Exception {
        System.out.println("Punctuation:" + arg1);
    }

    @Override
    public void shutdown() throws Exception {
        System.out.println("ShutDown");
    
    }

}

Please note the red words. If I do not add this line, although process() function can be executed, the average value can not be outputed to the .txt....and shutdown() will not be executed either.

Further, after adding this line, the average value can be outputed to the .txt, but shutdown() still can not be executed.

Do you know why shutdown() can not be executed in above 2 scenarios?

Thank you in advance!

  • Jason T
    Jason T
    31 Posts
    ACCEPTED ANSWER

    Re: Why shutdown() can not be executed in java operator?

    ‏2013-04-30T15:37:54Z  in response to waldstein

    Hello Baohua,

    The text in your post was all the same color (no red) so please be very specific about your question.

    For example...

    1. Shutdown does not work with the following line in the above code.

    <insert line here>

    Please also add any more information you may have about your scenario and your question.

    Thank You,
    Jason
     

    • waldstein
      waldstein
      33 Posts
      ACCEPTED ANSWER

      Re: Why shutdown() can not be executed in java operator?

      ‏2013-05-02T01:28:57Z  in response to Jason T

      Hello Jason,

      thank you for your attention :)

      I have already be clear of this situation: The application will not be closed unless mannual intervention.

      I will reshape my future questions to make it be easier for understanding

      Thank you!

      bao hua

  • danlopezv
    danlopezv
    22 Posts
    ACCEPTED ANSWER

    Re: Why shutdown() can not be executed in java operator?

    ‏2013-04-30T17:59:02Z  in response to waldstein

    Are you shutting down the Processing Element (PE) that is hosting that operator? If not, the void shutdown() method will not execute.

     

    Best regards,

    Daniel