69
69
public final class JavaRecoverableNetworkWordCount {
70
70
private static final Pattern SPACE = Pattern .compile (" " );
71
71
72
- private static JavaStreamingContext createContext (String ip , int port , String outputPath ) {
72
+ private static JavaStreamingContext createContext (String ip ,
73
+ int port ,
74
+ String checkpointDirectory ,
75
+ String outputPath ) {
73
76
74
77
// If you do not see this printed, that means the StreamingContext has been loaded
75
78
// from the new checkpoint
@@ -81,6 +84,7 @@ private static JavaStreamingContext createContext(String ip, int port, String ou
81
84
SparkConf sparkConf = new SparkConf ().setAppName ("JavaRecoverableNetworkWordCount" );
82
85
// Create the context with a 1 second batch size
83
86
JavaStreamingContext ssc = new JavaStreamingContext (sparkConf , Durations .seconds (1 ));
87
+ ssc .checkpoint (checkpointDirectory );
84
88
85
89
// Create a socket stream on target ip:port and count the
86
90
// words in input stream of \n delimited text (eg. generated by 'nc')
@@ -135,12 +139,12 @@ public static void main(String[] args) {
135
139
136
140
final String ip = args [0 ];
137
141
final int port = Integer .parseInt (args [1 ]);
138
- String checkpointDirectory = args [2 ];
142
+ final String checkpointDirectory = args [2 ];
139
143
final String outputPath = args [3 ];
140
144
JavaStreamingContextFactory factory = new JavaStreamingContextFactory () {
141
145
@ Override
142
146
public JavaStreamingContext create () {
143
- return createContext (ip , port , outputPath );
147
+ return createContext (ip , port , checkpointDirectory , outputPath );
144
148
}
145
149
};
146
150
JavaStreamingContext ssc = JavaStreamingContext .getOrCreate (checkpointDirectory , factory );
0 commit comments