Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val socketCancelable = SingleAssignmentCancelable()
- def doConnection: Option[TLSConnection] = {
- def initiateTLSConnection = scala.concurrent.blocking {
- val socket = new Socket(host, port)
- val bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream))
- TLSConnection(socket, bufferedReader)
- }
- try {
- val tLSConnection = initiateTLSConnection
- // our cancelable must be able to cleanly dispose of our connection
- socketCancelable := BooleanCancelable { () =>
- blocking {
- println("closing shit !!!!!")
- try tLSConnection.in.close()
- finally tLSConnection.socket.close()
- }
- }
- if (tLSConnection.in.readLine() == null || tLSConnection.in.read() == -1) {
- log.info(s"still connection unavailable... will retry")
- None
- } else {
- log.info(s"successfully connected")
- Some(tLSConnection)
- }
- } catch {
- case NonFatal(ex) =>
- log.error(ex.getMessage)
- socketCancelable.cancel()
- None
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement