public void open ( URL eventStreamURL ) throws IOException { log . info ( "Connecting to event stream |%s|." , eventStreamURL ) ; connection = ( HttpURLConnection ) eventStreamURL . openConnection ( ) ; connection . setConnectTimeout ( CONNECTION_TIMEOUT ) ; connection . setReadTimeout ( READ_TIMEOUT ) ; connection . setRequestProperty ( "Accept" , "text/event-stream" ) ; connection . setRequestProperty ( "Connection" , "keep-alive" ) ; connection . setRequestProperty ( "Pragma" , "no-cache" ) ; connection . setRequestProperty ( "Cache" , "no-cache" ) ; // at this point HTTP URL connection implementation sends request and waits for response // then parses first line and headers and return input stream for body content inputStream = connection . getInputStream ( ) ; }
Opens connection with given event stream and initialize internal input stream . Because this method involve networking and server side processes it is not instant . Anyway usually cannot exceed one second or two .