当前位置: 首页>>代码示例>>Java>>正文


Java Connection.addShutdownListener方法代码示例

本文整理汇总了Java中com.rabbitmq.client.Connection.addShutdownListener方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.addShutdownListener方法的具体用法?Java Connection.addShutdownListener怎么用?Java Connection.addShutdownListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rabbitmq.client.Connection的用法示例。


在下文中一共展示了Connection.addShutdownListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createConnection

import com.rabbitmq.client.Connection; //导入方法依赖的package包/类
private synchronized Connection createConnection() throws KeyManagementException, NoSuchAlgorithmException, IOException, TimeoutException {
    final ConnectionFactory factory = new ConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setHost(amqpHost);
    factory.setPort(port);

    if (virtualHost != null && !virtualHost.isEmpty()) {
        factory.setVirtualHost(virtualHost);
    } else {
        factory.setVirtualHost("/");
    }

    if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
        factory.useSslProtocol(secureProtocol);
    }
    final Connection connection = factory.newConnection();
    connection.addShutdownListener(disconnectHandler);
    connection.addBlockedListener(blockedConnectionHandler);
    s_connection = connection;
    return s_connection;
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:23,代码来源:RabbitMQEventBus.java

示例2: createConnection

import com.rabbitmq.client.Connection; //导入方法依赖的package包/类
private synchronized Connection createConnection() throws Exception {
    try {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setUsername(username);
        factory.setPassword(password);
        factory.setHost(amqpHost);
        factory.setPort(port);

        if (virtualHost != null && !virtualHost.isEmpty()) {
            factory.setVirtualHost(virtualHost);
        } else {
            factory.setVirtualHost("/");
        }

        if (useSsl != null && !useSsl.isEmpty() && useSsl.equalsIgnoreCase("true")) {
            factory.useSslProtocol(secureProtocol);
        }
        Connection connection = factory.newConnection();
        connection.addShutdownListener(disconnectHandler);
        connection.addBlockedListener(blockedConnectionHandler);
        s_connection = connection;
        return s_connection;
    } catch (Exception e) {
        throw e;
    }
}
 
开发者ID:apache,项目名称:cloudstack,代码行数:27,代码来源:RabbitMQEventBus.java

示例3: getConnection

import com.rabbitmq.client.Connection; //导入方法依赖的package包/类
private synchronized CachedConnection getConnection(AMQPConnectionParameters connectionParameters)
        throws IOException {
    String key = connectionParameters.getKey();
    CachedConnection connection = cachedConnections.get(key);
    if (connection == null) {
        logger.debug(String.format("creating a new connection %s", key));

        ConnectionFactory factory = new ConnectionFactory();
        if (socketFactory != null) {
            factory.setSocketFactory(socketFactory);
        }
        factory.setHost(connectionParameters.getHost());
        factory.setPort(connectionParameters.getPort());
        factory.setUsername(connectionParameters.getUsername());
        factory.setPassword(connectionParameters.getPassword());
        factory.setVirtualHost(connectionParameters.getVhost());
        Connection c = factory.newConnection();
        c.addShutdownListener(new AMQPShutDownListener(c.toString()));

        connection = new CachedConnection(this, c);
        cachedConnections.put(key, connection);
    }

    return connection;
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:26,代码来源:ConnectionAndChannelFactory.java

示例4: create

import com.rabbitmq.client.Connection; //导入方法依赖的package包/类
@Override
public Connection create() throws Exception {
	ConnectionFactory factory = null;
	Connection connection = null;
	do {
		try {
			factory = pickOne();
			connection = factory.newConnection();
		} catch (Exception e) {
			logger.error("fail to create new connection from factory: [" + factory.getHost() + ":"
					+ factory.getPort() + "], kicking this one out and retry...");
			kick(factory.getHost() + ":" + factory.getPort());
		}
	} while (connection == null
			&& ConnectionFactoryManager.getInstance().getAvailableFactories().keySet().size() > 0);
	if (connection == null) {
		throw new Exception("fail to get new connection. no hosts left to use.");
	}
	/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
	connection.addShutdownListener(new ShutdownListener() {
		public void shutdownCompleted(ShutdownSignalException cause) {
			String hardError = "";
			String applInit = "";
			if (cause.isHardError()) {
				hardError = "connection";
			} else {
				hardError = "channel";
			}

			if (cause.isInitiatedByApplication()) {
				applInit = "application";
			} else {
				applInit = "broker";
			}
			logger.warn("Connectivity to MQ has failed.  It was caused by " + applInit + " at the " + hardError
					+ " level.  Reason received " + cause.getReason());
		}
	});

	((Recoverable) connection).addRecoveryListener(new RecoveryListener() {
		public void handleRecovery(Recoverable recoverable) {
			if (recoverable instanceof Connection) {
				logger.info("Connection was recovered.");
			} else if (recoverable instanceof Channel) {
				int channelNumber = ((Channel) recoverable).getChannelNumber();
				logger.info("Connection to channel #" + channelNumber + " was recovered.");
			}
		}

		public void handleRecoveryStarted(Recoverable arg0) {
		}
	});
	/* ADD CONNECTION & CHANNEL CONNECTION LISTENER */
	logger.info(
			"new connection was establesed...from host <- [" + factory.getHost() + ":" + factory.getPort() + "]");
	return connection;
}
 
开发者ID:WengShengyuan,项目名称:rabbit-mq-client,代码行数:58,代码来源:PooledConnectionFactory.java


注:本文中的com.rabbitmq.client.Connection.addShutdownListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。