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


Java ConnectionContext类代码示例

本文整理汇总了Java中org.apache.activemq.broker.ConnectionContext的典型用法代码示例。如果您正苦于以下问题:Java ConnectionContext类的具体用法?Java ConnectionContext怎么用?Java ConnectionContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: addConsumer

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * Add new message consumer.
 *
 * @param context
 * @param info
 * @return
 * @throws Exception
 * @see org.apache.activemq.broker.BrokerFilter#addConsumer(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ConsumerInfo)
 */
public Subscription addConsumer(ConnectionContext context, ConsumerInfo info) throws Exception {

    ActiveMQDestination dest = info.getDestination();
    Connection conn = context.getConnection();
    if (dest != null) {
        String destName = info.getDestination().getPhysicalName();
        String clientId = context.getClientId();
        String allowedDest = userMap.get(clientId);

        logger.info(">>> Got Consumer Add request { Destination: " + destName
                + ", Remote Address: " + conn.getRemoteAddress()
                + ", ClientID: " + clientId
                + " }");
        if (allowedDest != null && (allowedDest.equals("*") || allowedDest.equals(destName) || destName.startsWith("ActiveMQ"))) {
            logger.info(">>> Subscription allowed");
        } else {
            logger.error(">>> Destination not allowed. Subscription denied!");
            throw new CmsAuthException(">>> Subscription denied!");
        }
    } else {
        logger.error("<<< Got Consumer Add request from Remote Address:" + conn.getRemoteAddress() + ". But destination is NULL.");
    }
    return super.addConsumer(context, info);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:34,代码来源:OneopsAuthBroker.java

示例2: addProducer

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * Add message producer.
 *
 * @param context
 * @param info
 * @throws Exception
 * @see org.apache.activemq.broker.BrokerFilter#addProducer(org.apache.activemq.broker.ConnectionContext, org.apache.activemq.command.ProducerInfo)
 */
public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {

    Connection conn = context.getConnection();
    ActiveMQDestination dest = info.getDestination();
    if (dest != null) {
        String destName = dest.getPhysicalName();
        String clientId = context.getClientId();

        logger.info(">>> Got Producer Add request { Destination: " + destName
                + ", Remote Address: " + conn.getRemoteAddress()
                + ", ClientID: " + clientId
                + " }");

        String allowedDest = userMap.get(context.getClientId());
        if (allowedDest != null && (allowedDest.equals("*") || "controller.response".equals(destName))) {
            logger.info("<<< Producer allowed");
        } else {
            logger.error("<<< Destination not allowed. Producer denied!");
            throw new CmsAuthException("<<< Producer denied!");
        }
    } else {
        logger.error("<<< Got Producer Add request from Remote Address:" + conn.getRemoteAddress() + ". But destination is NULL.");
    }
    super.addProducer(context, info);
}
 
开发者ID:oneops,项目名称:oneops,代码行数:34,代码来源:OneopsAuthBroker.java

示例3: addProducerTestProducerDenied

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Test(priority = 6, expectedExceptions = RuntimeException.class)
public void addProducerTestProducerDenied() {

	//create a mock ConnectionContext which was not used when setting up user map
	ConnectionContext ccForbidden = mock(ConnectionContext.class);
	when(ccForbidden.getClientId()).thenReturn("this-is-not-in-user-map");
	 final Connection connectionMock = mock(Connection.class);
		when(connectionMock.getRemoteAddress()).thenReturn(MOCK_REMOTE_ADDR);
			when(ccForbidden.getConnection()).thenAnswer(new Answer<Connection>() {
		@Override
		public Connection answer(InvocationOnMock invocation)
				throws Throwable {
			return connectionMock;
		}
	});
	
	try {
		this.oneopsAuthBroker.addProducer(ccForbidden, producerInfo);
	} catch (Exception e) {
		logger.warn("caught exception, make sure Broker is mocked",e);
		throw new RuntimeException(e);
	}
}
 
开发者ID:oneops,项目名称:oneops,代码行数:24,代码来源:OneopsAuthBrokerTest.java

示例4: isEmbeddedConnection

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * Check if the connection is internal
 * 
 * @param context
 *            the context
 * @param info
 *            the connection info
 * @return true if the connection is embedded
 */
private boolean isEmbeddedConnection(ConnectionContext context, ConnectionInfo info) {
    if (embeddedConfiguration != null) {
        // check the username and password of the connection
        if (embeddedConfiguration.getUsername().equals(info.getUserName())
                && embeddedConfiguration.getPassword()
                        .equals(info.getPassword())) {

            // check if its local
            if (CommunoteJaasLoginModule.isAddressLocal(context
                    .getConnection().getRemoteAddress())) {

                // it is as an embedded connection
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:28,代码来源:CommunoteJaasAuthenticationBroker.java

示例5: createSubscription

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
protected Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws JMSException {
    if (info.isDurable()) {
        throw new JMSException("A durable subscription cannot be created for a temporary topic.");
    }
    try {
        TopicSubscription answer = new TopicSubscription(broker, context, info, usageManager);
        // lets configure the subscription depending on the destination
        ActiveMQDestination destination = info.getDestination();
        if (destination != null && broker.getDestinationPolicy() != null) {
            PolicyEntry entry = broker.getDestinationPolicy().getEntryFor(destination);
            if (entry != null) {
                entry.configure(broker, usageManager, answer);
            }
        }
        answer.init();
        return answer;
    } catch (Exception e) {
        LOG.error("Failed to create TopicSubscription ", e);
        JMSException jmsEx = new JMSException("Couldn't create TopicSubscription");
        jmsEx.setLinkedException(e);
        throw jmsEx;
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:24,代码来源:TempTopicRegion.java

示例6: addProducer

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Override
public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception {
    final SecurityContext securityContext = checkSecurityContext(context);

    if (!securityContext.isBrokerContext() && info.getDestination() != null) {

        Set<?> allowedACLs = null;
        if (!info.getDestination().isTemporary()) {
            allowedACLs = authorizationMap.getWriteACLs(info.getDestination());
        } else {
            allowedACLs = authorizationMap.getTempDestinationWriteACLs();
        }
        if (allowedACLs != null && !securityContext.isInOneOf(allowedACLs)) {
            throw new SecurityException("User " + securityContext.getUserName() + " is not authorized to write to: " + info.getDestination());
        }
        securityContext.getAuthorizedWriteDests().put(info.getDestination(), info.getDestination());
    }

    super.addProducer(context, info);
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:21,代码来源:AuthorizationBroker.java

示例7: removeConnection

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * Overriding removeConnection to make sure the security context is cleaned.
 */
@Override
public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception {
    boolean isSSL;
    Connector connector = context.getConnector();
    if (connector instanceof TransportConnector) {
        TransportConnector transportConnector = (TransportConnector) connector;
        isSSL = (transportConnector.getServer() instanceof SslTransportServer);
    } else {
        isSSL = false;
    }
    super.removeConnection(context, info, error);
    if (isSSL) {
        this.sslBroker.removeConnection(context, info, error);
    } else {
        this.nonSslBroker.removeConnection(context, info, error);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:21,代码来源:JaasDualAuthenticationBroker.java

示例8: messageExpired

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Override
public void messageExpired(ConnectionContext context, Subscription subs, MessageReference reference) {
    LOG.debug("message expired: {}", reference);
    broker.messageExpired(context, reference, subs);
    destinationStatistics.getExpired().increment();
    try {
        removeMessage(context, subs, (QueueMessageReference) reference);
        messagesLock.writeLock().lock();
        try {
            messages.rollback(reference.getMessageId());
        } finally {
            messagesLock.writeLock().unlock();
        }
    } catch (IOException e) {
        LOG.error("Failed to remove expired Message from the store ", e);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:18,代码来源:Queue.java

示例9: addMessage

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * @param message
 * @throws IOException
 */
void addMessage(ConnectionContext context, final MessageStore destination, final Message message)
        throws IOException {

    if (message.getTransactionId() != null) {
        if (message.getTransactionId().isXATransaction() || theStore.isConcurrentStoreAndDispatchTransactions() == false) {
            destination.addMessage(context, message);
        } else {
            Tx tx = getTx(message.getTransactionId());
            tx.add(new AddMessageCommand(context) {
                @Override
                public Message getMessage() {
                    return message;
                }
                @Override
                public Future<Object> run(ConnectionContext ctx) throws IOException {
                    destination.addMessage(ctx, message);
                    return AbstractMessageStore.FUTURE;
                }

            });
        }
    } else {
        destination.addMessage(context, message);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:30,代码来源:KahaDBTransactionStore.java

示例10: removeSubscription

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Override
public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
    SubscriptionKey key = new SubscriptionKey(context.getClientId(), info.getSubscriptionName());
    DurableTopicSubscription sub = ((TopicRegion)((RegionBroker)next).getTopicRegion()).getDurableSubscription(key);

    super.removeSubscription(context, info);

    if (sub == null) {
        LOG.warn("We cannot send an advisory message for a durable sub removal when we don't know about the durable sub");
        return;
    }

    ActiveMQDestination dest = sub.getConsumerInfo().getDestination();

    // Don't advise advisory topics.
    if (!AdvisorySupport.isAdvisoryTopic(dest)) {
        ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(dest);
        fireConsumerAdvisory(context, dest, topic, info);
    }

}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:22,代码来源:AdvisoryBroker.java

示例11: messageExpired

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Override
public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) {
    super.messageExpired(context, messageReference, subscription);
    try {
        if(!messageReference.isAdvisory()) {
            ActiveMQTopic topic = AdvisorySupport.getExpiredMessageTopic(messageReference.getMessage().getDestination());
            Message payload = messageReference.getMessage().copy();
            payload.clearBody();
            ActiveMQMessage advisoryMessage = new ActiveMQMessage();
            advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
            fireAdvisory(context, topic, payload, null, advisoryMessage);
        }
    } catch (Exception e) {
        handleFireFailure("expired", e);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:17,代码来源:AdvisoryBroker.java

示例12: 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);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:20,代码来源:AdvisoryBroker.java

示例13: getConnection

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
/**
 * @returns the ObjectName of the Connection that created this subscription
 */
@Override
public ObjectName getConnection() {
    ObjectName result = null;

    if (clientId != null && subscription != null) {
        ConnectionContext ctx = subscription.getContext();
        if (ctx != null && ctx.getBroker() != null && ctx.getBroker().getBrokerService() != null) {
            BrokerService service = ctx.getBroker().getBrokerService();
            ManagementContext managementCtx = service.getManagementContext();
            if (managementCtx != null) {

                try {
                    ObjectName query = createConnectionQuery(managementCtx, service.getBrokerName());
                    Set<ObjectName> names = managementCtx.queryNames(query, null);
                    if (names.size() == 1) {
                        result = names.iterator().next();
                    }
                } catch (Exception e) {
                }
            }
        }
    }
    return result;
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:28,代码来源:SubscriptionView.java

示例14: acknowledge

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
public void acknowledge(final TopicMessageStore destination, final String clientId, final String subscriptionName,
                       final MessageId messageId, final MessageAck ack) throws IOException {
    if (doingRecover) {
        return;
    }

    if (ack.isInTransaction()) {
        Tx tx = getTx(ack.getTransactionId());
        tx.add(new RemoveMessageCommand() {
            public MessageAck getMessageAck() {
                return ack;
            }

            public void run(ConnectionContext ctx) throws IOException {
                destination.acknowledge(ctx, clientId, subscriptionName, messageId, ack);
            }

            @Override
            public MessageStore getMessageStore() {
                return destination;
            }
        });
    } else {
        destination.acknowledge(null, clientId, subscriptionName, messageId, ack);
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:27,代码来源:MemoryTransactionStore.java

示例15: slowConsumer

import org.apache.activemq.broker.ConnectionContext; //导入依赖的package包/类
@Override
public void slowConsumer(ConnectionContext context, Subscription subs) {
    if (maxSlowCount < 0 && maxSlowDuration < 0) {
        // nothing to do
        LOG.info("no limits set, slowConsumer strategy has nothing to do");
        return;
    }

    if (taskStarted.compareAndSet(false, true)) {
        scheduler.executePeriodically(this, checkPeriod);
    }

    if (!slowConsumers.containsKey(subs)) {
        slowConsumers.put(subs, new SlowConsumerEntry(context));
    } else if (maxSlowCount > 0) {
        slowConsumers.get(subs).slow();
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:19,代码来源:AbortSlowConsumerStrategy.java


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