类java.nio.channels.Channel源码实例Demo

下面列出了怎么用java.nio.channels.Channel的API类实例代码及写法,或者点击链接到github查看源代码。

/** {@inheritDoc} */
@Override public IgniteInternalFuture<Channel> openChannel(ClusterNode remote,
    Message initMsg) throws IgniteSpiException {
    try {
        if (block) {
            U.log(log, "Start waiting on trying open a new channel");

            latch.await(5, TimeUnit.SECONDS);
        }
    }
    catch (InterruptedException e) {
        throw new IgniteException(e);
    }

    return super.openChannel(remote, initMsg);
}
 
源代码2 项目: dragonwell8_jdk   文件: NullTest.java
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");
        }
    }
 
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;
}
 
源代码4 项目: TencentKona-8   文件: NullTest.java
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");
        }
    }
 
源代码5 项目: jdk8u60   文件: InheritedChannel.java
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;
}
 
源代码6 项目: j2objc   文件: InheritedChannel.java
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;
}
 
源代码7 项目: mpush-client-java   文件: TcpConnection.java
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();
    }
}
 
源代码8 项目: cacheonix-core   文件: IOUtils.java
/**
 * 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");
      }
   }
}
 
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;
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: InheritedChannel.java
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;
}
 
源代码11 项目: jdk8u-dev-jdk   文件: InheritedChannel.java
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;
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: NullTest.java
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");
        }
    }
 
源代码13 项目: jstorm   文件: NimbusData.java
public void createFileHandler() {
    ExpiredCallback<Object, Object> expiredCallback = new ExpiredCallback<Object, Object>() {
        @Override
        public void expire(Object key, Object val) {
            try {
                LOG.info("Close file " + String.valueOf(key));
                if (val != null) {
                    if (val instanceof Channel) {
                        Channel channel = (Channel) val;
                        channel.close();
                    } else if (val instanceof BufferFileInputStream) {
                        BufferFileInputStream is = (BufferFileInputStream) val;
                        is.close();
                    }
                }
            } catch (IOException e) {
                LOG.error(e.getMessage(), e);
            }

        }
    };
    int file_copy_expiration_secs = JStormUtils.parseInt(conf.get(Config.NIMBUS_FILE_COPY_EXPIRATION_SECS), 30);
    uploaders = new TimeCacheMap<>(file_copy_expiration_secs, expiredCallback);
    downloaders = new TimeCacheMap<>(file_copy_expiration_secs, expiredCallback);
}
 
源代码14 项目: openjdk-jdk9   文件: InheritedChannel.java
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;
}
 
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;
}
 
源代码16 项目: openjdk-8-source   文件: InheritedChannel.java
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;
}
 
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;
}
 
源代码18 项目: jdk8u-jdk   文件: NullTest.java
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");
        }
    }
 
源代码19 项目: uavstack   文件: UpgradeProcessLock.java
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) {
            }
        }
    }
 
源代码20 项目: hottub   文件: NullTest.java
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");
        }
    }
 
源代码21 项目: hottub   文件: InheritedChannelNotServerSocket.java
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;
}
 
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;
}
 
源代码23 项目: Bats   文件: OptimizedEventLoop.java
private void disconnectAllKeysAndShutdown()
{
  for (SelectionKey selectionKey : selector.keys()) {
    if (selectionKey.isValid()) {
      Channel channel = selectionKey.channel();
      if (channel != null && channel.isOpen()) {
        Listener l = (Listener)selectionKey.attachment();
        try {
          selectionKey.channel().close();
          if (l != null) {
            if (l instanceof Listener.ClientListener) {
              ((Listener.ClientListener)l).disconnected();
            }
            l.unregistered(selectionKey);
          }
        } catch (IOException e) {
          if (l != null) {
            l.handleException(e, this);
          } else {
            logger.warn("Exception while closing channel {} on unregistered key {}", channel, selectionKey, e);
          }
        }
      }
    }
  }
  alive = false;
  selector.wakeup();
}
 
源代码24 项目: spring-analysis-note   文件: DataBufferUtils.java
static void closeChannel(@Nullable Channel channel) {
	if (channel != null && channel.isOpen()) {
		try {
			channel.close();
		}
		catch (IOException ignored) {
		}
	}
}
 
源代码25 项目: jdk8u-jdk   文件: InheritedChannel.java
private static void checkAccess(Channel c) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(
            new RuntimePermission("inheritedChannel")
        );
    }
}
 
源代码26 项目: database   文件: WORMStrategy.java
@Override
public WriteCacheImpl newWriteCache(final IBufferAccess buf,
        final boolean useChecksum, final boolean bufferHasData,
        final IReopenChannel<? extends Channel> opener,
        final long fileExtent)
                throws InterruptedException {
    
    return new WriteCacheImpl(0/* baseOffset */, buf, useChecksum,
            bufferHasData, (IReopenChannel<FileChannel>) opener,
            fileExtent);
    
}
 
源代码27 项目: dragonwell8_jdk   文件: InheritedChannel.java
private static void checkAccess(Channel c) {
    SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(
            new RuntimePermission("inheritedChannel")
        );
    }
}
 
源代码28 项目: CloverETL-Engine   文件: FileUtils.java
/**
 * Closes all objects passed as the argument.
 * If any of them throws an exception, the first exception is thrown.
 * The remaining exceptions are added as suppressed to the first one.
 * 
 * @param closeables
 * @throws IOException
 */
public static void closeAll(Iterable<? extends AutoCloseable> closeables) throws IOException {
	if (closeables != null) {
		Exception firstException = null;
		
		for (AutoCloseable closeable: closeables) {
			if (closeable != null) {
				if ((closeable instanceof Channel) && !((Channel) closeable).isOpen()) {
					continue; // channel is already closed
				}
				try {
					closeable.close();
				} catch (Exception ex) {
					if (firstException == null) {
						firstException = ex;
					} else {
						firstException.addSuppressed(ex);
					}
				}
			}
		}
		
		if (firstException != null) {
			throw ExceptionUtils.getIOException(firstException);
		}
	}
}
 
源代码29 项目: olingo-odata4   文件: ODataNettyHandlerImpl.java
private static void closeStream(final Channel closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (IOException e) {
      // ignore
    }
  }
}
 
源代码30 项目: java-technology-stack   文件: DataBufferUtils.java
static void closeChannel(@Nullable Channel channel) {
	if (channel != null && channel.isOpen()) {
		try {
			channel.close();
		}
		catch (IOException ignored) {
		}
	}
}
 
 类所在包
 类方法
 同包方法