本文整理匯總了Java中java.nio.channels.AsynchronousCloseException類的典型用法代碼示例。如果您正苦於以下問題:Java AsynchronousCloseException類的具體用法?Java AsynchronousCloseException怎麽用?Java AsynchronousCloseException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
AsynchronousCloseException類屬於java.nio.channels包,在下文中一共展示了AsynchronousCloseException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: stop
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
@Override
public void stop(boolean waitDone) throws IOException, InterruptedException {
final CountDownLatch latch = connectionLatch;
if (running.compareAndSet(true, false)) {
try {
if (serverSocketChannel != null) {
serverSocketChannel.close();
serverSocketChannel = null;
}
} catch (AsynchronousCloseException e) {
e.printStackTrace();
} finally {
if (waitDone) {
latch.await();
}
}
}
}
示例2: failed
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
@Override
public void failed(Throwable exc, ByteBuffer buffer) {
if((exc instanceof AsynchronousCloseException) ||
(exc instanceof ClosedChannelException)){
return;
}
if(exc instanceof Exception){
Exception e = (Exception)exc;
//兼容 windows 的 "java.io.IOException: 指定的網絡名不再可用" 錯誤
if(e.getStackTrace()[0].getClassName().contains("sun.nio.ch")){
session.close();
return;
}
//觸發 onException 事件
EventTrigger.fireExceptionThread(session, (Exception)exc);
}
}
示例3: end
import java.nio.channels.AsynchronousCloseException; //導入依賴的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();
}
}
示例4: testSerializationSelf
import java.nio.channels.AsynchronousCloseException; //導入依賴的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 = "AsynchronousCloseException",
args = {}
)
})
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new AsynchronousCloseException());
}
示例5: testSerializationCompatibility
import java.nio.channels.AsynchronousCloseException; //導入依賴的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 = "AsynchronousCloseException",
args = {}
)
})
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this, new AsynchronousCloseException());
}
示例6: transferStreams
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
private void transferStreams( BufferedReader reader, PrintWriter writer, boolean receive ) throws IOException
{
try {
String line;
while( ( line = reader.readLine() ) != null ) {
writer.println( line );
writer.flush();
if( receive ) {
publishProgress( CONNECTED.toString(), output.toString() );
}
}
} catch( AsynchronousCloseException e ) {
// This exception is thrown when socket for receiver thread is closed by netcat
Log.w( CLASS_NAME, e.toString() );
}
}
示例7: end
import java.nio.channels.AsynchronousCloseException; //導入依賴的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();
}
}
示例8: end
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
/**
* End an IO operation that was previously started with <code>begin()</code>.
*
* @param success
* pass true if the operation succeeded and had a side effect on
* the Java system, or false if not.
* @throws AsynchronousCloseException
* the channel was closed while the IO operation was in
* progress.
* @throws java.nio.channels.ClosedByInterruptException
* the thread conducting the IO operation was interrupted.
*/
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();
}
}
示例9: readMessages
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
/**
* Reads the incoming network data from the socket and retrieves the OF
* messages.
*
* @return list of OF messages
* @throws Exception
*/
@Override
public List<OFMessage> readMessages() throws IOException {
if (!socket.isOpen()) {
return null;
}
List<OFMessage> msgs = null;
int bytesRead = -1;
bytesRead = socket.read(inBuffer);
if (bytesRead < 0) {
throw new AsynchronousCloseException();
}
inBuffer.flip();
msgs = factory.parseMessages(inBuffer);
if (inBuffer.hasRemaining()) {
inBuffer.compact();
} else {
inBuffer.clear();
}
return msgs;
}
示例10: unreferenceCheckClosed
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
/**
* Decrement the reference count, checking to make sure that the
* CloseableReferenceCount is not closed.
*
* @throws AsynchronousCloseException If the status is closed.
*/
public void unreferenceCheckClosed() throws ClosedChannelException {
int newVal = status.decrementAndGet();
if ((newVal & STATUS_CLOSED_MASK) != 0) {
throw new AsynchronousCloseException();
}
}
示例11: failed
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
@Override
public void failed(Throwable exc, AioServer serverHandler) {
if (exc instanceof AsynchronousCloseException) {
connectionLatch.countDown();
} else {
exc.printStackTrace();
}
}
示例12: processOnce
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
public void processOnce() throws IOException {
// set status of query to OK.
ctx.getState().reset();
executor = null;
// reset sequence id of MySQL protocol
final MysqlChannel channel = ctx.getMysqlChannel();
channel.setSequenceId(0);
// read packet from channel
try {
packetBuf = channel.fetchOnePacket();
if (packetBuf == null) {
logger.warn("Null packet received from network. remote: {}", channel.getRemote());
throw new IOException("Error happened when receiving packet.");
}
} catch (AsynchronousCloseException e) {
// when this happened, timeout checker close this channel
// killed flag in ctx has been already set, just return
return;
}
// dispatch
dispatch();
// finalize
finalizeCommand();
ctx.setCommand(MysqlCommand.COM_SLEEP);
}
示例13: failed
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
@Override
public void failed(Throwable exc, AioSocketChannel channel) {
if (exc instanceof AsynchronousCloseException) {
//FIXME 產生該異常的原因是shutdownOutput後對方收到 read(-1)然後調用shutdownOutput,本地在收到read(-1)之前關閉了連接
return;
}
logger.error(exc.getMessage() + ", channel:" + channel, exc);
CloseUtil.close(channel);
}
示例14: onFailed
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
void onFailed(Throwable e) {
if (e instanceof AsynchronousCloseException) {
onClosed();
return;
}
if (!connected) return;
synchronized (sendSync) {
connected = false;
completeOutstandingRequestsExceptionally(e);
}
}
示例15: read
import java.nio.channels.AsynchronousCloseException; //導入依賴的package包/類
private int read(ByteBuffer[] dsts, int offset, int length, AtomicInteger posToUpdate)
throws IOException {
if(!isOpenForRead){
throw new NonReadableChannelException();
}
throwExceptionIfClosed();
int counter = 0;
synchronized(readWriteMonitor){
for(int j=offset; j<length; j++){
ByteBuffer dst = dsts[j];
int r = dst.remaining();
for(int i=0; i<r; i++){
int b = NativeMockedIO.read(path, posToUpdate);
if(b < 0){ //end of stream
return -1;
}
if(closed){
throw new AsynchronousCloseException();
}
if(Thread.currentThread().isInterrupted()){
close();
throw new ClosedByInterruptException();
}
dst.put((byte)b);
counter++;
}
}
}
return counter;
}