blob: a24d16bef89444e7c853d0b243159e0769e439dc [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 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 java.util.Date;
import javax.management.JMException;
import javax.management.ObjectName;
import org.eclipse.statet.rj.servi.jmx.NodeStateMX;
import org.eclipse.statet.rj.servi.jmx.PoolStatusMX;
import org.eclipse.statet.rj.servi.pool.PoolNodeItem;
import org.eclipse.statet.rj.servi.pool.PoolServer;
import org.eclipse.statet.rj.servi.pool.PoolStatus;
public class MXPoolStatus extends PoolStatus<NodeStateMX> implements PoolStatusMX {
private ObjectName jmName;
private Date time;
public MXPoolStatus(final PoolServer server) {
super(server);
refresh();
}
public void initJM() throws JMException {
this.jmName= new ObjectName(this.server.getJMBaseName() + "type=Server.PoolStatus");
ManagementFactory.getPlatformMBeanServer().registerMBean(this, this.jmName);
}
public void disposeJM() throws JMException {
if (this.jmName != null) {
ManagementFactory.getPlatformMBeanServer().unregisterMBean(this.jmName);
this.jmName= null;
}
}
protected synchronized void refresh() {
final long stamp= System.currentTimeMillis();
refresh(this.server.getManager(), stamp);
this.time= new Date(stamp);
}
@Override
protected NodeStateMX createNodeState(final PoolNodeItem item) {
return new MXNodeState(item);
}
@Override
public synchronized Date getStatusTime() {
return this.time;
}
}