Java Code Examples for java.nio.channels.CompletionHandler

The following are top voted examples for showing how to use java.nio.channels.CompletionHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: FileManagerTransaction.java   View source code 6 votes vote down vote up
@Override
@NonNull
JavaFileObject createFileObject(
        @NonNull final Location location,
        @NonNull final File file,
        @NonNull final File root,
        @NullAllowed final JavaFileFilterImplementation filter,
        @NullAllowed final Charset encoding) {
    final CompletionHandler<Void,Void> handler = getAsyncHandler();
    return handler == null || !JavaIndexerWorker.supportsConcurrent()?
        FileObjects.fileFileObject(file, root, filter, encoding) :
        FileObjects.asyncWriteFileObject(
            file,
            root,
            filter,
            encoding,
            JavaIndexerWorker.getExecutor(),
            handler);
}
 
Example 2
Project: incubator-netbeans   File: FileObjects.java   View source code 6 votes vote down vote up
@NonNull
public static PrefetchableJavaFileObject asyncWriteFileObject(
    @NonNull final File file,
    @NonNull final File root,
    @NullAllowed JavaFileFilterImplementation filter,
    @NullAllowed Charset encoding,
    @NonNull final Executor pool,
    @NonNull final CompletionHandler<Void,Void> done) {
    final String[] pkgNamePair = getFolderAndBaseName(getRelativePath(root,file),File.separatorChar);
    return new AsyncWriteFileObject(
        file,
        convertFolder2Package(pkgNamePair[0], File.separatorChar),
        pkgNamePair[1],
        filter,
        encoding,
        pool,
        done);
}
 
Example 3
Project: tomcat7   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void read(ByteBuffer dst, A attachment,
        CompletionHandler<Integer,B> handler) {

    WrapperFuture<Integer,B> future =
            new WrapperFuture<Integer, B>(handler, attachment);

    if (!reading.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentRead"));
    }

    ReadTask readTask = new ReadTask(dst, future);

    executor.execute(readTask);
}
 
Example 4
Project: tomcat7   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {

    WrapperFuture<Long,B> future =
            new WrapperFuture<Long, B>(handler, attachment);

    if (!writing.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentWrite"));
    }

    WriteTask writeTask = new WriteTask(srcs, offset, length, future);

    executor.execute(writeTask);
}
 
Example 5
Project: apache-tomcat-7.0.73-with-comment   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void read(ByteBuffer dst, A attachment,
        CompletionHandler<Integer,B> handler) {

    WrapperFuture<Integer,B> future =
            new WrapperFuture<Integer, B>(handler, attachment);

    if (!reading.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentRead"));
    }

    ReadTask readTask = new ReadTask(dst, future);

    executor.execute(readTask);
}
 
Example 6
Project: apache-tomcat-7.0.73-with-comment   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {

    WrapperFuture<Long,B> future =
            new WrapperFuture<Long, B>(handler, attachment);

    if (!writing.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentWrite"));
    }

    WriteTask writeTask = new WriteTask(srcs, offset, length, future);

    executor.execute(writeTask);
}
 
Example 7
Project: dble   File: MySQLConnectionFactory.java   View source code 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler,
                            String schema) throws IOException {

    DBHostConfig dsc = pool.getConfig();
    NetworkChannel channel = openSocketChannel(DbleServer.getInstance().isAIO());

    MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
    c.setSocketParams(false);
    c.setHost(dsc.getIp());
    c.setPort(dsc.getPort());
    c.setUser(dsc.getUser());
    c.setPassword(dsc.getPassword());
    c.setSchema(schema);
    c.setHandler(new MySQLConnectionAuthenticator(c, handler));
    c.setPool(pool);
    c.setIdleTimeout(pool.getConfig().getIdleTimeout());
    if (channel instanceof AsynchronousSocketChannel) {
        ((AsynchronousSocketChannel) channel).connect(
                new InetSocketAddress(dsc.getIp(), dsc.getPort()), c,
                (CompletionHandler) DbleServer.getInstance().getConnector());
    } else {
        ((NIOConnector) DbleServer.getInstance().getConnector()).postConnect(c);
    }
    return c;
}
 
Example 8
Project: netty-book   File: ReadCompletionHandler.java   View source code 6 votes vote down vote up
private void doWrite(String currentTime) {
if (currentTime != null && currentTime.trim().length() > 0) {
    byte[] bytes = (currentTime).getBytes();
    ByteBuffer writeBuffer = ByteBuffer.allocate(bytes.length);
    writeBuffer.put(bytes);
    writeBuffer.flip();
    channel.write(writeBuffer, writeBuffer,
	    new CompletionHandler<Integer, ByteBuffer>() {
		@Override
		public void completed(Integer result, ByteBuffer buffer) {
		    // 如果没有发送完成,继续发送
		    if (buffer.hasRemaining())
			channel.write(buffer, buffer, this);
		}

		@Override
		public void failed(Throwable exc, ByteBuffer attachment) {
		    try {
			channel.close();
		    } catch (IOException e) {
			// ingnore on close
		    }
		}
	    });
}
   }
 
Example 9
Project: parallelism-benchmarks   File: FountainSocketBenchmark.java   View source code 6 votes vote down vote up
private CompletionHandler<AsynchronousSocketChannel, Integer> acceptCompletionHandler(
			int byteCount, AsynchronousServerSocketChannel socket) {
		return new CompletionHandler<AsynchronousSocketChannel, Integer>() {
			public void completed(
					AsynchronousSocketChannel ch,
					Integer acceptsToGo) {
				acceptsToGo = acceptsToGo-1;
//				System.out.println("server accepted, to go = " + acceptsToGo);
				writeStuffThreadAsync(socket, ch, byteCount, acceptsToGo);
				if (acceptsToGo > 0) {
					socket.accept(acceptsToGo, acceptCompletionHandler(byteCount, socket));
				}
			}
			public void failed(Throwable exc, Integer attachment) {
				exc.printStackTrace();
				try {
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		};
	}
 
Example 10
Project: hope-tactical-equipment   File: ReadCompletionHandler.java   View source code 6 votes vote down vote up
private void doWrite(String currentTime) {
    if (currentTime != null && currentTime.trim().length() > 0) {
        byte[] bytes = (currentTime).getBytes();
        ByteBuffer writeBuffer = ByteBuffer.allocate(bytes.length);
        writeBuffer.put(bytes);
        writeBuffer.flip();
        channel.write(writeBuffer, writeBuffer,
                new CompletionHandler<Integer, ByteBuffer>() {
                    @Override
                    public void completed(Integer result, ByteBuffer buffer) {
                        // 如果没有发送完成,继续发送
                        if (buffer.hasRemaining())
                            channel.write(buffer, buffer, this);
                    }

                    @Override
                    public void failed(Throwable exc, ByteBuffer attachment) {
                        try {
                            channel.close();
                        } catch (IOException e) {
                            // ingnore on close
                        }
                    }
                });
    }
}
 
Example 11
Project: ephemeralfs   File: EphemeralFsAsynchronousFileChannel.java   View source code 6 votes vote down vote up
@Override
public <A> void lock(final long position, final long size, final boolean shared,
        final A attachment, final CompletionHandler<FileLock, ? super A> handler) {
    
    if(handler == null) {
        throw new NullPointerException("handler is null");
    }
    
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try
            {
                handler.completed(channel.lock(position, size, shared), attachment);
            } catch(Exception e) {
                handler.failed(e, attachment);
            }
        }
    });
    
}
 
Example 12
Project: ephemeralfs   File: EphemeralFsAsynchronousFileChannel.java   View source code 6 votes vote down vote up
@Override
public <A> void read(final ByteBuffer dst, final long position, final A attachment,
        final CompletionHandler<Integer, ? super A> handler) {
    
    if(handler == null) {
        throw new NullPointerException("handler is null");
    }
    
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try
            {
                handler.completed(channel.read(dst, position), attachment);
            } catch(Exception e) {
                handler.failed(e, attachment);
            }
        }
    });
    
}
 
Example 13
Project: ephemeralfs   File: EphemeralFsAsynchronousFileChannel.java   View source code 6 votes vote down vote up
@Override
public <A> void write(final ByteBuffer src, final long position, final A attachment,
        final CompletionHandler<Integer, ? super A> handler) {
    
    if(handler == null) {
        throw new NullPointerException("handler is null");
    }
    
    executor.execute(new Runnable() {
        @Override
        public void run() {
            try
            {
                handler.completed(channel.write(src, position), attachment);
            } catch(Exception e) {
                handler.failed(e, attachment);
            }
        }
    });
    
}
 
Example 14
Project: class-guard   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void read(ByteBuffer dst, A attachment,
        CompletionHandler<Integer,B> handler) {

    WrapperFuture<Integer,B> future =
            new WrapperFuture<Integer, B>(handler, attachment);

    if (!reading.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentRead"));
    }

    ReadTask readTask = new ReadTask(dst, future);

    executor.execute(readTask);
}
 
Example 15
Project: class-guard   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {

    WrapperFuture<Long,B> future =
            new WrapperFuture<Long, B>(handler, attachment);

    if (!writing.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentWrite"));
    }

    WriteTask writeTask = new WriteTask(srcs, offset, length, future);

    executor.execute(writeTask);
}
 
Example 16
Project: apache-tomcat-7.0.57   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void read(ByteBuffer dst, A attachment,
        CompletionHandler<Integer,B> handler) {

    WrapperFuture<Integer,B> future =
            new WrapperFuture<Integer, B>(handler, attachment);

    if (!reading.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentRead"));
    }

    ReadTask readTask = new ReadTask(dst, future);

    executor.execute(readTask);
}
 
Example 17
Project: apache-tomcat-7.0.57   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {

    WrapperFuture<Long,B> future =
            new WrapperFuture<Long, B>(handler, attachment);

    if (!writing.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentWrite"));
    }

    WriteTask writeTask = new WriteTask(srcs, offset, length, future);

    executor.execute(writeTask);
}
 
Example 18
Project: apache-tomcat-7.0.57   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void read(ByteBuffer dst, A attachment,
        CompletionHandler<Integer,B> handler) {

    WrapperFuture<Integer,B> future =
            new WrapperFuture<Integer, B>(handler, attachment);

    if (!reading.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentRead"));
    }

    ReadTask readTask = new ReadTask(dst, future);

    executor.execute(readTask);
}
 
Example 19
Project: apache-tomcat-7.0.57   File: AsyncChannelWrapperSecure.java   View source code 6 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {

    WrapperFuture<Long,B> future =
            new WrapperFuture<Long, B>(handler, attachment);

    if (!writing.compareAndSet(false, true)) {
        throw new IllegalStateException(sm.getString(
                "asyncChannelWrapperSecure.concurrentWrite"));
    }

    WriteTask writeTask = new WriteTask(srcs, offset, length, future);

    executor.execute(writeTask);
}
 
Example 20
Project: incubator-netbeans   File: FileObjects.java   View source code 5 votes vote down vote up
AsyncWriteFileObject(
    @NonNull final File file,
    @NonNull final String pkgName,
    @NonNull final String name,
    @NullAllowed final JavaFileFilterImplementation filter,
    @NullAllowed final Charset encoding,
    @NonNull final Executor pool,
    @NonNull final CompletionHandler<Void,Void> done) {
    super(file, pkgName, name, filter, encoding);
    Parameters.notNull("pool", pool);   //NOI18N
    Parameters.notNull("done", done);   //NOI18N
    this.pool = pool;
    this.done = done;
}
 
Example 21
Project: incubator-netbeans   File: FileObjects.java   View source code 5 votes vote down vote up
AsyncOutputStream(
    @NonNull final Callable<OutputStream> superOpenOututStream,
    @NonNull final Executor pool,
    @NonNull final CompletionHandler<Void,Void> done) {
    this.superOpenOututStream = superOpenOututStream;
    this.pool = pool;
    this.done = done;
    if (done instanceof Runnable) {
        ((Runnable)done).run();
    }
    this.buffer = new byte[BUFSIZ];
}
 
Example 22
Project: mycat-src-1.6.1-RELEASE   File: PostgreSQLBackendConnectionFactory.java   View source code 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public PostgreSQLBackendConnection make(PostgreSQLDataSource pool,
		ResponseHandler handler, final String schema) throws IOException {

	final DBHostConfig dsc = pool.getConfig();
	NetworkChannel channel = this.openSocketChannel(MycatServer
			.getInstance().isAIO());

	final PostgreSQLBackendConnection c = new PostgreSQLBackendConnection(
			channel, pool.isReadNode());
	MycatServer.getInstance().getConfig().setSocketParams(c, false);
	// 设置NIOHandler
	c.setHandler(new PostgreSQLBackendConnectionHandler(c));
	c.setHost(dsc.getIp());
	c.setPort(dsc.getPort());
	c.setUser(dsc.getUser());
	c.setPassword(dsc.getPassword());
	c.setSchema(schema);
	c.setPool(pool);
	c.setResponseHandler(handler);
	c.setIdleTimeout(pool.getConfig().getIdleTimeout());
	if (channel instanceof AsynchronousSocketChannel) {
		((AsynchronousSocketChannel) channel).connect(
				new InetSocketAddress(dsc.getIp(), dsc.getPort()), c,
				(CompletionHandler) MycatServer.getInstance()
						.getConnector());
	} else {
		((NIOConnector) MycatServer.getInstance().getConnector())
				.postConnect(c);

	}
	return c;
}
 
Example 23
Project: mycat-src-1.6.1-RELEASE   File: MySQLConnectionFactory.java   View source code 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
// 这里传入的ResponseHandler为DelegateResponseHandler,在连接建立验证之后,会调用
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler,
		String schema) throws IOException {
	// DBHost配置
	DBHostConfig dsc = pool.getConfig();
	// 根据是否为NIO返回SocketChannel或者AIO的AsynchronousSocketChannel
	NetworkChannel channel = openSocketChannel(MycatServer.getInstance()
			.isAIO());
	// 新建MySQLConnection
	MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());
	// 根据配置初始化MySQLConnection
	MycatServer.getInstance().getConfig().setSocketParams(c, false);
	c.setHost(dsc.getIp());
	c.setPort(dsc.getPort());
	c.setUser(dsc.getUser());
	c.setPassword(dsc.getPassword());
	c.setSchema(schema);
	// 目前实际连接还未建立,handler为MySQL连接认证MySQLConnectionAuthenticatorHandler
	c.setHandler(new MySQLConnectionAuthenticatorHandler(c, handler));
	c.setPool(pool);
	c.setIdleTimeout(pool.getConfig().getIdleTimeout());
	// AIO和NIO连接方式建立实际的MySQL连接
	if (channel instanceof AsynchronousSocketChannel) {
		((AsynchronousSocketChannel) channel).connect(
				new InetSocketAddress(dsc.getIp(), dsc.getPort()), c,
				(CompletionHandler) MycatServer.getInstance()
						.getConnector());
	} else {
		// 通过NIOConnector建立连接
		// 通过NIOConnector建立实际连接的过程与前端连接的建立相似,
		// 也是先放在队列中,之后由NIOConnector去建立连接
		((NIOConnector) MycatServer.getInstance().getConnector())
				.postConnect(c);

	}
	return c;
}
 
Example 24
Project: tomcat7   File: AsyncChannelWrapperNonSecure.java   View source code 5 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {
    socketChannel.write(
            srcs, offset, length, timeout, unit, attachment, handler);
}
 
Example 25
Project: apache-tomcat-7.0.73-with-comment   File: AsyncChannelWrapperNonSecure.java   View source code 5 votes vote down vote up
@Override
public <B,A extends B> void write(ByteBuffer[] srcs, int offset, int length,
        long timeout, TimeUnit unit, A attachment,
        CompletionHandler<Long,B> handler) {
    socketChannel.write(
            srcs, offset, length, timeout, unit, attachment, handler);
}
 
Example 26
Project: jdk8u-jdk   File: Client.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
    ByteBuffer input = ByteBuffer.allocate(256);
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 27
Project: lazycat   File: AsyncChannelWrapperSecure.java   View source code 5 votes vote down vote up
@Override
public <B, A extends B> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit,
		A attachment, CompletionHandler<Long, B> handler) {

	WrapperFuture<Long, B> future = new WrapperFuture<Long, B>(handler, attachment);

	if (!writing.compareAndSet(false, true)) {
		throw new IllegalStateException(sm.getString("asyncChannelWrapperSecure.concurrentWrite"));
	}

	WriteTask writeTask = new WriteTask(srcs, offset, length, future);

	executor.execute(writeTask);
}
 
Example 28
Project: waterwave   File: AioClientChannel.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public final void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
	//log.log(1, "Cliet: start client read ");
	
    ByteBuffer input = BufferTools.getBuffer();
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 29
Project: waterwave   File: AioClientChannel.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public final void write(ByteBuffer b ,CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
	//log.log(1, "start client write ");
	
    if (!channel.isOpen()) {
        return;
    }
    channel.write(b, b, completionHandler);
}
 
Example 30
Project: waterwave   File: AioServerChannel.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public final void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
    ByteBuffer input = BufferTools.getBuffer();
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 31
Project: waterwave   File: AioServerChannel.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public final void write(ByteBuffer b ,CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
	//log.log(1, "start server write ");
	
    if (!channel.isOpen()) {
        return;
    }
    channel.write(b, b, completionHandler);
}
 
Example 32
Project: openjdk9   File: Client.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
    ByteBuffer input = ByteBuffer.allocate(256);
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 33
Project: jdk8u_jdk   File: Client.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
    ByteBuffer input = ByteBuffer.allocate(256);
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 34
Project: lookaside_java-1.8.0-openjdk   File: Client.java   View source code 5 votes vote down vote up
/**
 * Enqueue a read
 * @param completionHandler callback on completed read
 */
public void read(CompletionHandler<Integer, ? super ByteBuffer> completionHandler) {
    ByteBuffer input = ByteBuffer.allocate(256);
    if (!channel.isOpen()) {
        return;
    }
    channel.read(input, input, completionHandler);
}
 
Example 35
Project: antsdb   File: AsyncFile.java   View source code 5 votes vote down vote up
/**
 * 
 * @param buf
 */
public void write(ByteBuffer buf, CompletionHandler<Object, Object> handler) {
    if (this.closeAfterWrite) {
        throw new CodingError("file is already closed");
    }
    
    // find out the max. number of bytes can be written
    
    int bytesToWrite = (int)Math.min(buf.remaining(), this.filesize - pos);
    ByteBuffer another = buf.asReadOnlyBuffer();
    another.limit(another.position() + bytesToWrite);
    
    // increase write count, prevent accidental closing
    
    this.writeCount.incrementAndGet();
    
    // close this file if it reaches the end
    
    if (bytesToWrite == this.filesize - pos) {
        this.closeAfterWrite = true;
    }
    
    // write to the file
    
    _log.trace("writting {} bytes", bytesToWrite);
    this.ch.write(another, this.pos, null, new MyHandler(bytesToWrite, handler));
    try {
        this.ch.force(true);
    }
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.pos += bytesToWrite;
    
    // reposition the read pointer
    
    buf.position(buf.position() + bytesToWrite);
}
 
Example 36
Project: redkale   File: Sncp.java   View source code 5 votes vote down vote up
static void checkAsyncModifier(Class param, Method method) {
    if (param == CompletionHandler.class) return;
    if (Modifier.isFinal(param.getModifiers())) {
        throw new RuntimeException("CompletionHandler Type Parameter on {" + method + "} cannot final modifier");
    }
    if (!Modifier.isPublic(param.getModifiers())) {
        throw new RuntimeException("CompletionHandler Type Parameter on {" + method + "} must be public modifier");
    }
    if (param.isInterface()) return;
    boolean constructorflag = false;
    for (Constructor c : param.getDeclaredConstructors()) {
        if (c.getParameterCount() == 0) {
            int mod = c.getModifiers();
            if (Modifier.isPublic(mod) || Modifier.isProtected(mod)) {
                constructorflag = true;
                break;
            }
        }
    }
    if (param.getDeclaredConstructors().length == 0) constructorflag = true;
    if (!constructorflag) throw new RuntimeException(param + " must have a empty parameter Constructor");
    for (Method m : param.getMethods()) {
        if (m.getName().equals("completed") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s completed method cannot final modifier");
        } else if (m.getName().equals("failed") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s failed method cannot final modifier");
        } else if (m.getName().equals("sncp_getParams") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s sncp_getParams method cannot final modifier");
        } else if (m.getName().equals("sncp_setParams") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s sncp_setParams method cannot final modifier");
        } else if (m.getName().equals("sncp_setFuture") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s sncp_setFuture method cannot final modifier");
        } else if (m.getName().equals("sncp_getFuture") && Modifier.isFinal(m.getModifiers())) {
            throw new RuntimeException(param + "'s sncp_getFuture method cannot final modifier");
        }
    }
}
 
Example 37
Project: redkale   File: HttpContext.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
protected <H extends CompletionHandler> Creator<H> loadAsyncHandlerCreator(Class<H> handlerClass) {
    Creator<H> creator = asyncHandlerCreators.get(handlerClass);
    if (creator == null) {
        creator = createAsyncHandlerCreator(handlerClass);
        asyncHandlerCreators.put(handlerClass, creator);
    }
    return creator;
}
 
Example 38
Project: redkale   File: BCService.java   View source code 5 votes vote down vote up
public void bcCurrentTime(final CompletionHandler<String, Void> handler, final String name) {
    cService.ccCurrentTime(Utility.createAsyncHandler((v, a) -> {
        System.out.println("执行了 BCService.bcCurrentTime----异步方法");
        String rs = "异步bcCurrentTime: " + (v == null ? null : v.getResult());
        if (handler != null) handler.completed(rs, null);
    }, (t, a) -> {
        if (handler != null) handler.failed(t, a);
    }), name);
}
 
Example 39
Project: jephyr   File: PendingFuture.java   View source code 5 votes vote down vote up
PendingFuture(AsynchronousChannel channel,
              CompletionHandler<V,? super A> handler,
              A attachment,
              Object context)
{
    this.channel = channel;
    this.handler = handler;
    this.attachment = attachment;
    this.context = context;
}
 
Example 40
Project: jephyr   File: PendingFuture.java   View source code 5 votes vote down vote up
PendingFuture(AsynchronousChannel channel,
              CompletionHandler<V,? super A> handler,
              A attachment)
{
    this.channel = channel;
    this.handler = handler;
    this.attachment = attachment;
}