mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noël Rouvignac
02.28.2016 77e0cf98df62ea367b263021fd67c58ed48a753c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2006-2008 Sun Microsystems, Inc.
 * Portions Copyright 2015 ForgeRock AS.
 */
package org.opends.server.protocols.jmx;
 
import java.io.IOException;
import java.util.Map;
 
import javax.management.ListenerNotFoundException;
import javax.management.MBeanServerConnection;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.security.auth.Subject;
 
/**
 * Wrapper class for the JMX's RMI connector. This class has the exact same
 * functionalities but maintain inner variables which are used during the
 * connection phase.
 * <p>
 * Note that the javadoc has been copied from the
 * javax.management.remote.JMXConnector interface.
 */
public class OpendsJmxConnector implements JMXConnector
{
 
  /** The wrapped JMX RMI connector. */
  private JMXConnector jmxc;
 
  /** The connection environment set at creation. */
  private Map<String,Object> environment;
 
  /** The JMX Service URL. */
  private JMXServiceURL serviceURL;
 
  /**
   * Creates a connector client for the connector server at the
   * given host and port.  The resultant client is not connected until its
   *  connect method is called.
   *
   * @param serverHostname the target server hostname
   *
   * @param serverPort the target server port
   *
   * @param environment a set of attributes to determine how the
   * connection is made.  This parameter can be null.  Keys in this
   * map must be Strings.  The appropriate type of each associated
   * value depends on the attribute.  The contents of
   * <code>environment</code> are not changed by this call.
   *
   * @exception IOException if the connector client cannot be made
   * because of a communication problem.
   */
  public OpendsJmxConnector(String serverHostname, int serverPort,
      Map<String,Object> environment) throws IOException
  {
    serviceURL = new JMXServiceURL(
        "service:jmx:rmi:///jndi/rmi://" + serverHostname + ":" + serverPort
            + "/org.opends.server.protocols.jmx.client-unknown");
 
    this.jmxc = JMXConnectorFactory.newJMXConnector(serviceURL, environment);
    this.environment = environment ;
  }
 
  /**
   * Returns the connection environment.
   *
   * @return Map the connection environment used by new connections
   */
  public Map<String, Object> getConnectionEnv()
  {
    return environment;
  }
 
  /** {@inheritDoc} */
  @Override
  public void connect() throws IOException, SecurityException
  {
    connect(null);
  }
 
  /** {@inheritDoc} */
  @Override
  public void connect(Map<String,?> env) throws IOException, SecurityException
  {
    jmxc.connect(env);
  }
 
  /** {@inheritDoc} */
  @Override
  public MBeanServerConnection getMBeanServerConnection() throws IOException
  {
    return jmxc.getMBeanServerConnection();
  }
 
  /** {@inheritDoc} */
  @Override
  public MBeanServerConnection getMBeanServerConnection(
      Subject delegationSubject) throws IOException
  {
    return jmxc.getMBeanServerConnection(delegationSubject);
  }
 
  /** {@inheritDoc} */
  @Override
  public void close() throws IOException
  {
    jmxc.close();
  }
 
  /** {@inheritDoc} */
  @Override
  public void addConnectionNotificationListener(
      NotificationListener listener, NotificationFilter filter,
      Object handback) throws NullPointerException
  {
    jmxc.addConnectionNotificationListener(listener, filter, handback);
  }
 
  /** {@inheritDoc} */
  @Override
  public void removeConnectionNotificationListener(
      NotificationListener listener) throws ListenerNotFoundException,
      NullPointerException
  {
    jmxc.removeConnectionNotificationListener(listener);
  }
 
  /** {@inheritDoc} */
  @Override
  public void removeConnectionNotificationListener(
      NotificationListener l, NotificationFilter f, Object handback)
      throws ListenerNotFoundException
  {
    jmxc.removeConnectionNotificationListener(l, f, handback);
  }
 
  /** {@inheritDoc} */
  @Override
  public String getConnectionId() throws IOException
  {
    return jmxc.getConnectionId();
  }
}