本文整理汇总了Java中org.apache.activemq.broker.BrokerRegistry类的典型用法代码示例。如果您正苦于以下问题:Java BrokerRegistry类的具体用法?Java BrokerRegistry怎么用?Java BrokerRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BrokerRegistry类属于org.apache.activemq.broker包,在下文中一共展示了BrokerRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: beforeTest
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
/**
* @throws Exception If failed.
*/
@Before
@SuppressWarnings("unchecked")
public void beforeTest() throws Exception {
grid().<Integer, String>getOrCreateCache(defaultCacheConfiguration());
broker = new BrokerService();
broker.setDeleteAllMessagesOnStartup(true);
broker.setPersistent(false);
broker.setPersistenceAdapter(null);
broker.setPersistenceFactory(null);
PolicyMap plcMap = new PolicyMap();
PolicyEntry plc = new PolicyEntry();
plc.setQueuePrefetch(1);
broker.setDestinationPolicy(plcMap);
broker.getDestinationPolicy().setDefaultEntry(plc);
broker.setSchedulerSupport(false);
broker.start(true);
connFactory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
}
示例2: lookup
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
/**
* @param brokerName
* @return the BrokerService
*/
public MessageBrokerView lookup(String brokerName) {
MessageBrokerView result = null;
synchronized (mutex) {
result = brokerViews.get(brokerName);
if (result==null){
BrokerService brokerService = BrokerRegistry.getInstance().lookup(brokerName);
if (brokerService != null){
result = new MessageBrokerView(brokerService);
brokerViews.put(brokerName,result);
}
}
}
return result;
}
示例3: lookupBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
/**
* @param registry
* @param brokerName
* @param waitForStart - time in milliseconds to wait for a broker to appear
* @return
*/
private BrokerService lookupBroker(final BrokerRegistry registry, final String brokerName, int waitForStart) {
BrokerService broker = null;
synchronized(registry.getRegistryMutext()) {
broker = registry.lookup(brokerName);
if (broker == null && waitForStart > 0) {
final long expiry = System.currentTimeMillis() + waitForStart;
while ((broker == null || !broker.isStarted()) && expiry > System.currentTimeMillis()) {
long timeout = Math.max(0, expiry - System.currentTimeMillis());
try {
LOG.debug("waiting for broker named: " + brokerName + " to start");
registry.getRegistryMutext().wait(timeout);
} catch (InterruptedException ignored) {
}
broker = registry.lookup(brokerName);
}
}
}
return broker;
}
示例4: validateBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
private boolean validateBroker(String host) {
boolean result = true;
if (BROKERS.containsKey(host) || SERVERS.containsKey(host) || CONNECTORS.containsKey(host)) {
// check the broker is still in the BrokerRegistry
TransportConnector connector = CONNECTORS.get(host);
if (BrokerRegistry.getInstance().lookup(host) == null
|| (connector != null && connector.getBroker().isStopped())) {
result = false;
// clean-up
BROKERS.remove(host);
SERVERS.remove(host);
if (connector != null) {
CONNECTORS.remove(host);
if (connector != null) {
ServiceSupport.dispose(connector);
}
}
}
}
return result;
}
示例5: testCreateVMConnectionWithEmbdeddBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
public void testCreateVMConnectionWithEmbdeddBroker() throws URISyntaxException, JMSException {
ActiveMQXAConnectionFactory cf = new ActiveMQXAConnectionFactory("vm://myBroker?broker.persistent=false");
// Make sure the broker is not created until the connection is
// instantiated.
assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
connection = (ActiveMQConnection) cf.createConnection();
// This should create the connection.
assertNotNull(connection);
// Verify the broker was created.
assertNotNull(BrokerRegistry.getInstance().lookup("myBroker"));
connection.close();
// Verify the broker was destroyed.
//comment out this check as it doesn't apply to artemis
//assertNull(BrokerRegistry.getInstance().lookup("myBroker"));
connection.close();
}
示例6: assertTransactionGoneFromConnection
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
private void assertTransactionGoneFromConnection(String brokerName,
String clientId,
ConnectionId connectionId,
Xid tid) throws Exception {
BrokerService broker = BrokerRegistry.getInstance().lookup(brokerName);
CopyOnWriteArrayList<TransportConnection> connections = broker.getTransportConnectors().get(0).getConnections();
for (TransportConnection connection : connections) {
if (connection.getConnectionId().equals(clientId)) {
try {
connection.processPrepareTransaction(new TransactionInfo(connectionId, new XATransactionId(tid), TransactionInfo.PREPARE));
fail("did not get expected exception on missing transaction, it must be still there in error!");
} catch (IllegalStateException expectedOnNoTransaction) {
}
}
}
}
示例7: testCreateVMConnectionWithEmbeddedBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
public void testCreateVMConnectionWithEmbeddedBroker() throws URISyntaxException, JMSException {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://myBroker2?broker.persistent=false");
// Make sure the broker is not created until the connection is
// instantiated.
assertNull(BrokerRegistry.getInstance().lookup("myBroker2"));
connection = (ActiveMQConnection) cf.createConnection();
// This should create the connection.
assertNotNull(connection);
// Verify the broker was created.
assertNotNull(BrokerRegistry.getInstance().lookup("myBroker2"));
connection.close();
// Verify the broker was destroyed.
//I comment out this because this is pure client behavior in
//amq5. there shouldn't be any use-case like that with Artemis.
//assertNull(BrokerRegistry.getInstance().lookup("myBroker2"));
}
示例8: restartRemoteBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
/**
* Simulates a broker restart. The memory based persistence adapter is
* reused so that it does not "loose" it's "persistent" messages.
*
* @throws Exception
*/
protected void restartRemoteBroker() throws Exception {
BrokerRegistry.getInstance().unbind("remotehost");
remoteConnector.stop();
remoteBroker.stop();
remotePersistenceAdapter.stop();
remotePersistenceAdapter = createRemotePersistenceAdapter(false);
remotePersistenceAdapter.start();
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
remoteBroker.addConnector(getRemoteURI());
remoteBroker.start();
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
}
示例9: tearDown
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
@Override
protected void tearDown() throws Exception {
for (Iterator<StubConnection> iter = connections.iterator(); iter.hasNext(); ) {
StubConnection connection = iter.next();
connection.stop();
iter.remove();
}
BrokerRegistry.getInstance().unbind("remotehost");
remoteConnector.stop();
connector.stop();
remoteBroker.stop();
remoteBroker.waitUntilStopped();
remotePersistenceAdapter.stop();
super.tearDown();
}
示例10: MessageBrokerView
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
/**
* Create a view of a running Broker
* @param brokerName
*/
public MessageBrokerView(String brokerName){
this.brokerService = BrokerRegistry.getInstance().lookup(brokerName);
if (brokerService == null){
throw new NullPointerException("BrokerService is null");
}
if (!brokerService.isStarted()){
throw new IllegalStateException("BrokerService " + brokerService.getBrokerName() + " is not started");
}
}
示例11: doConnect
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
@Override
public Transport doConnect(URI location) throws Exception {
//here check broker, if no broker, we start one
Map<String, String> params = URISupport.parseParameters(location);
String brokerId = params.remove("invmBrokerId");
boolean autoCreate = true;
String create = params.remove("create");
if (create != null) {
autoCreate = "true".equals(create);
}
URI location1 = URISupport.createRemainingURI(location, Collections.EMPTY_MAP);
LOG.info("deciding whether starting an internal broker: " + brokerService + " flag: " + BrokerService.disableWrapper);
if (autoCreate && brokerService == null && !BrokerService.disableWrapper && BrokerService.checkPort(location1.getPort())) {
LOG.info("starting internal broker: " + location1);
ArtemisBrokerHelper.startArtemisBroker(location1);
brokerService = new InternalServiceInfo(location.toString());
if (brokerId != null) {
BrokerRegistry.getInstance().bind(brokerId, ArtemisBrokerHelper.getBroker());
LOG.info("bound: " + brokerId);
}
}
//remove unused invm parameters
params.remove("broker.persistent");
params.remove("broker.useJmx");
params.remove("marshal");
params.remove("create");
params.remove("asyncQueueDepth");
URI location2 = URISupport.createRemainingURI(location, params);
return super.doConnect(location2);
}
示例12: assertTransactionGoneFromBroker
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
private void assertTransactionGoneFromBroker(Xid tid) throws Exception {
BrokerService broker = BrokerRegistry.getInstance().lookup("localhost");
TransactionBroker transactionBroker = (TransactionBroker) broker.getBroker().getAdaptor(TransactionBroker.class);
try {
transactionBroker.getTransaction(null, new XATransactionId(tid), false);
fail("expected exception on tx not found");
} catch (XAException expectedOnNotFound) {
}
}
示例13: setUp
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
remotePersistenceAdapter = createRemotePersistenceAdapter(true);
remoteBroker = createRemoteBroker(remotePersistenceAdapter);
remoteConnector = createRemoteConnector();
remoteBroker.addConnector(remoteConnector);
BrokerRegistry.getInstance().bind("remotehost", remoteBroker);
remoteBroker.start();
}
示例14: testVmBrokerPropertiesFile
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
public void testVmBrokerPropertiesFile() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?brokerConfig=properties:org/apache/activemq/config/broker.properties");
Connection connection = factory.createConnection();
BrokerService broker = BrokerRegistry.getInstance().lookup("Cheese");
LOG.info("Found broker : " + broker);
assertNotNull(broker);
assertEquals("isUseJmx()", false, broker.isUseJmx());
assertEquals("isPersistent()", false, broker.isPersistent());
assertEquals("getBrokerName()", "Cheese", broker.getBrokerName());
connection.close();
broker.stop();
}
示例15: get
import org.apache.activemq.broker.BrokerRegistry; //导入依赖的package包/类
public MessageInterceptorRegistry get(String brokerName){
BrokerService brokerService = BrokerRegistry.getInstance().lookup(brokerName);
return get(brokerService);
}