/** * Connects to the JMX agent in the local process. * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if the JDK management agent cannot be found and loaded */ private void connect() throws ConnectionFailedException, IOException { try { final JMXServiceURL jmxUrl = getJMXServiceURL(); this.jmxc = JMXConnectorFactory.connect(jmxUrl); this.server = this.jmxc.getMBeanServerConnection(); } catch (AttachNotSupportedException e) { throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e); } }
/** * Connects to the process and tells it to shut down. * * @param namePattern the name pattern of the MBean to use for stopping * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param stopMethod the name of the MBean operation to invoke * @param attributes the names of the MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if a communication problem occurred when talking to the MBean server * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason */ private void stop(final ObjectName namePattern, final String pidAttribute, final String stopMethod, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException { invokeOperationOnTargetMBean(namePattern, pidAttribute, stopMethod, attributes, values); }
throws ConnectionFailedException, IOException, MBeanInvocationFailedException { ObjectName objectName = namePattern; connect(); try { final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values); final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint); return invoke(objectName, methodName); } catch (InstanceNotFoundException e) { throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e); throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e); } finally { disconnect();
@Override public String status() throws UnableToControlProcessException, ConnectionFailedException, IOException, MBeanInvocationFailedException { return status(this.arguments.getNamePattern(), this.arguments.getPidAttribute(), this.arguments.getStatusMethod(), this.arguments.getAttributes(), this.arguments.getValues()); }
@Override public void stop() throws UnableToControlProcessException, ConnectionFailedException, IOException, MBeanInvocationFailedException { stop(this.arguments.getNamePattern(), this.arguments.getPidAttribute(), this.arguments.getStopMethod(), this.arguments.getAttributes(), this.arguments.getValues()); }
public ProcessController createProcessController(final ProcessControllerParameters arguments, final int pid) { if (arguments == null) { throw new NullPointerException("ProcessControllerParameters must not be null"); } if (pid < 1) { throw new IllegalArgumentException("Invalid pid '" + pid + "' specified"); } try { if (isAttachAPIFound()) { return new MBeanProcessController((MBeanControllerParameters)arguments, pid); } else { return new FileProcessController((FileControllerParameters)arguments, pid); } } catch (final ExceptionInInitializerError e) { //LOGGER.warn("Attach API class not found", e); } return null; }
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
throws ConnectionFailedException, IOException, MBeanInvocationFailedException { ObjectName objectName = namePattern; connect(); try { final QueryExp constraint = buildQueryExp(pidAttribute, attributes, values); final Set<ObjectName> mbeanNames = this.server.queryNames(namePattern, constraint); return invoke(objectName, methodName); } catch (InstanceNotFoundException e) { throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e); throw new MBeanInvocationFailedException("Failed to invoke " + methodName + " on " + objectName, e); } finally { disconnect();
@Override public String status() throws UnableToControlProcessException, ConnectionFailedException, IOException, MBeanInvocationFailedException { return status(this.arguments.getNamePattern(), this.arguments.getPidAttribute(), this.arguments.getStatusMethod(), this.arguments.getAttributes(), this.arguments.getValues()); }
@Override public void stop() throws UnableToControlProcessException, ConnectionFailedException, IOException, MBeanInvocationFailedException { stop(this.arguments.getNamePattern(), this.arguments.getPidAttribute(), this.arguments.getStopMethod(), this.arguments.getAttributes(), this.arguments.getValues()); }
public ProcessController createProcessController(final ProcessControllerParameters arguments, final int pid) { if (pid < 1) { throw new IllegalArgumentException("Invalid pid '" + pid + "' specified"); } try { if (isAttachAPIFound()) { return new MBeanProcessController((MBeanControllerParameters)arguments, pid); } else { return new FileProcessController((FileControllerParameters)arguments, pid); } } catch (final ExceptionInInitializerError e) { //LOGGER.warn("Attach API class not found", e); } return null; }
/** * Builds the QueryExp used to identify the target MBean. * * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param attributes the names of additional MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return the main QueryExp for matching the target MBean */ private QueryExp buildQueryExp(final String pidAttribute, final String[] attributes, final Object[] values) { final QueryExp optionalAttributes = buildOptionalQueryExp(attributes, values); QueryExp constraint; if (optionalAttributes != null) { constraint = Query.and(optionalAttributes, Query.eq( Query.attr(pidAttribute), Query.value(this.pid))); } else { constraint = Query.eq( Query.attr(pidAttribute), Query.value(this.pid)); } return constraint; }
/** * Connects to the process and tells it to shut down. * * @param namePattern the name pattern of the MBean to use for stopping * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param stopMethod the name of the MBean operation to invoke * @param attributes the names of the MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if a communication problem occurred when talking to the MBean server * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason */ private void stop(final ObjectName namePattern, final String pidAttribute, final String stopMethod, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException { invokeOperationOnTargetMBean(namePattern, pidAttribute, stopMethod, attributes, values); }
/** * Connects to the JMX agent in the local process. * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if the JDK management agent cannot be found and loaded */ private void connect() throws ConnectionFailedException, IOException { try { final JMXServiceURL jmxUrl = getJMXServiceURL(); this.jmxc = JMXConnectorFactory.connect(jmxUrl); this.server = this.jmxc.getMBeanServerConnection(); } catch (AttachNotSupportedException e) { throw new ConnectionFailedException("Failed to connect to process '" + this.pid + "'", e); } }
/** * Connects to the process and acquires its status. * * @param namePattern the name pattern of the MBean to use for stopping * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param statusMethod the name of the MBean operation to invoke * @param attributes the names of the MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return string describing the status of the process * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if a communication problem occurred when talking to the MBean server * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason */ private String status(final ObjectName namePattern, final String pidAttribute, final String statusMethod, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException { return invokeOperationOnTargetMBean(namePattern, pidAttribute, statusMethod, attributes, values).toString(); }
/** * Connects to the process and acquires its status. * * @param namePattern the name pattern of the MBean to use for stopping * @param pidAttribute the name of the MBean attribute with the process id to compare against * @param statusMethod the name of the MBean operation to invoke * @param attributes the names of the MBean attributes to compare with expected values * @param values the expected values of the specified MBean attributes * * @return string describing the status of the process * * @throws ConnectionFailedException if there was a failure to connect to the local JMX connector in the process * @throws IOException if a communication problem occurred when talking to the MBean server * @throws MBeanInvocationFailedException if failed to invoke stop on the MBean for any reason */ private String status(final ObjectName namePattern, final String pidAttribute, final String statusMethod, final String[] attributes, final Object[] values) throws ConnectionFailedException, IOException, MBeanInvocationFailedException { return invokeOperationOnTargetMBean(namePattern, pidAttribute, statusMethod, attributes, values).toString(); }