本文整理汇总了Java中org.apache.activemq.broker.ConnectionContext.setBroker方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionContext.setBroker方法的具体用法?Java ConnectionContext.setBroker怎么用?Java ConnectionContext.setBroker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.activemq.broker.ConnectionContext
的用法示例。
在下文中一共展示了ConnectionContext.setBroker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fireFailedForwardAdvisory
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
private void fireFailedForwardAdvisory(MessageDispatch messageDispatch, Throwable error) {
if (configuration.isAdvisoryForFailedForward()) {
AdvisoryBroker advisoryBroker = null;
try {
advisoryBroker = (AdvisoryBroker) brokerService.getBroker().getAdaptor(AdvisoryBroker.class);
if (advisoryBroker != null) {
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(brokerService.getBroker());
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setStringProperty("cause", error.getLocalizedMessage());
advisoryBroker.fireAdvisory(context, AdvisorySupport.getNetworkBridgeForwardFailureAdvisoryTopic(), messageDispatch.getMessage(), null,
advisoryMessage);
}
} catch (Exception e) {
LOG.warn("failed to fire forward failure advisory, cause: {}", e);
LOG.debug("detail", e);
}
}
}
示例2: networkBridgeStarted
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void networkBridgeStarted(BrokerInfo brokerInfo, boolean createdByDuplex, String remoteIp) {
try {
if (brokerInfo != null) {
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setBooleanProperty("started", true);
advisoryMessage.setBooleanProperty("createdByDuplex", createdByDuplex);
advisoryMessage.setStringProperty("remoteIp", remoteIp);
networkBridges.putIfAbsent(brokerInfo, advisoryMessage);
ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(getBrokerService().getBroker());
fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("network bridge started", e);
}
}
示例3: networkBridgeStopped
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void networkBridgeStopped(BrokerInfo brokerInfo) {
try {
if (brokerInfo != null) {
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
advisoryMessage.setBooleanProperty("started", false);
networkBridges.remove(brokerInfo);
ActiveMQTopic topic = AdvisorySupport.getNetworkBridgeAdvisoryTopic();
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(getBrokerService().getBroker());
fireAdvisory(context, topic, brokerInfo, null, advisoryMessage);
}
} catch (Exception e) {
handleFireFailure("network bridge stopped", e);
}
}
示例4: createDurableSubscriber
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public ObjectName createDurableSubscriber(String clientId, String subscriberName, String topicName,
String selector) throws Exception {
ConnectionContext context = new ConnectionContext();
context.setBroker(safeGetBroker());
context.setClientId(clientId);
ConsumerInfo info = new ConsumerInfo();
ConsumerId consumerId = new ConsumerId();
consumerId.setConnectionId(clientId);
consumerId.setSessionId(sessionIdCounter.incrementAndGet());
consumerId.setValue(0);
info.setConsumerId(consumerId);
info.setDestination(new ActiveMQTopic(topicName));
info.setSubscriptionName(subscriberName);
info.setSelector(selector);
Subscription subscription = safeGetBroker().addConsumer(context, info);
safeGetBroker().removeConsumer(context, info);
if (subscription != null) {
return subscription.getObjectName();
}
return null;
}
示例5: setUp
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
System.setProperty("brokername", "testbroker");
brokerService = createBroker();
broker = brokerService.getBroker();
// started automatically
// brokerService.start();
context = new ConnectionContext();
context.setBroker(broker);
info = new ConnectionInfo();
info.setClientId("James");
info.setUserName("James");
info.setConnectionId(new ConnectionId("1234"));
try {
broker.addConnection(context, info);
} catch (Throwable e) {
e.printStackTrace();
fail(e.getMessage());
}
assertNotNull("No broker created!");
}
示例6: nowMasterBroker
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void nowMasterBroker() {
super.nowMasterBroker();
try {
ActiveMQTopic topic = AdvisorySupport.getMasterBrokerAdvisoryTopic();
ActiveMQMessage advisoryMessage = new ActiveMQMessage();
ConnectionContext context = new ConnectionContext();
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.setBroker(getBrokerService().getBroker());
fireAdvisory(context, topic,null,null,advisoryMessage);
} catch (Exception e) {
handleFireFailure("now master broker", e);
}
}
示例7: destroy
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
* Destroys the durable subscription so that messages will no longer be
* stored for this subscription
*/
public void destroy() throws Exception {
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
info.setClientId(clientId);
info.setSubscriptionName(subscriptionInfo.getSubscriptionName());
ConnectionContext context = new ConnectionContext();
context.setBroker(broker);
context.setClientId(clientId);
brokerService.getBroker().removeSubscription(context, info);
}
示例8: destroy
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
* Destroys the durable subscription so that messages will no longer be
* stored for this subscription
*/
public void destroy() throws Exception {
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
info.setClientId(clientId);
info.setSubscriptionName(subscriptionName);
ConnectionContext context = new ConnectionContext();
context.setBroker(broker);
context.setClientId(clientId);
brokerService.getBroker().removeSubscription(context, info);
}
示例9: destroyDurableSubscriber
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public void destroyDurableSubscriber(String clientId, String subscriberName) throws Exception {
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
info.setClientId(clientId);
info.setSubscriptionName(subscriberName);
ConnectionContext context = new ConnectionContext();
context.setBroker(safeGetBroker());
context.setClientId(clientId);
brokerService.getBroker().removeSubscription(context, info);
}
示例10: createConnectionContext
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
protected ConnectionContext createConnectionContext() {
ConnectionContext answer = new ConnectionContext(new NonCachedMessageEvaluationContext());
answer.setBroker(this.broker);
answer.getMessageEvaluationContext().setDestination(getActiveMQDestination());
answer.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
return answer;
}
示例11: discardExpiredMessage
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
private void discardExpiredMessage(MessageReference reference) {
LOG.debug("Discarding expired message {}", reference);
if (broker.isExpired(reference)) {
ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
context.setBroker(broker);
((Destination)reference.getRegionDestination()).messageExpired(context, null, new IndirectMessageReference(reference.getMessage()));
}
}
示例12: createAdminConnectionContext
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
* Factory method to create the new administration connection context
* object. Note this method is here rather than inside a default broker
* implementation to ensure that the broker reference inside it is the outer
* most interceptor
*/
protected static ConnectionContext createAdminConnectionContext(Broker broker) {
ConnectionContext context = new ConnectionContext();
context.setBroker(broker);
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
return context;
}
示例13: doDirectUnsubscribe
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
public void doDirectUnsubscribe(boolean restart) throws Exception {
createSubscriptions();
createAdvisorySubscription();
Thread.sleep(1000);
assertCount(100, 0);
if (restart) {
restartBroker();
createAdvisorySubscription();
assertCount(100, 0);
}
for (int i = 0; i < 100; i++) {
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
info.setClientId(getName());
info.setSubscriptionName("SubsId" + i);
ConnectionContext context = new ConnectionContext();
context.setBroker(broker.getRegionBroker());
context.setClientId(getName());
broker.getBroker().removeSubscription(context, info);
if (i % 20 == 0) {
Thread.sleep(1000);
assertCount(100 - i - 1, 0);
}
}
assertCount(0, 0);
if (restart) {
restartBroker();
createAdvisorySubscription();
assertCount(0, 0);
}
}
示例14: testMoveMessages
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
* The test queue is filled with QUEUE_SIZE test messages, each with a
* numeric id property beginning at 0. Once the queue is filled, the last
* message (id = QUEUE_SIZE-1) is moved to another queue. The test succeeds
* if the move completes within TEST_TIMEOUT milliseconds.
*
* @throws Exception
*/
public void testMoveMessages() throws Exception {
final int QUEUE_SIZE = 30000;
final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
final long TEST_TIMEOUT = 20000;
// Populate a test queue with uniquely-identifiable messages.
Connection conn = createConnection();
try {
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(destination);
for (int i = 0; i < QUEUE_SIZE; i++) {
Message message = session.createMessage();
message.setIntProperty("id", i);
producer.send(message);
}
session.commit();
} finally {
conn.close();
}
// Access the implementation of the test queue and move the last message
// to another queue. Verify that the move occurred within the limits of
// the test.
Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
context.setBroker(broker.getBroker());
context.getMessageEvaluationContext().setDestination(destination);
long startTimeMillis = System.currentTimeMillis();
Assert.assertEquals(1, queue.moveMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
long durationMillis = System.currentTimeMillis() - startTimeMillis;
LOG.info("It took " + durationMillis + "ms to move the last message from a queue a " + QUEUE_SIZE + " messages.");
Assert.assertTrue("Moving the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
示例15: testCopyMessages
import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
public void testCopyMessages() throws Exception {
final int QUEUE_SIZE = 30000;
final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
final long TEST_TIMEOUT = 10000;
// Populate a test queue with uniquely-identifiable messages.
Connection conn = createConnection();
try {
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(destination);
for (int i = 0; i < QUEUE_SIZE; i++) {
Message message = session.createMessage();
message.setIntProperty("id", i);
producer.send(message);
}
session.commit();
} finally {
conn.close();
}
// Access the implementation of the test queue and move the last message
// to another queue. Verify that the move occurred within the limits of
// the test.
Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
context.setBroker(broker.getBroker());
context.getMessageEvaluationContext().setDestination(destination);
long startTimeMillis = System.currentTimeMillis();
Assert.assertEquals(1, queue.copyMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
long durationMillis = System.currentTimeMillis() - startTimeMillis;
LOG.info("It took " + durationMillis + "ms to copy the last message from a queue a " + QUEUE_SIZE + " messages.");
Assert.assertTrue("Copying the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}