1 /* 2 * Copyright 2015 The Netty Project 3 * 4 * The Netty Project licenses this file to you under the Apache License, 5 * version 2.0 (the "License"); you may not use this file except in compliance 6 * with the License. You may obtain a copy of the License at: 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 * License for the specific language governing permissions and limitations 14 * under the License. 15 */ 16 package io.netty.channel.pool; 17 18 import io.netty.channel.Channel; 19 import io.netty.channel.EventLoop; 20 import io.netty.util.concurrent.Future; 21 import io.netty.util.concurrent.Promise; 22 23 /** 24 * Called before a {@link Channel} will be returned via {@link ChannelPool#acquire()} or 25 * {@link ChannelPool#acquire(Promise)}. 26 */ 27 public interface ChannelHealthChecker { 28 29 /** 30 * {@link ChannelHealthChecker} implementation that checks if {@link Channel#isActive()} returns {@code true}. 31 */ 32 ChannelHealthChecker ACTIVE = new ChannelHealthChecker() { 33 @Override 34 public Future<Boolean> isHealthy(Channel channel) { 35 EventLoop loop = channel.eventLoop(); 36 return channel.isActive()? loop.newSucceededFuture(Boolean.TRUE) : loop.newSucceededFuture(Boolean.FALSE); 37 } 38 }; 39 40 /** 41 * Check if the given channel is healthy which means it can be used. The returned {@link Future} is notified once 42 * the check is complete. If notified with {@link Boolean#TRUE} it can be used {@link Boolean#FALSE} otherwise. 43 * 44 * This method will be called by the {@link EventLoop} of the {@link Channel}. 45 */ 46 Future<Boolean> isHealthy(Channel channel); 47 }