001/*
002 * JPPF.
003 * Copyright (C) 2005-2019 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.management;
020
021import java.util.*;
022
023import org.jppf.load.balancer.LoadBalancingInformation;
024import org.jppf.utils.stats.JPPFStatistics;
025
026/**
027 * MBean interface for the management of a JPPF driver.
028 * @author Laurent Cohen
029 */
030public interface JPPFDriverAdminMBean extends JPPFAdminMBean {
031  /**
032   * Name of the driver's admin MBean.
033   */
034  String MBEAN_NAME = "org.jppf:name=admin,type=driver";
035
036  /**
037   * Get the latest statistics snapshot from the JPPF driver.
038   * @return a <code>JPPFStatistics</code> instance.
039   * @throws Exception if any error occurs.
040   */
041  JPPFStatistics statistics() throws Exception;
042
043  /**
044   * Get the number of nodes attached to the driver.
045   * Note that this method is equivalent to calling {@link #nbNodes(NodeSelector) nbNodes(null)}.
046   * @return the number of nodes, or -1 if information on the nodes could not be retrieved. The returned number does not include peer drivers.
047   * @throws Exception if any error occurs.
048   */
049  Integer nbNodes() throws Exception;
050
051  /**
052   * Get the number of nodes attached to the driver that satisfy the specified selector.
053   * @param selector specifies which nodes shouyld be counted. If null, then {@link NodeSelector#ALL_NODES} will be used.
054   * @return the number of nodes, or -1 if information on the nodes could not be retrieved. The returned number does not include peer drivers.
055   * @throws Exception if any error occurs.
056   * @since 5.0
057   */
058  Integer nbNodes(NodeSelector selector) throws Exception;
059
060  /**
061   * Request the JMX connection information for all the nodes attached to the server.
062   * Note that this method is equivalent to calling {@link #nodesInformation(NodeSelector, boolean) nodesInformation(null, false)}.
063   * @return a collection of {@link JPPFManagementInfo} instances, or {@code null} if information on the nodes could not be retrieved.
064   * @throws Exception if any error occurs.
065   */
066  Collection<JPPFManagementInfo> nodesInformation() throws Exception;
067
068  /**
069   * Request the JMX connection information for all the nodes attached to the server which satisfy the specified selector.
070   * Note that this method is equivalent to calling {@link #nodesInformation(NodeSelector, boolean) nodesInformation(selector, false)}.
071   * @param selector specifies which nodes shouyld be counted. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
072   * @return a collection of {@link JPPFManagementInfo} instances, or {@code null} if information on the nodes could not be retrieved.
073   * @throws Exception if any error occurs.
074   */
075  Collection<JPPFManagementInfo> nodesInformation(NodeSelector selector) throws Exception;
076
077  /**
078   * Request the JMX connection information for all the nodes attached to the server which satisfy the specified selector.
079   * @param selector specifies which nodes shouyld be counted. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
080   * @param includePeers whether peer drivers should be counted as nodes and included.
081   * @return a collection of {@link JPPFManagementInfo} instances, or {@code null} if information on the nodes could not be retrieved.
082   * @throws Exception if any error occurs.
083   */
084  Collection<JPPFManagementInfo> nodesInformation(NodeSelector selector, final boolean includePeers) throws Exception;
085
086  /**
087   * Perform a shutdown or restart of the server.
088   * @param shutdownDelay the delay before shutting down the server, once the command is received.
089   * @param restartDelay the delay before restarting, once the server is shutdown. If it is < 0, no restart occurs.
090   * @return an acknowledgement message.
091   * @throws Exception if any error occurs.
092   */
093  String restartShutdown(Long shutdownDelay, Long restartDelay) throws Exception;
094
095  /**
096   * Change the bundle size tuning settings.
097   * @param algorithm the name opf the load-balancing algorithm to set.
098   * @param parameters the algorithm's parameters.
099   * @return an acknowledgement or error message.
100   * @throws Exception if an error occurred while updating the settings.
101   */
102  String changeLoadBalancerSettings(String algorithm, Map<Object, Object> parameters) throws Exception;
103
104  /**
105   * Obtain the current load-balancing settings.
106   * @return an instance of <code>LoadBalancingInformation</code>.
107   * @throws Exception if an error occurred while fetching the settings.
108   */
109  LoadBalancingInformation loadBalancerInformation() throws Exception;
110
111  /**
112   * Reset this server's statistics.
113   * This method triggers a <code>reset()</code> event via the <code>JPPFDriverStatsManager</code> instance.
114   * @throws Exception if any error occurs.
115   */
116  void resetStatistics() throws Exception;
117
118  /**
119   * Get the number of nodes currently idle.
120   * Note that this method is equivalent to calling {@link #nbIdleNodes(NodeSelector) nbIdleNodes(null)}.
121   * @return the number of idle nodes, or -1 if information on the nodes could not be retrieved. The returned number does not include peer drivers.
122   * @throws Exception if any error occurs.
123   */
124  Integer nbIdleNodes() throws Exception;
125
126  /**
127   * Get the number of idle nodes attached to the driver that satisfy the specified selector.
128   * @param selector specifies which nodes should be counted. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
129   * @return the number of idle nodes, or -1 if information on the nodes could not be retrieved. The returned number does not include peer drivers.
130   * @throws Exception if any error occurs.
131   * @since 5.0
132   */
133  Integer nbIdleNodes(NodeSelector selector) throws Exception;
134
135  /**
136   * Get the number of idle nodes attached to the driver that satisfy the specified selector.
137   * @param selector specifies which nodes should be counted. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
138   * @param includePeers whether peer drivers should be counted as nodes and included.
139   * @return the number of idle nodes, or -1 if information on the nodes could not be retrieved. The returned number does not include peer drivers.
140   * @throws Exception if any error occurs.
141   * @since 5.0
142   */
143  Integer nbIdleNodes(NodeSelector selector, boolean includePeers) throws Exception;
144
145  /**
146   * Request the JMX connection information for all the idle nodes attached to the server.
147   * Note that this method is equivalent to calling {@link #idleNodesInformation(NodeSelector) idleNodesInformation(null)}.
148   * @return a collection of {@link JPPFManagementInfo} instances, or {@code null} if information on the nodes could not be retrieved.
149   * @throws Exception if any error occurs.
150   */
151  Collection<JPPFManagementInfo> idleNodesInformation() throws Exception;
152
153  /**
154   * Request the JMX connection information for all the idle nodes attached to the server which satisfy the specified selector.
155   * @param selector specifies which nodes shouyld be counted. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
156   * @return a collection of {@link JPPFManagementInfo} instances, or {@code null} if information on the nodes could not be retrieved.
157   * @throws Exception if any error occurs.
158   */
159  Collection<JPPFManagementInfo> idleNodesInformation(NodeSelector selector) throws Exception;
160
161  /**
162   * Toggle the activate state of the specified nodes. Nodes in 'active' state will be deactivated, nodes in 'inactive' state will be activated.
163   * @param selector determines which nodes will be activated or deactivated.  If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
164   * @throws Exception if any error occurs.
165   */
166  void toggleActiveState(NodeSelector selector) throws Exception;
167
168  /**
169   * Get the active states of the nodes specified vith a {@link NodeSelector}.
170   * @param selector specifies for which nodes to retrieve the active states. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
171   * @return a mmaping of node uuids to their active state.
172   * @throws Exception if any error occurs.
173   */
174  Map<String, Boolean> getActiveState(NodeSelector selector) throws Exception;
175
176  /**
177   * Set the active state of the specified nodes.
178   * @param selector determines which nodes will be activated or deactivated. If {@code null}, then {@link NodeSelector#ALL_NODES} will be used.
179   * @param active specifies the activer state to set on the selected nodes.
180   * @throws Exception if any error occurs.
181   */
182  void setActiveState(NodeSelector selector, boolean active) throws Exception;
183
184  /**
185   * Activate or deactivate the broadcasting of the driver's connection information.
186   * if the broadcast is already in the desired state, this method has no effect.
187   * @param broadcasting {@code true} to activate the broadcast, {@code false} to deactivate it.
188   * @throws Exception if any error occurs.
189   */
190  void setBroadcasting(boolean broadcasting) throws Exception;
191
192  /**
193   * Determine whether the driver is broadcasting or not.
194   * @return {@code true} if the broadcasting service is on, {@code false} if it is off.
195   * @throws Exception if any error occurs.
196   */
197  boolean getBroadcasting() throws Exception;
198}