當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。