本文整理汇总了Java中java.nio.channels.ClosedByInterruptException类的典型用法代码示例。如果您正苦于以下问题:Java ClosedByInterruptException类的具体用法?Java ClosedByInterruptException怎么用?Java ClosedByInterruptException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClosedByInterruptException类属于java.nio.channels包,在下文中一共展示了ClosedByInterruptException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInterruptedWaitForProxy
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* This test sets off a blocking thread and then interrupts it, before
* checking that the thread was interrupted
*
* @throws Throwable any exception other than that which was expected
*/
@Test(timeout = 10000)
public void testInterruptedWaitForProxy() throws Throwable {
RpcThread worker = new RpcThread(100);
worker.start();
Thread.sleep(1000);
assertTrue("worker hasn't started", worker.waitStarted);
worker.interrupt();
worker.join();
Throwable caught = worker.getCaught();
assertNotNull("No exception was raised", caught);
// looking for the root cause here, which can be wrapped
// as part of the NetUtils work. Having this test look
// a the type of exception there would be brittle to improvements
// in exception diagnostics.
Throwable cause = caught.getCause();
if (cause == null) {
// no inner cause, use outer exception as root cause.
cause = caught;
}
if (!(cause instanceof InterruptedIOException)
&& !(cause instanceof ClosedByInterruptException)) {
throw caught;
}
}
示例2: getCharSequence
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* Converts an input file stream into a char sequence.
*
* @throws IOException
*/
static CharBuffer getCharSequence(final FileInputStream stream, Charset encoding) throws IOException {
FileChannel channel = stream.getChannel();
ByteBuffer bbuf = ByteBuffer.allocate((int) channel.size());
try {
channel.read(bbuf, 0);
} catch (ClosedByInterruptException cbie) {
return null; //this is actually okay
} finally {
channel.close();
}
bbuf.rewind();
CharBuffer cbuf = encoding.decode(bbuf);
return cbuf;
}
示例3: handleRefreshException
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
private void handleRefreshException(Exception e) {
if (e instanceof AlreadyClosedException) {
// ignore
} else if (e instanceof RefreshFailedEngineException) {
RefreshFailedEngineException rfee = (RefreshFailedEngineException) e;
if (rfee.getCause() instanceof InterruptedException) {
// ignore, we are being shutdown
} else if (rfee.getCause() instanceof ClosedByInterruptException) {
// ignore, we are being shutdown
} else if (rfee.getCause() instanceof ThreadInterruptedException) {
// ignore, we are being shutdown
} else {
if (state != IndexShardState.CLOSED) {
logger.warn("Failed to perform engine refresh", e);
}
}
} else {
if (state != IndexShardState.CLOSED) {
logger.warn("Failed to perform engine refresh", e);
}
}
}
示例4: position
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* set position in events from start of file
*
* @param event the number of the event, starting with 0
*/
@Override
synchronized public void position(long event) {
// if(event==size()) event=event-1;
int newChunkNumber;
try {
if ((newChunkNumber = getChunkNumber(event)) != chunkNumber) {
mapChunk(newChunkNumber);
}
byteBuffer.position((int) ((event * eventSizeBytes) % chunkSizeBytes));
position = event;
} catch (ClosedByInterruptException e3) {
log.info("caught interrupt, probably from single stepping this file");
} catch (ClosedChannelException cce) {
log.warning("caught exception " + cce);
cce.printStackTrace();
} catch (IOException e) {
log.warning("caught exception " + e);
e.printStackTrace();
} catch (IllegalArgumentException e2) {
log.warning("caught " + e2);
e2.printStackTrace();
}
}
示例5: doUninterruptibly
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* Perform an operation on the file, reopening the file and redoing the operation if necessary
* if we are interrupted in the middle of the operation
*/
private long doUninterruptibly(FileOperation op) throws IOException {
boolean interrupted = false;
try {
synchronized (UninterruptibleRandomAccessFile.this) {
while (true) {
interrupted |= Thread.interrupted();
FileChannel d = delegate();
long lastPosition = UninterruptibleRandomAccessFile.this.getFilePointer();
try {
return op.doOp(d);
} catch (ClosedByInterruptException e) {
interrupted = true;
UninterruptibleRandomAccessFile.this.reopen(lastPosition);
}
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
示例6: handleException
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
void handleException(DebugContext debug, IOException e) {
if (debug != null && DebugOptions.DumpingErrorsAreFatal.getValue(debug.getOptions())) {
throw new GraalError(e);
}
if (e instanceof ClosedByInterruptException) {
/*
* The current dumping was aborted by an interrupt so treat this as a transient failure.
*/
failuresCount = 0;
} else {
failuresCount++;
}
printer = null;
e.printStackTrace(TTY.out);
if (failuresCount > FAILURE_LIMIT) {
TTY.println("Too many failures with dumping. Disabling dump in thread " + Thread.currentThread());
}
}
示例7: reopen
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
private void reopen(int i, IOException e) throws IOException {
if (i > 20) {
throw e;
}
if (!(e instanceof ClosedByInterruptException) &&
!(e instanceof ClosedChannelException)) {
throw e;
}
// clear the interrupt flag, to avoid re-opening many times
Thread.interrupted();
FileChannel before = channel;
// ensure we don't re-open concurrently;
// sometimes we don't re-open, which is fine,
// as this method is called in a loop
synchronized (this) {
if (before == channel) {
open();
reLock();
}
}
}
示例8: handleException
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
void handleException(IOException e) {
if (GraalDebugConfig.Options.DumpingErrorsAreFatal.getValue(DebugScope.getConfig().getOptions())) {
throw new GraalError(e);
}
if (e instanceof ClosedByInterruptException) {
/*
* The current dumping was aborted by an interrupt so treat this as a transient failure.
*/
failuresCount = 0;
} else {
failuresCount++;
}
printer = null;
if (failuresCount > FAILURE_LIMIT) {
e.printStackTrace(TTY.out);
TTY.println("Too many failures with dumping. Disabling dump in thread " + Thread.currentThread());
} else {
TTY.println(e.getMessage());
}
}
示例9: run
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
@Override
public void run()
{
try {
L2CAPConnection clientConnection;
CommChannel channel;
while ( (clientConnection = connectionNotifier.acceptAndOpen()) != null ) {
channel = new BTL2CapCommChannel(
clientConnection,
inputPort().location(),
createProtocol() );
channel.setParentInputPort( inputPort() );
interpreter().commCore().scheduleReceive( channel, inputPort() );
channel = null; // Dispose for garbage collection
}
} catch( ClosedByInterruptException ce ) {
try {
connectionNotifier.close();
} catch( IOException ioe ) {
ioe.printStackTrace();
}
} catch( IOException e ) {
e.printStackTrace();
}
}
示例10: checkDiskError
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/** Check if there is no space in disk
* @param e that caused this checkDiskError call
**/
protected void checkDiskError(Exception e ) throws IOException {
LOG.warn("checkDiskError: exception: ", e);
if (e instanceof SocketException || e instanceof SocketTimeoutException
|| e instanceof ClosedByInterruptException
|| e.getMessage().startsWith("An established connection was aborted")
|| e.getMessage().startsWith("Broken pipe")
|| e.getMessage().startsWith("Connection reset")
|| e.getMessage().contains("java.nio.channels.SocketChannel")) {
LOG.info("Not checking disk as checkDiskError was called on a network" +
" related exception");
return;
}
if (e.getMessage() != null &&
e.getMessage().startsWith("No space left on device")) {
throw new DiskOutOfSpaceException("No space left on device");
} else {
checkDiskError();
}
}
示例11: doDownload
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
private static Void doDownload(AddonReleaseData releaseData) throws WarDownloadException {
String warURL = releaseData.getDownloadUrl();
String dlPath = dlPath(releaseData.getVersion());
try {
URL website = new URL(warURL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(dlPath);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
try (FileInputStream fis = new FileInputStream(dlPath)) {
String sha256 = DigestUtils.sha256Hex(fis);
if (!sha256.equals(releaseData.getSha256())) {
throw new WarDownloadException("Download of War file either corrupted or some 3rd party has changed the file");
}
}
} catch (ClosedByInterruptException ignored) {
App.logger.error("War download interrupted before it could complete");
} catch (IOException e) {
throw new WarDownloadException(e);
}
return null;
}
示例12: end
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* Indicates the end of a code section that has been started with
* {@code begin()} and that includes a potentially blocking I/O operation.
*
* @param success
* pass {@code true} if the blocking operation has succeeded and
* has had a noticeable effect; {@code false} otherwise.
* @throws AsynchronousCloseException
* if this channel is closed by another thread while this method
* is executing.
* @throws ClosedByInterruptException
* if another thread interrupts the calling thread while this
* method is executing.
*/
protected final void end(boolean success) throws AsynchronousCloseException {
// FIXME: be accommodate before VM actually provides
// setInterruptAction method
if (setInterruptAction != null) {
try {
setInterruptAction.invoke(Thread.currentThread(),
new Object[] { null });
} catch (Exception e) {
throw new RuntimeException(e);
}
if (interrupted) {
interrupted = false;
throw new ClosedByInterruptException();
}
}
if (!success && closed) {
throw new AsynchronousCloseException();
}
}
示例13: testSerializationSelf
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationSelf",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "ClosedByInterruptException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new ClosedByInterruptException());
}
示例14: testSerializationCompatibility
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/**
* @tests serialization/deserialization compatibility with RI.
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "!SerializationGolden",
args = {}
),
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies serialization/deserialization compatibility.",
method = "ClosedByInterruptException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this, new ClosedByInterruptException());
}
示例15: handleInterruptible
import java.nio.channels.ClosedByInterruptException; //导入依赖的package包/类
/***
*
* @param ex
* @return
* @throws InterruptedException
*/
public static <T extends Throwable> T handleInterruptible(final T ex) throws InterruptedException {
if (getInitialException(ex, ClosedByInterruptException.class) != null) {
// This is how you detect InterruptedException from within BufferedReader.
// I figured this out by looking at the source code for the GNU nio Channels
// interface but it's backed up by
// http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/ClosedByInterruptException.html
throw (InterruptedException) new InterruptedException().initCause(ex);
}
if (getInitialException(ex, InterruptedException.class) != null) {
// There was an underlying InterruptedException that was chained below another error.
throw (InterruptedException) new InterruptedException().initCause(ex);
}
// The exception probably wasn't an InterruptedException.
return ex;
}