java.nio.channels.Channel Java Examples
The following examples show how to use
java.nio.channels.Channel.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TcpConnection.java From mpush-client-java with Apache License 2.0 | 6 votes |
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(); } }
Example #2
Source File: InheritedChannelNotServerSocket.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #3
Source File: InheritedChannel.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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; }
Example #4
Source File: NullTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #5
Source File: UpgradeProcessLock.java From uavstack with Apache License 2.0 | 6 votes |
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) { } } }
Example #6
Source File: NullTest.java From hottub with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #7
Source File: GridIoManagerFileTransmissionSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** {@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); }
Example #8
Source File: InheritedChannelNotServerSocket.java From hottub with GNU General Public License v2.0 | 6 votes |
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; }
Example #9
Source File: InheritedChannelNotServerSocket.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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; }
Example #10
Source File: NullTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #11
Source File: InheritedChannelNotServerSocket.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #12
Source File: InheritedChannelNotServerSocket.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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; }
Example #13
Source File: NullTest.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #14
Source File: NullTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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"); } }
Example #15
Source File: InheritedChannel.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #16
Source File: InheritedChannel.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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; }
Example #17
Source File: InheritedChannel.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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; }
Example #18
Source File: InheritedChannel.java From j2objc with Apache License 2.0 | 6 votes |
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; }
Example #19
Source File: InheritedChannelNotServerSocket.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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; }
Example #20
Source File: InheritedChannel.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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; }
Example #21
Source File: IOUtils.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * 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"); } } }
Example #22
Source File: NimbusData.java From jstorm with Apache License 2.0 | 6 votes |
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); }
Example #23
Source File: SimpleCanalConnector.java From canal with Apache License 2.0 | 5 votes |
private void quietlyClose(Channel channel) { try { channel.close(); } catch (IOException e) { logger.warn("exception on closing channel:{} \n {}", channel, e); } }
Example #24
Source File: TcpCommunicationSpi.java From ignite with Apache License 2.0 | 5 votes |
/** * @param remote Destination cluster node to communicate with. * @param initMsg Configuration channel attributes wrapped into the message. * @return The future, which will be finished on channel ready. * @throws IgniteSpiException If fails. */ public IgniteInternalFuture<Channel> openChannel( ClusterNode remote, Message initMsg ) throws IgniteSpiException { assert !remote.isLocal() : remote; assert initMsg != null; assert chConnPlc != null;
Example #25
Source File: Http2Channel.java From lams with GNU General Public License v2.0 | 5 votes |
public void sendGoAway(int status, final ChannelExceptionHandler<AbstractHttp2StreamSinkChannel> exceptionHandler) { if (thisGoneAway) { return; } thisGoneAway = true; if(UndertowLogger.REQUEST_IO_LOGGER.isTraceEnabled()) { UndertowLogger.REQUEST_IO_LOGGER.tracef(new ClosedChannelException(), "Sending goaway on channel %s", this); } Http2GoAwayStreamSinkChannel goAway = new Http2GoAwayStreamSinkChannel(this, status, lastGoodStreamId); try { goAway.shutdownWrites(); if (!goAway.flush()) { goAway.getWriteSetter().set(ChannelListeners.flushingChannelListener(new ChannelListener<Channel>() { @Override public void handleEvent(Channel channel) { IoUtils.safeClose(Http2Channel.this); } }, exceptionHandler)); goAway.resumeWrites(); } else { IoUtils.safeClose(this); } } catch (IOException e) { exceptionHandler.handleException(goAway, e); } catch (Throwable t) { exceptionHandler.handleException(goAway, new IOException(t)); } }
Example #26
Source File: NIOSender.java From swift-k with Apache License 2.0 | 5 votes |
public NIOSender() { super("NIO Sender"); setDaemon(true); queues = new HashMap<SelectableChannel, BlockingQueue<NIOSendEntry>>(); add = new LinkedBlockingQueue<AbstractStreamCoasterChannel>(); registered = new HashMap<Channel, BlockingQueue<NIOSendEntry>>(); try { selector = Selector.open(); } catch (IOException e) { AbstractStreamCoasterChannel.logger.warn("Could not create selector", e); } }
Example #27
Source File: InheritedChannel.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void checkAccess(Channel c) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission( new RuntimePermission("inheritedChannel") ); } }
Example #28
Source File: AutoDeployTestSupport.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public void cleanupChannels() { for (Channel ch : channels) { try { ch.close(); } catch (Exception ignored) { } } }
Example #29
Source File: InheritedChannel.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static void checkAccess(Channel c) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { sm.checkPermission( new RuntimePermission("inheritedChannel") ); } }
Example #30
Source File: DataBufferUtils.java From spring-analysis-note with MIT License | 5 votes |
static void closeChannel(@Nullable Channel channel) { if (channel != null && channel.isOpen()) { try { channel.close(); } catch (IOException ignored) { } } }