本文整理汇总了Java中com.rabbitmq.client.Channel.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.isOpen方法的具体用法?Java Channel.isOpen怎么用?Java Channel.isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rabbitmq.client.Channel
的用法示例。
在下文中一共展示了Channel.isOpen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: close
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
private void close(Connection connection, Channel channel) {
try {
if (channel != null && channel.isOpen()) {
if (this.consumerTag != null) {
channel.basicCancel(this.consumerTag);
this.consumerTag = null;
}
log.info("Closing RabbitMQ Channel - " + this.serverIP);
channel.close();
this.channel = null;
}
if (connection != null && connection.isOpen()) {
log.info("Closing RabbitMQ Connection - " + this.serverIP);
connection.close(CLOSE_CONNECTION_TIMEOUT);
this.connection = null;
}
} catch (Exception e) {
log.error("Failed to close RabbitMQ connections " + this.serverIP, e);
}
}
示例2: execute
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
/**
* Do something with a pooled channel (similar to Spring JDBC TransactionTemplate#execute)
*/
private <T> T execute(ChannelCallback<T> callback) throws Exception {
Channel channel;
try {
channel = channelPool.borrowObject();
} catch (IllegalStateException e) {
// Since this method is not synchronized its possible the
// channelPool has been cleared by another thread
checkConnectionAndChannelPool();
channel = channelPool.borrowObject();
}
if (!channel.isOpen()) {
log.warn("Got a closed channel from the pool");
// Reconnect if another thread hasn't yet
checkConnectionAndChannelPool();
channel = channelPool.borrowObject();
}
try {
return callback.doWithChannel(channel);
} finally {
channelPool.returnObject(channel);
}
}
示例3: closeChannel
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
private void closeChannel(Channel channel) throws IOException, TimeoutException {
try {
if (channel != null && channel.isOpen()) {
channel.close();
}
} catch (Exception e) {
logger.warn("RabbitMQ channel erred on close",
new ContextedRuntimeException(e)
.addContextValue("queueName", queueName)
.addContextValue("connectionFactory",
ToStringBuilder.reflectionToString(connectionFactory)));
}
}
示例4: getChannel
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
/**
* Get a {@link Channel} for the specified key. If the key does not exist then a channel is created.
* <p>
* Note: Do not cache the returned Channel, as it could become invalid if the underlying connection is closed. The key is
* usually an object that's requiring a channel.
* <p>
* @param key client specific key, usually a reference to themselves
* <p>
* @return Channel for this key, can change over time
*/
public synchronized Channel getChannel( Object key )
{
Channel channel = null;
do {
channel = channels.computeIfAbsent( key, k
-> {
try {
LOG.log( Level.FINE, "creating channel" );
return getConnection().
createChannel();
}
catch( IOException ex ) {
throw new UncheckedIOException( ex );
}
} );
if( channel != null && !channel.isOpen() ) {
LOG.log( Level.FINE, "discarding dead channel" );
channels.remove( key );
channel = null;
}
}
while( channel == null );
return channel;
}
示例5: close
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
@Override
public void close() {
final Channel subscriptionChannel = channel.get();
try {
if (subscriptionChannel != null && subscriptionChannel.isOpen()) {
subscriptionChannel.close();
}
onClose.accept(this);
} catch (IOException | TimeoutException e) {
throw new ChannelException(
String.format("Error while closing consumer: '%s' channel", consumerTag()), e);
}
}
示例6: validateObject
import com.rabbitmq.client.Channel; //导入方法依赖的package包/类
@Override
public boolean validateObject(Channel t) {
return t.isOpen();
}