blob: ac47d62f43df87d2584a64f599ee9002e052e016 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2013, 2018 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.internal.rj.servi;
import java.lang.management.ManagementFactory;
import javax.management.JMException;
import javax.management.ObjectName;
import javax.management.OperationsException;
import org.eclipse.statet.rj.servi.jmx.PoolConfigMXBean;
import org.eclipse.statet.rj.servi.pool.PoolConfig;
import org.eclipse.statet.rj.servi.pool.PoolServer;
public class MXPoolConfig extends PoolConfig implements PoolConfigMXBean {
private final PoolServer server;
private ObjectName jmName;
public MXPoolConfig(final PoolServer server) throws JMException {
if (server == null) {
throw new NullPointerException("server");
}
this.server= server;
}
public void initJM() throws JMException {
this.jmName= new ObjectName(this.server.getJMBaseName() + "type=Server.PoolConfig");
ManagementFactory.getPlatformMBeanServer().registerMBean(this, this.jmName);
}
public void disposeJM() throws JMException {
if (this.jmName != null) {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(this.jmName);
this.jmName= null;
}
}
@Override
public void apply() throws OperationsException {
synchronized (this) {
MXUtil.validate(this);
this.server.setPoolConfig(this);
}
}
@Override
public void loadActual() throws OperationsException {
this.server.getPoolConfig(this);
}
@Override
public void loadDefault() throws OperationsException {
load(new PoolConfig());
}
@Override
public void loadSaved() throws OperationsException {
MXUtil.load(this, this.server.getRJContext());
}
@Override
public void save() throws OperationsException {
MXUtil.save(this, this.server.getRJContext());
}
}