use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.
the class ConnectionFactoryWriteAttributeHandler method applyOperationToActiveMQService.
private void applyOperationToActiveMQService(final OperationContext context, String name, String attributeName, ModelNode value, ServiceController<?> serverServiceController) {
if (attributeName.equals(Common.CONNECTORS.getName()) || attributeName.equals(Common.DISCOVERY_GROUP.getName())) {
return;
}
ActiveMQServer server = ActiveMQServer.class.cast(serverServiceController.getValue());
ConnectionFactoryControl control = ConnectionFactoryControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_CONNECTION_FACTORY + name));
try {
if (attributeName.equals(CommonAttributes.CLIENT_ID.getName())) {
control.setClientID(value.isDefined() ? value.asString() : null);
} else if (attributeName.equals(Common.COMPRESS_LARGE_MESSAGES.getName())) {
control.setCompressLargeMessages(value.asBoolean());
} else if (attributeName.equals(Common.CLIENT_FAILURE_CHECK_PERIOD.getName())) {
control.setClientFailureCheckPeriod(value.asLong());
} else if (attributeName.equals(CommonAttributes.CALL_TIMEOUT.getName())) {
control.setCallTimeout(value.asLong());
} else if (attributeName.equals(CommonAttributes.CALL_FAILOVER_TIMEOUT.getName())) {
control.setCallFailoverTimeout(value.asLong());
} else if (attributeName.equals(Common.DUPS_OK_BATCH_SIZE.getName())) {
control.setDupsOKBatchSize(value.asInt());
} else if (attributeName.equals(Common.CONSUMER_MAX_RATE.getName())) {
control.setConsumerMaxRate(value.asInt());
} else if (attributeName.equals(Common.CONSUMER_WINDOW_SIZE.getName())) {
control.setConsumerWindowSize(value.asInt());
} else if (attributeName.equals(Common.PRODUCER_MAX_RATE.getName())) {
control.setProducerMaxRate(value.asInt());
} else if (attributeName.equals(Common.CONFIRMATION_WINDOW_SIZE.getName())) {
control.setConfirmationWindowSize(value.asInt());
} else if (attributeName.equals(Common.BLOCK_ON_ACKNOWLEDGE.getName())) {
control.setBlockOnAcknowledge(value.asBoolean());
} else if (attributeName.equals(Common.BLOCK_ON_DURABLE_SEND.getName())) {
control.setBlockOnDurableSend(value.asBoolean());
} else if (attributeName.equals(Common.BLOCK_ON_NON_DURABLE_SEND.getName())) {
control.setBlockOnNonDurableSend(value.asBoolean());
} else if (attributeName.equals(Common.PRE_ACKNOWLEDGE.getName())) {
control.setPreAcknowledge(value.asBoolean());
} else if (attributeName.equals(Common.CONNECTION_TTL.getName())) {
control.setConnectionTTL(value.asLong());
} else if (attributeName.equals(Common.TRANSACTION_BATCH_SIZE.getName())) {
control.setTransactionBatchSize(value.asInt());
} else if (attributeName.equals(CommonAttributes.MIN_LARGE_MESSAGE_SIZE.getName())) {
control.setMinLargeMessageSize(value.asInt());
} else if (attributeName.equals(Common.AUTO_GROUP.getName())) {
control.setAutoGroup(value.asBoolean());
} else if (attributeName.equals(Common.RETRY_INTERVAL.getName())) {
control.setRetryInterval(value.asLong());
} else if (attributeName.equals(Common.RETRY_INTERVAL_MULTIPLIER.getName())) {
control.setRetryIntervalMultiplier(value.asDouble());
} else if (attributeName.equals(Common.RECONNECT_ATTEMPTS.getName())) {
control.setReconnectAttempts(value.asInt());
} else if (attributeName.equals(Common.FAILOVER_ON_INITIAL_CONNECTION.getName())) {
control.setFailoverOnInitialConnection(value.asBoolean());
} else if (attributeName.equals(Common.PRODUCER_WINDOW_SIZE.getName())) {
control.setProducerWindowSize(value.asInt());
} else if (attributeName.equals(Common.CACHE_LARGE_MESSAGE_CLIENT.getName())) {
control.setCacheLargeMessagesClient(value.asBoolean());
} else if (attributeName.equals(CommonAttributes.MAX_RETRY_INTERVAL.getName())) {
control.setMaxRetryInterval(value.asLong());
} else if (attributeName.equals(Common.SCHEDULED_THREAD_POOL_MAX_SIZE.getName())) {
control.setScheduledThreadPoolMaxSize(value.asInt());
} else if (attributeName.equals(Common.THREAD_POOL_MAX_SIZE.getName())) {
control.setThreadPoolMaxSize(value.asInt());
} else if (attributeName.equals(Common.GROUP_ID.getName())) {
control.setGroupID(value.isDefined() ? value.asString() : null);
} else if (attributeName.equals(Common.USE_GLOBAL_POOLS.getName())) {
control.setUseGlobalPools(value.asBoolean());
} else if (attributeName.equals(Common.CONNECTION_LOAD_BALANCING_CLASS_NAME.getName())) {
control.setConnectionLoadBalancingPolicyClassName(value.asString());
} else if (attributeName.equals(Common.PROTOCOL_MANAGER_FACTORY.getName())) {
control.setProtocolManagerFactoryStr(value.asString());
} else {
// Bug! Someone added the attribute to the set but did not implement
throw MessagingLogger.ROOT_LOGGER.unsupportedRuntimeAttribute(attributeName);
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.
the class JMSTopicControlHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
final String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
TopicControl control = TopicControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_TOPIC + topicName));
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (LIST_ALL_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listAllSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_ALL_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listAllSubscriptionsAsJSON());
} else if (LIST_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listDurableSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listDurableSubscriptionsAsJSON());
} else if (LIST_NON_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listNonDurableSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_NON_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listNonDurableSubscriptionsAsJSON());
} else if (LIST_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
String json = control.listMessagesForSubscriptionAsJSON(queueName);
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_MESSAGES_FOR_SUBSCRIPTION_AS_JSON.equals(operationName)) {
final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
context.getResult().set(control.listMessagesForSubscriptionAsJSON(queueName));
} else if (COUNT_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
String filter = resolveFilter(context, operation);
context.getResult().set(control.countMessagesForSubscription(clientId, subscriptionName, filter));
} else if (DROP_DURABLE_SUBSCRIPTION.equals(operationName)) {
String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
control.dropDurableSubscription(clientId, subscriptionName);
context.getResult();
} else if (DROP_ALL_SUBSCRIPTIONS.equals(operationName)) {
control.dropAllSubscriptions();
context.getResult();
} else if (REMOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.removeMessages(filter));
} else {
// Bug
throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
context.getFailureDescription().set(e.toString());
}
context.completeStep(OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER);
}
use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.
the class JMSTopicReadAttributeHandler method executeRuntimeStep.
@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (ignoreOperationIfServerNotActive(context, operation)) {
return;
}
validator.validate(operation);
final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
TopicControl control = TopicControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_TOPIC + topicName));
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) {
try {
context.getResult().set(control.getMessageCount());
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
} else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getDeliveringCount());
} else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) {
context.getResult().set(control.getMessagesAdded());
} else if (DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getDurableMessageCount());
} else if (NON_DURABLE_MESSAGE_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getNonDurableMessageCount());
} else if (SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getSubscriptionCount());
} else if (DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getDurableSubscriptionCount());
} else if (NON_DURABLE_SUBSCRIPTION_COUNT.getName().equals(attributeName)) {
context.getResult().set(control.getNonDurableSubscriptionCount());
} else if (TOPIC_ADDRESS.getName().equals(attributeName)) {
context.getResult().set(control.getAddress());
} else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
context.getResult().set(control.isTemporary());
} else {
throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
}
}
use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.
the class HTTPUpgradeService method selectServer.
private static ActiveMQServer selectServer(HttpServerExchange exchange, ActiveMQServer rootServer) {
String activemqServerName = exchange.getRequestHeaders().getFirst(TransportConstants.ACTIVEMQ_SERVER_NAME);
if (activemqServerName == null) {
return rootServer;
}
ClusterManager clusterManager = rootServer.getClusterManager();
if (clusterManager != null) {
HAManager haManager = clusterManager.getHAManager();
if (haManager != null) {
for (Map.Entry<String, ActiveMQServer> entry : haManager.getBackupServers().entrySet()) {
if (entry.getKey().equals(activemqServerName)) {
return entry.getValue();
}
}
}
}
if (activemqServerName.equals(rootServer.getConfiguration().getName())) {
return rootServer;
} else {
return null;
}
}
use of org.apache.activemq.artemis.core.server.ActiveMQServer in project wildfly by wildfly.
the class HTTPUpgradeService method start.
@Override
public void start(StartContext context) throws StartException {
ListenerRegistry.Listener listenerInfo = listenerRegistry.getValue().getListener(httpListenerName);
assert listenerInfo != null;
httpUpgradeMetadata = new ListenerRegistry.HttpUpgradeMetadata(getProtocol(), CORE);
listenerInfo.addHttpUpgradeMetadata(httpUpgradeMetadata);
MessagingLogger.ROOT_LOGGER.registeredHTTPUpgradeHandler(ACTIVEMQ_REMOTING, acceptorName);
ServiceController<?> activeMQService = context.getController().getServiceContainer().getService(MessagingServices.getActiveMQServiceName(activeMQServerName));
ActiveMQServer activeMQServer = ActiveMQServer.class.cast(activeMQService.getValue());
httpUpgradeListener = switchToMessagingProtocol(activeMQServer, acceptorName, getProtocol());
injectedRegistry.getValue().addProtocol(getProtocol(), httpUpgradeListener, new SimpleHttpUpgradeHandshake(MAGIC_NUMBER, getSecKeyHeader(), getSecAcceptHeader()) {
/**
* override the default upgrade handshake to take into account the {@code TransportConstants.HTTP_UPGRADE_ENDPOINT_PROP_NAME} header
* to select the correct acceptors among all that are configured in ActiveMQ.
*
* If the request does not have this header, the first acceptor will be used.
*/
@Override
public boolean handleUpgrade(HttpServerExchange exchange) throws IOException {
if (super.handleUpgrade(exchange)) {
ActiveMQServer server = selectServer(exchange, activeMQServer);
if (server == null) {
return false;
}
// If ActiveMQ remoting service is stopped (eg during shutdown), refuse
// the handshake so that the ActiveMQ client will detect the connection has failed
RemotingService remotingService = server.getRemotingService();
final String endpoint = exchange.getRequestHeaders().getFirst(getHttpUpgradeEndpointKey());
if (!server.isActive() || !remotingService.isStarted()) {
return false;
}
if (endpoint == null) {
return true;
} else {
return acceptorName.equals(endpoint);
}
} else {
return false;
}
}
});
}
Aggregations