本文整理汇总了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;
}