Java Code Examples for java.nio.channels.Channel#close()

The following examples show how to use java.nio.channels.Channel#close() . 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: NimbusData.java    From jstorm with Apache License 2.0 6 votes vote down vote up
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 2
Source File: UpgradeProcessLock.java    From uavstack with Apache License 2.0 6 votes vote down vote up
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 3
Source File: IOUtil.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
/**
 * 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
    }
}
 
Example 4
Source File: IOUtils.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 5
Source File: IOHandler.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Selectable selectable) {
    Channel channel = selectable.getChannel();
    if (channel != null) {
        try {
            channel.close();
        } catch(IOException ioException) {
            // Ignore
        }
    }
}
 
Example 6
Source File: SimpleCanalConnector.java    From canal with Apache License 2.0 5 votes vote down vote up
private void quietlyClose(Channel channel) {
    try {
        channel.close();
    } catch (IOException e) {
        logger.warn("exception on closing channel:{} \n {}", channel, e);
    }
}
 
Example 7
Source File: SimpleAdminConnector.java    From canal with Apache License 2.0 5 votes vote down vote up
private void quietlyClose(Channel channel) {
    try {
        channel.close();
    } catch (IOException e) {
        logger.warn("exception on closing channel:{} \n {}", channel, e);
    }
}
 
Example 8
Source File: TestProxy.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void closeChannel(Channel channel) {
    if (channel != null && channel.isOpen()) {
        try {
            channel.close();
        } catch (IOException e) {
            LOG.error("cannot close", e);
        }
    }
}
 
Example 9
Source File: AutoDeployTestSupport.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void cleanupChannels() {
    for (Channel ch : channels) {
        try {
            ch.close();
        }
        catch (Exception ignored) {
        }
    }
}
 
Example 10
Source File: ODataHttpHandlerImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static void closeStream(final Channel closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (IOException e) {
      // ignore
    }
  }
}
 
Example 11
Source File: ODataNettyHandlerImpl.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private static void closeStream(final Channel closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (IOException e) {
      // ignore
    }
  }
}
 
Example 12
Source File: DataBufferUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
static void closeChannel(@Nullable Channel channel) {
	if (channel != null && channel.isOpen()) {
		try {
			channel.close();
		}
		catch (IOException ignored) {
		}
	}
}
 
Example 13
Source File: HttpSendFileTests.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
private static void closeChannel(Channel channel) {
	if (channel != null && channel.isOpen()) {
		try {
			channel.close();
		}
		catch (IOException ignored) {
			// noop
		}
	}
}
 
Example 14
Source File: IOUtils.java    From genDoc with Apache License 2.0 5 votes vote down vote up
public static void close(Channel channel) {
    if(channel != null) {
        try {
            channel.close();
        } catch (IOException var2) {
            ;
        }

    }
}
 
Example 15
Source File: DataBufferUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
static void closeChannel(@Nullable Channel channel) {
	if (channel != null && channel.isOpen()) {
		try {
			channel.close();
		}
		catch (IOException ignored) {
		}
	}
}
 
Example 16
Source File: SimpleCanalConnector.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private void quietlyClose(Channel channel) {
    try {
        channel.close();
    } catch (IOException e) {
        logger.warn("exception on closing channel:{} \n {}", channel, e);
    }
}
 
Example 17
Source File: DefaultMultipartMessageReader.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void close(Channel channel) {
	try {
		channel.close();
	}
	catch (IOException ignore) {
	}
}