org.jppf.management.JPPFDriverAdmin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jppf-server Show documentation
Show all versions of jppf-server Show documentation
JPPF, the open source grid computing solution
The newest version!
/*
* JPPF.
* Copyright (C) 2005-2019 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jppf.management;
import static org.jppf.utils.stats.JPPFStatisticsHelper.*;
import java.util.*;
import org.jppf.load.balancer.LoadBalancingInformation;
import org.jppf.load.balancer.spi.JPPFBundlerFactory;
import org.jppf.server.*;
import org.jppf.server.nio.nodeserver.BaseNodeContext;
import org.jppf.utils.*;
import org.jppf.utils.stats.*;
import org.slf4j.*;
/**
* Instances of this class encapsulate the administration functionalities for a JPPF driver.
* @author Laurent Cohen
* @exclude
*/
public class JPPFDriverAdmin implements JPPFDriverAdminMBean {
/**
* Explicit serialVersionUID.
*/
private static final long serialVersionUID = 1L;
/**
* Logger for this class.
*/
private static final Logger log = LoggerFactory.getLogger(JPPFDriverAdmin.class);
/**
* Determines whether debug log statements are enabled.
*/
private static boolean debugEnabled = LoggingUtils.isDebugEnabled(log);
/**
* Base name used for localization lookups.
*/
private static final String I18N_BASE = "org.jppf.server.i18n.server_messages";
/**
* Reference to the driver.
*/
private final JPPFDriver driver;
/**
* The latest load-balancing information set via JMX.
*/
private LoadBalancingInformation currentLoadBalancingInformation;
/**
* Synchronization lock.
*/
private final Object loadBalancingInformationLock = new Object();
/**
*
*/
private final NodeSelectionHelper selectionHelper;
/**
*
* @param driver the jppf driver that holds this mbean.
*/
public JPPFDriverAdmin(final JPPFDriver driver) {
this.driver = driver;
selectionHelper = new NodeSelectionHelper(driver);
}
@Override
public Integer nbNodes() throws Exception {
return nbNodes(null);
}
@Override
public Integer nbNodes(final NodeSelector selector) throws Exception {
return selectionHelper.getNbChannels(selector == null ? NodeSelector.ALL_NODES : selector, false, false);
}
@Override
public Collection nodesInformation() {
return nodesInformation(null, false);
}
@Override
public Collection nodesInformation(final NodeSelector selector) {
return nodesInformation(selector, false);
}
@Override
public Collection nodesInformation(final NodeSelector selector, final boolean includePeers) {
try {
final Set nodes = selectionHelper.getChannels(selector == null ? NodeSelector.ALL_NODES : selector, includePeers, false);
final List list = new ArrayList<>(nodes.size());
for (final BaseNodeContext context : nodes) {
final JPPFManagementInfo info = context.getManagementInfo();
if (info != null) list.add(info);
}
return list;
} catch(final Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
@Override
public Integer nbIdleNodes() throws Exception {
return nbIdleNodes(null);
}
@Override
public Integer nbIdleNodes(final NodeSelector selector) throws Exception {
return nbIdleNodes(selector, false);
}
@Override
public Integer nbIdleNodes(final NodeSelector selector, final boolean includePeers) throws Exception {
final Set nodes = selectionHelper.getChannels(selector == null ? NodeSelector.ALL_NODES : selector, includePeers, false);
if (nodes == null) return -1;
int result = 0;
for (final BaseNodeContext node: nodes) {
final boolean idle = node.getIdle().get();
if (idle) result++;
}
if (debugEnabled) log.debug("there are {} nodes, including {} idle nodes", nodes.size(), result);
return result;
}
@Override
public Collection idleNodesInformation() throws Exception {
return idleNodesInformation(null);
}
@Override
public Collection idleNodesInformation(final NodeSelector selector) {
try {
final Set nodes = selectionHelper.getChannels(selector == null ? NodeSelector.ALL_NODES : selector, false, false);
final List list = new ArrayList<>(nodes.size());
for (final BaseNodeContext node : nodes) {
if (node.getIdle().get()) {
final JPPFManagementInfo info = node.getManagementInfo();
if (info != null) list.add(info);
}
}
return list;
} catch(final Exception e) {
log.error(e.getMessage(), e);
return null;
}
}
@Override
public JPPFStatistics statistics() throws Exception {
try {
final JPPFStatistics stats = driver.getStatistics();
if (log.isTraceEnabled()) log.trace("stats request = " + stats);
return stats;
} catch(final Throwable e) {
log.error(e.getMessage(), e);
return null;
}
}
@Override
public String changeLoadBalancerSettings(final String algorithm, final Map