private CFEndPoint cloneEndpoint ( final CFEndPoint originalEndPoint ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . entry ( this , tc , "cloneEndpoint" , originalEndPoint ) ; CFEndPoint endPoint ; ByteArrayOutputStream baos = null ; ObjectOutputStream out = null ; ObjectInputStream in = null ; try { baos = new ByteArrayOutputStream ( ) ; out = new ObjectOutputStream ( baos ) ; out . writeObject ( originalEndPoint ) ; out . flush ( ) ; ClassLoader cl = AccessController . doPrivileged ( new PrivilegedAction < ClassLoader > ( ) { @ Override public ClassLoader run ( ) { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; in = new DeserializationObjectInputStream ( new ByteArrayInputStream ( baos . toByteArray ( ) ) , cl ) ; endPoint = ( CFEndPoint ) in . readObject ( ) ; } catch ( IOException e ) { FFDCFilter . processException ( e , CLASS_NAME + ".cloneEndpoint" , JFapChannelConstants . RICHCLIENTFRAMEWORK_CLONE_01 , this ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "Caught IOException copying endpoint" , e ) ; //Use input parameter. endPoint = originalEndPoint ; } catch ( ClassNotFoundException e ) { FFDCFilter . processException ( e , CLASS_NAME + ".cloneEndpoint" , JFapChannelConstants . RICHCLIENTFRAMEWORK_CLONE_02 , this ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) SibTr . debug ( this , tc , "Caught ClassNotFoundException copying endpoint" , e ) ; //Use input parameter. endPoint = originalEndPoint ; } finally { //Tidy up resources. try { if ( out != null ) { out . close ( ) ; } if ( in != null ) { in . close ( ) ; } } catch ( IOException e ) { //No FFDC code needed. //Absorb any exceptions as we no longer care. } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) SibTr . exit ( this , tc , "cloneEndpoint" , endPoint ) ; return endPoint ; }
Creates a copy of originalEndPoint . This is to prevent us causing problems when we change it . As there is no exposed way to do this we will use serialization . It may be a bit slow but it is implementation safe as the implementation of CFEndPoint is designed to be serialized by WLM . Plus we only need to do this when creating the original connection so it is not main line code .