001/*002 * Copyright 2002-2012 the original author or authors.003 *004 * Licensed under the Apache License, Version 2.0 (the "License");005 * you may not use this file except in compliance with the License.006 * You may obtain a copy of the License at007 *008 * https://www.apache.org/licenses/LICENSE-2.0009 *010 * Unless required by applicable law or agreed to in writing, software011 * distributed under the License is distributed on an "AS IS" BASIS,012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.013 * See the License for the specific language governing permissions and014 * limitations under the License.015 */016017package org.springframework.jmx.access;018019import java.io.IOException;020import java.net.MalformedURLException;021import java.util.Arrays;022import java.util.Map;023import javax.management.MBeanServerConnection;024import javax.management.ObjectName;025import javax.management.remote.JMXServiceURL;026027import org.apache.commons.logging.Log;028import org.apache.commons.logging.LogFactory;029030import org.springframework.beans.factory.DisposableBean;031import org.springframework.beans.factory.InitializingBean;032import org.springframework.jmx.JmxException;033import org.springframework.jmx.MBeanServerNotFoundException;034import org.springframework.jmx.support.NotificationListenerHolder;035import org.springframework.util.CollectionUtils;036037/**038 * Registrar object that associates a specific {@link javax.management.NotificationListener}039 * with one or more MBeans in an {@link javax.management.MBeanServer}040 * (typically via a {@link javax.management.MBeanServerConnection}).041 *042 * @author Juergen Hoeller043 * @since 2.5.2044 * @see #setServer045 * @see #setMappedObjectNames046 * @see #setNotificationListener047 */048public class NotificationListenerRegistrar extends NotificationListenerHolder049 implements InitializingBean, DisposableBean {050051 /** Logger available to subclasses */052 protected final Log logger = LogFactory.getLog(getClass());053054 private MBeanServerConnection server;055056 private JMXServiceURL serviceUrl;057058 private Map<String, ?> environment;059060 private String agentId;061062 private final ConnectorDelegate connector = new ConnectorDelegate();063064 private ObjectName[] actualObjectNames;065066067 /**068 * Set the {@code MBeanServerConnection} used to connect to the069 * MBean which all invocations are routed to.070 */071 public void setServer(MBeanServerConnection server) {072 this.server = server;073 }074075 /**076 * Specify the environment for the JMX connector.077 * @see javax.management.remote.JMXConnectorFactory#connect(javax.management.remote.JMXServiceURL, java.util.Map)078 */<