public CommPort open ( String TheOwner , int i ) throws gnu . io . PortInUseException { LOGGER . fine ( "CommPortIdentifier:open(" + TheOwner + ", " + i + ")" ) ; boolean isAvailable ; synchronized ( this ) { isAvailable = this . Available ; if ( isAvailable ) { //assume ownership inside the synchronized block this . Available = false ; this . Owner = TheOwner ; } } if ( ! isAvailable ) { long waitTimeEnd = System . currentTimeMillis ( ) + i ; //fire the ownership event outside the synchronized block fireOwnershipEvent ( CommPortOwnershipListener . PORT_OWNERSHIP_REQUESTED ) ; long waitTimeCurr ; synchronized ( this ) { while ( ! Available && ( waitTimeCurr = System . currentTimeMillis ( ) ) < waitTimeEnd ) { try { wait ( waitTimeEnd - waitTimeCurr ) ; } catch ( InterruptedException e ) { Thread . currentThread ( ) . interrupt ( ) ; break ; } } isAvailable = this . Available ; if ( isAvailable ) { //assume ownership inside the synchronized block this . Available = false ; this . Owner = TheOwner ; } } } if ( ! isAvailable ) { throw new gnu . io . PortInUseException ( getCurrentOwner ( ) ) ; } //At this point, the CommPortIdentifier is owned by us. try { if ( commPort == null ) { commPort = RXTXDriver . getCommPort ( portName , portType ) ; } if ( commPort != null ) { fireOwnershipEvent ( CommPortOwnershipListener . PORT_OWNED ) ; return commPort ; } else { String err_msg ; try { err_msg = native_psmisc_report_owner ( portName ) ; } catch ( Throwable t ) { err_msg = "Port " + portName + " already owned... unable to open." ; } throw new gnu . io . PortInUseException ( err_msg ) ; } } finally { if ( commPort == null ) { //something went wrong reserving the commport -> unown the port synchronized ( this ) { this . Available = true ; this . Owner = null ; } } } }
not written in java? I can t see where this request is done .