本文整理匯總了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();
}