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


Java Channel.close方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: createFileHandler

import java.nio.channels.Channel; //导入方法依赖的package包/类
public void createFileHandler() {
    TimeCacheMap.ExpiredCallback<Object, Object> expiredCallback = new TimeCacheMap.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<Object, Object>(file_copy_expiration_secs, expiredCallback);
    downloaders = new TimeCacheMap<Object, Object>(file_copy_expiration_secs, expiredCallback);
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:27,代码来源:NimbusData.java

示例5: 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:CCM-Modding,项目名称:Nucleum-Omnium,代码行数:22,代码来源:IOUtil.java

示例6: createFileHandler

import java.nio.channels.Channel; //导入方法依赖的package包/类
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);
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:26,代码来源:NimbusData.java

示例7: close

import java.nio.channels.Channel; //导入方法依赖的package包/类
private void close(RandomAccessFile file, Channel channel, MappedByteBuffer mappedFile) {
    if (mappedFile == null) {
        return;
    }
    // sync to disk
    mappedFile.force();
    try {
        // close mappedFile
        AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
            Method cleaner = mappedFile.getClass().getMethod("cleaner");
            cleaner.setAccessible(true);
            ((Cleaner) cleaner.invoke(mappedFile)).clean();
            return null;
        });
        // close channel
        if (channel != null && channel.isOpen()) {
            channel.close();
        }
        // close file
        if (file != null) {
            file.close();
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        e.printStackTrace();
    }
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:28,代码来源:FileMappedQueue.java

示例8: run

import java.nio.channels.Channel; //导入方法依赖的package包/类
@Override
public void run(Selectable selectable) {
    Channel channel = selectable.getChannel();
    if (channel != null) {
        try {
            channel.close();
        } catch(IOException ioException) {
            // Ignore
        }
    }
}
 
开发者ID:apache,项目名称:qpid-proton-j,代码行数:12,代码来源:IOHandler.java

示例9: closeQuietly

import java.nio.channels.Channel; //导入方法依赖的package包/类
/**
 * Close the passed Channel, logging any IOExceptions but not re-throwing them.
 * 
 * @param channel Channel to be closed (can be null).
 */
public static void closeQuietly(Channel channel) {
  if (channel != null) {
    try {
      channel.close();
    } catch (IOException e) {
      log.error(e);
    }
  }
}
 
开发者ID:massdosage,项目名称:citrine-scheduler,代码行数:15,代码来源:LastIoUtils.java

示例10: createNimbusData

import java.nio.channels.Channel; //导入方法依赖的package包/类
private NimbusData createNimbusData(Map conf, INimbus inimbus)
		throws Exception {

	TimeCacheMap.ExpiredCallback<Object, Object> expiredCallback = new TimeCacheMap.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);
	TimeCacheMap<Object, Object> uploaders = new TimeCacheMap<Object, Object>(
			file_copy_expiration_secs, expiredCallback);
	TimeCacheMap<Object, Object> downloaders = new TimeCacheMap<Object, Object>(
			file_copy_expiration_secs, expiredCallback);

	// Callback callback=new TimerCallBack();
	// StormTimer timer=Timer.mkTimerTimer(callback);
	NimbusData data = new NimbusData(conf, downloaders, uploaders, inimbus);

	return data;

}
 
开发者ID:zhangjunfang,项目名称:jstorm-0.9.6.3-,代码行数:39,代码来源:NimbusServer.java

示例11: createNimbusData

import java.nio.channels.Channel; //导入方法依赖的package包/类
/**
 * 1.此处定义一个TimcacheMap缓存失效时候的callback函数,关闭channel和stream
 * 建立上传和下载两个缓存,缓存流
 * 新建一个Nimbus对象
 */
@SuppressWarnings("rawtypes")
private NimbusData createNimbusData(Map conf, INimbus inimbus) throws Exception {

    TimeCacheMap.ExpiredCallback<Object, Object> expiredCallback = new TimeCacheMap.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);
    TimeCacheMap<Object, Object> uploaders = new TimeCacheMap<Object, Object>(file_copy_expiration_secs,
            expiredCallback);
    TimeCacheMap<Object, Object> downloaders = new TimeCacheMap<Object, Object>(file_copy_expiration_secs,
            expiredCallback);

    // Callback callback=new TimerCallBack();
    // StormTimer timer=Timer.mkTimerTimer(callback);
    NimbusData data = new NimbusData(conf, downloaders, uploaders, inimbus);

    return data;

}
 
开发者ID:songtk,项目名称:learn_jstorm,代码行数:43,代码来源:NimbusServer.java

示例12: destroy

import java.nio.channels.Channel; //导入方法依赖的package包/类
/**
 * Destroy Channel instance.
 *
 * @param channel instance of the channel.
 */
public static void destroy(final Channel channel) {
  if (null != channel) {
    try {
      channel.close();
    } catch (final Throwable ignored) {
      Log.i(PreferencesUnified.LOG_TAG, ignored.getMessage());
    }
  }
}
 
开发者ID:gitter-badger,项目名称:UnifiedPreferences,代码行数:15,代码来源:CleanupUtils.java

示例13: createNimbusData

import java.nio.channels.Channel; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
private NimbusData createNimbusData(Map conf, INimbus inimbus)
		throws Exception {

	TimeCacheMap.ExpiredCallback<Object, Object> expiredCallback = new TimeCacheMap.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);
	TimeCacheMap<Object, Object> uploaders = new TimeCacheMap<Object, Object>(
			file_copy_expiration_secs, expiredCallback);
	TimeCacheMap<Object, Object> downloaders = new TimeCacheMap<Object, Object>(
			file_copy_expiration_secs, expiredCallback);

	// Callback callback=new TimerCallBack();
	// StormTimer timer=Timer.mkTimerTimer(callback);
	NimbusData data = new NimbusData(conf, downloaders, uploaders, inimbus);

	return data;

}
 
开发者ID:greeenSY,项目名称:Tstream,代码行数:40,代码来源:NimbusServer.java

示例14: close

import java.nio.channels.Channel; //导入方法依赖的package包/类
/**
 * Shutdown the given channel.
 *
 * @param channel The channel to close.
 * @return True if successful, false if an error occurred
 */
public static boolean close(Channel channel)
{
   try { 
      channel.close(); 
      return true;
   } catch(Exception ex) {
      return false;
   }
}
 
开发者ID:cfloersch,项目名称:Stdlib,代码行数:16,代码来源:NIOUtils.java

示例15: close

import java.nio.channels.Channel; //导入方法依赖的package包/类
public static void close(Channel ch) {
    try {
        if (ch != null)
            ch.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:SyncFree,项目名称:SwiftCloud,代码行数:9,代码来源:IO.java


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