/** * Tries to close the component's connection(s). Ignores any problems which * normally would be reported by the {@link #close()} method with an * according exception. * * The default implementation tries to invoke a "flush()" in case the * implementing instance implements the {@link java.io.Flushable} interface * before invoking {@link #close()}. Additionally the default implementation * tries {@link IoRetryCount#NORM} number of times to invoke * {@link #close()} till a timeout of {@link IoTimeout#NORM} is reached. In * any case this method will return quietly without throwing any exception. */ default void closeQuietly() { if ( this instanceof java.io.Flushable ) { try { ((java.io.Flushable) this).flush(); } catch ( Exception ignore ) {} } RetryTimeout theRetryTimeout = new RetryTimeoutImpl( IoTimeout.NORM.getMilliseconds(), IoRetryCount.NORM.getNumber() ); while ( theRetryTimeout.hasNextRetry() ) { try { close(); return; } catch ( CloseException ignore ) {} } }
/** * Pushes a datagram into the receiver and puts it into the blocking queue * containing the so far received datagrams. Them datagrams can be retrieved * via {@link #readDatagram()}: use {@link #hasDatagram()} to test * beforehand whether there is a datagram available. * * @param aDatagram The datagram to be pushed at the end of the blocking * queue; to be retrieved with the {@link #readDatagram()} method. * @throws OpenException the open exception */ protected void pushDatagram( DATA aDatagram ) throws OpenException { if ( !isOpened() ) { throw new OpenException( "Unable to push datagram <" + aDatagram.getClass().getName() + "> as the connection is NOT OPEN; connection status is " + getConnectionStatus() + "." ); } RetryCounter theRetryCounter = new RetryCounterImpl( IoRetryCount.MAX.getNumber() ); try { while ( !_datagramQueue.offer( aDatagram, LoopSleepTime.MAX.getMilliseconds(), TimeUnit.MILLISECONDS ) && theRetryCounter.nextRetry() ) { warn( "Trying to offer (add) a datagram to the datagram queue, though the queue is full, this is retry # <" + theRetryCounter.getRetryCount() + ">, aborting after <" + theRetryCounter.getRetryNumber() + "> retries. Retrying now after a delay of <" + (LoopSleepTime.MAX.getMilliseconds() / 1000) + "> seconds..." ); if ( !theRetryCounter.hasNextRetry() ) { throw new OpenException( "Unable to process the datagram after <" + theRetryCounter.getRetryNumber() + "> retries, aborting retries, dismissing datagram \"" + aDatagram.toString() + "\"!", null, null ); } } } catch ( InterruptedException ignored ) {} }
/** * Pushes a datagram into the receiver and puts it into the blocking queue * containing the so far received datagrams. Them datagrams can be retrieved * via {@link #readDatagram()}: * * Use {@link AbstractByteReceiver} extension's * {@link AbstractByteReceiver#hasDatagram()} to test beforehand whether * there is a datagram available. * * @param aDatagram The datagram to be pushed at the end of the blocking * queue; to be retrieved with the {@link #readDatagram()} method. * @throws OpenException the open exception */ protected void pushDatagram( byte aDatagram ) throws OpenException { RetryCounter theRetryCounter = new RetryCounterImpl( IoRetryCount.MAX.getNumber() ); try { while ( !_datagramQueue.offer( aDatagram, LoopSleepTime.MAX.getMilliseconds(), TimeUnit.MILLISECONDS ) && theRetryCounter.nextRetry() ) { warn( "Trying to offer (add) a datagram to the datagram queue, though the queue is full, this is retry # <" + theRetryCounter.getRetryCount() + ">, aborting after <" + theRetryCounter.getRetryNumber() + "> retries. Retrying now after a delay of <" + (LoopSleepTime.MAX.getMilliseconds() / 1000) + "> seconds..." ); if ( !theRetryCounter.hasNextRetry() ) { throw new OpenException( "Unable to process the datagram after <" + theRetryCounter.getRetryNumber() + "> retries, aborting retries, dismissing datagram \"" + aDatagram + "\"!", null, null ); } } } catch ( InterruptedException ignored ) {} }
/** * Pushes a datagram into the receiver and puts it into the blocking queue * containing the so far received datagrams. Them datagrams can be retrieved * via {@link #readDatagram()}: use {@link #hasDatagram()} to test * beforehand whether there is a datagram available. * * @param aDatagram The datagram to be pushed at the end of the blocking * queue; to be retrieved with the {@link #readDatagram()} method. * @throws OpenException the open exception */ protected void pushDatagram( short aDatagram ) throws OpenException { if ( !isOpened() ) { throw new OpenException( "Unable to push datagram <" + aDatagram + "> as the connection is NOT OPEN; connection status is " + getConnectionStatus() + "." ); } RetryCounter theRetryCounter = new RetryCounterImpl( IoRetryCount.MAX.getNumber() ); try { while ( !_datagramQueue.offer( aDatagram, LoopSleepTime.MAX.getMilliseconds(), TimeUnit.MILLISECONDS ) && theRetryCounter.nextRetry() ) { warn( "Trying to offer (add) a datagram to the datagram queue, though the queue is full, this is retry # <" + theRetryCounter.getRetryCount() + ">, aborting after <" + theRetryCounter.getRetryNumber() + "> retries. Retrying now after a delay of <" + (LoopSleepTime.MAX.getMilliseconds() / 1000) + "> seconds..." ); if ( !theRetryCounter.hasNextRetry() ) { throw new OpenException( "Unable to process the datagram after <" + theRetryCounter.getRetryNumber() + "> retries, aborting retries, dismissing datagram \"" + aDatagram + "\"!", null, null ); } } } catch ( InterruptedException ignored ) {} }
RetryCounter theRetryCounter = new RetryCounterImpl( IoRetryCount.NORM.getNumber(), LatencySleepTime.MIN.getMilliseconds(), LoopExtensionTime.NORM.getMilliseconds() ); while ( theRetryCounter.nextRetry() ) { List<CipherVersion> theCipherVersions = _decryptionService.getCipherVersions();
/** * Waits for the {@link DatagramTransceiver} to open up; in case it is * open, then true is returned; in case it does not open within a given * period of time then false is returned. * * @return True in case the {@link DatagramTransceiver} is (finally) * open. */ private boolean isOpened() { if ( !AbstractRemote.this.isOpened() ) { return false; } else if ( _transceiver.isOpened() && AbstractRemote.this.isOpened() ) { return true; } else if ( AbstractRemote.this.isOpened() && !_transceiver.isOpened() ) { RetryCounter theRetryCounter = new RetryCounterImpl( IoRetryCount.NORM.getNumber(), LatencySleepTime.NORM.getMilliseconds(), LoopExtensionTime.NORM.getMilliseconds() ); while ( AbstractRemote.this.isOpened() && theRetryCounter.hasNextRetry() && !_transceiver.isOpened() ) { // @formatter:off if ( ENABLE_EXTENDED_DEBUG_LOGGING ) LOGGER.debug( "Wait loop <" + theRetryCounter.getRetryCount() + "> while waiting for OPEN for <" + WAIT_FOR_REPLY_LOOPS + "> ms; connection status is " + getConnectionStatus() + " (transceiver connection status is " + _transceiver.getConnectionStatus() + ")."); // @formatter:on theRetryCounter.nextRetry(); } } if ( _transceiver.isOpened() && AbstractRemote.this.isOpened() ) { return true; } return false; }