All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zusmart.base.network.ChannelUtils Maven / Gradle / Ivy

Go to download

提供基础的工具类及方法类,Logging,Scanner,Buffer,NetWork,Future,Thread

There is a newer version: 1.0.6
Show newest version
package com.zusmart.base.network;

import java.io.IOException;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

import com.zusmart.base.logging.Logger;
import com.zusmart.base.logging.LoggerFactory;

public abstract class ChannelUtils {

	private static final Logger logger = LoggerFactory.getLogger(ChannelUtils.class);

	public static void close(Selector selector) {
		if (null != selector) {
			try {
				selector.close();
			} catch (IOException e) {
				logger.error(e.getMessage(), e);
			}
		}
	}

	public static void close(ServerSocketChannel channel) {
		if (null != channel) {
			try {
				channel.close();
			} catch (IOException e) {
				logger.error(e.getMessage(), e);
			}
		}
	}

	public static void close(SocketChannel channel) {
		if (null != channel) {
			try {
				channel.close();
			} catch (IOException e) {
				logger.error(e.getMessage(), e);
			}
		}
	}

	public static void cancel(SelectionKey key) {
		if (null != key) {
			key.cancel();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy