Java Code Examples for java.nio.channels.CompletionHandler#completed()

The following examples show how to use java.nio.channels.CompletionHandler#completed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TlsAsynchronousSocketChannel.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Main entry point from caller.
 */
@Override
public <A> void read(ByteBuffer dest, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> hdlr) {
    try {
        if (this.handler != null) {
            hdlr.completed(0, null);
        }
        this.handler = hdlr;
        this.dst = dest;
        if (this.clearTextBuffer.hasRemaining()) {
            // copy any remaining data directly to client
            dispatchData();
        } else if (this.cipherTextBuffer.hasRemaining()) {
            // otherwise, decrypt ciphertext data remaining from last time
            decryptAndDispatch();
        } else {
            // otherwise, issue a new read request
            this.cipherTextBuffer.clear();
            this.channel.read(this.cipherTextBuffer, null, this);
        }
    } catch (Throwable ex) {
        hdlr.failed(ex, null);
    }
}
 
Example 2
Source File: TlsAsynchronousSocketChannel.java    From FoxTelem with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Main entry point from caller.
 */
@Override
public <A> void read(ByteBuffer dest, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer, ? super A> hdlr) {
    try {
        if (this.handler != null) {
            hdlr.completed(0, null);
        }
        this.handler = hdlr;
        this.dst = dest;
        if (this.clearTextBuffer.hasRemaining()) {
            // copy any remaining data directly to client
            dispatchData();
        } else if (this.cipherTextBuffer.hasRemaining()) {
            // otherwise, decrypt ciphertext data remaining from last time
            decryptAndDispatch();
        } else {
            // otherwise, issue a new read request
            this.cipherTextBuffer.clear();
            this.channel.read(this.cipherTextBuffer, null, this);
        }
    } catch (Throwable ex) {
        hdlr.failed(ex, null);
    }
}
 
Example 3
Source File: TlsAsynchronousSocketChannel.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Completion handler for a read. Prepare the buffer for decryption and continue with {@link #decryptAndDispatch()}.
 */
public void completed(Integer result, Void attachment) {
    if (result < 0) {
        CompletionHandler<Integer, ?> h = this.handler;
        this.handler = null;
        h.completed(result, null);
        return;
    }
    this.cipherTextBuffer.flip();
    decryptAndDispatch();
}
 
Example 4
Source File: SyncMessageSender.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
public void send(XMessage message, CompletionHandler<Long, Void> callback) {
    synchronized (this.waitingAsyncOperationMonitor) {
        MessageLite msg = message.getMessage();
        try {
            send(message);
            long result = 4 + 1 + msg.getSerializedSize();
            callback.completed(result, null);
        } catch (Throwable t) {
            callback.failed(t, null);
        }
    }
}
 
Example 5
Source File: TlsAsynchronousSocketChannel.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Completion handler for a read. Prepare the buffer for decryption and continue with {@link #decryptAndDispatch()}.
 * 
 * @param result
 *            number of processed bytes
 * @param attachment
 *            Void
 */
public void completed(Integer result, Void attachment) {
    if (result < 0) {
        CompletionHandler<Integer, ?> h = this.handler;
        this.handler = null;
        h.completed(result, null);
        return;
    }
    this.cipherTextBuffer.flip();
    decryptAndDispatch();
}
 
Example 6
Source File: SncpTestServiceImpl.java    From redkale with Apache License 2.0 4 votes vote down vote up
public void queryResult(CompletionHandler<String, SncpTestBean> handler, @RpcAttachment SncpTestBean bean) {
    System.out.println(Thread.currentThread().getName() + " handler 运行了queryResult方法");
    if (handler != null) handler.completed("result: " + bean, bean);
}
 
Example 7
Source File: CService.java    From redkale with Apache License 2.0 4 votes vote down vote up
public void ccCurrentTime(final CompletionHandler<RetResult<String>, Void> handler, final String name) {
    String rs = "异步ccCurrentTime: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
    System.out.println("执行了 CService.ccCurrentTime----异步方法");
    if (handler != null) handler.completed(new RetResult(rs), null);
}
 
Example 8
Source File: HelloService.java    From redkale with Apache License 2.0 4 votes vote down vote up
@RestMapping(name = "asyncfind2")
public void asyncFindHello(CompletionHandler hander, @RestParam(name = "#") int id) {  //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
    if (source != null) source.findAsync(HelloEntity.class, id);
    System.out.println("-----------进入asyncfind2--------" + hander);
    hander.completed(new HelloEntity(id), id);
}