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


Java Channel类代码示例

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


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

示例1: handleException

import java.nio.channels.Channel; //导入依赖的package包/类
@Override
public void handleException(Channel channel, IOException exception) {
    IoUtils.safeClose(channel);
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(clientConnection);
        UndertowLogger.REQUEST_IO_LOGGER.debug("Exception reading from target server", exception);
        if (!exchange.isResponseStarted()) {
            exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
            exchange.endExchange();
        } else {
            IoUtils.safeClose(exchange.getConnection());
        }
    } else {
        exchange.setResponseCode(StatusCodes.INTERNAL_SERVER_ERROR);
        exchange.endExchange();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:ProxyHandler.java

示例2: getChannel

import java.nio.channels.Channel; //导入依赖的package包/类
public static synchronized Channel getChannel() throws IOException {
    if (devnull < 0) {
        devnull = open0("/dev/null", O_RDWR);
    }

    // If we don't have the channel try to create it
    if (!haveChannel) {
        channel = createChannel();
        haveChannel = true;
    }

    // if there is a channel then do the security check before
    // returning it.
    if (channel != null) {
        checkAccess(channel);
    }
    return channel;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:InheritedChannel.java

示例3: inheritedChannel

import java.nio.channels.Channel; //导入依赖的package包/类
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("SP.inheritedChannel");
    if (channel == null) {
        channel = SocketChannel.open();
        Socket socket = channel.socket();
        System.err.println("socket = " + socket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            Registry registry =
                LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
            Callback obj = (Callback) registry.lookup("Callback");
            obj.notifyTest();
        } catch (NotBoundException nbe) {
            throw (IOException)
                new IOException("callback object not bound").
                    initCause(nbe);
        }
    }
    return channel;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:InheritedChannelNotServerSocket.java

示例4: main

import java.nio.channels.Channel; //导入依赖的package包/类
public static void main(String args[]) {

        // test the assertion that SelectorProvider.inheritedChannel()
        // and System.inheritedChannel return null when standard input
        // is not connected to a socket

        Channel c1, c2;
        try {
            c1 = SelectorProvider.provider().inheritedChannel();
            c2 = System.inheritedChannel();
        } catch (IOException ioe) {
            throw new RuntimeException("Unexpected IOException: " + ioe);
        }
        if (c1 != null || c2 != null) {
            throw new RuntimeException("Channel returned - unexpected");
        }
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:NullTest.java

示例5: releaseFileLock

import java.nio.channels.Channel; //导入依赖的package包/类
public void releaseFileLock() {

        if (fileLock != null) {
            if (log.isTraceEnable()) {
                log.info(this, "Releasing the file lock of " + this.filePath.getFileName());
            }

            Channel fc = fileLock.acquiredBy();

            try {
                fileLock.release();
                fileLock = null;

                if (fc != null) {
                    fc.close();
                }
            }
            catch (IOException e) {
            }
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:UpgradeProcessLock.java

示例6: inheritedChannel

import java.nio.channels.Channel; //导入依赖的package包/类
public synchronized Channel inheritedChannel() throws IOException {
    System.err.println("SP.inheritedChannel");
    if (channel == null) {
        channel = SocketChannel.open();
        Socket socket = channel.socket();
        System.err.println("socket = " + socket);

        /*
         * Notify test that inherited channel was created.
         */
        try {
            System.err.println("notify test...");
            int registryPort = Integer.getInteger(
                    "test.java.rmi.rmidViaInheritedChannel.registry.port", 0);
            Registry registry = LocateRegistry.getRegistry(registryPort);
            Callback obj = (Callback) registry.lookup("Callback");
            obj.notifyTest();
        } catch (NotBoundException nbe) {
            throw (IOException)
                new IOException("callback object not bound").
                    initCause(nbe);
        }
    }
    return channel;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:InheritedChannelNotServerSocket.java

示例7: completed

import java.nio.channels.Channel; //导入依赖的package包/类
@Override
public void completed(final ClientConnection connection) {
    final ServerConnection serverConnection = exchange.getConnection();
    //we attach to the connection so it can be re-used
    serverConnection.putAttachment(clientAttachmentKey, connection);
    serverConnection.addCloseListener(serverConnection1 -> IoUtils.safeClose(connection));
    connection.getCloseSetter().set((ChannelListener<Channel>) channel -> serverConnection.removeAttachment(clientAttachmentKey));

    exchange.setRelativePath("/");
    Realm realm = realmCache.matches(exchange.getRequestPath());
    Application application = realmCache.getApplication(realm);
    String path = exchange.getRequestURI();
    if (path.startsWith(application.getVirtualPath())) {
        String passTo = calculatePathTo(path, application);
        exchange.setRequestPath(passTo);
        exchange.setRequestURI(passTo);
    }
    callback.completed(exchange, new ProxyConnection(connection, "/"));
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:20,代码来源:MultiAppProxyClient.java

示例8: fsync

import java.nio.channels.Channel; //导入依赖的package包/类
/**
 * Internal fsync implementation.
 */
private static void fsync(PyObject fd, boolean metadata) {
    RawIOBase rawIO = FileDescriptors.get(fd);
    rawIO.checkClosed();
    Channel channel = rawIO.getChannel();
    if (!(channel instanceof FileChannel)) {
        throw Py.OSError(Errno.EINVAL);
    }

    try {
        ((FileChannel)channel).force(metadata);
    } catch (ClosedChannelException cce) {
        // In the rare case it's closed but the rawIO wasn't
        throw Py.ValueError("I/O operation on closed file");
    } catch (IOException ioe) {
        throw Py.OSError(ioe);
    }
}
 
开发者ID:RunasSudo,项目名称:PyAndroid,代码行数:21,代码来源:PosixModule.java

示例9: doClose

import java.nio.channels.Channel; //导入依赖的package包/类
private void doClose() {
    connLock.lock();
    try {
        Channel channel = this.channel;
        if (channel != null) {
            if (channel.isOpen()) {
                IOUtils.close(channel);
                listener.onDisConnected(client);
                logger.w("channel closed !!!");
            }
            this.channel = null;
        }
    } finally {
        state.set(disconnected);
        connLock.unlock();
    }
}
 
开发者ID:mpusher,项目名称:mpush-client-java,代码行数:18,代码来源:TcpConnection.java

示例10: startListening

import java.nio.channels.Channel; //导入依赖的package包/类
public void startListening() {
	while (isAlive) {
		Channel channel;
		channel = network.choosingConnection(); // first stop here!
		if (channel instanceof ServerSocketChannel) {
			//System.out.println("TCP received!");
			// TODO: Read TCP received message, convert to enum and reply in another class.
			
			TcpReceiver tcpReceiver = new TcpReceiver(channel);
			new Thread(tcpReceiver).start();
		}
		else if (channel instanceof DatagramChannel) {
			System.out.println("UDP received!");
			// TODO: Read UDP received message, convert to enum and reply in another class.
		} else {
			System.out.println("meh");
		}
	}
}
 
开发者ID:thiloilg,项目名称:video-streaming,代码行数:20,代码来源:VideoStreamServer.java

示例11: choosingConnection

import java.nio.channels.Channel; //导入依赖的package包/类
@Override
public Channel choosingConnection() {
	try {
		selector.select(); // stop here!
		//System.out.println("Selector chose something!");
		Set<SelectionKey> keys = selector.selectedKeys();
		for (Iterator<SelectionKey> i = keys.iterator(); i.hasNext();) {
            SelectionKey key = (SelectionKey) i.next();
            i.remove();
            Channel c = (Channel) key.channel();
            if (key.isAcceptable() && c == tcpChannel)
            	return tcpChannel;
            else if (key.isReadable() && c == udpChannel) 
            	return udpChannel;
		}

	} catch (IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:thiloilg,项目名称:video-streaming,代码行数:22,代码来源:Network.java

示例12: close

import java.nio.channels.Channel; //导入依赖的package包/类
/**
 * Closes a channel. Channel can be null and any IOException's will be swallowed.
 *
 * @param channel The stream to close.
 */
public static void close( Channel channel )
{
    if ( channel == null )
    {
        return;
    }

    try
    {
        channel.close();
    }
    catch ( IOException ex )
    {
        // ignore
    }
}
 
开发者ID:ctripcorp,项目名称:x-pipe,代码行数:22,代码来源:IOUtil.java

示例13: doReleaseExclusiveReadLock

import java.nio.channels.Channel; //导入依赖的package包/类
@Override
protected void doReleaseExclusiveReadLock(GenericFileOperations<File> operations,
                                          GenericFile<File> file, Exchange exchange) throws Exception {
    // must call super
    super.doReleaseExclusiveReadLock(operations, file, exchange);

    FileLock lock = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), FileLock.class);
    RandomAccessFile rac = exchange.getProperty(asReadLockKey(file, Exchange.FILE_LOCK_EXCLUSIVE_LOCK), RandomAccessFile.class);

    String target = file.getFileName();
    if (lock != null) {
        Channel channel = lock.acquiredBy();
        try {
            lock.release();
        } finally {
            // close channel as well
            IOHelper.close(channel, "while releasing exclusive read lock for file: " + target, LOG);
            IOHelper.close(rac, "while releasing exclusive read lock for file: " + target, LOG);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:FileLockExclusiveReadLockStrategy.java

示例14: closeHard

import java.nio.channels.Channel; //导入依赖的package包/类
/**
 * This should be followed by closing a selector.
 *
 * @param channel the channel to close.
 */
public static void closeHard(final Channel channel) {

   if (channel != null) {
      try {

         // Close socket
         if (channel instanceof SocketChannel) {

            closeHard(((SocketChannel) channel).socket());
         }

         // Close channel
         channel.close();
      } catch (final Exception e) {
         ignoreException(e, "closing hard");
      }
   }
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:24,代码来源:IOUtils.java

示例15: test

import java.nio.channels.Channel; //导入依赖的package包/类
@Test
public void test(){
    ByteBuffer byteBuffer = ByteBuffer.allocate(10);
    byteBuffer.put((byte) 'a');
    byteBuffer.put((byte) 'b');
    byteBuffer.put((byte) 'c');

    Channel channel = Channels.newChannel(new InputStream() {
        @Override
        public int read() throws IOException {
            return 0;
        }
    });

    CharBuffer charBuffer = CharBuffer.allocate(10);
    charBuffer.put('a');
    charBuffer.put('b');
    charBuffer.put('c');

    System.out.println(charBuffer.get());
}
 
开发者ID:Jdoing,项目名称:example,代码行数:22,代码来源:BufferTest.java


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