當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。