当前位置: 首页>>代码示例>>Java>>正文


Java CompletionHandler类代码示例

本文整理汇总了Java中java.nio.channels.CompletionHandler的典型用法代码示例。如果您正苦于以下问题:Java CompletionHandler类的具体用法?Java CompletionHandler怎么用?Java CompletionHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CompletionHandler类属于java.nio.channels包,在下文中一共展示了CompletionHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFileObject

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:FileManagerTransaction.java

示例2: asyncWriteFileObject

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FileObjects.java

示例3: read

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:17,代码来源:AsyncChannelWrapperSecure.java

示例4: write

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:18,代码来源:AsyncChannelWrapperSecure.java

示例5: make

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:actiontech,项目名称:dble,代码行数:27,代码来源:MySQLConnectionFactory.java

示例6: doWrite

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
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
		    }
		}
	    });
}
   }
 
开发者ID:changyuefeng,项目名称:netty-book,代码行数:27,代码来源:ReadCompletionHandler.java

示例7: acceptCompletionHandler

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
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();
				}
			}
		};
	}
 
开发者ID:arienkock,项目名称:parallelism-benchmarks,代码行数:24,代码来源:FountainSocketBenchmark.java

示例8: doWrite

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
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
                        }
                    }
                });
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:27,代码来源:ReadCompletionHandler.java

示例9: lock

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
            }
        }
    });
    
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:22,代码来源:EphemeralFsAsynchronousFileChannel.java

示例10: read

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
            }
        }
    });
    
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:22,代码来源:EphemeralFsAsynchronousFileChannel.java

示例11: write

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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);
            }
        }
    });
    
}
 
开发者ID:sbridges,项目名称:ephemeralfs,代码行数:22,代码来源:EphemeralFsAsynchronousFileChannel.java

示例12: AsyncWriteFileObject

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:FileObjects.java

示例13: AsyncOutputStream

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
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];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:FileObjects.java

示例14: make

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:34,代码来源:PostgreSQLBackendConnectionFactory.java

示例15: make

import java.nio.channels.CompletionHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:39,代码来源:MySQLConnectionFactory.java


注:本文中的java.nio.channels.CompletionHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。