mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 19:37:49 +01:00
Merge f04d181d8a
into 1090649211
This commit is contained in:
commit
26f5fd885d
2 changed files with 1 additions and 74 deletions
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2013 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.bitcoinj.net;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A base class which provides basic support for socket timeouts. It is used instead of integrating timeouts into the
|
|
||||||
* NIO select thread both for simplicity and to keep code shared between NIO and blocking sockets as much as possible.
|
|
||||||
* <p>
|
|
||||||
* @deprecated Don't extend this class, implement {@link TimeoutHandler} using {@link SocketTimeoutTask} instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public abstract class AbstractTimeoutHandler implements TimeoutHandler {
|
|
||||||
private final SocketTimeoutTask timeoutTask;
|
|
||||||
|
|
||||||
public AbstractTimeoutHandler() {
|
|
||||||
timeoutTask = new SocketTimeoutTask(this::timeoutOccurred);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Enables or disables the timeout entirely. This may be useful if you want to store the timeout value but wish
|
|
||||||
* to temporarily disable/enable timeouts.</p>
|
|
||||||
*
|
|
||||||
* <p>The default is for timeoutEnabled to be true but timeout to be set to {@link Duration#ZERO} (ie disabled).</p>
|
|
||||||
*
|
|
||||||
* <p>This call will reset the current progress towards the timeout.</p>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public synchronized final void setTimeoutEnabled(boolean timeoutEnabled) {
|
|
||||||
timeoutTask.setTimeoutEnabled(timeoutEnabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <p>Sets the receive timeout, automatically killing the connection if no
|
|
||||||
* messages are received for this long</p>
|
|
||||||
*
|
|
||||||
* <p>A timeout of 0{@link Duration#ZERO} is interpreted as no timeout.</p>
|
|
||||||
*
|
|
||||||
* <p>The default is for timeoutEnabled to be true but timeout to be set to {@link Duration#ZERO} (ie disabled).</p>
|
|
||||||
*
|
|
||||||
* <p>This call will reset the current progress towards the timeout.</p>
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public synchronized final void setSocketTimeout(Duration timeout) {
|
|
||||||
timeoutTask.setSocketTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Resets the current progress towards timeout to 0.
|
|
||||||
*/
|
|
||||||
protected synchronized void resetTimeout() {
|
|
||||||
timeoutTask.resetTimeout();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void timeoutOccurred();
|
|
||||||
}
|
|
|
@ -69,10 +69,8 @@ public class SocketTimeoutTask implements TimeoutHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the current progress towards timeout to 0.
|
* Resets the current progress towards timeout to 0.
|
||||||
* @deprecated This will be made private once {@link AbstractTimeoutHandler} is removed.
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
private synchronized void resetTimeout() {
|
||||||
synchronized void resetTimeout() {
|
|
||||||
if (timeoutTask != null)
|
if (timeoutTask != null)
|
||||||
timeoutTask.cancel();
|
timeoutTask.cancel();
|
||||||
if (timeout.isZero() || !timeoutEnabled)
|
if (timeout.isZero() || !timeoutEnabled)
|
||||||
|
|
Loading…
Add table
Reference in a new issue