@ SuppressWarnings ( "unchecked" ) protected void _handshake ( ) throws IOException { // do connection handshake PyroSerializer ser = PyroSerializer . getFor ( Config . SERIALIZER ) ; Map < String , Object > handshakedata = new HashMap < String , Object > ( ) ; handshakedata . put ( "handshake" , pyroHandshake ) ; if ( Config . METADATA ) handshakedata . put ( "object" , objectid ) ; byte [ ] data = ser . serializeData ( handshakedata ) ; int flags = Config . METADATA ? Message . FLAGS_META_ON_CONNECT : 0 ; Message msg = new Message ( Message . MSG_CONNECT , data , ser . getSerializerId ( ) , flags , sequenceNr , annotations ( ) , pyroHmacKey ) ; IOUtil . send ( sock_out , msg . to_bytes ( ) ) ; if ( Config . MSG_TRACE_DIR != null ) { Message . TraceMessageSend ( sequenceNr , msg . get_header_bytes ( ) , msg . get_annotations_bytes ( ) , msg . data ) ; } // process handshake response msg = Message . recv ( sock_in , new int [ ] { Message . MSG_CONNECTOK , Message . MSG_CONNECTFAIL } , pyroHmacKey ) ; responseAnnotations ( msg . annotations , msg . type ) ; Object handshake_response = "?" ; if ( msg . data != null ) { if ( ( msg . flags & Message . FLAGS_COMPRESSED ) != 0 ) { _decompressMessageData ( msg ) ; } try { ser = PyroSerializer . getFor ( msg . serializer_id ) ; handshake_response = ser . deserializeData ( msg . data ) ; } catch ( Exception x ) { msg . type = Message . MSG_CONNECTFAIL ; handshake_response = "<not available because unsupported serialization format>" ; } } if ( msg . type == Message . MSG_CONNECTOK ) { if ( ( msg . flags & Message . FLAGS_META_ON_CONNECT ) != 0 ) { HashMap < String , Object > response_dict = ( HashMap < String , Object > ) handshake_response ; HashMap < String , Object > metadata = ( HashMap < String , Object > ) response_dict . get ( "meta" ) ; _processMetadata ( metadata ) ; handshake_response = response_dict . get ( "handshake" ) ; try { validateHandshake ( handshake_response ) ; } catch ( IOException x ) { close ( ) ; throw x ; } } } else if ( msg . type == Message . MSG_CONNECTFAIL ) { close ( ) ; throw new PyroException ( "connection rejected, reason: " + handshake_response ) ; } else { close ( ) ; throw new PyroException ( "connect: invalid msg type " + msg . type + " received" ) ; } }
Perform the Pyro protocol connection handshake with the Pyro daemon .