How to use addNotificationListener method of com.consol.citrus.jmx.client.JmxClient class

Best Citrus code snippet using com.consol.citrus.jmx.client.JmxClient.addNotificationListener

Source:JmxClient.java Github

copy

Full Screen

...129 correlationManager.store(correlationKey, JmxMessage.result());130 }131 }132 } else {133 addNotificationListener(objectName, correlationKey, serverConnection);134 }135 } catch (JMException e) {136 throw new CitrusRuntimeException("Failed to execute MBean operation", e);137 } catch (IOException e) {138 throw new CitrusRuntimeException("Failed to execute MBean operation", e);139 }140 }141 /**142 * Establish network connection to remote mBean server.143 * @return144 */145 private MBeanServerConnection getNetworkConnection() {146 try {147 JMXServiceURL url = new JMXServiceURL(getEndpointConfiguration().getServerUrl());148 String[] creds = {getEndpointConfiguration().getUsername(), getEndpointConfiguration().getPassword()};149 JMXConnector networkConnector = JMXConnectorFactory.connect(url, Collections.singletonMap(JMXConnector.CREDENTIALS, creds));150 connectionId = networkConnector.getConnectionId();151 networkConnector.addConnectionNotificationListener(this, null, null);152 return networkConnector.getMBeanServerConnection();153 } catch (IOException e) {154 throw new CitrusRuntimeException("Failed to connect to network MBean server", e);155 }156 }157 @Override158 public Message receive(TestContext context) {159 return receive(correlationManager.getCorrelationKey(160 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context);161 }162 @Override163 public Message receive(String selector, TestContext context) {164 return receive(selector, context, getEndpointConfiguration().getTimeout());165 }166 @Override167 public Message receive(TestContext context, long timeout) {168 return receive(correlationManager.getCorrelationKey(169 getEndpointConfiguration().getCorrelator().getCorrelationKeyName(getName()), context), context, timeout);170 }171 @Override172 public Message receive(String selector, TestContext context, long timeout) {173 Message message = correlationManager.find(selector, timeout);174 if (message == null) {175 throw new ActionTimeoutException("Action timeout while receiving synchronous reply message from MBean server");176 }177 return message;178 }179 @Override180 public void handleNotification(Notification notification, Object handback) {181 JMXConnectionNotification connectionNotification = (JMXConnectionNotification) notification;182 if (connectionNotification.getConnectionId().equals(getConnectionId()) && connectionLost(connectionNotification)) {183 log.warn("JmxClient lost JMX connection for : {}", getEndpointConfiguration().getServerUrl());184 if (getEndpointConfiguration().isAutoReconnect()) {185 scheduleReconnect();186 }187 }188 }189 /**190 * Finds connection lost type notifications.191 * @param connectionNotification192 * @return193 */194 private boolean connectionLost(JMXConnectionNotification connectionNotification) {195 return connectionNotification.getType().equals(JMXConnectionNotification.NOTIFS_LOST)196 || connectionNotification.getType().equals(JMXConnectionNotification.CLOSED)197 || connectionNotification.getType().equals(JMXConnectionNotification.FAILED);198 }199 /**200 * Schedules an attempt to re-initialize a lost connection after the reconnect delay201 */202 public void scheduleReconnect() {203 Runnable startRunnable = new Runnable() {204 @Override205 public void run() {206 try {207 MBeanServerConnection serverConnection = getNetworkConnection();208 if (notificationListener != null) {209 serverConnection.addNotificationListener(objectName, notificationListener, getEndpointConfiguration().getNotificationFilter(), getEndpointConfiguration().getNotificationHandback());210 }211 } catch (Exception e) {212 log.warn("Failed to reconnect to JMX MBean server. {}", e.getMessage());213 scheduleReconnect();214 }215 }216 };217 log.info("Reconnecting to MBean server {} in {} milliseconds.", getEndpointConfiguration().getServerUrl(), getEndpointConfiguration().getDelayOnReconnect());218 scheduledExecutor.schedule(startRunnable, getEndpointConfiguration().getDelayOnReconnect(), TimeUnit.MILLISECONDS);219 }220 /**221 * Add notification listener for response messages.222 * @param objectName223 * @param correlationKey224 * @param serverConnection225 */226 private void addNotificationListener(ObjectName objectName, final String correlationKey, MBeanServerConnection serverConnection) {227 try {228 notificationListener = new NotificationListener() {229 @Override230 public void handleNotification(Notification notification, Object handback) {231 correlationManager.store(correlationKey, new DefaultMessage(notification.getMessage()));232 }233 };234 serverConnection.addNotificationListener(objectName, notificationListener, getEndpointConfiguration().getNotificationFilter(), getEndpointConfiguration().getNotificationHandback());235 } catch (InstanceNotFoundException e) {236 throw new CitrusRuntimeException("Failed to find object name instance", e);237 } catch (IOException e) {238 throw new CitrusRuntimeException("Failed to add notification listener", e);239 }240 }241 /**242 * Creates a message producer for this endpoint for sending messages243 * to this endpoint.244 */245 @Override246 public Producer createProducer() {247 return this;248 }...

Full Screen

Full Screen

addNotificationListener

Using AI Code Generation

copy

Full Screen

1: the JMX server URL (required)2: the JMX server credentials (optional)3: the name of the test case (optional)4: the description of the test case (optional)5: the JMX server URL (required)6: the JMX server credentials (optional)7: the JMX server URL (required)8: the JMX server credentials (optional)9: the JMX server URL (required)10: the JMX server credentials (optional)11: the JMX server URL (required)12: the JMX server credentials (optional)13: the JMX server URL (required)14: the JMX server credentials (optional)

Full Screen

Full Screen

addNotificationListener

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.jmx;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.testng.TestNGCitrusTestRunner;4import com.consol.citrus.jmx.client.JmxClient;5import org.testng.annotations.Test;6public class JmxClientIT extends TestNGCitrusTestRunner {7 public void jmxClient() {8 variable("jmxServerPort", "1099");9 variable("jmxServerObjectName", "com.consol.citrus:type=JmxServer");10 variable("jmxServerNotificationFilter", "com.consol.citrus.jmx.server.JmxServerNotificationFilter");11 variable("jmxServerNotificationListener", "com.consol.citrus.jmx.server.JmxServerNotificationListener");12 echo("Create JMX client");13 JmxClient jmxClient = new JmxClient();14 jmxClient.setServerUrl("${jmxServerUrl}");15 jmxClient.setPort("${jmxServerPort}");16 jmxClient.setNotificationListener("${jmxServerNotificationListener}");17 jmxClient.setNotificationFilter("${jmxServerNotificationFilter

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful